usbengines/usbdevcon/inc/cstatemachine.h
changeset 0 1e05558e2206
child 87 18fe5224f0dc
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     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:  State machine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CSTATEMACHINE_H
       
    20 #define CSTATEMACHINE_H
       
    21 
       
    22 class CRequestsHandler;
       
    23 class CEP0Reader;
       
    24 class CEP0Writer;
       
    25 
       
    26 /**
       
    27  *  State machine for the control transfers
       
    28  *  Switches usbdevcon states between Setup-Data-Status
       
    29  *
       
    30  *  @lib usbdevcon.lib
       
    31  *  @since S60 v.5.0 
       
    32  */
       
    33  
       
    34 class CStateMachine : public CBase 
       
    35     {
       
    36 
       
    37 public:
       
    38 
       
    39     /**  States */
       
    40     enum TState
       
    41     {
       
    42         ENoneState,     // State is not defined 
       
    43         ESetupStage,    // ready for getting control setup transaction
       
    44         EDataStage,     // reading data from host, in Data stage        
       
    45         EStatusStage    // waiting for Status transaction, after writing data to host
       
    46     };
       
    47 
       
    48      /**
       
    49      * Two-phased constructor.
       
    50      *
       
    51      * @since S60 v.5.0
       
    52      * @param aRequestHandler Handles requests
       
    53      * @param aLdd Link to LDD services
       
    54      * @return Constructed instance
       
    55      */ 
       
    56     static CStateMachine* NewL(CRequestsHandler& aRequestsHandler, RDevUsbcClient& aLdd);
       
    57     
       
    58     /**
       
    59     * Destructor.
       
    60     *
       
    61     * @since S60 v.5.0
       
    62     */
       
    63     virtual ~CStateMachine();
       
    64     
       
    65     /**
       
    66      * Call back from CEP0Reader
       
    67      *
       
    68      * @since S60 v.5.0
       
    69      * @param aBuffer Data read from EP0
       
    70      * @param aStatus status of Read request, completed
       
    71      */
       
    72     void ReadEP0(RBuf8& aBuffer, const TRequestStatus& aStatus);
       
    73     
       
    74     /**
       
    75      * Call back from CEP0Writer
       
    76      *
       
    77      * @since S60 v.5.0
       
    78      * @param aStatus status of Write request, completed
       
    79      */
       
    80     void WroteEP0(const TRequestStatus& aStatus);
       
    81     
       
    82     /**
       
    83      * Starts machine
       
    84      *
       
    85      * @since S60 v.5.0
       
    86      */
       
    87     void Start();
       
    88     
       
    89     /**
       
    90      * Stops machine
       
    91      *
       
    92      * @since S60 v.5.0
       
    93      */
       
    94     void Stop();
       
    95     
       
    96     /**
       
    97      * Machine is started
       
    98      *
       
    99      * @since S60 v.5.0
       
   100      * @return ETrue if state machine is started
       
   101      */
       
   102     TBool IsStarted() const;
       
   103     
       
   104 private:
       
   105     
       
   106     /**
       
   107      * Default construction
       
   108      *
       
   109      * @since S60 v.5.0
       
   110      * @param aRequestHandler Handles requests
       
   111      * @param aLdd Link to LDD services
       
   112      */
       
   113     CStateMachine(CRequestsHandler& aRequestsHandler, RDevUsbcClient& aLdd);
       
   114     
       
   115     /**
       
   116      * Two-phased constructor.
       
   117      *
       
   118      * @since S60 v.5.0
       
   119      */
       
   120     void ConstructL();
       
   121     
       
   122     /**
       
   123      * Process setup packet
       
   124      *
       
   125      * @since S60 v.5.0
       
   126      * @param aSetupPacket Will be processed
       
   127      */
       
   128     void ProcessSetupPacket(RBuf8& aSetupPacket);
       
   129     
       
   130     /**
       
   131      * Checks wheather data required to be sent from host to device 
       
   132      *
       
   133      * @since S60 v.5.0
       
   134      * @param aSetupPacket Contains data direction bit, and length of data
       
   135      * @param aDataLength Length of data to be sent
       
   136      * @return ETrue If data stage is required
       
   137      */
       
   138     TBool IsDataFromHostRequired(const RBuf8& aSetupPacket, TUint& aDatalength) const;
       
   139     
       
   140     /**
       
   141      * Checks wheather data required to be sent from device to host
       
   142      *
       
   143      * @since S60 v.5.0
       
   144      * @param aSetupPacket Contains data direction bit, and length of data
       
   145      * @param aDataLength Length of data to be sent
       
   146      * @return ETrue If data stage is required
       
   147      */
       
   148     TBool IsDataFromDeviceRequired(const RBuf8& aSetupPacket, TUint& aDatalength) const;
       
   149     
       
   150 private: // data
       
   151     
       
   152     /**
       
   153      * EP0 reader
       
   154      * Own.  
       
   155      */
       
   156     CEP0Reader* iEP0Reader;
       
   157     
       
   158     /**
       
   159      * EP0 writer
       
   160      * Own.  
       
   161      */
       
   162     CEP0Writer* iEP0Writer;
       
   163     
       
   164     /**
       
   165      * Requests handler
       
   166      * Not own.  
       
   167      */
       
   168     CRequestsHandler& iRequestsHandler;
       
   169     
       
   170     /**
       
   171      * LDD
       
   172      * Not own.  
       
   173      */
       
   174     RDevUsbcClient& iLdd;
       
   175     
       
   176     /**
       
   177      * State
       
   178      */
       
   179     TState iState;
       
   180     
       
   181     /**
       
   182      * Buffer to keep request, if needed to receive data from host in Data stage
       
   183      * In case if request require data to be send from device to host,
       
   184      * iBuffer keeps result of that request
       
   185      */
       
   186     RBuf8 iBuffer;
       
   187         
       
   188     };
       
   189 
       
   190 #endif // CSTATEMACHINE_H