First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\us_mes.cpp
23 EXPORT_C void RServer2::Receive(RMessage2& aMessage)
25 // Receive a message for the server synchronously.
30 User::WaitForRequest(s);
31 __ASSERT_ALWAYS(s==KErrNone,Panic(ETMesReceiveFailed));
36 GLDEF_C void CompleteRequest(TRequestStatus &aStatus,TInt aCode)
38 TRequestStatus *pS=(&aStatus);
39 User::RequestComplete(pS,aCode);
44 EXPORT_C TInt RSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs) const
46 // Send a message and wait for the reply synchronously.
49 if (TUint(aFunction)<=TUint(KMaxTInt))
50 return SendSync(aFunction,aArgs);
52 Panic(ETMesBadFunctionNumber);
58 EXPORT_C TInt RSessionBase::DoSend(TInt aFunction,const TIpcArgs* aArgs) const
60 // Send a blind message to the server.
63 if (TUint(aFunction)<=TUint(KMaxTInt))
64 return SendAsync(aFunction,aArgs,NULL);
66 Panic(ETMesBadFunctionNumber);
72 EXPORT_C void RSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs,TRequestStatus &aStatus) const
74 // Send a message and wait for the reply asynchronously.
77 if (TUint(aFunction)<=TUint(KMaxTInt))
79 aStatus=KRequestPending;
80 TInt r=SendAsync(aFunction,aArgs,&aStatus);
82 ::CompleteRequest(aStatus,r);
85 Panic(ETMesBadFunctionNumber);
90 TInt RSubSessionBase::DoCreateSubSession(RSessionBase& aSession,TInt aFunction,const TIpcArgs* aArgs, TBool aAutoClose)
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;
100 TPckgBuf<TInt> reply;
102 TInt r=aSession.SendReceive(aFunction,a);
105 iSubSessionHandle=reply();
109 // set the caller's session handle to NULL to discourage the caller from closing it.
110 aSession.SetHandle(KNullHandle);
114 // Set session handle with 'no close' set, to prevent CloseSubSession()
115 // from closing down the session
116 iSession.SetHandleNC(aSession.Handle());
122 iSession.SetHandle(KNullHandle);
123 // Close the caller's session so it isn't left orphaned
132 EXPORT_C TInt RSubSessionBase::DoCreateSubSession(const RSessionBase& aSession,TInt aFunction,const TIpcArgs* aArgs)
134 // need to cast away const
135 return DoCreateSubSession( (RSessionBase&) aSession, aFunction, aArgs, EFalse);
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.
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
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.
157 @return KErrNone if successful, otherwise one of the other system-wide error
161 EXPORT_C TInt RSubSessionBase::CreateAutoCloseSubSession(RSessionBase& aSession,TInt aFunction,const TIpcArgs& aArgs)
163 return DoCreateSubSession(aSession, aFunction, &aArgs, ETrue);
169 Returns a copy of the session associated with this sub-session.
171 @return a copy of the session
173 EXPORT_C const RSessionBase RSubSessionBase::Session() const
175 RSessionBase session = iSession;
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;
194 Closes the sub-session.
196 @param aFunction The opcode specifying the requested service;
197 the server should interpret this as a request to close
200 EXPORT_C void RSubSessionBase::CloseSubSession(TInt aFunction)
202 if (iSubSessionHandle)
204 iSession.SendReceive(aFunction,TIpcArgs(TIpcArgs::ENothing,TIpcArgs::ENothing,TIpcArgs::ENothing,iSubSessionHandle));
205 iSubSessionHandle=KNullHandle;
207 // Close the session - will only work if CObjectIx::ENoClose is clear
208 // i.e. the sub-session was created using CreateAutoCloseSubSession()
215 EXPORT_C TInt RSubSessionBase::DoSend(TInt aFunction,const TIpcArgs* aArgs) const
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);
228 a.iArgs[3] = iSubSessionHandle;
229 return(iSession.Send(aFunction,a));
234 EXPORT_C void RSubSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs,TRequestStatus &aStatus) const
236 // Send and wait for reply asynchronously.
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);
247 a.iArgs[3] = iSubSessionHandle;
248 iSession.SendReceive(aFunction,a,aStatus);
253 EXPORT_C TInt RSubSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs) const
255 // Send and wait for reply synchronously.
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);
266 a.iArgs[3] = iSubSessionHandle;
267 return(iSession.SendReceive(aFunction,a));