usbmgmt/usbmgr/host/functiondrivers/ms/msmm/server/src/eventqueue.cpp
branchRCL_3
changeset 15 f92a4f87e424
parent 0 c9bc50fca66e
child 16 012cc2ee6408
equal deleted inserted replaced
14:d3e8e7d462dd 15:f92a4f87e424
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    25 #include "msmmserver.h"
    25 #include "msmmserver.h"
    26 #include "msmmnodebase.h"
    26 #include "msmmnodebase.h"
    27 #include "msmmengine.h"
    27 #include "msmmengine.h"
    28 #include <usb/hostms/msmmpolicypluginbase.h>
    28 #include <usb/hostms/msmmpolicypluginbase.h>
    29 #include <usb/usblogger.h>
    29 #include <usb/usblogger.h>
    30 
    30 #include "OstTraceDefinitions.h"
    31 #ifdef __FLOG_ACTIVE
    31 #ifdef OST_TRACE_COMPILER_IN_USE
    32 _LIT8(KLogComponent, "UsbHostMsmmServer");
    32 #include "eventqueueTraces.h"
    33 #endif
    33 #endif
       
    34 
    34 
    35 
    35 // Public member functions
    36 // Public member functions
    36 CDeviceEventQueue::~CDeviceEventQueue( )
    37 CDeviceEventQueue::~CDeviceEventQueue( )
    37     {
    38     {
    38     LOG_FUNC
    39     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_CDEVICEEVENTQUEUE_DES_ENTRY );
       
    40     
    39     Cancel();
    41     Cancel();
    40     delete iHandler;
    42     delete iHandler;
    41     iEventArray.Close();
    43     iEventArray.Close();
       
    44     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_CDEVICEEVENTQUEUE_DES_EXIT );
    42     }
    45     }
    43 
    46 
    44 CDeviceEventQueue* CDeviceEventQueue::NewL(MMsmmSrvProxy& aServer)
    47 CDeviceEventQueue* CDeviceEventQueue::NewL(MMsmmSrvProxy& aServer)
    45     {
    48     {
    46     LOG_STATIC_FUNC_ENTRY
    49     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_NEWL_ENTRY );
       
    50     
    47     CDeviceEventQueue* self = CDeviceEventQueue::NewLC(aServer);
    51     CDeviceEventQueue* self = CDeviceEventQueue::NewLC(aServer);
    48     CleanupStack::Pop(self);
    52     CleanupStack::Pop(self);
    49     
    53     
       
    54     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_NEWL_EXIT );
    50     return self;
    55     return self;
    51     }
    56     }
    52 CDeviceEventQueue* CDeviceEventQueue::NewLC(MMsmmSrvProxy& aServer)
    57 CDeviceEventQueue* CDeviceEventQueue::NewLC(MMsmmSrvProxy& aServer)
    53     {
    58     {
    54     LOG_STATIC_FUNC_ENTRY
    59     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_NEWLC_ENTRY );
       
    60     
    55     CDeviceEventQueue* self = new (ELeave) CDeviceEventQueue(aServer);
    61     CDeviceEventQueue* self = new (ELeave) CDeviceEventQueue(aServer);
    56     CleanupStack::PushL(self);
    62     CleanupStack::PushL(self);
    57     self->ConstructL();
    63     self->ConstructL();
    58     
    64     
       
    65     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_NEWLC_EXIT );
    59     return self;
    66     return self;
    60     }
    67     }
    61 
    68 
    62 void CDeviceEventQueue::PushL(const TDeviceEvent& aEvent)
    69 void CDeviceEventQueue::PushL(const TDeviceEvent& aEvent)
    63     {
    70     {
    64     LOG_FUNC
    71     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_PUSHL_ENTRY );
    65     
    72 
    66     // Perform optimization for remove device event
    73     // Perform optimization for remove device event
    67     AppendAndOptimizeL(aEvent);
    74     AppendAndOptimizeL(aEvent);
    68     
    75     
    69     // Start handling first event in queue
    76     // Start handling first event in queue
    70     StartL();
    77     StartL();
       
    78     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_PUSHL_EXIT );
    71     }
    79     }
    72 
    80 
    73 void CDeviceEventQueue::Finalize()
    81 void CDeviceEventQueue::Finalize()
    74     {
    82     {
    75     TInt index(0);
    83     TInt index(0);
    93 
   101 
    94 
   102 
    95 // Protected member functions
   103 // Protected member functions
    96 void CDeviceEventQueue::DoCancel()
   104 void CDeviceEventQueue::DoCancel()
    97     {
   105     {
    98     LOG_FUNC
   106     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_DOCANCEL_ENTRY );
       
   107     
    99     iEventArray.Reset();
   108     iEventArray.Reset();
   100     iHandler->Cancel();
   109     iHandler->Cancel();
       
   110     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_DOCANCEL_EXIT );
   101     }
   111     }
   102 
   112 
   103 void CDeviceEventQueue::RunL()
   113 void CDeviceEventQueue::RunL()
   104     {
   114     {
   105     LOG_FUNC
   115     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_RUNL_ENTRY );
       
   116     
   106     // Check the completion code from CDeviceEventHandler. If there
   117     // Check the completion code from CDeviceEventHandler. If there
   107     // is some error occured. We need issue error notification here.
   118     // is some error occured. We need issue error notification here.
   108     TInt err = iStatus.Int();
   119     TInt err = iStatus.Int();
   109     if ((KErrNone != err) && (KErrCancel != err))
   120     if ((KErrNone != err) && (KErrCancel != err))
   110         {
   121         {
   114     iHandler->ResetHandler();
   125     iHandler->ResetHandler();
   115     if (IsEventAvailable())
   126     if (IsEventAvailable())
   116         {
   127         {
   117         SendEventL();
   128         SendEventL();
   118         }
   129         }
       
   130     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_RUNL_EXIT );
   119     }
   131     }
   120 
   132 
   121 TInt CDeviceEventQueue::RunError(TInt aError)
   133 TInt CDeviceEventQueue::RunError(TInt aError)
   122     {
   134     {
   123     LOG_FUNC
   135     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_RUNERROR_ENTRY );
       
   136     
   124     THostMsErrData errData;
   137     THostMsErrData errData;
   125     switch (aError)
   138     switch (aError)
   126         {
   139         {
   127     case KErrNoMemory:
   140     case KErrNoMemory:
   128         errData.iError = EHostMsErrOutOfMemory;
   141         errData.iError = EHostMsErrOutOfMemory;
   142         errData.iProductString.Copy(deviceNode->iDevice.iProductString);
   155         errData.iProductString.Copy(deviceNode->iDevice.iProductString);
   143         }
   156         }
   144     errData.iDriveName = 0x0;
   157     errData.iDriveName = 0x0;
   145     TInt err(KErrNone);
   158     TInt err(KErrNone);
   146     TRAP(err, iServer.PolicyPlugin()->SendErrorNotificationL(errData));
   159     TRAP(err, iServer.PolicyPlugin()->SendErrorNotificationL(errData));
       
   160     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_RUNERROR_EXIT );
   147     return KErrNone;
   161     return KErrNone;
   148     }
   162     }
   149 
   163 
   150 // Private member functions
   164 // Private member functions
   151 CDeviceEventQueue::CDeviceEventQueue(MMsmmSrvProxy& aServer):
   165 CDeviceEventQueue::CDeviceEventQueue(MMsmmSrvProxy& aServer):
   152 CActive(EPriorityStandard),
   166 CActive(EPriorityStandard),
   153 iServer(aServer)
   167 iServer(aServer)
   154     {
   168     {
   155     LOG_FUNC
   169     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_CDEVICEEVENTQUEUE_CONS_ENTRY );
       
   170     
   156     CActiveScheduler::Add(this);
   171     CActiveScheduler::Add(this);
       
   172     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_CDEVICEEVENTQUEUE_CONS_EXIT );
   157     }
   173     }
   158 
   174 
   159 void CDeviceEventQueue::ConstructL()
   175 void CDeviceEventQueue::ConstructL()
   160     {
   176     {
   161     LOG_FUNC
   177     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_CONSTRUCTL_ENTRY );
       
   178     
   162     iHandler = CDeviceEventHandler::NewL(iServer);
   179     iHandler = CDeviceEventHandler::NewL(iServer);
       
   180     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_CONSTRUCTL_EXIT );
   163     }
   181     }
   164 
   182 
   165 void CDeviceEventQueue::AppendAndOptimizeL(const TDeviceEvent& aEvent)
   183 void CDeviceEventQueue::AppendAndOptimizeL(const TDeviceEvent& aEvent)
   166     {
   184     {
   167     LOG_FUNC
   185     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_APPENDANDOPTIMIZEL_ENTRY );
       
   186     
   168     if (EDeviceEventRemoveDevice == aEvent.iEvent)
   187     if (EDeviceEventRemoveDevice == aEvent.iEvent)
   169         {
   188         {
   170         // Scan the event queue to discard all pending related adding 
   189         // Scan the event queue to discard all pending related adding 
   171         // function events.
   190         // function events.
   172         TInt index(0);
   191         TInt index(0);
   194             break;
   213             break;
   195         case EDeviceEventRemoveDevice:
   214         case EDeviceEventRemoveDevice:
   196             if (aEvent.iDeviceId == iHandler->Event().iDeviceId && IsActive())
   215             if (aEvent.iDeviceId == iHandler->Event().iDeviceId && IsActive())
   197                 {
   216                 {
   198                 // Discard duplicated removing event.
   217                 // Discard duplicated removing event.
       
   218                 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_APPENDANDOPTIMIZEL_EXIT );
   199                 return;
   219                 return;
   200                 }
   220                 }
   201             break;
   221             break;
   202             }
   222             }
   203         }
   223         }
   204         iEventArray.AppendL(aEvent);
   224         iEventArray.AppendL(aEvent);
       
   225     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_APPENDANDOPTIMIZEL_EXIT_DUP1 );
   205     }
   226     }
   206 
   227 
   207 void CDeviceEventQueue::StartL()
   228 void CDeviceEventQueue::StartL()
   208     {
   229     {
   209     LOG_FUNC
   230     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_STARTL_ENTRY );
       
   231     
   210     if (IsActive())
   232     if (IsActive())
   211         {
   233         {
       
   234         OstTraceFunctionExit0( CDEVICEEVENTQUEUE_STARTL_EXIT );
   212         return;
   235         return;
   213         }
   236         }
   214 
   237 
   215     if (IsEventAvailable())
   238     if (IsEventAvailable())
   216         {
   239         {
   217         SendEventL();
   240         SendEventL();
   218         }
   241         }
       
   242     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_STARTL_EXIT_DUP1 );
   219     }
   243     }
   220 
   244 
   221 void CDeviceEventQueue::SendEventL()
   245 void CDeviceEventQueue::SendEventL()
   222     {
   246     {
   223     LOG_FUNC     
   247     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_SENDEVENTL_ENTRY );
       
   248          
   224     // If the handler is available, sending oldest event to it
   249     // If the handler is available, sending oldest event to it
   225     iHandler->HandleEventL(iStatus, Pop());
   250     iHandler->HandleEventL(iStatus, Pop());
   226         
   251         
   227     // Activiate the manager again to wait for the handler 
   252     // Activiate the manager again to wait for the handler 
   228     // finish current event
   253     // finish current event
   229     SetActive();
   254     SetActive();
       
   255     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_SENDEVENTL_EXIT );
   230     }
   256     }
   231 
   257 
   232 TDeviceEvent CDeviceEventQueue::Pop()
   258 TDeviceEvent CDeviceEventQueue::Pop()
   233     {
   259     {
   234     LOG_FUNC
   260     OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_POP_ENTRY );
       
   261     
   235     TDeviceEvent event = iEventArray[0];
   262     TDeviceEvent event = iEventArray[0];
   236     iEventArray.Remove(0);
   263     iEventArray.Remove(0);
       
   264     OstTraceFunctionExit0( CDEVICEEVENTQUEUE_POP_EXIT );
   237     return event;
   265     return event;
   238     }
   266     }
   239 
   267 
   240 // End of file
   268 // End of file