usbclasses/usbobexclasscontroller/src/CUsbObexClassController.cpp
changeset 0 1e05558e2206
child 21 ff9df6630274
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 /*
       
     2 * Copyright (c) 2002 - 2006 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:  Implements OBEX class controller
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CUsbObexClassController.h"
       
    20 #include <usb_std.h>
       
    21 #include <obex.h>
       
    22 #include <SrcsInterface.h>
       
    23 #include <mmf/common/mmfcontrollerpluginresolver.h> //for CleanupResetAndDestroyPushL
       
    24 // Panic category only used in debug builds
       
    25 #ifdef _DEBUG
       
    26 _LIT( KObexCcPanicCategory, "OBEXCC" );
       
    27 #endif
       
    28 
       
    29 #ifdef __FLOG_ACTIVE
       
    30 _LIT8(KLogComponent, "UsbObexCc");
       
    31 #endif
       
    32 
       
    33 /**
       
    34  * Panic codes for the USB OBEX Class Controller.
       
    35  */
       
    36 enum TObexCCPanic
       
    37   {
       
    38   /** Illigal calling of asynchronous function */
       
    39   EBadAsynchronousCall = 0,
       
    40   /** Start() called while in an illegal state */
       
    41   EBadApiCallStart = 1,
       
    42   /** Stop() called while in an illegal state */
       
    43   EBadApiCallStop = 2,
       
    44   };
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Constructs a CUsbObexClassController object.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CUsbObexClassController* CUsbObexClassController::NewL(
       
    51   MUsbClassControllerNotify& aOwner)
       
    52   {
       
    53   LOG_STATIC_FUNC_ENTRY
       
    54 
       
    55   CUsbObexClassController* self = new (ELeave) CUsbObexClassController(aOwner);
       
    56   CleanupStack::PushL(self);
       
    57   self->ConstructL();
       
    58   CleanupStack::Pop(self);
       
    59   return self;
       
    60   }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // Constructor
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CUsbObexClassController::CUsbObexClassController(
       
    67     MUsbClassControllerNotify& aOwner)
       
    68   : CUsbClassControllerPlugIn(aOwner, KObexClassPriority)
       
    69   {
       
    70   LOG_FUNC
       
    71   iState = EUsbServiceIdle;
       
    72   }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Method to perform second phase construction.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CUsbObexClassController::ConstructL()
       
    79   {
       
    80   LOG_FUNC
       
    81   iObexSM = CObexUSB::NewL();
       
    82   }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // From class CUsbClassControllerPlugIn.
       
    86 // Destructor
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CUsbObexClassController::~CUsbObexClassController()
       
    90   {
       
    91   LOG_FUNC
       
    92   Cancel();
       
    93   delete iObexSM; 
       
    94   }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // From class CUsbClassControllerPlugIn.
       
    98 // Called by UsbMan to start this class.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CUsbObexClassController::Start(TRequestStatus& aStatus)
       
   102   {
       
   103 
       
   104   LOG_FUNC
       
   105   //Start() should never be called if started, starting or stopping (or in state EUsbServiceFatalError)
       
   106   __ASSERT_DEBUG(iState == EUsbServiceIdle, _USB_PANIC(KObexCcPanicCategory, EBadApiCallStart));
       
   107 
       
   108   // Start OBEX SM
       
   109   iRequestStatus = &aStatus;
       
   110   iState = EUsbServiceStarting;
       
   111   aStatus = KRequestPending;
       
   112   LOGTEXT(_L8("CUsbObexClassController::Start() calling ManageUSBService(ETrue)")); 
       
   113   iObexSM->ManageUSBServices(ETrue, iStatus);
       
   114   SetActive();
       
   115   }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // From class CUsbClassControllerPlugIn.
       
   119 // Called by UsbMan to stop this class.
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CUsbObexClassController::Stop(TRequestStatus& aStatus)
       
   123   {
       
   124 
       
   125   LOG_FUNC
       
   126   LOGTEXT2(_L8("CUsbObexClassController::Stop iState = %d"), iState);
       
   127   
       
   128   //Stop() should never be called if stopping or starting (or in state EUsbServiceFatalError)
       
   129   __ASSERT_DEBUG(iState == EUsbServiceStarted || iState == EUsbServiceIdle, _USB_PANIC(KObexCcPanicCategory, EBadApiCallStop));
       
   130 
       
   131   //state may be idle after Cancel
       
   132   if ( iState == EUsbServiceIdle )
       
   133     {
       
   134     TRequestStatus* status = &aStatus;
       
   135     User::RequestComplete(status, KErrNone);
       
   136     }
       
   137   else
       
   138     {
       
   139     // Stop OBEX SM
       
   140     iRequestStatus = &aStatus;
       
   141     iState = EUsbServiceStopping;   
       
   142     aStatus = KRequestPending;
       
   143     LOGTEXT(_L8("CUsbObexClassController::Stop() calling ManageUSBService(EFalse)")); 
       
   144     iObexSM->ManageUSBServices(EFalse, iStatus);
       
   145     SetActive();
       
   146     }
       
   147   }
       
   148   
       
   149 // ---------------------------------------------------------------------------
       
   150 // From class CActive.
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CUsbObexClassController::RunL()
       
   154   {
       
   155 
       
   156   LOG_FUNC
       
   157   if (iStatus != KErrNone)
       
   158     {
       
   159     LOGTEXT2(_L8("CUsbObexClassController::RunL() Error = %d"), iStatus.Int());
       
   160     User::RequestComplete(iRequestStatus, iStatus.Int());
       
   161     return;
       
   162     }
       
   163   LOGTEXT2(_L8("CUsbObexClassController::RunL() State is %d"), iState);
       
   164 
       
   165             switch (iState)
       
   166                 {
       
   167                 case EUsbServiceStarting:
       
   168                     iState = EUsbServiceStarted;
       
   169                     User::RequestComplete(iRequestStatus, KErrNone);
       
   170                     break;
       
   171                     
       
   172                 case EUsbServiceStopping:
       
   173                     iState = EUsbServiceIdle;
       
   174                     User::RequestComplete(iRequestStatus, KErrNone);
       
   175                     break;
       
   176 
       
   177                 case EUsbServiceStarted:
       
   178                 case EUsbServiceIdle:
       
   179 
       
   180                 default:
       
   181             LOGTEXT(_L8("CUsbObexClassController::RunL() Error or Unknown State"));
       
   182                     break;
       
   183                 }
       
   184   }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // From class CUsbClassControllerPlugIn.
       
   188 // Returns information about the interfaces supported by this class.
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void CUsbObexClassController::GetDescriptorInfo(TUsbDescriptor& aDescriptorInfo) const
       
   192   {
       
   193   LOG_FUNC
       
   194   TRAPD(ret, DoGetDescriptorInfoL(aDescriptorInfo));
       
   195         if(ret!=KErrNone)
       
   196           {
       
   197                  LOGTEXT2(_L8("CUsbObexClassController::GetDescriptorInfo leave with code: %d"), ret);
       
   198           }
       
   199         }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // Leave version of GetDescriptor info function for fit in Class Controller framework.
       
   203 // Returns information about the interfaces supported by this class.
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CUsbObexClassController::DoGetDescriptorInfoL(TUsbDescriptor& aDescriptorInfo) const
       
   207   {
       
   208   LOG_FUNC
       
   209         RImplInfoPtrArray implInfoArray;
       
   210         CleanupResetAndDestroyPushL(implInfoArray);
       
   211         TEComResolverParams resolverParams;
       
   212         resolverParams.SetDataType(KSrcsTransportUSB);
       
   213         resolverParams.SetWildcardMatch(EFalse);
       
   214         REComSession::ListImplementationsL(KCSrcsInterfaceUid, resolverParams, implInfoArray);
       
   215 
       
   216         LOGTEXT2(_L8("CUsbObexClassController::DoGetDescriptorInfoL Number of Interfaces is %d"),
       
   217                    implInfoArray.Count());
       
   218         aDescriptorInfo.iNumInterfaces = (implInfoArray.Count())*KObexNumInterfaces;
       
   219         aDescriptorInfo.iLength = 0;
       
   220 
       
   221         CleanupStack::PopAndDestroy(&implInfoArray);    
       
   222         }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // From class CActive.
       
   226 // Will only be called when an asynchronous request is currently active.
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CUsbObexClassController::DoCancel()
       
   230   {
       
   231   LOG_FUNC
       
   232 
       
   233   switch (iState)
       
   234     {
       
   235     case EUsbServiceStarting:
       
   236     case EUsbServiceStopping:
       
   237       iObexSM->CancelManageUSBServices();
       
   238       break;
       
   239 
       
   240     default:
       
   241       __ASSERT_DEBUG( EFalse, _USB_PANIC(KObexCcPanicCategory, EBadAsynchronousCall) );
       
   242       break;
       
   243     }
       
   244 
       
   245   iState = EUsbServiceIdle;        
       
   246   User::RequestComplete(iRequestStatus, KErrCancel);                  
       
   247   }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // From class CActive.
       
   251 // Should return KErrNone to avoid an active scheduler panic. This function
       
   252 // should never be called as there is another mechanism for catching errors.
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 TInt CUsbObexClassController::RunError(TInt aError)
       
   256   {
       
   257   LOG_FUNC
       
   258   LOGTEXT2(_L8("CUsbObexClassController::RunError aError=%d"), aError);
       
   259   return KErrNone;
       
   260   }
       
   261   
       
   262 // End of File