0
|
1 |
// Copyright (c) 1995-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 the License "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 |
// e32\euser\us_mes.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "us_std.h"
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
EXPORT_C void RServer2::Receive(RMessage2& aMessage)
|
|
24 |
//
|
|
25 |
// Receive a message for the server synchronously.
|
|
26 |
//
|
|
27 |
{
|
|
28 |
TRequestStatus s;
|
|
29 |
Receive(aMessage,s);
|
|
30 |
User::WaitForRequest(s);
|
|
31 |
__ASSERT_ALWAYS(s==KErrNone,Panic(ETMesReceiveFailed));
|
|
32 |
}
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
GLDEF_C void CompleteRequest(TRequestStatus &aStatus,TInt aCode)
|
|
37 |
{
|
|
38 |
TRequestStatus *pS=(&aStatus);
|
|
39 |
User::RequestComplete(pS,aCode);
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
EXPORT_C TInt RSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs) const
|
|
45 |
//
|
|
46 |
// Send a message and wait for the reply synchronously.
|
|
47 |
//
|
|
48 |
{
|
|
49 |
if (TUint(aFunction)<=TUint(KMaxTInt))
|
|
50 |
return SendSync(aFunction,aArgs);
|
|
51 |
|
|
52 |
Panic(ETMesBadFunctionNumber);
|
|
53 |
return 0;
|
|
54 |
}
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
EXPORT_C TInt RSessionBase::DoSend(TInt aFunction,const TIpcArgs* aArgs) const
|
|
59 |
//
|
|
60 |
// Send a blind message to the server.
|
|
61 |
//
|
|
62 |
{
|
|
63 |
if (TUint(aFunction)<=TUint(KMaxTInt))
|
|
64 |
return SendAsync(aFunction,aArgs,NULL);
|
|
65 |
|
|
66 |
Panic(ETMesBadFunctionNumber);
|
|
67 |
return 0;
|
|
68 |
}
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
EXPORT_C void RSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs,TRequestStatus &aStatus) const
|
|
73 |
//
|
|
74 |
// Send a message and wait for the reply asynchronously.
|
|
75 |
//
|
|
76 |
{
|
|
77 |
if (TUint(aFunction)<=TUint(KMaxTInt))
|
|
78 |
{
|
|
79 |
aStatus=KRequestPending;
|
|
80 |
TInt r=SendAsync(aFunction,aArgs,&aStatus);
|
|
81 |
if (r!=KErrNone)
|
|
82 |
::CompleteRequest(aStatus,r);
|
|
83 |
}
|
|
84 |
else
|
|
85 |
Panic(ETMesBadFunctionNumber);
|
|
86 |
}
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
TInt RSubSessionBase::DoCreateSubSession(RSessionBase& aSession,TInt aFunction,const TIpcArgs* aArgs, TBool aAutoClose)
|
|
91 |
{
|
|
92 |
TIpcArgs a;
|
|
93 |
if (aArgs!=NULL)
|
|
94 |
{
|
|
95 |
a.iArgs[0] = aArgs->iArgs[0];
|
|
96 |
a.iArgs[1] = aArgs->iArgs[1];
|
|
97 |
a.iArgs[2] = aArgs->iArgs[2];
|
|
98 |
a.iFlags = aArgs->iFlags;
|
|
99 |
}
|
|
100 |
TPckgBuf<TInt> reply;
|
|
101 |
a.Set(3,&reply);
|
|
102 |
TInt r=aSession.SendReceive(aFunction,a);
|
|
103 |
if (r==KErrNone)
|
|
104 |
{
|
|
105 |
iSubSessionHandle=reply();
|
|
106 |
if (aAutoClose)
|
|
107 |
{
|
|
108 |
iSession=aSession;
|
|
109 |
// set the caller's session handle to NULL to discourage the caller from closing it.
|
|
110 |
aSession.SetHandle(KNullHandle);
|
|
111 |
}
|
|
112 |
else
|
|
113 |
{
|
|
114 |
// Set session handle with 'no close' set, to prevent CloseSubSession()
|
|
115 |
// from closing down the session
|
|
116 |
iSession.SetHandleNC(aSession.Handle());
|
|
117 |
}
|
|
118 |
}
|
|
119 |
else
|
|
120 |
{
|
|
121 |
iSubSessionHandle=0;
|
|
122 |
iSession.SetHandle(KNullHandle);
|
|
123 |
// Close the caller's session so it isn't left orphaned
|
|
124 |
if (aAutoClose)
|
|
125 |
aSession.Close();
|
|
126 |
}
|
|
127 |
return(r);
|
|
128 |
}
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
EXPORT_C TInt RSubSessionBase::DoCreateSubSession(const RSessionBase& aSession,TInt aFunction,const TIpcArgs* aArgs)
|
|
133 |
{
|
|
134 |
// need to cast away const
|
|
135 |
return DoCreateSubSession( (RSessionBase&) aSession, aFunction, aArgs, EFalse);
|
|
136 |
}
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
/**
|
|
141 |
Creates a new sub-session within an existing session. The new sub-session takes
|
|
142 |
ownership of the session so that when the sub-session is closed, the session is
|
|
143 |
closed too. If the creation of the sub-session fails, the session is closed immediately.
|
|
144 |
In other words, this method will always take ownership of the session, whether it succeeds
|
|
145 |
or not and the caller should never need to close it.
|
|
146 |
|
|
147 |
@param aSession The session to which this sub-session will belong.
|
|
148 |
@param aFunction The opcode specifying the requested service;
|
|
149 |
the server should interpret this as a request to create
|
|
150 |
a sub-session.
|
|
151 |
@param aArgs The arguments to be sent to the server as part of the
|
|
152 |
sub-session create request. The fourth argument is not
|
|
153 |
sent to the server, instead it is replaced with a descriptor
|
|
154 |
reference to the 32bit value where the server should store
|
|
155 |
the handle of the created sub-session.
|
|
156 |
|
|
157 |
@return KErrNone if successful, otherwise one of the other system-wide error
|
|
158 |
codes.
|
|
159 |
|
|
160 |
*/
|
|
161 |
EXPORT_C TInt RSubSessionBase::CreateAutoCloseSubSession(RSessionBase& aSession,TInt aFunction,const TIpcArgs& aArgs)
|
|
162 |
{
|
|
163 |
return DoCreateSubSession(aSession, aFunction, &aArgs, ETrue);
|
|
164 |
}
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
/**
|
|
169 |
Returns a copy of the session associated with this sub-session.
|
|
170 |
|
|
171 |
@return a copy of the session
|
|
172 |
*/
|
|
173 |
EXPORT_C const RSessionBase RSubSessionBase::Session() const
|
|
174 |
{
|
|
175 |
RSessionBase session = iSession;
|
|
176 |
|
|
177 |
// If this is a "normal" subsession, then the ENoClose flag will be set
|
|
178 |
// to prevent the closing of the subsession from closing down the main session
|
|
179 |
// so in this case we need to turn the ENoClose flag OFF to allow someone
|
|
180 |
// to use the returned session to call RSessionBase::Close().
|
|
181 |
// If this is a "autoclose" subsession, then the ENoClose flag will be clear
|
|
182 |
// to allow the closing of the subsession to close down the main session
|
|
183 |
// so in this case we need to turn the ENoClose flag ON to stop someone from
|
|
184 |
// using the returned session to call RSessionBase::Close().
|
|
185 |
session.iHandle ^= CObjectIx::ENoClose;
|
|
186 |
|
|
187 |
|
|
188 |
return session;
|
|
189 |
}
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
/**
|
|
194 |
Closes the sub-session.
|
|
195 |
|
|
196 |
@param aFunction The opcode specifying the requested service;
|
|
197 |
the server should interpret this as a request to close
|
|
198 |
the sub-session.
|
|
199 |
*/
|
|
200 |
EXPORT_C void RSubSessionBase::CloseSubSession(TInt aFunction)
|
|
201 |
{
|
|
202 |
if (iSubSessionHandle)
|
|
203 |
{
|
|
204 |
iSession.SendReceive(aFunction,TIpcArgs(TIpcArgs::ENothing,TIpcArgs::ENothing,TIpcArgs::ENothing,iSubSessionHandle));
|
|
205 |
iSubSessionHandle=KNullHandle;
|
|
206 |
|
|
207 |
// Close the session - will only work if CObjectIx::ENoClose is clear
|
|
208 |
// i.e. the sub-session was created using CreateAutoCloseSubSession()
|
|
209 |
iSession.Close();
|
|
210 |
}
|
|
211 |
}
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
EXPORT_C TInt RSubSessionBase::DoSend(TInt aFunction,const TIpcArgs* aArgs) const
|
|
216 |
//
|
|
217 |
// Blind send.
|
|
218 |
//
|
|
219 |
{
|
|
220 |
TIpcArgs a;
|
|
221 |
if(aArgs)
|
|
222 |
{
|
|
223 |
a.iArgs[0] = aArgs->iArgs[0];
|
|
224 |
a.iArgs[1] = aArgs->iArgs[1];
|
|
225 |
a.iArgs[2] = aArgs->iArgs[2];
|
|
226 |
a.iFlags = aArgs->iFlags&((1<<(3*TIpcArgs::KBitsPerType))-1);
|
|
227 |
}
|
|
228 |
a.iArgs[3] = iSubSessionHandle;
|
|
229 |
return(iSession.Send(aFunction,a));
|
|
230 |
}
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
EXPORT_C void RSubSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs,TRequestStatus &aStatus) const
|
|
235 |
//
|
|
236 |
// Send and wait for reply asynchronously.
|
|
237 |
//
|
|
238 |
{
|
|
239 |
TIpcArgs a;
|
|
240 |
if(aArgs)
|
|
241 |
{
|
|
242 |
a.iArgs[0] = aArgs->iArgs[0];
|
|
243 |
a.iArgs[1] = aArgs->iArgs[1];
|
|
244 |
a.iArgs[2] = aArgs->iArgs[2];
|
|
245 |
a.iFlags = aArgs->iFlags&((1<<(3*TIpcArgs::KBitsPerType))-1);
|
|
246 |
}
|
|
247 |
a.iArgs[3] = iSubSessionHandle;
|
|
248 |
iSession.SendReceive(aFunction,a,aStatus);
|
|
249 |
}
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
EXPORT_C TInt RSubSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs) const
|
|
254 |
//
|
|
255 |
// Send and wait for reply synchronously.
|
|
256 |
//
|
|
257 |
{
|
|
258 |
TIpcArgs a;
|
|
259 |
if(aArgs)
|
|
260 |
{
|
|
261 |
a.iArgs[0] = aArgs->iArgs[0];
|
|
262 |
a.iArgs[1] = aArgs->iArgs[1];
|
|
263 |
a.iArgs[2] = aArgs->iArgs[2];
|
|
264 |
a.iFlags = aArgs->iFlags&((1<<(3*TIpcArgs::KBitsPerType))-1);
|
|
265 |
}
|
|
266 |
a.iArgs[3] = iSubSessionHandle;
|
|
267 |
return(iSession.SendReceive(aFunction,a));
|
|
268 |
}
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|