sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* Base class functionality for server-side asynchronous requests.
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
@file
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
#include <scs/scsserver.h>
|
sl@0
|
26 |
#include "scsserverconstants.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
EXPORT_C CAsyncRequest::CAsyncRequest(CScsSession* aSession, CScsSubsession* aSubsession, const RMessage2& aMessage)
|
sl@0
|
29 |
/**
|
sl@0
|
30 |
Record the session, subsession, and function associated with this request.
|
sl@0
|
31 |
These are required to complete or to cancel the request later.
|
sl@0
|
32 |
|
sl@0
|
33 |
Adds this object to the active scheduler.
|
sl@0
|
34 |
|
sl@0
|
35 |
@param aSession Session used to launch this request.
|
sl@0
|
36 |
@param aSubsession Subsession on which this request is queued. This
|
sl@0
|
37 |
should be NULL if the request is relative to a session,
|
sl@0
|
38 |
instead of a subsession
|
sl@0
|
39 |
@param aMessage Handle to the kernel-side request object, which
|
sl@0
|
40 |
will be completed later.
|
sl@0
|
41 |
*/
|
sl@0
|
42 |
: CActive(CActive::EPriorityStandard),
|
sl@0
|
43 |
iSession(aSession),
|
sl@0
|
44 |
iSubsession(aSubsession),
|
sl@0
|
45 |
iMessagePtr2(aMessage)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
// extract implementation function
|
sl@0
|
48 |
ScsImpl::ExtractScsAndImplFunctions(aMessage, NULL, &iFunction);
|
sl@0
|
49 |
|
sl@0
|
50 |
CActiveScheduler::Add(this);
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
EXPORT_C void CAsyncRequest::TransferToScsFrameworkL()
|
sl@0
|
54 |
/**
|
sl@0
|
55 |
Adds this asynchronous request to the global collection.
|
sl@0
|
56 |
This should be called after the subclass has performed its
|
sl@0
|
57 |
own initialization, but before the active request has been
|
sl@0
|
58 |
set up.
|
sl@0
|
59 |
*/
|
sl@0
|
60 |
{
|
sl@0
|
61 |
iSession->iServer.AddAsyncRequestL(this);
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
EXPORT_C void CAsyncRequest::RunL()
|
sl@0
|
65 |
/**
|
sl@0
|
66 |
Implement CActive by completing the server client's request status
|
sl@0
|
67 |
with the AO error code, i.e. iStatus. This function also marks this
|
sl@0
|
68 |
object for deletion.
|
sl@0
|
69 |
|
sl@0
|
70 |
If a subclass overrides this implementation then it must call
|
sl@0
|
71 |
CompleteAndMarkForDeletion itself to complete the client-side
|
sl@0
|
72 |
request.
|
sl@0
|
73 |
|
sl@0
|
74 |
@see CompleteAndMarkForDeletion
|
sl@0
|
75 |
*/
|
sl@0
|
76 |
{
|
sl@0
|
77 |
TInt r = iStatus.Int();
|
sl@0
|
78 |
CompleteAndMarkForDeletion(r);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
EXPORT_C TInt CAsyncRequest::RunError(TInt aError)
|
sl@0
|
82 |
/**
|
sl@0
|
83 |
Override CActive by completing the request with the
|
sl@0
|
84 |
supplied error code and marking this object for deletion.
|
sl@0
|
85 |
The default implementation of RunL cannot leave, but the
|
sl@0
|
86 |
subclass may override it with a more complex implementation.
|
sl@0
|
87 |
|
sl@0
|
88 |
@param aError Error code with which aError left.
|
sl@0
|
89 |
@return KErrNone, meaning do not propagate
|
sl@0
|
90 |
the error to the active scheduler.
|
sl@0
|
91 |
*/
|
sl@0
|
92 |
{
|
sl@0
|
93 |
CompleteAndMarkForDeletion(aError);
|
sl@0
|
94 |
return KErrNone;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
void CAsyncRequest::CancelCompleteAndMarkForDeletion()
|
sl@0
|
98 |
/**
|
sl@0
|
99 |
Cancel this asynchronous request and complete the client
|
sl@0
|
100 |
request with KErrCancel. On exit, this object has been
|
sl@0
|
101 |
marked for deletion.
|
sl@0
|
102 |
*/
|
sl@0
|
103 |
{
|
sl@0
|
104 |
CompleteAndMarkForDeletion(KErrCancel);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
EXPORT_C void CAsyncRequest::CompleteAndMarkForDeletion(TInt aError)
|
sl@0
|
108 |
/**
|
sl@0
|
109 |
Completes the client-side request associated with this
|
sl@0
|
110 |
asynchronous request and marks this object for deletion.
|
sl@0
|
111 |
|
sl@0
|
112 |
If the error was because the client passed a bad descriptor then
|
sl@0
|
113 |
panick the client instead of completing the request for consistency
|
sl@0
|
114 |
with synchronous requests.
|
sl@0
|
115 |
|
sl@0
|
116 |
@param aError Error code with which the client request
|
sl@0
|
117 |
will be completed.
|
sl@0
|
118 |
*/
|
sl@0
|
119 |
{
|
sl@0
|
120 |
if (aError == KErrBadDescriptor)
|
sl@0
|
121 |
PanicClient(iMessagePtr2, ScsImpl::EScsClBadDesc);
|
sl@0
|
122 |
else
|
sl@0
|
123 |
iMessagePtr2.Complete(aError);
|
sl@0
|
124 |
MarkForDeletion();
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
void CAsyncRequest::MarkForDeletion()
|
sl@0
|
128 |
/**
|
sl@0
|
129 |
Mark this outstanding request for deletion, so it is
|
sl@0
|
130 |
cleaned up when the cleanup AO runs.
|
sl@0
|
131 |
*/
|
sl@0
|
132 |
{
|
sl@0
|
133 |
DoCleanup();
|
sl@0
|
134 |
// The deletion is processed at priority CActive::EPriorityHigh,
|
sl@0
|
135 |
// so should happen ahead of any pending or new requests.
|
sl@0
|
136 |
CAsyncCallBack* acb = iSession->iServer.iAsyncCleanup;
|
sl@0
|
137 |
acb->CallBack(); // no effect if already queued
|
sl@0
|
138 |
iSession = NULL; // mark for deletion
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
EXPORT_C void CAsyncRequest::DoCleanup()
|
sl@0
|
142 |
/**
|
sl@0
|
143 |
This virtual function is called whenever the SCS needs to cancel an operation.
|
sl@0
|
144 |
|
sl@0
|
145 |
If the asynchronous request implementation ALWAYS has an internal request active
|
sl@0
|
146 |
for the duration of the client request, then this default implementation can be used, which
|
sl@0
|
147 |
simply calls CActive::Cancel which will call the derived classe's DoCancel (if, and only if
|
sl@0
|
148 |
the object IsActive).
|
sl@0
|
149 |
|
sl@0
|
150 |
A more complex case is where the asynchronous requests may enter an internal queue where
|
sl@0
|
151 |
the client request is (obviously still active), but the derived class has not outstanding request.
|
sl@0
|
152 |
In this case the default implementation will cause a HANG, because Cancel will not call DoCancel if
|
sl@0
|
153 |
the object is not active...
|
sl@0
|
154 |
|
sl@0
|
155 |
In the generic case, the derived class should provide an overload for the Cleanup method.
|
sl@0
|
156 |
This function should call Cancel to cancel any outstanding operation, then perform whatever other
|
sl@0
|
157 |
cleanup is required to cleanup the request (closing handles, removing from queues etc).
|
sl@0
|
158 |
The framework will then complete the client request.
|
sl@0
|
159 |
|
sl@0
|
160 |
nb. The destructor of the CAsyncRequest may not run until sometime after the client request has been
|
sl@0
|
161 |
completed.
|
sl@0
|
162 |
*/
|
sl@0
|
163 |
{
|
sl@0
|
164 |
Cancel();
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|