usbengines/usblocodplugin/src/usblcdactive.cpp
changeset 34 7858bc6ead78
parent 31 dfdd8240f7c8
child 35 9d8b04ca6939
equal deleted inserted replaced
31:dfdd8240f7c8 34:7858bc6ead78
     1 /*
       
     2 * Copyright (c) 2006 - 2010 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:  Active object class used to manage asynchronous request.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32property.h>
       
    20 #include "usblcdactive.h"
       
    21 #include <UsbWatcherInternalPSKeys.h>
       
    22 #include <usbpersonalityids.h>
       
    23 
       
    24 #ifdef __FLOG_ACTIVE
       
    25 _LIT8(KLogComponent, "USBLcdPlugin");
       
    26 #endif
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // Constructs a CUsbLcdActive object.
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CUsbLcdActive* CUsbLcdActive::NewL(MLocodBearerPluginObserver& aObserver)
       
    35     {
       
    36     LOG_STATIC_FUNC_ENTRY
       
    37     CUsbLcdActive* self = new (ELeave) CUsbLcdActive(aObserver);
       
    38     CleanupStack::PushL(self);
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop(self);
       
    41     return self;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // Destructor
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CUsbLcdActive::~CUsbLcdActive()
       
    49     {
       
    50     LOG_FUNC
       
    51     Cancel();
       
    52     iProperty.Close();
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // From class CActive
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 void CUsbLcdActive::DoCancel()
       
    61     {
       
    62     iProperty.Cancel();
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // RunL() From class CActive
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69    
       
    70 void CUsbLcdActive::RunL()
       
    71     {
       
    72     LOG_FUNC
       
    73     TInt value;
       
    74     
       
    75     if( iStatus != KErrNone )
       
    76        {
       
    77        LOGTEXT2(_L8("CUsbLcdActive::RunL() error = %d"),iStatus.Int());
       
    78        }
       
    79     else
       
    80        {
       
    81 
       
    82         TInt ret = iProperty.Get( value );
       
    83         LOGTEXT3(_L8("Personality: %d, ret: %d"), value, ret);  
       
    84         iProperty.Subscribe(iStatus);
       
    85         SetActive();
       
    86         if (ret == KErrNone)
       
    87             { 
       
    88             HandleUsbPersonalityChange( value );
       
    89             }    
       
    90        }
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // From class CActive
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97     
       
    98 TInt CUsbLcdActive::RunError( TInt /*aError*/ )
       
    99     {
       
   100     LOG_FUNC
       
   101     return KErrNone; 
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // Constructor
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CUsbLcdActive::CUsbLcdActive(MLocodBearerPluginObserver& aObserver)
       
   109     : CActive(EPriorityStandard), iObserver(aObserver)
       
   110     {
       
   111     LOG_FUNC
       
   112     CActiveScheduler::Add( this );
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // Method to perform second phase construction.
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 void CUsbLcdActive::ConstructL()
       
   121     {  
       
   122     LOG_FUNC
       
   123     User::LeaveIfError(iProperty.Attach(KPSUidUsbWatcher, KUsbWatcherSelectedPersonality));
       
   124     Start();
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Start() function is called to initiate RProperty subscription
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CUsbLcdActive::Start()
       
   132     {     
       
   133     LOG_FUNC
       
   134     iProperty.Subscribe(iStatus);
       
   135     SetActive();
       
   136     // Check the starting state
       
   137     TInt usbPersonalityId( KUsbWatcherSelectedPersonalityNone );
       
   138     TInt ret = iProperty.Get( usbPersonalityId );
       
   139     if ( ( ret == KErrNone ) && 
       
   140         ( usbPersonalityId != KUsbWatcherSelectedPersonalityNone ) )
       
   141         {
       
   142         HandleUsbPersonalityChange( usbPersonalityId ); 
       
   143         }
       
   144     }
       
   145      
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // This function handles the USB active personality change, and notify LoCoD
       
   149 // framework whether PC Suite is active 
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void CUsbLcdActive::HandleUsbPersonalityChange( TInt aNewPersonalityId )
       
   153     {
       
   154     LOG_FUNC
       
   155     LOGTEXT2( _L8( "aNewPersonalityId: %d"), aNewPersonalityId );
       
   156     TBool isPcSuiteActive( EFalse );
       
   157     if ( ( aNewPersonalityId == KUsbPersonalityIdPCSuite ) ||
       
   158          ( aNewPersonalityId == KUsbPersonalityIdPCSuiteMTP ) )
       
   159         {
       
   160         isPcSuiteActive = ETrue;
       
   161         }
       
   162     iObserver.NotifyBearerStatus( ELocodBearerUSB, isPcSuiteActive );
       
   163     }
       
   164     
       
   165 //End of file