usbengines/usbotgwatcher/inc/cusbstate.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:  Base class for states in state machine
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef C_USBSTATE_H
       
    19 #define C_USBSTATE_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <usbotgdefs.h>
       
    23 #include <usbman.h>
       
    24 
       
    25 #include "definitions.h"
       
    26 
       
    27 class CUsbOtgWatcher;
       
    28 
       
    29 /**
       
    30  *  Base class for usb states
       
    31  *  Defines default implementation for events
       
    32  *  Class is C, due to there are possible future extentions
       
    33  *  for the class to own heap-based data. Class is not inherited
       
    34  *  from CActive, due to not all states are active objects. 
       
    35  *  If concrete state need to be an active object, it can aggregate CActive,
       
    36  *  rather than inherit (due to multiple inheritence of C classes is not allowed)
       
    37  *
       
    38  */
       
    39 NONSHARABLE_CLASS( CUsbState ) : public CBase
       
    40 
       
    41     {
       
    42 
       
    43     /**
       
    44      *  Only UsbOtgWatcher intended to call any of protected methods from the class
       
    45      * (except ChangeState and ChangeHostState, called by concrete subclasses),
       
    46      *	and those methods are protected, due to have to be re-implemented in subclasses
       
    47      * Class is not intended for instantiation, that's why no any public construction methods
       
    48      */
       
    49     friend class CUsbOtgWatcher;
       
    50 
       
    51     /******************************************************************************* */
       
    52 public:
       
    53 
       
    54     /**
       
    55      * This function is needed to find a real state by id
       
    56      * This might be used in switching states in watcher. New state object searched by its id
       
    57      * @return Id
       
    58      */
       
    59     virtual TUsbStateIds Id() = 0;
       
    60 
       
    61     /**
       
    62      * Destruction
       
    63      */
       
    64     virtual ~CUsbState();
       
    65 
       
    66 protected:
       
    67     /**
       
    68      * default constructor is protected to be able to be inherited be child classes
       
    69      * @param aOwner owner of the state
       
    70      */
       
    71     CUsbState(CUsbOtgWatcher& aOwner);
       
    72 
       
    73     /* *
       
    74      * Changes state in Device state machine
       
    75      * @param aNewStateId new state id
       
    76      */
       
    77     void ChangeStateL(TUsbStateIds aNewStateId);
       
    78 
       
    79     /**
       
    80      * Changes state in host state machine
       
    81      * @param aNewStateId new host state
       
    82      */
       
    83     void ChangeHostStateL(TUsbStateIds aNewStateId);
       
    84 
       
    85     /**
       
    86      * Handles special situation (error, or something else)
       
    87      * @param aWhat to hande (id)
       
    88      * @param aWhereTohandle state id where to handle
       
    89      */
       
    90     virtual void HandleL(TInt aWhat, TUsbStateIds aWhereTohandle);
       
    91 
       
    92     /**
       
    93      * State machine calls this, state object to perform any initial  
       
    94      * activity, once just entered this state
       
    95      *
       
    96      */
       
    97     virtual void JustAdvancedToThisStateL();
       
    98 
       
    99     /**
       
   100      * State machine calls this, state object to perform any initial  
       
   101      * activity, just before leaving this state
       
   102      *
       
   103      */
       
   104     virtual void JustBeforeLeavingThisStateL();
       
   105 
       
   106     /**
       
   107      * Following virtual functions are called by UsbOtgWatcher
       
   108      * on getting accodring event. Those are implemented in concret states.
       
   109      */
       
   110 
       
   111     /**
       
   112      * 2nd phase construction
       
   113      */
       
   114     void ConstructL();
       
   115 
       
   116     /**
       
   117      * Sets personality
       
   118      */
       
   119     virtual void SetPersonalityL();
       
   120 
       
   121     /**
       
   122      * Cancels setting personality async.
       
   123      */
       
   124     virtual void CancelSetPersonalityL();
       
   125 
       
   126     /**
       
   127      *
       
   128      * Sets previous personality
       
   129      */
       
   130     virtual void SetPreviousPersonalityL();
       
   131 
       
   132     /**
       
   133      * Cancels async. set prev personality request
       
   134      */
       
   135     virtual void CancelSetPreviousPersonalityL();
       
   136 
       
   137     /**
       
   138      *
       
   139      * Sets prev. personality on disconnecting device
       
   140      */
       
   141     virtual void SetPreviousPreviousPersonalityOnDisconnectL();
       
   142 
       
   143     /**
       
   144      * Id Pin OFF
       
   145      */
       
   146     virtual void IdPinOffL();
       
   147     /**
       
   148      * Id Pin On
       
   149      */
       
   150     virtual void IdPinOnL();
       
   151 
       
   152     // From VBus observer
       
   153     /**
       
   154      * VBus down
       
   155      */
       
   156     virtual void VBusDownL();
       
   157     /**
       
   158      * VBus UP
       
   159      */
       
   160     virtual void VBusUpL();
       
   161 
       
   162     // From OTG state observer
       
   163     /**
       
   164      * Became to Idle when A
       
   165      */
       
   166     virtual void AIdleL();
       
   167     /**
       
   168      * Became a Host when A
       
   169      */
       
   170     virtual void AHostL();
       
   171     /**
       
   172      * Became a peripheral when A
       
   173      */
       
   174     virtual void APeripheralL();
       
   175     /**
       
   176      * VBus error happen
       
   177      */
       
   178     virtual void AVBusErrorL();
       
   179     /**
       
   180      * Became to Idle when B
       
   181      */
       
   182     virtual void BIdleL();
       
   183     /**
       
   184      * Became a peripheral when B
       
   185      */
       
   186     virtual void BPeripheralL();
       
   187     /**
       
   188      * Became a Host when B
       
   189      */
       
   190     virtual void BHostL();
       
   191 
       
   192     // From bus activity observer
       
   193     /**
       
   194      * Bus is in idle
       
   195      */
       
   196     virtual void BusIdleL();
       
   197     /**
       
   198      * Bus active
       
   199      */
       
   200     virtual void BusActiveL();
       
   201 
       
   202     // From Host Event notification observer
       
   203     /**
       
   204      * Device is attached
       
   205      * @param aInfo Device event data
       
   206      */
       
   207     virtual void DeviceAttachedL(TDeviceEventInformation aInfo);
       
   208     /**
       
   209      * Device is detached
       
   210      * @param aInfo Device event data
       
   211      */
       
   212     virtual void DeviceDetachedL(TDeviceEventInformation aInfo);
       
   213     /**
       
   214      * Drivers successfully loaded
       
   215      * @param aInfo Device event data
       
   216      */
       
   217     virtual void DriverLoadSuccessL(TDeviceEventInformation aInfo);
       
   218     /**
       
   219      * Drivers loaded partially
       
   220      * @param aInfo Device event data
       
   221      */
       
   222     virtual void DriverLoadPartialSuccessL(TDeviceEventInformation aInfo);
       
   223     /**
       
   224      * Drivers loading failed
       
   225      * @param aInfo Device event data
       
   226      */
       
   227     virtual void DriverLoadFailureL(TDeviceEventInformation aInfo);
       
   228 
       
   229     // From message notification observer
       
   230     /**
       
   231      * Message received
       
   232      * @param aMessage message id
       
   233      */
       
   234     virtual void MessageNotificationReceivedL(TInt aMessage);
       
   235     /**
       
   236      * Connected to hub in wrong level 
       
   237      */
       
   238     virtual void BadHubPositionL();
       
   239     /**
       
   240      * VBus error happened
       
   241      */
       
   242     virtual void VBusErrorL();
       
   243     /**
       
   244      * SRP request received
       
   245      */
       
   246     virtual void SrpReceivedL();
       
   247     /**
       
   248      * Session request received
       
   249      */
       
   250     virtual void SessionRequestedL();
       
   251 
       
   252 protected:
       
   253     // data
       
   254 
       
   255     /**
       
   256      * Owner
       
   257      * Not own.  
       
   258      */
       
   259     CUsbOtgWatcher& iWatcher;
       
   260 
       
   261     };
       
   262 
       
   263 #endif // C_USBSTATE_H