os/security/authorisation/userpromptservice/examples/integration/tmsgclient/tmsgclient.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/authorisation/userpromptservice/examples/integration/tmsgclient/tmsgclient.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,78 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Example Code
    1.19 +* No changes necessary to support User Prompt Service
    1.20 +*
    1.21 +*/
    1.22 +
    1.23 +
    1.24 +#include <e32cmn.h>
    1.25 +#include "tmsgclient.h"
    1.26 +
    1.27 +static TInt StartServer()
    1.28 +	{
    1.29 +	const TUidType serverUid(KNullUid,KNullUid,KMsgServerUid3);
    1.30 +	RProcess server;
    1.31 +	TInt r=server.Create(KMsgServerImg,KNullDesC,serverUid);
    1.32 +	if (r!=KErrNone)
    1.33 +		return r;
    1.34 +	TRequestStatus stat;
    1.35 +	server.Rendezvous(stat);
    1.36 +	if (stat!=KRequestPending)
    1.37 +		server.Kill(0);		// abort startup
    1.38 +	else
    1.39 +		server.Resume();	// logon OK - start the server
    1.40 +	User::WaitForRequest(stat);		// wait for start or death
    1.41 +	r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
    1.42 +	server.Close();
    1.43 +	return r;
    1.44 +	}
    1.45 +
    1.46 +EXPORT_C TInt RMsgSession::Connect()
    1.47 +	{
    1.48 +	TInt retry=2;
    1.49 +	for (;;)
    1.50 +		{
    1.51 +		TVersion version(KMsgServerVersionMajor, KMsgServerVersionMinor, KMsgServerVersionBuild);
    1.52 +		TInt r=CreateSession(KMsgServerName, version);
    1.53 +		if (r!=KErrNotFound && r!=KErrServerTerminated)
    1.54 +			return r;
    1.55 +		if (--retry==0)
    1.56 +			return r;
    1.57 +		r=StartServer();
    1.58 +		if (r!=KErrNone && r!=KErrAlreadyExists)
    1.59 +			return r;
    1.60 +		}
    1.61 +	}
    1.62 +
    1.63 +EXPORT_C void RMsgSession::SendMsg(const TDesC& aTo, const TDesC& aBody, TRequestStatus& aStatus) const
    1.64 +/**
    1.65 + Sends a message
    1.66 + @param aTo		The recipient of the message.
    1.67 + @param	aBody	The message body.	
    1.68 + @param aStatus	The server completes this request object when it has finished handling the request. 
    1.69 + */
    1.70 +	{
    1.71 +	aStatus = KRequestPending;
    1.72 +	SendReceive(ESendMsg, TIpcArgs(&aTo, &aBody), aStatus);
    1.73 +	}
    1.74 +
    1.75 +EXPORT_C void RMsgSession::CancelSendMsg() const
    1.76 +/**
    1.77 + Cancels an active call to SendMsg
    1.78 + */
    1.79 +	{
    1.80 +	SendReceive(ECancelSendMsg);
    1.81 +	}