usbengines/usbotgwatcher/src/cusbnotifmanager.cpp
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:  Implementation
       
    15  *
       
    16 */
       
    17 
       
    18 #include <usbuinotif.h> 
       
    19 
       
    20 #include "cusbnotifmanager.h"
       
    21 #include "cusbwaitnotifier.h"
       
    22 #include "cusbwarningnotifier.h"
       
    23 #include "cusbindicatornotifier.h"
       
    24 
       
    25 #include "debug.h"
       
    26 #include "panic.h"
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // 
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CWaitNotifierInfo::CWaitNotifierInfo(CUsbNotifier* aWaitNotifier,
       
    33         MWaitNotifierObserver* aObserver) :
       
    34     iWaitNotifier(aWaitNotifier), iObserver(aObserver)
       
    35     {
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // 
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 void CWaitNotifierInfo::ConstructL()
       
    43     {
       
    44         FLOG( _L( "[USBOTGWATCHER]\tCWaitNotifierInfo::ConstructL" ) );
       
    45     // owenrship for iWaitNotifier transferred in default constructor.
       
    46     // this object is responsible for deletion of the iWaitNotifier then	
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // 
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CWaitNotifierInfo* CWaitNotifierInfo::NewL(CUsbNotifier* aWaitNotifier,
       
    54         MWaitNotifierObserver* aObserver)
       
    55     {
       
    56         FLOG( _L( "[USBOTGWATCHER]\tCWaitNotifierInfo::NewL" ) );
       
    57     CWaitNotifierInfo* self = new (ELeave) CWaitNotifierInfo(aWaitNotifier,
       
    58             aObserver);
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop(self);
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // 
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CWaitNotifierInfo::~CWaitNotifierInfo()
       
    70     {
       
    71         FLOG( _L( "[USBOTGWATCHER]\tCWaitNotifierInfo::~CWaitNotifierInfo" ) );
       
    72     delete iWaitNotifier;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // 
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CUsbNotifier* CWaitNotifierInfo::WaitNotifier() const
       
    80     {
       
    81     return iWaitNotifier;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // 
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 MWaitNotifierObserver* CWaitNotifierInfo::Observer() const
       
    89     {
       
    90     return iObserver;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // 
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CUsbNotifManager::CUsbNotifManager()
       
    98     {
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // 
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CUsbNotifManager::ConstructL()
       
   106     {
       
   107 
       
   108         FLOG( _L( "[USBOTGWATCHER]\tCUsbNotifManager::ConstructL" ) );
       
   109 
       
   110     User::LeaveIfError(iNotifier.Connect());
       
   111 
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // 
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 CUsbNotifManager* CUsbNotifManager::NewL()
       
   119     {
       
   120 
       
   121         FLOG( _L( "[USBOTGWATCHER]\tCUsbNotifManager::NewL" ) );
       
   122 
       
   123     CUsbNotifManager* self = new (ELeave) CUsbNotifManager();
       
   124     CleanupStack::PushL(self);
       
   125     self->ConstructL();
       
   126     CleanupStack::Pop(self);
       
   127     return self;
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // 
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 CUsbNotifManager::~CUsbNotifManager()
       
   135     {
       
   136 
       
   137         FLOG( _L( "[USBOTGWATCHER]\tCUsbNotifManager::~CUsbNotifManager" ) );
       
   138 
       
   139     CloseAllNotifiers();
       
   140 
       
   141     iNotifier.Close();
       
   142 
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // 
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 void CUsbNotifManager::ShowNotifierL(TUid aCat, TUint aNotifId,
       
   150         MWaitNotifierObserver* aObserver)
       
   151     {
       
   152         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbNotifManager::ShowNotifier aCat = 0x%X aNotifId = %d, aObserver=0x%X" ),
       
   153                         aCat, aNotifId, aObserver));
       
   154 
       
   155     // remove non-feedback notifiers from the list
       
   156     for (TUint i(0); i < iWaitNotifiers.Count(); ++i)
       
   157         {
       
   158         CWaitNotifierInfo* waitNotifier = iWaitNotifiers[i];
       
   159         if (!(waitNotifier->WaitNotifier()->IsFeedbackNeeded()))
       
   160             {
       
   161             delete waitNotifier;
       
   162             iWaitNotifiers.Remove(i);
       
   163             }
       
   164         }
       
   165     //If not suspened a short while between closing a present note and showing a new one,
       
   166     //error - CUsbWaitNotifier::RunL iStatus = 4 - will happen. Necessary here to pause a while 
       
   167     //to allow notfier framework to do some cleaning work.
       
   168     //Should find another way to solve this problem.
       
   169     const TUint KTenthOfASecond = 100000;
       
   170     User::After(TTimeIntervalMicroSeconds32(KTenthOfASecond));
       
   171 
       
   172     // can not have switch-case selector here, due to constants are of type Uids
       
   173     // notifier requires feedback => create CWaitNotifier for it
       
   174     // As notifiers can be more than two types such as warning, error, indicator ...
       
   175     // to create concret notifiers according to categories instead of checking aObserver null
       
   176     CUsbNotifier* notifier(NULL);
       
   177     if (aCat == KUsbUiNotifOtgError)
       
   178         {
       
   179         __ASSERT_ALWAYS(aObserver != NULL, Panic(EWrongNotifierCategory));
       
   180         notifier = CUsbWaitNotifier::NewL(iNotifier, this, aNotifId);
       
   181         }
       
   182     else if (aCat == KUsbUiNotifOtgWarning)
       
   183         {
       
   184         notifier = CUsbWarningNotifier::NewL(iNotifier, this, aNotifId);
       
   185         }
       
   186     else
       
   187         {
       
   188             FLOG( _L( "[USBOTGWATCHER]\tCUsbNotifManager::ShowNotifierL - Unexpected aCat" ) );
       
   189         Panic(EWrongNotifierCategory);
       
   190         }
       
   191 
       
   192     CleanupStack::PushL(notifier);
       
   193     
       
   194     iWaitNotifiers.AppendL(CWaitNotifierInfo::NewL(notifier, aObserver));
       
   195 
       
   196         FLOG( _L( "[USBOTGWATCHER]\tCUsbNotifManager::ShowNotifierL - Start to show note" ) );
       
   197     notifier->ShowL();
       
   198 
       
   199     CleanupStack::Pop(notifier);    
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // 
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CUsbNotifManager::BlinkIndicatorL(TBool aBlinking)
       
   207     {
       
   208         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbNotifManager::BlinkIndicatorL, aBlinking=%d" ), aBlinking));
       
   209 
       
   210     if (!iIndicatorNotifier)
       
   211         iIndicatorNotifier = CUsbIndicatorNotifier::NewL(this);
       
   212 
       
   213     if (aBlinking)
       
   214         iIndicatorNotifier->ShowL();
       
   215     else
       
   216         iIndicatorNotifier->Close();
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // 
       
   221 // ---------------------------------------------------------------------------
       
   222 //
       
   223 void CUsbNotifManager::ShowIndicatorL(TBool aVisible)
       
   224     {
       
   225         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbNotifManager::ShowIndicatorL, aVisible=%d" ), aVisible ));
       
   226 
       
   227     if (!iIndicatorNotifier)
       
   228         iIndicatorNotifier = CUsbIndicatorNotifier::NewL(this);
       
   229 
       
   230     iIndicatorNotifier->ShowIndicatorL(aVisible);
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 void CUsbNotifManager::NotifierShowCompletedL(CUsbNotifier* aWaitNotifier,
       
   238         TInt aResult, TInt aFeedback)
       
   239     {
       
   240         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbNotifManager::NotifierShowCompleted aResult = %d" ), aResult));
       
   241 
       
   242     // remove Notifier from the list
       
   243     for (TUint i(0); i < iWaitNotifiers.Count(); ++i)
       
   244         {
       
   245         if (aWaitNotifier == iWaitNotifiers[i]->WaitNotifier())
       
   246             {
       
   247             MWaitNotifierObserver* observer = iWaitNotifiers[i]->Observer();
       
   248 
       
   249             delete iWaitNotifiers[i];
       
   250             iWaitNotifiers.Remove(i);
       
   251 
       
   252             if (observer)
       
   253                 observer->WaitNotifierCompletedL(aFeedback);
       
   254             }
       
   255         }
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // 
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CUsbNotifManager::CloseAllNotifiers()
       
   263     {
       
   264         FLOG( _L( "[USBOTGWATCHER]\tCUsbNotifManager::CloseAllNotifiers" ) );
       
   265 
       
   266     iWaitNotifiers.ResetAndDestroy();
       
   267     delete iIndicatorNotifier;
       
   268     iIndicatorNotifier = NULL;
       
   269     }