btobexprofiles/obexserviceman/plugins/src/usb/obexsmusbconnection.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     1 /*
       
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class handles service connections.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "obexsmusbconnection.h"
       
    23 #include "debug.h"
       
    24 #include <d32usbc.h>
       
    25 #include "obexutilsopaquedata.h"
       
    26 #include <centralrepository.h>
       
    27 #include "obexservicemanprivatecrkeys.h"
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 
       
    31 // ---------------------------------------------------------
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // ---------------------------------------------------------
       
    35 //
       
    36 CObexSMUsbConnection::CObexSMUsbConnection()
       
    37     {
       
    38     }
       
    39 // ---------------------------------------------------------
       
    40 // Constructor
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 CObexSMUsbConnection::CObexSMUsbConnection(TAny* aInitParams)        
       
    44     :iImplementationInfo((CImplementationInformation *)aInitParams)
       
    45     {    
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // Destructor
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 CObexSMUsbConnection::~CObexSMUsbConnection()
       
    53     {
       
    54     // Cleanup       
       
    55     FLOG(_L("[SRCS] CSrcsUsbConnection: StopObexServer"));              
       
    56     if(iServer)
       
    57         {
       
    58         iServer->Stop();
       
    59         }
       
    60 	
       
    61     // Delete OBEX Server    
       
    62     if (iServer)
       
    63         {
       
    64         delete iServer;
       
    65         FLOG(_L("[SRCS]\tserver\tCSrcsBtConnection::~CSrcsBtConnection obex server deleted."));
       
    66         iServer = NULL;
       
    67         }
       
    68     
       
    69     // Delete Service Controller callback
       
    70     delete iController;
       
    71     iController = NULL;    
       
    72     
       
    73     FLOG(_L("[SRCS] CSrcsUsbConnection: ~CSrcsUsbConnection: Completed\t"));    
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // NewL
       
    78 // ---------------------------------------------------------
       
    79 //
       
    80 CObexSMUsbConnection* CObexSMUsbConnection::NewL(TAny* aInitParams)
       
    81     {
       
    82     FLOG(_L("[SRCS]\tserver\tCSrcsUsbConnection: NewL"));
       
    83     CObexSMUsbConnection* self = new (ELeave) CObexSMUsbConnection(aInitParams);
       
    84     CleanupStack::PushL(self);
       
    85     self->ConstructL();
       
    86     CleanupStack::Pop();
       
    87     return self;
       
    88     }
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // ConstructL
       
    93 // Method to create BT connections.
       
    94 // ---------------------------------------------------------
       
    95 //
       
    96 void CObexSMUsbConnection::ConstructL()
       
    97     {    
       
    98     // Save service controller implementation UID for deferred initialization
       
    99     iImplUid = iImplementationInfo->ImplementationUid();
       
   100 
       
   101     FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: CSrcsInterface::NewL\t"));
       
   102 
       
   103     // parsing opaque_data in iImplementationInfo
       
   104     TPtrC8 res_string = iImplementationInfo->OpaqueData();
       
   105     
       
   106     CObexUtilsOpaqueData res_data(res_string);
       
   107     TBuf8<KObexUtilsMaxOpaqueDataStringLen> op_StringDesc, op_LocalWho, op_SkipStr;
       
   108     TUint	op_SkipInt; //used to skip certain fields
       
   109 	TUint	op_ReceiveMtu(KSRCSDefaultReceiveMtu), op_TransmitMtu(KSRCSDefaultTransmitMtu);    
       
   110     // get 1st entry: USB interface string descriptor    
       
   111 	User::LeaveIfError ( res_data.GetString(op_StringDesc) );    
       
   112     // get 2nd entry: OBEX local who
       
   113     User::LeaveIfError ( res_data.GetString(op_LocalWho) );    
       
   114     // skip 3rd to 7th entry
       
   115 	// All service ID should be strings !
       
   116     res_data.GetString(op_SkipStr);
       
   117     res_data.GetNumber(op_SkipInt);
       
   118     res_data.GetNumber(op_SkipInt);
       
   119     res_data.GetNumber(op_SkipInt);
       
   120     res_data.GetNumber(op_SkipInt);    
       
   121 
       
   122 	// Get OBEX packet size:
       
   123 	if( res_data.GetNumber(op_ReceiveMtu) != KErrNone )
       
   124 		{
       
   125 		op_ReceiveMtu = KSRCSDefaultReceiveMtu; // restore default value in case it is modified;
       
   126 	    FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: op_ReceiveMtu not specified.\t"));
       
   127 		}
       
   128 	
       
   129 	if( res_data.GetNumber(op_TransmitMtu) != KErrNone )
       
   130 		{
       
   131 		op_TransmitMtu = KSRCSDefaultTransmitMtu; // restore default value in case it is modified;
       
   132 	    FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: op_TransmitMtu not specified.\t"));
       
   133 		}   
       
   134 
       
   135     FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: Successfully get all data from opaque_data.\t"));
       
   136 
       
   137 	// Get OBEX usb dma usage
       
   138     CRepository* cenrep = NULL;
       
   139     TRAP_IGNORE(cenrep = CRepository::NewL(KCRUidObexServiceMan));
       
   140     TInt dmaUsage = EObexUsbDmaInUse;
       
   141     if (cenrep)
       
   142         {
       
   143         cenrep->Get(KObexUsbDmaUsage, dmaUsage);
       
   144         delete cenrep;
       
   145         }
       
   146 
       
   147 	// set up the protocol stack...    
       
   148     TObexUsbProtocolInfoV2 obexUsbProtocolInfo;
       
   149     obexUsbProtocolInfo.iTransport = KObexUsbProtocolV2;
       
   150     obexUsbProtocolInfo.iInterfaceStringDescriptor.Copy(op_StringDesc);
       
   151     if(dmaUsage == EObexUsbDmaInUse)
       
   152 	    {
       
   153 	    obexUsbProtocolInfo.iDmaOnInEndpoint = ETrue;
       
   154 	    obexUsbProtocolInfo.iDmaOnOutEndpoint = ETrue;
       
   155 	    }
       
   156 	 else
       
   157 	 	{
       
   158 	 	obexUsbProtocolInfo.iDmaOnInEndpoint = EFalse;
       
   159 	    obexUsbProtocolInfo.iDmaOnOutEndpoint = EFalse;
       
   160 	 	}	
       
   161     obexUsbProtocolInfo.iBandwidthPriority = EUsbcBandwidthOUTPlus2 | EUsbcBandwidthINPlus2;
       
   162 
       
   163 
       
   164 
       
   165 	// Configure Obex packet size
       
   166 	TObexProtocolPolicy aObexProtocolPolicy;
       
   167 	aObexProtocolPolicy.SetReceiveMtu( static_cast<TUint16>(op_ReceiveMtu) );
       
   168 	aObexProtocolPolicy.SetTransmitMtu( static_cast<TUint16>(op_TransmitMtu) );
       
   169 	FTRACE(FPrint(_L("[SRCS] CSrcsUsbConnection: ConstructL: op_ReceiveMtu[%x] op_TransmitMtu[%x]"), 
       
   170 		aObexProtocolPolicy.ReceiveMtu(), aObexProtocolPolicy.TransmitMtu() ));
       
   171 
       
   172 	// Try to create OBEX server
       
   173 	iServer = CObexServer::NewL(obexUsbProtocolInfo, aObexProtocolPolicy);
       
   174     FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: CObexServer::NewL"));
       
   175     // if there is "local who" field
       
   176     if(op_LocalWho.Size())
       
   177         {
       
   178         User::LeaveIfError ( iServer->SetLocalWho( op_LocalWho ) );
       
   179         FLOG(_L("[SRCS] CSrcsUsbConnection: ConstructL: SetLocalWho"));
       
   180         }
       
   181     
       
   182     // The rest of initialization procedure is executed in PostInitialzeL()
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------
       
   186 // GetUserPasswordL(const TDesC& )
       
   187 // Purpose: Get the Obex password from user with ObexPasskeyNotifier
       
   188 // Parameters:
       
   189 // Return value:
       
   190 // ---------------------------------------------------------
       
   191 //
       
   192 void CObexSMUsbConnection::GetUserPasswordL( const TDesC& )
       
   193     {
       
   194     FLOG( _L( "[SRCS] CSrcsUsbConnection: GetUserPassword\t" ) );
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------
       
   198 // Check if OBEX service is still active.
       
   199 // @return ETrue:  OBEX service is still active.
       
   200 //  	   EFalse: OBEX service is inactive.
       
   201 // ---------------------------------------------------------
       
   202 //
       
   203 
       
   204 TBool CObexSMUsbConnection::IsOBEXActive()
       
   205 	{
       
   206     FLOG( _L( "[SRCS] CSrcsUsbConnection: IsOBEXActive\t" ) );
       
   207 	return ETrue;	
       
   208 	}     
       
   209 
       
   210 void CObexSMUsbConnection::PostInitializeL()
       
   211     {
       
   212     FTRACE(FPrint(_L("[SRCS] CObexSMUsbConnection: PostInitializeL(%08X)"), iImplUid.iUid));
       
   213 
       
   214     iController = CSrcsInterface::NewL(iImplUid);
       
   215     iController->SetMediaType( ESrcsMediaUSB );
       
   216 
       
   217     FLOG(_L("[SRCS] CObexSMUsbConnection::PostInitializeL(): SetObexServer\t"));
       
   218     // Try to start server 
       
   219     User::LeaveIfError ( iController->SetObexServer( iServer ));
       
   220     FLOG( _L( "[SRCS] CObexSMUsbConnection: PostInitializeL() exits\t" ) );
       
   221     }
       
   222 
       
   223 // End of file