telephonyserverplugins/ctsydispatchlayer/src/requestqueueoneshot.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "requestqueueoneshot.h"
       
    17 #include "mdispatchercallback.h"
       
    18 #include <ctsy/ltsy/ltsylogger.h>
       
    19 #include "ctsydispatcherpanic.h"
       
    20 #include <ctsy/pluginapi/cmmdatapackage.h>
       
    21 
       
    22 const TInt KNoIpc = -1;
       
    23 
       
    24 CRequestQueueOneShot::TIpcDataPackage::TIpcDataPackage()
       
    25 	: iIpc(KNoIpc), 
       
    26 	  iDataPackage(NULL), 
       
    27 	  iResultCode(KErrNone), 
       
    28 	  iCleanupOnly(EFalse), 
       
    29 	  iDispatcherCallback(NULL) ,
       
    30 	  iLink()
       
    31 	{
       
    32 	} // CRequestQueueOneShot::TIpcDataPackage::TIpcDataPackage
       
    33 
       
    34 CRequestQueueOneShot::TIpcDataPackage::~TIpcDataPackage()
       
    35 	{
       
    36 	delete iDataPackage;
       
    37 	iDataPackage = NULL;
       
    38 	} // CRequestQueueOneShot::TIpcDataPackage::~TIpcDataPackage
       
    39 
       
    40 CRequestQueueOneShot::CRequestQueueOneShot()
       
    41 	: CAsyncOneShot(CActive::EPriorityStandard),
       
    42 	  iIpcQueue(_FOFF(TIpcDataPackage,iLink))
       
    43 	{
       
    44 	} // CRequestQueueOneShot::CRequestQueueOneShot
       
    45 
       
    46 
       
    47 CRequestQueueOneShot::~CRequestQueueOneShot()
       
    48 	{
       
    49 	TSYLOGENTRYEXIT;
       
    50 	
       
    51 	Cancel();
       
    52 
       
    53 	TIpcDataPackage* ipcDataPackage;
       
    54 	while (!iIpcQueue.IsEmpty())
       
    55 		{
       
    56 		ipcDataPackage = iIpcQueue.First();
       
    57 		iIpcQueue.Remove(*ipcDataPackage);
       
    58 		ipcDataPackage->iCleanupOnly = ETrue;
       
    59 		// Callback to dispatcher to ensure that dispatcher cleans up any heap data
       
    60 		// in the CMmDataPackage inside the TIpcDataPackage.
       
    61 		ipcDataPackage->iDispatcherCallback->CallbackSync(*ipcDataPackage);
       
    62 		}
       
    63 	
       
    64 	} // CRequestQueueOneShot::~CRequestQueueOneShot
       
    65 
       
    66 
       
    67 CRequestQueueOneShot* CRequestQueueOneShot::NewLC()
       
    68 	{
       
    69 	CRequestQueueOneShot* self = new (ELeave)CRequestQueueOneShot();
       
    70 	CleanupStack::PushL (self);
       
    71 	self->ConstructL();
       
    72 	return self;
       
    73 	} // CRequestQueueOneShot::NewLC
       
    74 
       
    75 
       
    76 CRequestQueueOneShot* CRequestQueueOneShot::NewL()
       
    77 	{
       
    78 	TSYLOGENTRYEXIT;
       
    79 	CRequestQueueOneShot* self = CRequestQueueOneShot::NewLC();
       
    80 	CleanupStack::Pop(self);
       
    81 	return self;
       
    82 	} // CRequestQueueOneShot::NewL
       
    83 
       
    84 
       
    85 void CRequestQueueOneShot::ConstructL()
       
    86 	{
       
    87 	} // CRequestQueueOneShot::ConstructL
       
    88 
       
    89 
       
    90 void CRequestQueueOneShot::QueueRequest(TIpcDataPackage& aIpcDataPackage)
       
    91 /**
       
    92  * Add the request to the queue.
       
    93  * 
       
    94  * @param aIpcDataPackage The encapsulated request to add to the queue.
       
    95  */
       
    96 	{
       
    97 	TSYLOGENTRYEXITARGS(_L8("IPC=%d,err=%d"), aIpcDataPackage.iIpc, aIpcDataPackage.iResultCode);
       
    98 
       
    99 	__ASSERT_DEBUG(aIpcDataPackage.iDispatcherCallback != NULL, CtsyDispatcherPanic(EInvalidNullPtr)); 
       
   100 	aIpcDataPackage.iCleanupOnly = EFalse;
       
   101 	iIpcQueue.AddLast(aIpcDataPackage);
       
   102 	
       
   103 	// This object is only active if there is something in the queue
       
   104 	if (!IsActive())
       
   105 		{
       
   106 		Call();
       
   107 		}
       
   108 	
       
   109 	} // CRequestQueueOneShot::QueueRequest
       
   110 
       
   111 
       
   112 void CRequestQueueOneShot::DoCancel()
       
   113 	{
       
   114 	} // CRequestQueueOneShot::DoCancel
       
   115 
       
   116 
       
   117 void CRequestQueueOneShot::RunL()
       
   118 /**
       
   119  * Completes the request at the head of the queue.
       
   120  */
       
   121 	{
       
   122 	TSYLOGENTRYEXIT;
       
   123 	
       
   124 	if (iStatus == KErrNone)
       
   125 		{
       
   126 		__ASSERT_DEBUG(!iIpcQueue.IsEmpty(), CtsyDispatcherPanic(ERequestNotFound));
       
   127 		TIpcDataPackage* ipcDataPackage = iIpcQueue.First();
       
   128 		iIpcQueue.Remove(*ipcDataPackage);
       
   129 		ipcDataPackage->iDispatcherCallback->CallbackSync(*ipcDataPackage);
       
   130 		}
       
   131 	
       
   132 	if (!iIpcQueue.IsEmpty())
       
   133 		{
       
   134 		Call(); // Restart active object to process next request at the head of the queue
       
   135 		}
       
   136 	
       
   137 	} // CRequestQueueOneShot::RunL
       
   138 
       
   139