usbengines/usbdevcon/src/crequestshandler.cpp
changeset 35 9d8b04ca6939
parent 0 1e05558e2206
child 55 c00b160ac7eb
equal deleted inserted replaced
34:7858bc6ead78 35:9d8b04ca6939
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Requests handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <ecom/ecom.h>
       
    21 #include <cusbdevicecontrolplugin.h>
       
    22 
       
    23 #include "cusbdevcon.h"
       
    24 #include "crequestshandler.h"
       
    25 #include "debug.h"
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // Two-phase construction
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CRequestsHandler* CRequestsHandler::NewL(RDevUsbcClient& aLdd,
       
    32                                          RUsbWatcher& aUsbWatcher,
       
    33                                          RUsb& aUsbManager)
       
    34     {
       
    35     
       
    36     FLOG( _L( "[USBDEVCON]\tCRequestsHandler::NewL" ) );
       
    37 
       
    38     CRequestsHandler* self = new (ELeave) CRequestsHandler(aLdd, aUsbWatcher, aUsbManager);
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop(self);
       
    42     return self;    
       
    43     }
       
    44     
       
    45 // -------------------------------------Handle--------------------------------------
       
    46 // Two-phase construction
       
    47 // ---------------------------------------------------------------------------
       
    48 //  
       
    49 void CRequestsHandler::ConstructL()
       
    50     {
       
    51     
       
    52     FLOG( _L( "[USBDEVCON]\tCRequestsHandler::ConstructL" ) );
       
    53     
       
    54     // read, construct and attach handlers
       
    55     
       
    56     RImplInfoPtrArray implementations;
       
    57     const TEComResolverParams noResolverParams;
       
    58     REComSession::ListImplementationsL(KUsbCMHandlerInterface, noResolverParams, KRomOnlyResolverUid, implementations);
       
    59     
       
    60     for (TUint i(0); i < implementations.Count(); ++i)
       
    61         {
       
    62         TUid uid(implementations[i]->ImplementationUid());
       
    63         CUsbCMHandler* handler = (reinterpret_cast<CUsbCMHandler*>(REComSession::CreateImplementationL
       
    64                                                                                                     (uid, _FOFF(CUsbCMHandler, iPrivateEComUID))));
       
    65         iHandlers.Append(handler);
       
    66         }
       
    67        
       
    68    implementations.Close(); // cleanup
       
    69         
       
    70    FTRACE(FPrint(
       
    71            _L("[USBDEVCON]\tCRequestsHandler::ConstructL: Amount of handlers attached = %d" ), iHandlers.Count()));
       
    72 
       
    73     // initialize handlers, pass them iLdd, iUsbWatcher, iUsbManager
       
    74     for(TInt i(0); i < iHandlers.Count(); ++i)
       
    75         {
       
    76         iHandlers[i]->Initialize(iLdd, iUsbWatcher, iUsbManager);
       
    77         }
       
    78     }
       
    79     
       
    80 // ---------------------------------------------------------------------------
       
    81 // Default construction
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CRequestsHandler::CRequestsHandler( RDevUsbcClient& aLdd, 
       
    85                                     RUsbWatcher& aUsbWatcher,
       
    86                                     RUsb& aUsbManager) : 
       
    87                             iLdd (aLdd),
       
    88                             iUsbWatcher(aUsbWatcher),
       
    89                             iUsbManager(aUsbManager)
       
    90     {
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // Destruction
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CRequestsHandler::~CRequestsHandler()
       
    98     {
       
    99 
       
   100     FLOG( _L( "[USBDEVCON]\tCRequestsHandler::~CRequestsHandler()" ) );
       
   101     // destroy handlers  
       
   102     iHandlers.ResetAndDestroy();
       
   103     
       
   104     REComSession::FinalClose(); // plug-ins final cleanup
       
   105     
       
   106     }   
       
   107 
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Search plugin which can handle the request
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 TInt CRequestsHandler::Handle(const RBuf8& aSetupPacket, RBuf8& aData)
       
   114     {
       
   115     
       
   116     FLOG( _L( "[USBDEVCON]\tCRequestsHandler::Handle" ) );
       
   117     
       
   118     TInt err(KErrNotSupported);
       
   119     TUint counter(0); // handlers counter
       
   120     
       
   121     // loop through handlers, call handle() while error == KErrNotSupported
       
   122     while((err == KErrNotSupported) && (counter < iHandlers.Count()))               
       
   123         {
       
   124         err = iHandlers[counter]->Handle(aSetupPacket, aData);
       
   125         ++counter;
       
   126         }
       
   127         
       
   128     return err;
       
   129     
       
   130     }
       
   131     
       
   132 
       
   133