os/kernelhwsrv/kernel/eka/euser/us_mes.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/euser/us_mes.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,274 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\euser\us_mes.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "us_std.h"
    1.22 +
    1.23 +
    1.24 +
    1.25 +
    1.26 +EXPORT_C void RServer2::Receive(RMessage2& aMessage)
    1.27 +//
    1.28 +// Receive a message for the server synchronously.
    1.29 +//
    1.30 +	{
    1.31 +	TRequestStatus s;
    1.32 +	Receive(aMessage,s);
    1.33 +	User::WaitForRequest(s);
    1.34 +	__ASSERT_ALWAYS(s==KErrNone,Panic(ETMesReceiveFailed));
    1.35 +	}
    1.36 +
    1.37 +
    1.38 +
    1.39 +GLDEF_C void CompleteRequest(TRequestStatus &aStatus,TInt aCode)
    1.40 +	{
    1.41 +	TRequestStatus *pS=(&aStatus);
    1.42 +	User::RequestComplete(pS,aCode);
    1.43 +	}
    1.44 +
    1.45 +
    1.46 +
    1.47 +EXPORT_C TInt RSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs) const
    1.48 +//
    1.49 +// Send a message and wait for the reply synchronously.
    1.50 +//
    1.51 +	{
    1.52 +	if (TUint(aFunction)<=TUint(KMaxTInt))
    1.53 +		return SendSync(aFunction,aArgs);
    1.54 +
    1.55 +	Panic(ETMesBadFunctionNumber);
    1.56 +	return 0;
    1.57 +	}
    1.58 +
    1.59 +
    1.60 +
    1.61 +EXPORT_C TInt RSessionBase::DoSend(TInt aFunction,const TIpcArgs* aArgs) const
    1.62 +//
    1.63 +// Send a blind message to the server.
    1.64 +//
    1.65 +	{
    1.66 +	if (TUint(aFunction)<=TUint(KMaxTInt))
    1.67 +		return SendAsync(aFunction,aArgs,NULL);
    1.68 +
    1.69 +	Panic(ETMesBadFunctionNumber);
    1.70 +	return 0;
    1.71 +	}
    1.72 +
    1.73 +
    1.74 +
    1.75 +EXPORT_C void RSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs,TRequestStatus &aStatus) const
    1.76 +//
    1.77 +// Send a message and wait for the reply asynchronously.
    1.78 +//
    1.79 +	{
    1.80 +	if (TUint(aFunction)<=TUint(KMaxTInt))
    1.81 +		{
    1.82 +		aStatus=KRequestPending;
    1.83 +		TInt r=SendAsync(aFunction,aArgs,&aStatus);
    1.84 +		if (r!=KErrNone)
    1.85 +			::CompleteRequest(aStatus,r);
    1.86 +		}
    1.87 +	else
    1.88 +		Panic(ETMesBadFunctionNumber);
    1.89 +	}
    1.90 +
    1.91 +
    1.92 +
    1.93 +TInt RSubSessionBase::DoCreateSubSession(RSessionBase& aSession,TInt aFunction,const TIpcArgs* aArgs, TBool aAutoClose)
    1.94 +	{
    1.95 +	TIpcArgs a;
    1.96 +	if (aArgs!=NULL)
    1.97 +		{
    1.98 +		a.iArgs[0] = aArgs->iArgs[0];
    1.99 +		a.iArgs[1] = aArgs->iArgs[1];
   1.100 +		a.iArgs[2] = aArgs->iArgs[2];
   1.101 +		a.iFlags = aArgs->iFlags;
   1.102 +		}
   1.103 +	TPckgBuf<TInt> reply;
   1.104 +	a.Set(3,&reply);
   1.105 +	TInt r=aSession.SendReceive(aFunction,a);
   1.106 +	if (r==KErrNone)
   1.107 +		{
   1.108 +		iSubSessionHandle=reply();
   1.109 +		if (aAutoClose)
   1.110 +			{
   1.111 +			iSession=aSession;
   1.112 +			// set the caller's session handle to NULL to discourage the caller from closing it.
   1.113 +			aSession.SetHandle(KNullHandle);
   1.114 +			}
   1.115 +		else
   1.116 +			{
   1.117 +			// Set session handle with 'no close' set, to prevent CloseSubSession() 
   1.118 +			// from closing down the session
   1.119 +			iSession.SetHandleNC(aSession.Handle());
   1.120 +			}
   1.121 +		}
   1.122 +	else
   1.123 +		{
   1.124 +		iSubSessionHandle=0;
   1.125 +		iSession.SetHandle(KNullHandle);
   1.126 +		// Close the caller's session so it isn't left orphaned
   1.127 +		if (aAutoClose)
   1.128 +			aSession.Close();
   1.129 +		}
   1.130 +	return(r);
   1.131 +	}
   1.132 +
   1.133 +
   1.134 +
   1.135 +EXPORT_C TInt RSubSessionBase::DoCreateSubSession(const RSessionBase& aSession,TInt aFunction,const TIpcArgs* aArgs)
   1.136 +	{
   1.137 +	// need to cast away const	
   1.138 +	return DoCreateSubSession( (RSessionBase&) aSession, aFunction, aArgs, EFalse);
   1.139 +	}
   1.140 +
   1.141 +
   1.142 +
   1.143 +/**
   1.144 +Creates a new sub-session within an existing session. The new sub-session takes 
   1.145 +ownership of the session so that when the sub-session is closed, the session is 
   1.146 +closed too. If the creation of the sub-session fails, the session is closed immediately.
   1.147 +In other words, this method will always take ownership of the session, whether it succeeds
   1.148 +or not and the caller should never need to close it.
   1.149 +
   1.150 +@param aSession The session to which this sub-session will belong.
   1.151 +@param aFunction The opcode specifying the requested service;
   1.152 +                the server should interpret this as a request to create
   1.153 +                a sub-session.
   1.154 +@param aArgs	The arguments to be sent to the server as part of the 
   1.155 +				sub-session create request. The fourth argument is not 
   1.156 +				sent to the server, instead it is replaced with a descriptor 
   1.157 +				reference to the 32bit value where the server should store 
   1.158 +				the handle of the created sub-session.
   1.159 +
   1.160 +@return KErrNone if successful, otherwise one of the other system-wide error
   1.161 +        codes.
   1.162 +
   1.163 +*/
   1.164 +EXPORT_C TInt RSubSessionBase::CreateAutoCloseSubSession(RSessionBase& aSession,TInt aFunction,const TIpcArgs& aArgs)
   1.165 +	{
   1.166 +	return DoCreateSubSession(aSession, aFunction, &aArgs, ETrue);
   1.167 +	}
   1.168 +
   1.169 +
   1.170 +
   1.171 +/**
   1.172 +Returns a copy of the session associated with this sub-session.
   1.173 +
   1.174 +@return a copy of the session
   1.175 +*/
   1.176 +EXPORT_C const RSessionBase RSubSessionBase::Session() const
   1.177 +	{
   1.178 +	RSessionBase session = iSession;
   1.179 +
   1.180 +	// If this is a "normal" subsession, then the ENoClose flag will be set
   1.181 +	// to prevent the closing of the subsession from closing down the main session
   1.182 +	// so in this case we need to turn the ENoClose flag OFF to allow someone
   1.183 +	// to use the returned session to call RSessionBase::Close().
   1.184 +	// If this is a "autoclose" subsession, then the ENoClose flag will be clear
   1.185 +	// to allow the closing of the subsession to close down the main session
   1.186 +	// so in this case we need to turn the ENoClose flag ON to stop someone from
   1.187 +	// using the returned session to call RSessionBase::Close().
   1.188 +	session.iHandle ^= CObjectIx::ENoClose;
   1.189 +
   1.190 +
   1.191 +	return session;
   1.192 +	}
   1.193 +
   1.194 +
   1.195 +
   1.196 +/**
   1.197 +Closes the sub-session.
   1.198 +
   1.199 +@param aFunction The opcode specifying the requested service;
   1.200 +                 the server should interpret this as a request to close
   1.201 +                 the sub-session.
   1.202 +*/
   1.203 +EXPORT_C void RSubSessionBase::CloseSubSession(TInt aFunction)
   1.204 +	{
   1.205 +	if (iSubSessionHandle)
   1.206 +		{
   1.207 +		iSession.SendReceive(aFunction,TIpcArgs(TIpcArgs::ENothing,TIpcArgs::ENothing,TIpcArgs::ENothing,iSubSessionHandle));
   1.208 +		iSubSessionHandle=KNullHandle;
   1.209 +
   1.210 +		// Close the session - will only work if CObjectIx::ENoClose is clear 
   1.211 +		// i.e. the sub-session was created using CreateAutoCloseSubSession()
   1.212 +		iSession.Close();
   1.213 +		}
   1.214 +	}
   1.215 +
   1.216 +
   1.217 +
   1.218 +EXPORT_C TInt RSubSessionBase::DoSend(TInt aFunction,const TIpcArgs* aArgs) const
   1.219 +//
   1.220 +// Blind send. 
   1.221 +//
   1.222 +	{
   1.223 +	TIpcArgs a;
   1.224 +	if(aArgs)
   1.225 +		{
   1.226 +		a.iArgs[0] = aArgs->iArgs[0];
   1.227 +		a.iArgs[1] = aArgs->iArgs[1];
   1.228 +		a.iArgs[2] = aArgs->iArgs[2];
   1.229 +		a.iFlags = aArgs->iFlags&((1<<(3*TIpcArgs::KBitsPerType))-1);
   1.230 +		}
   1.231 +	a.iArgs[3] = iSubSessionHandle;
   1.232 +	return(iSession.Send(aFunction,a));
   1.233 +	}
   1.234 +
   1.235 +
   1.236 +
   1.237 +EXPORT_C void RSubSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs,TRequestStatus &aStatus) const
   1.238 +//
   1.239 +// Send and wait for reply asynchronously.
   1.240 +//
   1.241 +	{
   1.242 +	TIpcArgs a;
   1.243 +	if(aArgs)
   1.244 +		{
   1.245 +		a.iArgs[0] = aArgs->iArgs[0];
   1.246 +		a.iArgs[1] = aArgs->iArgs[1];
   1.247 +		a.iArgs[2] = aArgs->iArgs[2];
   1.248 +		a.iFlags = aArgs->iFlags&((1<<(3*TIpcArgs::KBitsPerType))-1);
   1.249 +		}
   1.250 +	a.iArgs[3] = iSubSessionHandle;
   1.251 +	iSession.SendReceive(aFunction,a,aStatus);
   1.252 +	}
   1.253 +
   1.254 +
   1.255 +
   1.256 +EXPORT_C TInt RSubSessionBase::DoSendReceive(TInt aFunction,const TIpcArgs* aArgs) const
   1.257 +//
   1.258 +// Send and wait for reply synchronously.
   1.259 +//
   1.260 +	{
   1.261 +	TIpcArgs a;
   1.262 +	if(aArgs)
   1.263 +		{
   1.264 +		a.iArgs[0] = aArgs->iArgs[0];
   1.265 +		a.iArgs[1] = aArgs->iArgs[1];
   1.266 +		a.iArgs[2] = aArgs->iArgs[2];
   1.267 +		a.iFlags = aArgs->iFlags&((1<<(3*TIpcArgs::KBitsPerType))-1);
   1.268 +		}
   1.269 +	a.iArgs[3] = iSubSessionHandle;
   1.270 +	return(iSession.SendReceive(aFunction,a));
   1.271 +	}
   1.272 +
   1.273 +
   1.274 +
   1.275 +
   1.276 +
   1.277 +