First public contribution.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Base class functionality for server-side asynchronous requests.
25 #include <scs/scsserver.h>
26 #include "scsserverconstants.h"
28 EXPORT_C CAsyncRequest::CAsyncRequest(CScsSession* aSession, CScsSubsession* aSubsession, const RMessage2& aMessage)
30 Record the session, subsession, and function associated with this request.
31 These are required to complete or to cancel the request later.
33 Adds this object to the active scheduler.
35 @param aSession Session used to launch this request.
36 @param aSubsession Subsession on which this request is queued. This
37 should be NULL if the request is relative to a session,
38 instead of a subsession
39 @param aMessage Handle to the kernel-side request object, which
40 will be completed later.
42 : CActive(CActive::EPriorityStandard),
44 iSubsession(aSubsession),
45 iMessagePtr2(aMessage)
47 // extract implementation function
48 ScsImpl::ExtractScsAndImplFunctions(aMessage, NULL, &iFunction);
50 CActiveScheduler::Add(this);
53 EXPORT_C void CAsyncRequest::TransferToScsFrameworkL()
55 Adds this asynchronous request to the global collection.
56 This should be called after the subclass has performed its
57 own initialization, but before the active request has been
61 iSession->iServer.AddAsyncRequestL(this);
64 EXPORT_C void CAsyncRequest::RunL()
66 Implement CActive by completing the server client's request status
67 with the AO error code, i.e. iStatus. This function also marks this
70 If a subclass overrides this implementation then it must call
71 CompleteAndMarkForDeletion itself to complete the client-side
74 @see CompleteAndMarkForDeletion
77 TInt r = iStatus.Int();
78 CompleteAndMarkForDeletion(r);
81 EXPORT_C TInt CAsyncRequest::RunError(TInt aError)
83 Override CActive by completing the request with the
84 supplied error code and marking this object for deletion.
85 The default implementation of RunL cannot leave, but the
86 subclass may override it with a more complex implementation.
88 @param aError Error code with which aError left.
89 @return KErrNone, meaning do not propagate
90 the error to the active scheduler.
93 CompleteAndMarkForDeletion(aError);
97 void CAsyncRequest::CancelCompleteAndMarkForDeletion()
99 Cancel this asynchronous request and complete the client
100 request with KErrCancel. On exit, this object has been
104 CompleteAndMarkForDeletion(KErrCancel);
107 EXPORT_C void CAsyncRequest::CompleteAndMarkForDeletion(TInt aError)
109 Completes the client-side request associated with this
110 asynchronous request and marks this object for deletion.
112 If the error was because the client passed a bad descriptor then
113 panick the client instead of completing the request for consistency
114 with synchronous requests.
116 @param aError Error code with which the client request
120 if (aError == KErrBadDescriptor)
121 PanicClient(iMessagePtr2, ScsImpl::EScsClBadDesc);
123 iMessagePtr2.Complete(aError);
127 void CAsyncRequest::MarkForDeletion()
129 Mark this outstanding request for deletion, so it is
130 cleaned up when the cleanup AO runs.
134 // The deletion is processed at priority CActive::EPriorityHigh,
135 // so should happen ahead of any pending or new requests.
136 CAsyncCallBack* acb = iSession->iServer.iAsyncCleanup;
137 acb->CallBack(); // no effect if already queued
138 iSession = NULL; // mark for deletion
141 EXPORT_C void CAsyncRequest::DoCleanup()
143 This virtual function is called whenever the SCS needs to cancel an operation.
145 If the asynchronous request implementation ALWAYS has an internal request active
146 for the duration of the client request, then this default implementation can be used, which
147 simply calls CActive::Cancel which will call the derived classe's DoCancel (if, and only if
148 the object IsActive).
150 A more complex case is where the asynchronous requests may enter an internal queue where
151 the client request is (obviously still active), but the derived class has not outstanding request.
152 In this case the default implementation will cause a HANG, because Cancel will not call DoCancel if
153 the object is not active...
155 In the generic case, the derived class should provide an overload for the Cleanup method.
156 This function should call Cancel to cancel any outstanding operation, then perform whatever other
157 cleanup is required to cleanup the request (closing handles, removing from queues etc).
158 The framework will then complete the client request.
160 nb. The destructor of the CAsyncRequest may not run until sometime after the client request has been