usbuis/usbui/USBClassChangeUIPlugin/src/USBClassChangeUIPluginCRWatcher.cpp
branchRCL_3
changeset 24 e02eb84a14d2
parent 0 1e05558e2206
equal deleted inserted replaced
23:25fce757be94 24:e02eb84a14d2
       
     1 /*
       
     2 * Copyright (c) 2005, 2006 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:  This implements USBClassChangeUIPluginCRWatcher class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "USBClassChangeUIPluginCRWatcher.h"
       
    22 #include "UsbWatcherInternalCRKeys.h"
       
    23 #include "USBClassChangeUIPluginModel.h"
       
    24 #include "USBClassChangeUIPluginDebug.h"
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CUSBClassChangeUIPluginCRWatcher::NewL
       
    33 // Two-phased constructor.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CUSBClassChangeUIPluginCRWatcher* CUSBClassChangeUIPluginCRWatcher::NewL(
       
    37     MUSBUICRSettingObserver& aOwner, TUint32 aKey, TBool aOneShot)
       
    38     {
       
    39     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher:NewL"));
       
    40     CUSBClassChangeUIPluginCRWatcher* self 
       
    41         = new (ELeave) CUSBClassChangeUIPluginCRWatcher(aOwner, aKey, aOneShot);
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self ); 
       
    45     return self;
       
    46     }
       
    47 
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CUSBClassChangeUIPluginCRWatcher::~CUSBClassChangeUIPluginCRWatcher
       
    51 // C++ default destructor
       
    52 // -----------------------------------------------------------------------------
       
    53 //    
       
    54 CUSBClassChangeUIPluginCRWatcher::~CUSBClassChangeUIPluginCRWatcher()
       
    55     {
       
    56     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher: desctructor"));
       
    57     Cancel(); // cancels any existing active object orders for iStatus
       
    58     delete iPersonalityRepository; // deletes CRepository* member object.
       
    59     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher: desctructor complete"));
       
    60     }
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CUSBClassChangeUIPluginCRWatcher::CUSBClassChangeUIPluginCRWatcher
       
    65 // C++ default constructor can NOT contain any code, that
       
    66 // might leave.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CUSBClassChangeUIPluginCRWatcher::CUSBClassChangeUIPluginCRWatcher(
       
    70     MUSBUICRSettingObserver& aOwner, TUint32 aKey, TBool aOneShot)
       
    71     : CActive(EPriorityStandard), 
       
    72     iOwner(aOwner),
       
    73     iKey(aKey),
       
    74     iOneShot(aOneShot)
       
    75     {
       
    76     }
       
    77 
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CUSBClassChangeUIPluginCRWatcher::RunError
       
    82 // Standard active object error function.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 
       
    86 TInt CUSBClassChangeUIPluginCRWatcher::RunError(TInt /*aError*/)
       
    87     {
       
    88     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher::RunError: ERROR %d \
       
    89         from RunL.") );
       
    90     return KErrNone;
       
    91     }
       
    92 
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CUSBClassChangeUIPluginCRWatcher::RunL
       
    96 // This function will be called upon a change in the watched key.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CUSBClassChangeUIPluginCRWatcher::RunL()
       
   100     {
       
   101     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher::RunL"));
       
   102 
       
   103     iOwner.SettingChangedL( iKey );        
       
   104     if (!iOneShot)
       
   105         {
       
   106         StartListeningL(); 
       
   107         }
       
   108 
       
   109     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher::RunL complete."));
       
   110     }
       
   111 
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CUSBClassChangeUIPluginCRWatcher::ConstructL
       
   115 // Construct member variable iPersonalityRepository that is to access the
       
   116 // repository. Then start listening of the changes in the repository.
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CUSBClassChangeUIPluginCRWatcher::ConstructL()
       
   120     {
       
   121     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher: ConstructL"));
       
   122     CActiveScheduler::Add(this);
       
   123 
       
   124     iPersonalityRepository = CRepository::NewL( KCRUidUsbWatcher );
       
   125     
       
   126     StartListeningL();
       
   127     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher: ConstructL complete"));        
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CUSBClassChangeUIPluginCRWatcher::StopListening
       
   132 // Cancels notifications.
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 void CUSBClassChangeUIPluginCRWatcher::StopListening()
       
   136     {
       
   137     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher: StopListening"));
       
   138     Cancel();
       
   139     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher: StopListening complete"));
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CUSBClassChangeUIPluginCRWatcher::StartListeningL
       
   144 // Orders notifications and sets the object active.
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CUSBClassChangeUIPluginCRWatcher::StartListeningL()
       
   148     {
       
   149     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher: StartListeningL"));
       
   150     if(IsActive())
       
   151         {
       
   152         return;   
       
   153         }
       
   154 
       
   155     User::LeaveIfError(iPersonalityRepository->NotifyRequest(
       
   156         iKey, 
       
   157         iStatus ) );
       
   158     SetActive();
       
   159     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher: StartListening complete"));
       
   160     }
       
   161 
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CUSBClassChangeUIPluginCRWatcher::DoCancel
       
   165 // Standard active object cancellation function.
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CUSBClassChangeUIPluginCRWatcher::DoCancel()
       
   169     {
       
   170     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher::DoCancel"));
       
   171     
       
   172     if ( iPersonalityRepository )
       
   173         {
       
   174         // cancel the order for change notifications
       
   175         iPersonalityRepository->NotifyCancel( iKey );
       
   176         }
       
   177     FLOG(_L("[USBCLASSCHANGEUIPLUGIN]\tCUSBClassChangeUIPluginCRWatcher::DoCancel complete"));
       
   178     }
       
   179 
       
   180 
       
   181 // End of file