serviceproviders/sapi_mediamanagement/mediamanagementservice/src/asynchrequestmanager.cpp
changeset 22 fc9cf246af83
equal deleted inserted replaced
19:989d2f495d90 22:fc9cf246af83
       
     1 /*
       
     2 * Copyright (c) 2002 - 2007 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 the License "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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <apgcli.h>
       
    21 
       
    22 #include "asynchrequestmanager.h"
       
    23 #include "mgclfoperationobserver.h"
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CCAsynchRequestManager ::NewLC
       
    27 // Returns the instance of CCAsynchRequestManager  class.
       
    28 // -----------------------------------------------------------------------------
       
    29 CAsynchRequestManager * CAsynchRequestManager ::NewL()
       
    30 	{
       
    31 	CAsynchRequestManager * self = new ( ELeave )CAsynchRequestManager ();
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CCAsynchRequestManager ::~CCAsynchRequestManager
       
    38 // Destructor
       
    39 // -----------------------------------------------------------------------------
       
    40 
       
    41 CAsynchRequestManager ::~CAsynchRequestManager ()
       
    42 	{
       
    43 
       
    44 	//Cancel All pending request
       
    45 
       
    46 	TInt pos = iAsyncObjArray.Count() - 1;
       
    47 	TAsyncRequestInfo obj;
       
    48 	for ( ; pos >= 0; pos-- )
       
    49 		{
       
    50 		obj = iAsyncObjArray[pos];
       
    51 		//No need to inform for this cancel
       
    52 	
       
    53 	    obj.iAsyncObj->CancelL();
       
    54 	    delete obj.iAsyncObj;
       
    55 		}
       
    56     iAsyncObjArray.Close();
       
    57 
       
    58     }
       
    59 
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CCAsynchRequestManager ::Cancel
       
    64 // Cancel the pending asynchronous request
       
    65 // -----------------------------------------------------------------------------
       
    66 TInt CAsynchRequestManager ::Cancel( TInt32 aTransactionID )
       
    67 	{
       
    68 
       
    69     TInt pos = iAsyncObjArray.Count() - 1;
       
    70 	TAsyncRequestInfo obj;
       
    71 	for ( ; pos >= 0; pos-- )
       
    72 		{
       
    73 		obj = iAsyncObjArray[pos];
       
    74 		if( obj.iTransactionId == aTransactionID )
       
    75 			{
       
    76 			obj.iAsyncObj->CancelL();
       
    77 			delete obj.iAsyncObj;
       
    78 	    	return KErrNone;
       
    79 			}
       
    80 		}
       
    81 	return KErrNotFound;
       
    82 
       
    83 	}
       
    84 
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CCAsynchRequestManager ::RequestComplete
       
    88 // This is called by the observer when asynch request complete
       
    89 // -----------------------------------------------------------------------------
       
    90 void CAsynchRequestManager ::RequestComplete( TInt32 aTransactionID )
       
    91 
       
    92 	{
       
    93     TInt pos = iAsyncObjArray.Count()-1;
       
    94 	TAsyncRequestInfo obj;
       
    95 	for ( ; pos >= 0; pos-- )
       
    96 		{
       
    97 		obj = iAsyncObjArray[pos];
       
    98 		if( obj.iTransactionId == aTransactionID )
       
    99 			{
       
   100 			iAsyncObjArray.Remove(pos);
       
   101 			iAsyncObjArray.Compress();
       
   102 			return;
       
   103 			}
       
   104 		}
       
   105 	}
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CAsynchRequestManager ::AddObserverL
       
   109 // AddObserever
       
   110 // -----------------------------------------------------------------------------
       
   111 void CAsynchRequestManager ::AddObserverL(CClfOperationObserver* aServiceObserver, TUint aTransactionID)
       
   112 
       
   113 	{
       
   114     // Add the given observer in array and return the laucher observer
       
   115     // strutcure for binding the transaction ID and callback object
       
   116 
       
   117     TAsyncRequestInfo asyncRequestInfo;
       
   118 	asyncRequestInfo.iTransactionId = aTransactionID;
       
   119 
       
   120 	//observer for observering underlying classes
       
   121 	asyncRequestInfo.iAsyncObj = aServiceObserver;
       
   122 
       
   123 	User::LeaveIfError( iAsyncObjArray.Append( asyncRequestInfo ) );
       
   124 
       
   125    	}
       
   126 
       
   127 
       
   128 
       
   129 
       
   130 
       
   131