usbuis/usbui/USBClassChangeUIPlugin/inc/USBClassChangeUIPluginModel.h
branchRCL_3
changeset 24 e02eb84a14d2
parent 0 1e05558e2206
equal deleted inserted replaced
23:25fce757be94 24:e02eb84a14d2
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Declares model class for application.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef USBCLASSCHANGEUIPLUGINMODEL_H
       
    20 #define USBCLASSCHANGEUIPLUGINMODEL_H
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 #include <badesca.h>
       
    25 #include <usbman.h>
       
    26 #include <usbwatcher.h>
       
    27 #include <eikfrlb.h>
       
    28 #include <eikclb.h>
       
    29 #include <aknlists.h> 
       
    30 #include "USBClassChangeUIPlugin.hrh"
       
    31 #include "USBClassChangeUIPluginCRWatcher.h"
       
    32 #include "USBDeviceStateWatcher.h"
       
    33 #include "usbotghoststatewatcher.h"
       
    34 
       
    35 // CONSTANTS
       
    36 /** granularity for supported modes array */
       
    37 const TInt KUSBClassChangeUISupportedModesGranularity = 3;
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 class CUSBDeviceStateWatcher;
       
    41 
       
    42 // CLASS DECLARATION
       
    43 
       
    44 /**
       
    45  * A callback interface for informing change of settings and device state.
       
    46  */
       
    47 class MUSBUIObserver : public MUSBDeviceStateObserver, 
       
    48     public MUSBOtgHostStateObserver
       
    49     {
       
    50     public: // New functions
       
    51         
       
    52         /**
       
    53         * Informs the observer that a setting has been changed. 
       
    54         * The list should be refreshed.
       
    55         */
       
    56         virtual void SettingChanged() = 0;
       
    57     };
       
    58 
       
    59 /**
       
    60 * This class has access to all data needed by this application.
       
    61 * All manipulation of data is done through this class.
       
    62 */
       
    63 class CUSBClassChangeUIPluginModel : public CActive, 
       
    64     public MUSBUICRSettingObserver, MUSBDeviceStateObserver, MUSBOtgHostStateObserver
       
    65     {
       
    66     public: // Constructors and destructor
       
    67 
       
    68 	    /**
       
    69         * Destructor.
       
    70         */
       
    71         virtual ~CUSBClassChangeUIPluginModel(); 
       
    72 
       
    73     public: // New functions
       
    74         
       
    75         
       
    76         /**
       
    77         * Factory method NewL
       
    78         * @return a pointer to itself
       
    79         */
       
    80         static CUSBClassChangeUIPluginModel* NewL();
       
    81         
       
    82         
       
    83         /**
       
    84         * Sets the USB mode.
       
    85         * @param aMode the id of the selected personality 
       
    86         */
       
    87         void SetUSBModeL( TInt aMode );
       
    88 
       
    89         /**
       
    90         * Gets the USB mode.
       
    91         * @return the id of the personality
       
    92         */
       
    93         TInt USBMode();
       
    94         
       
    95         /**
       
    96          * Gets the number of usb personalities.
       
    97          * @return the number of existing personalities 
       
    98          */
       
    99         TInt PersonalityCount() ;
       
   100         /**
       
   101          * Gets the current device state.
       
   102          * @param   aState  receives the current state of the USB device
       
   103          * @return  KErrNone if successful, otherwise the error that occurred
       
   104          */
       
   105         TInt GetDeviceState(TUsbDeviceState& aState);
       
   106 
       
   107         /**
       
   108          * Gets description for the specified USB mode (personality ID)
       
   109          * @param   aMode a personality id
       
   110          * @param   aDescription a localized text string
       
   111          * @return  KErrNone if successful, otherwise the error that occurred.
       
   112          */
       
   113         TInt GetDescription(TInt aMode, HBufC*& aDescription);
       
   114 
       
   115         /**
       
   116         * Updates temporary member variable data.        
       
   117         * @param aObserver Reference to MUSBUIObserver instance.        
       
   118         */
       
   119         void SetSettingsObserver(MUSBUIObserver* aObserver);
       
   120         
       
   121         /*
       
   122         * Reads the supported USB modes from the resource file and CenRep.
       
   123         * Adds modes to the CDesCArrayFlat lists to be used either
       
   124         * for list box or for setting page
       
   125         * @param aListBox The list where the USB modes are appended for list box
       
   126         * @param aListBoxDefault The list where the USB modes are appended with their secondary line "default" 
       
   127         * @param aListBoxActive The list where the USB modes are appended with their secondary line "active" 
       
   128         * @param aPopUpItems The list where the descriptive strings will be stored 
       
   129         * @param aIconArray The list where icons for USB modes are stored
       
   130         */
       
   131         void SupportedUSBModeArraysL(  CDesCArrayFlat& aListBox, CDesCArrayFlat& aListBoxDefault,
       
   132                 CDesCArrayFlat& aListBoxActive, CDesCArrayFlat& aPopUpItems, CArrayPtrFlat<CGulIcon>& aIconArray );       
       
   133         
       
   134         /**
       
   135         * From MUSBUICRSettingObserver.
       
   136         * Changes the USB mode in the USB application. 
       
   137         * Called by CUSBClassChangeUICenRepWatcher, when the key 
       
   138         * KUsbWatcherPersonality is changed by the USBWatcher.
       
   139         * @param aKey identifies the setting that has changed
       
   140         */
       
   141         void SettingChangedL( TUint32 aKey );
       
   142 
       
   143         /**
       
   144          * From MUSBOtgHostStateObserver
       
   145          * @see MUSBOtgHostStateObserver::OtgHostIdPinStateChanged
       
   146          */
       
   147         void OtgHostIdPinStateChanged(TBool aIsIdPinOn);
       
   148         
       
   149         /**
       
   150          * From MUSBOtgHostStateObserver
       
   151          * @see MUSBOtgHostStateObserver::OtgHostIdPinStateChanged
       
   152          */
       
   153         void HostEventNotify(TDeviceEventInformation aEventInfo);
       
   154         
       
   155         /**
       
   156          * From MUSBDeviceStateObserver.
       
   157          * Informs the observer that USB device state has changed.
       
   158          * @param aPreviousState previous device state.
       
   159          * @param aCurrentState current device state.
       
   160          */
       
   161         void DeviceStateChanged(TUsbDeviceState aPreviousState,
       
   162                                 TUsbDeviceState aCurrentState);
       
   163 
       
   164         
       
   165         /**
       
   166         * Gets the IDs of supported USB personalities.
       
   167         * @return RArray of personality IDs
       
   168         */
       
   169         RArray<TInt>& GetUsbIds();
       
   170              
       
   171         /**
       
   172          * Returns if it acts as a host and the driver to the attached pheripheral 
       
   173          * is loaded successfully(or partially). 
       
   174          * NOTE: Only single perihperal supported now.
       
   175          * @param aHasPeripheralEnabled Is A-device is ready to be used or not
       
   176          * @return KErrNone if successful, otherwise the error that occurred
       
   177          */
       
   178         TInt HasPeripheralEnabled(TBool& aHasPeripheralEnabled);
       
   179         
       
   180   
       
   181     protected:
       
   182         /**
       
   183         * Default ConstructL can leave.
       
   184         */
       
   185         void ConstructL();
       
   186 
       
   187 	    /**
       
   188         * C++ default constructor.
       
   189         */
       
   190         CUSBClassChangeUIPluginModel();        
       
   191         
       
   192         /**
       
   193         * Derived from CActive
       
   194         */
       
   195         void RunL();
       
   196 
       
   197         /**
       
   198         * Derived from CActive
       
   199         */
       
   200         void DoCancel();
       
   201         
       
   202     private:
       
   203         /**
       
   204          * selects the icon related to each mode to be added into the iconlist
       
   205          * @param aMode the mode id
       
   206          * @param aIconArray The list where icons for USB modes are stored
       
   207          */
       
   208         void AddIconL (TInt aMode, CArrayPtrFlat<CGulIcon>& aIconArray);
       
   209                
       
   210         /**
       
   211          * creats and append the icons to the list
       
   212          * @param aID Item ID of the masked bitmap to be created.
       
   213          * @param aFilename Filename to be used to construct the item.
       
   214          * @param aBitmapId The ID if bitmap 
       
   215          * @param aMaskId The ID of bitmap's mask
       
   216          * @param aIconArray The list where icons for USB modes are stored
       
   217          */
       
   218         void CreateAndAppendIconL( const TAknsItemID& aID,
       
   219                                    const TDesC& aFileName,
       
   220                                    const TInt aBitmapId,
       
   221                                    const TInt aMaskId,
       
   222                                    CArrayPtrFlat<CGulIcon>& aIconArray);
       
   223                  
       
   224     private: // Data
       
   225          // Reference to settings observer
       
   226          MUSBUIObserver* iObserver;
       
   227 
       
   228          // References to central repository watcher
       
   229          // owned by this class
       
   230          CUSBClassChangeUIPluginCRWatcher* iCRPersonalityWatcher;
       
   231 
       
   232          // Reference to device state watcher
       
   233          // owned by this class
       
   234          CUSBDeviceStateWatcher* iDeviceStateWatcher;
       
   235          
       
   236          // Contains USB mode indexes
       
   237          RArray<TInt> iUsbModeIndexes; 
       
   238          
       
   239          // Central repository handle 
       
   240          // owned by this class
       
   241          CRepository* iRepository; 
       
   242          
       
   243          /** Handle to usbman for retrieving the personalities */
       
   244          RUsb iUsbman;
       
   245          
       
   246          /** Handle to USBWatcher for setting the personality */
       
   247          RUsbWatcher iUsbWatcher;         
       
   248          
       
   249          /** Is connected to USB Watcher */
       
   250          TBool iUsbWatcherConnected;
       
   251          
       
   252          /** UsbOtg status watcher */
       
   253          CUSBOtgHostStateWatcher* iOtgHostStateWatcher;
       
   254          
       
   255          /**
       
   256           * Ids of the devices for which host drivers have been loaded.
       
   257           * When we start to support hubs, there may be more than one element
       
   258           * in this array.
       
   259           */
       
   260          RArray<TInt> iDeviceIDs;
       
   261 		 
       
   262          //Number of personalities
       
   263          TInt iPersonalityCount;
       
   264          
       
   265     };
       
   266 
       
   267 #endif // USBCLASSCHANGEUIPLUGINMODEL_H
       
   268 
       
   269 // End of File