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