usbengines/usbotgwatcher/src/cusbnotifmanager.cpp
changeset 35 9d8b04ca6939
child 63 ef2686f7597e
equal deleted inserted replaced
34:7858bc6ead78 35:9d8b04ca6939
       
     1 /*
       
     2  * Copyright (c) 2008 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     LOG_FUNC
       
    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     LOG_FUNC
       
    57 
       
    58     CWaitNotifierInfo* self = new (ELeave) CWaitNotifierInfo(aWaitNotifier,
       
    59             aObserver);
       
    60     CleanupStack::PushL(self);
       
    61     self->ConstructL();
       
    62     CleanupStack::Pop(self);
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // 
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CWaitNotifierInfo::~CWaitNotifierInfo()
       
    71     {
       
    72     LOG_FUNC
       
    73     delete iWaitNotifier;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // 
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CUsbNotifier* CWaitNotifierInfo::WaitNotifier() const
       
    81     {
       
    82     return iWaitNotifier;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // 
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 MWaitNotifierObserver* CWaitNotifierInfo::Observer() const
       
    90     {
       
    91     return &iObserver;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // 
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CUsbNotifManager* CUsbNotifManager::NewL(CUsbOtgWatcher& aOtgWatcher)
       
    99     {
       
   100     LOG_FUNC
       
   101 
       
   102     CUsbNotifManager* self = new (ELeave) CUsbNotifManager();
       
   103     CleanupStack::PushL(self);
       
   104     self->ConstructL(aOtgWatcher);
       
   105     CleanupStack::Pop(self);
       
   106     return self;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // 
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CUsbNotifManager::ConstructL(CUsbOtgWatcher& aOtgWatcher)
       
   114     {
       
   115     LOG_FUNC
       
   116 
       
   117     LEAVEIFERROR(iNotifier.Connect());
       
   118 
       
   119     iIndicatorNotifier = CUsbIndicatorNotifier::NewL(*this, aOtgWatcher);
       
   120 
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // 
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 CUsbNotifManager::CUsbNotifManager()
       
   128     {
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // 
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 CUsbNotifManager::~CUsbNotifManager()
       
   136     {
       
   137     LOG_FUNC
       
   138 
       
   139     CloseAllNotifiers();
       
   140 
       
   141     delete iIndicatorNotifier;
       
   142 
       
   143     iNotifier.Close();
       
   144 
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // 
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CUsbNotifManager::ShowNotifierL(TUid aCat, TUint aNotifId,
       
   152         MWaitNotifierObserver* aObserver)
       
   153     {
       
   154     LOG_FUNC
       
   155 
       
   156     LOG3( "aCat = 0x%X aNotifId = %d, aObserver=0x%X" , aCat, aNotifId, aObserver);
       
   157 
       
   158     // remove non-feedback notifiers from the list
       
   159     for (TUint i(0); i < iWaitNotifiers.Count(); ++i)
       
   160         {
       
   161         CWaitNotifierInfo* waitNotifierInfo = iWaitNotifiers[i];
       
   162         if (!(waitNotifierInfo->WaitNotifier()->IsFeedbackNeeded()))
       
   163             {
       
   164             delete waitNotifierInfo;
       
   165             iWaitNotifiers.Remove(i);
       
   166             }
       
   167         }
       
   168     //If not suspened a short while between closing a present note and showing a new one,
       
   169     //error - CUsbWaitNotifier::RunL iStatus = 4 - will happen. Necessary here to pause a while 
       
   170     //to allow notfier framework to do some cleaning work.
       
   171     //Should find another way to solve this problem.
       
   172     const TUint KTenthOfASecond = 100000;
       
   173     User::After(TTimeIntervalMicroSeconds32(KTenthOfASecond));
       
   174 
       
   175     // can not have switch-case selector here, due to constants are of type Uids
       
   176     // notifier requires feedback => create CWaitNotifier for it
       
   177     // As notifiers can be more than two types such as warning, error, indicator ...
       
   178     // to create concret notifiers according to categories instead of checking aObserver null
       
   179     CUsbNotifier* notifier(NULL);
       
   180     if (aCat == KUsbUiNotifOtgError)
       
   181         {
       
   182         ASSERT_PANIC(aObserver != NULL, EWrongNotifierCategory);
       
   183         notifier = CUsbWaitNotifier::NewL(iNotifier, *this, aNotifId);
       
   184         }
       
   185     else if (aCat == KUsbUiNotifOtgWarning)
       
   186         {
       
   187         notifier = CUsbWarningNotifier::NewL(iNotifier, *this, aNotifId);
       
   188         }
       
   189     else
       
   190         {
       
   191         LOG1("Unexpected aCat = 0x%X", aCat );
       
   192         PANIC(EWrongNotifierCategory);
       
   193         }
       
   194 
       
   195     CleanupStack::PushL(notifier);
       
   196 
       
   197     iWaitNotifiers.AppendL(CWaitNotifierInfo::NewL(notifier, *aObserver));
       
   198 
       
   199     notifier->ShowL();
       
   200 
       
   201     CleanupStack::Pop(notifier);
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CUsbNotifManager::NotifierShowCompletedL(CUsbNotifier& aWaitNotifier,
       
   209         TInt aResult, TInt aFeedback)
       
   210     {
       
   211     LOG_FUNC
       
   212 
       
   213     LOG1( "aResult = %d", aResult);
       
   214 
       
   215     // remove Notifier from the list
       
   216     for (TUint i(0); i < iWaitNotifiers.Count(); ++i)
       
   217         {
       
   218         if (&aWaitNotifier == iWaitNotifiers[i]->WaitNotifier())
       
   219             {
       
   220             MWaitNotifierObserver* observer = iWaitNotifiers[i]->Observer();
       
   221 
       
   222             delete iWaitNotifiers[i];
       
   223             iWaitNotifiers.Remove(i);
       
   224 
       
   225             if (observer)
       
   226                 observer->WaitNotifierCompletedL(aFeedback);
       
   227             }
       
   228         }
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // 
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void CUsbNotifManager::CloseAllNotifiers()
       
   236     {
       
   237     LOG_FUNC
       
   238 
       
   239     iWaitNotifiers.ResetAndDestroy();
       
   240     iIndicatorNotifier->Close();
       
   241     }