usbengines/usbotgwatcher/inc/cusbservicecontrol.h
changeset 35 9d8b04ca6939
child 63 ef2686f7597e
equal deleted inserted replaced
34:7858bc6ead78 35:9d8b04ca6939
       
     1 /*
       
     2  * Copyright (c) 2008 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:  Implementation 
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef C_USBSERVICECONTROL_H
       
    19 #define C_USBSERVICECONTROL_H
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 class RUsb;
       
    24 
       
    25 /**
       
    26  *  usb service control observer interface, to get feedback on usb service state change
       
    27  *
       
    28  */
       
    29 NONSHARABLE_CLASS( MUsbServiceControlObserver)
       
    30     {
       
    31 public:
       
    32 
       
    33     /**
       
    34      * called when request for usb services is completed
       
    35      * if there were few requests in a row, during operation, 
       
    36      * only the last one's completion is notified
       
    37      * @param aError error code
       
    38      */
       
    39     virtual void UsbServiceControlReqCompletedL(TInt aError) = 0;
       
    40 
       
    41     };
       
    42 
       
    43 /**
       
    44  *  This class implements starting/stopping usb services 
       
    45  *
       
    46  */
       
    47 NONSHARABLE_CLASS( CUsbServiceControl ) : public CActive
       
    48     {
       
    49 
       
    50 public:
       
    51 
       
    52     enum TUsbServiceRequest
       
    53         {
       
    54         ERequestUndefined,
       
    55         EStartUsbService,
       
    56         EStopUsbService
       
    57         };
       
    58 
       
    59     /**
       
    60      * Two-phased constructor.
       
    61      * @param aObserver Observer
       
    62      * @param aUsb RUsb API
       
    63      */
       
    64     static CUsbServiceControl* NewL(MUsbServiceControlObserver& aObserver,
       
    65             RUsb& aUsb);
       
    66 
       
    67     /**
       
    68      * Destructor.
       
    69      */
       
    70     virtual ~CUsbServiceControl();
       
    71 
       
    72     /**
       
    73      * Starts usb service. When service is started call back function 
       
    74      * MUsbServiceControlObserver::UsbServiceControlReqCompletedL will be called.
       
    75      * Client should not worry is usb service already started, or not,
       
    76      * and which one personality is started. Just request this API 
       
    77      * @param aPersonalityId personality id (required by RUsb API to start usb services) 
       
    78      * @return error code
       
    79      */
       
    80     TInt StartL(TInt aPersonalityId);
       
    81 
       
    82     /**
       
    83      * Stops service. When service is stopped call back function 
       
    84      * MUsbServiceControlObserver::UsbServiceControlReqCompletedL will be called
       
    85      * @return error code
       
    86      */
       
    87     TInt StopL();
       
    88 
       
    89 public:
       
    90 
       
    91     // from base class CActive
       
    92     /**
       
    93      * Called when request is completed
       
    94      */
       
    95     void RunL();
       
    96 
       
    97     /**
       
    98      * called when RunL leaves
       
    99      * @param aError error code
       
   100      * @return error code
       
   101      */
       
   102     TInt RunError(TInt aError);
       
   103 
       
   104     /**
       
   105      * Called when request is cancelled
       
   106      */
       
   107     void DoCancel();
       
   108 
       
   109 private:
       
   110 
       
   111     /**
       
   112      * Default constructor
       
   113      * @param aObserver receives call back when service started or stopped
       
   114      * @param aUsb usbman API
       
   115      */
       
   116     CUsbServiceControl(MUsbServiceControlObserver& aObserver, RUsb& aUsb);
       
   117 
       
   118     /**
       
   119      * 2nd phase construction
       
   120      */
       
   121     void ConstructL();
       
   122 
       
   123 private:
       
   124 
       
   125     /**
       
   126      * Observer
       
   127      * not own
       
   128      */
       
   129     MUsbServiceControlObserver& iObserver;
       
   130 
       
   131     /**
       
   132      * RUsb API
       
   133      */
       
   134     RUsb& iUsb;
       
   135 
       
   136     /**
       
   137      * personality ID, to be started
       
   138      */
       
   139     TInt iPersonalityId;
       
   140 
       
   141     /**
       
   142      * Service state
       
   143      */
       
   144     TUsbServiceState iServiceState; // required as a parameter for service states notifications 
       
   145 
       
   146     };
       
   147 
       
   148 #endif //  C_USBSTATEHOSTAHANDLE_H