usbengines/usbwatcher/inc/cusbwatcher.h
changeset 34 7858bc6ead78
parent 31 dfdd8240f7c8
child 35 9d8b04ca6939
equal deleted inserted replaced
31:dfdd8240f7c8 34:7858bc6ead78
     1 /*
       
     2 * Copyright (c) 2002-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:  Header file for class CUsbWatcher
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CUSBWATCHER_H
       
    20 #define CUSBWATCHER_H
       
    21 
       
    22 #include <bldvariant.hrh>
       
    23 #include <e32base.h>
       
    24 #include <usbman.h>
       
    25 #include <e32property.h>
       
    26 #include <PSVariables.h>
       
    27 #include <centralrepository.h>
       
    28 #include <usbuinotif.h>
       
    29 #include <usbwatcher.h>
       
    30 #include "debug.h"
       
    31 #include "musbwatchernotify.h"
       
    32 #include "cusbwatchersession.h"
       
    33 #include "tusbindicatorhandler.h"
       
    34 
       
    35 
       
    36 class CUsbActiveState;
       
    37 class CUsbActivePersonalityHandler;
       
    38 class CUsbDeviceLock;
       
    39 class CUsbDevConStarter;
       
    40 class CUsbGlobalSystemStateObserver;
       
    41 class CUsbOtgWatcher; //OTG
       
    42 
       
    43 /**
       
    44 *  Struct for supported personalities.
       
    45 *
       
    46 *  This struct is used to store supported personalities.
       
    47 *
       
    48 *  @since Series 60 3.2
       
    49 */
       
    50 struct TUsbSupportedPersonalityInf
       
    51     {
       
    52     
       
    53     /**
       
    54      * implementation Uid of the personality
       
    55      */
       
    56     TUid  iPersonalityUid;
       
    57     
       
    58     /**
       
    59      * personality id
       
    60      */
       
    61     TInt  iPersonalityId;
       
    62     
       
    63     /**
       
    64      * if set then serial number is used by the personality
       
    65      */
       
    66     TBool iUseSerialNumber;
       
    67     };
       
    68 
       
    69 /**
       
    70 *  UsbWatcher core class.
       
    71 *
       
    72 *  This class starts, stops and changes personalities depending on the cable
       
    73 *  state or client changing the personality. There is always only one instance
       
    74 *  of this class.
       
    75 *
       
    76 *  @since Series 60 2.?
       
    77 */
       
    78 NONSHARABLE_CLASS( CUsbWatcher ): public CActive
       
    79     {
       
    80 
       
    81 public:
       
    82 
       
    83     static CUsbWatcher* NewL();
       
    84         
       
    85     virtual ~CUsbWatcher();
       
    86    
       
    87     /**
       
    88      * Used to register observer. Each created session will register observer.
       
    89      *
       
    90      * @since S60 3.2
       
    91      * @param aObserver Pointer to observer class to be added.
       
    92      */
       
    93     void RegisterObserverL( MUsbWatcherNotify* aObserver );
       
    94 
       
    95     /**
       
    96      * Used to deregister observer. When session is terminated, 
       
    97      * it must deregister the observer.
       
    98      *
       
    99      * @since S60 3.2
       
   100      * @param aObserver Pointer to observer class to be removed.
       
   101      */
       
   102     void DeRegisterObserver( MUsbWatcherNotify* aObserver );
       
   103 
       
   104     /**
       
   105      * This method is called when operation is finished.
       
   106      *
       
   107      * @since S60 3.2
       
   108      * @param aStatus Status of the ended operation.
       
   109      */
       
   110 	void Notify( TInt aStatus );
       
   111 
       
   112     /**
       
   113      * This method returns personalities supported by the system.
       
   114      *
       
   115      * @since S60 3.2
       
   116      * @return Refernce to the supported personalities array.
       
   117      */
       
   118     inline const RArray<TUsbSupportedPersonalityInf>& Personalities() const;
       
   119 
       
   120     /**
       
   121      * This method updates central repository key and if USB is connected
       
   122      * it will also change the personality to new one.
       
   123      * 
       
   124      * Note that if KErrDiskFull is returned while the cable is connected,
       
   125      * the personality was loaded, but it was not stored to Central Repository.
       
   126      *
       
   127      * @since S60 3.2
       
   128      * @param aPersonalityId Personality id
       
   129      * @param aNonBlocking If true, no personality switch  queries are shown
       
   130      * @return KErrNone if success, otherwise system-wide error code.
       
   131      */
       
   132     void SetPersonality( TInt aPersonalityId, TBool aNonBlocking );
       
   133     
       
   134     /**
       
   135      * Cancel outstanding SetPersonality() request. Everything is returned
       
   136      * to the state before request was done.
       
   137      *
       
   138      * @since S60 3.2
       
   139      */    
       
   140     void CancelSetPersonality();
       
   141 
       
   142     /**
       
   143      * Set previous personality.
       
   144      *
       
   145      * @since S60 3.2
       
   146      */
       
   147     void SetPreviousPersonality();
       
   148 
       
   149     /**
       
   150      * Cancel outstanding SetPreviousPersonality() request. After this request
       
   151      * everything is returned to the state like it was before the request.
       
   152      *
       
   153      * @since S60 3.2
       
   154      */
       
   155     void CancelSetPreviousPersonality();
       
   156 
       
   157     /**
       
   158      * Set previous personality when USB cable is disconnected. Note that
       
   159      * if cable is already disconnected when this request is issued, service
       
   160      * does nothing.
       
   161      *
       
   162      * @since S60 3.2
       
   163      */
       
   164     void SetPreviousPersonalityOnDisconnect();
       
   165             
       
   166     /**
       
   167      * Write personality id to the central repository
       
   168      *
       
   169      * @since Series 60 3.2
       
   170      * @param aPersonalityId Current personality id setting
       
   171      * @return KErrNone in case of success
       
   172      */
       
   173     TInt WritePersonalityId( TInt aPersonalityId );
       
   174 
       
   175     /**
       
   176      * This method is called by the CUsbActiveState class when there is
       
   177      * a change in USB state.
       
   178      *
       
   179      * @since Series 60 2.?
       
   180      * @param aStateOld old device state
       
   181      * @param aStateNew new device state
       
   182      */
       
   183     void StateChangeNotify( TUsbDeviceState aStateOld, 
       
   184             TUsbDeviceState aStateNew );
       
   185     
       
   186    
       
   187     /**
       
   188      * This callback function is called when device is locked.
       
   189      * 
       
   190      * @since Series 60 2.?
       
   191      * @return error
       
   192      */
       
   193     void Lock();
       
   194     
       
   195     /**
       
   196      * This callback function is called when device is unlocked.
       
   197      * 
       
   198      * @since Series 60 2.?
       
   199      * @return error
       
   200      */
       
   201     void Unlock();
       
   202         
       
   203     /**
       
   204      * Stop loaded personality
       
   205      * 
       
   206      * @since Series 60 3.2
       
   207      */
       
   208     void StopPersonality();
       
   209     
       
   210     /**
       
   211      * Start personality
       
   212      * 
       
   213      * @since Series 60 3.2    
       
   214      */
       
   215     void StartPersonality();
       
   216 
       
   217      /**
       
   218       * Check if self is A-device (A-end connected).
       
   219       * @return ETrue if self is in A-device state.
       
   220       */
       
   221       TBool IsDeviceA();
       
   222     
       
   223 public: // from base class CActive
       
   224 
       
   225     /**
       
   226      * From CActive.
       
   227      * Implements state machine for this class.
       
   228      *
       
   229      * @since Series 60 3.0
       
   230      */
       
   231     void RunL();
       
   232 
       
   233     /**
       
   234      * From CActive.
       
   235      * Never called in this implementation.
       
   236      *
       
   237      * @since Series 60 3.0
       
   238      * @param aError The error returned
       
   239      * @return error
       
   240      */
       
   241     TInt RunError( TInt /*aError*/ );
       
   242 
       
   243     /**
       
   244      * From CActive
       
   245      * Cancels outstanding request.
       
   246      *
       
   247      * @since Series 60 3.0
       
   248      */
       
   249     void DoCancel();
       
   250 
       
   251 	/**
       
   252      * Check if there is an observer with ask on connection suppression.
       
   253      * Check if one or more sessions have suppressed the ask on 
       
   254      * connection mode query.
       
   255      *
       
   256      * @since S60 5.0
       
   257      * @return ETrue if suppression found
       
   258      */	
       
   259     TBool IsAskOnConnectionSuppression();
       
   260 	
       
   261 private:
       
   262 
       
   263     /**
       
   264      * C++ default constructor.
       
   265      */
       
   266     CUsbWatcher();
       
   267 
       
   268     /**
       
   269      * By default Symbian 2nd phase constructor is private.
       
   270      */
       
   271     void ConstructL();
       
   272 
       
   273     /**
       
   274      * Get personality plugins.
       
   275      *
       
   276      * @since Series 60 3.2
       
   277      */
       
   278     void GetPersonalityPluginsL();
       
   279         
       
   280     /**
       
   281      * Switch personality according to USB state.
       
   282      * @param aConfirmUnload If true, no personality switch blocking queries are shown.
       
   283      * @since Series 60 3.2
       
   284      */
       
   285     void SwitchPersonality( TBool aNonBlocking = EFalse );
       
   286 
       
   287     /**
       
   288      * Starts personality/USB.
       
   289      *
       
   290      * @since Series 60 2.?
       
   291      */
       
   292     void Start();
       
   293 
       
   294     /**
       
   295      * Stops personality/USB.
       
   296      *
       
   297      * @since Series 60 2.?
       
   298      */    
       
   299     void Stop();
       
   300         
       
   301     /**
       
   302      * Stops and starts personality.
       
   303      * @param aConfirmUnload If true, no personality switch blocking queries are shown.
       
   304      * @since Series 60 3.0
       
   305      */    
       
   306     void StopStart( TBool aNonBlocking );
       
   307 
       
   308 	/**
       
   309      * Get personality id. Used in charging mode.
       
   310      *
       
   311      * @since Series 60 3.2
       
   312      * @return error
       
   313      */
       
   314     TInt GetChargingPersonalityId( TInt& aPersonalityId ); 
       
   315 	
       
   316 private: // Data
       
   317     /** 
       
   318      * states for USB starting and stopping 
       
   319      */
       
   320     enum TUsbState
       
   321         {
       
   322         EUsbIdle,
       
   323         EUsbStarting,
       
   324         EUsbStarted,
       
   325         EUsbStopping,
       
   326         EUsbConfirmStop
       
   327         };
       
   328 
       
   329     /**
       
   330      * Personalities supported by this system
       
   331      */
       
   332     RArray<TUsbSupportedPersonalityInf> iSupportedPersonalities;
       
   333 
       
   334     /**
       
   335      * Object to follow device state
       
   336      */
       
   337     CUsbActiveState* iActiveState;
       
   338 
       
   339     /**
       
   340      * Handle to Usb Manager
       
   341      */
       
   342     RUsb iUsbMan;
       
   343 
       
   344     /**
       
   345      * Object to start or stop current personality
       
   346      */
       
   347     CUsbActivePersonalityHandler* iPersonalityHandler;
       
   348 
       
   349     /**
       
   350      * Current personality id
       
   351      */
       
   352     TInt iPersonalityId;
       
   353     
       
   354     /**
       
   355      * Previous personality id
       
   356      */
       
   357     TInt iPrevPersonalityId;
       
   358     
       
   359     /**
       
   360      * Earlier previous personality id
       
   361      */
       
   362     TInt iOldPrevPersonalityId;
       
   363     
       
   364     /**
       
   365      * Current ask on connection setting
       
   366      */
       
   367     TInt iAskOnConnectionSetting;
       
   368     
       
   369     /**
       
   370      * State for USB starting/stoping
       
   371      */
       
   372     TUsbState iState;
       
   373 
       
   374     /**
       
   375      * Flag to detect when stop+start scenario ongoing
       
   376      */
       
   377     TBool iStopStartScenario;
       
   378 
       
   379     /**
       
   380      * Registered by CUsbWatcherSession when connection established
       
   381      */
       
   382 	RPointerArray<MUsbWatcherNotify> iObservers;
       
   383     
       
   384     /**
       
   385      * Access to central repository
       
   386      */
       
   387     CRepository* iPersonalityRepository;
       
   388 
       
   389     /**
       
   390      * Flag to detect when personality change is ongoing
       
   391      */
       
   392     TBool iPersonalityChangeOngoing;
       
   393 
       
   394     /**
       
   395      * Flag to detect when set personality request is ongoing
       
   396      */
       
   397     TBool iSetPersonalityOngoing;
       
   398 
       
   399     /**
       
   400      * Flag to detect when set previous personality request is ongoing
       
   401      */
       
   402     TBool iSetPreviousPersonalityOngoing;
       
   403 
       
   404     /**
       
   405      * Flag to detect when client has requested personality change on disconnect
       
   406      */
       
   407     TBool iSetPreviousPersonalityOnDisconnect;
       
   408     
       
   409     /**
       
   410      * Flag to detect when personality is changed from the ask on connection
       
   411      */
       
   412     TBool iChangePersonalityOngoing;    
       
   413     
       
   414     /**
       
   415      * Device lock feature
       
   416      */
       
   417     CUsbDeviceLock* iUsbDeviceLock;
       
   418     
       
   419     /**
       
   420      * Usbdevcon process starter
       
   421      * Own.
       
   422      */
       
   423     CUsbDevConStarter* iUsbDevConStarter;
       
   424 
       
   425     /**
       
   426      * Global system state listener
       
   427      * Start/stop personality depending on global state changes.
       
   428      * Own.
       
   429      */
       
   430     CUsbGlobalSystemStateObserver* iGlobalStateObserver;
       
   431     
       
   432     /**
       
   433      * Personality loading ongoing
       
   434      */
       
   435     TBool iStarted;
       
   436     
       
   437     /**
       
   438      * OTG Watcher
       
   439      */
       
   440     CUsbOtgWatcher* iOtgWatcher; //OTG
       
   441     
       
   442     /*
       
   443      * USB indicator handler to handle device side indicator
       
   444      */
       
   445     TUsbIndicatorHandler iUsbIndicatorHandler;
       
   446     
       
   447     /*
       
   448      * Starting mode is normal?
       
   449      */
       
   450     TBool iNormalStart;
       
   451     };
       
   452     
       
   453 #include "cusbwatcher.inl"
       
   454 
       
   455 #endif   // CUSBWATCHER_H
       
   456 
       
   457 // End of File