examples/SFExamples/Symbian_OS_Explained_Hercules-v9_Example_Code/src/asynchandler.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 // asynchandler.cpp
00017 // Skeleton active object, for asynchronous server requests
00018 
00019 #include <e32base.h>
00020 #include "server.h"
00021 
00022 CAsyncHandler* CAsyncHandler::NewL()
00023         {
00024         CAsyncHandler* me = CAsyncHandler::NewLC();
00025         CleanupStack::Pop(me);
00026         return (me);
00027         }
00028 
00029 CAsyncHandler* CAsyncHandler::NewLC()
00030         {
00031         CAsyncHandler* me = new (ELeave) CAsyncHandler();
00032         CleanupStack::PushL(me);
00033         me->ConstructL();
00034         return (me);
00035         }
00036 
00037 CAsyncHandler::~CAsyncHandler()
00038         {
00039         Cancel();
00040         iTimer.Close(); 
00041         }
00042 
00043 CAsyncHandler::CAsyncHandler()
00044 : CActive(EPriorityStandard) 
00045         { 
00046         CActiveScheduler::Add(this); 
00047         }
00048 
00049 void CAsyncHandler::ConstructL()
00050         {
00051         User::LeaveIfError(iTimer.CreateLocal());
00052         }
00053 
00054 void CAsyncHandler::ServiceAsyncRequest(const RMessage2& aMessage)
00055         {// Only allow one request to be submitted at a time
00056         _LIT(KOutstandingRequestPanic, "InUse");
00057         __ASSERT_ALWAYS(!IsActive(), User::Panic(KOutstandingRequestPanic, KErrInUse));
00058         iMessage = aMessage;
00059         iTimer.After(iStatus, 2000000); // Set the RTimer to expire in 2 seconds
00060         SetActive(); // Mark this object active 
00061         }
00062 
00063 void CAsyncHandler::DoCancel()
00064         {
00065         iTimer.Cancel();
00066         iMessage.Complete(KErrCancel);
00067         }
00068 
00069 void CAsyncHandler::RunL()
00070         {
00071         iMessage.Complete(iStatus.Int());
00072         }
00073 

Generated by  doxygen 1.6.2