os/security/authorisation/userpromptservice/examples/integration/tmsgclient/tmsgclient.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * Example Code
    16 * No changes necessary to support User Prompt Service
    17 *
    18 */
    19 
    20 
    21 #include <e32cmn.h>
    22 #include "tmsgclient.h"
    23 
    24 static TInt StartServer()
    25 	{
    26 	const TUidType serverUid(KNullUid,KNullUid,KMsgServerUid3);
    27 	RProcess server;
    28 	TInt r=server.Create(KMsgServerImg,KNullDesC,serverUid);
    29 	if (r!=KErrNone)
    30 		return r;
    31 	TRequestStatus stat;
    32 	server.Rendezvous(stat);
    33 	if (stat!=KRequestPending)
    34 		server.Kill(0);		// abort startup
    35 	else
    36 		server.Resume();	// logon OK - start the server
    37 	User::WaitForRequest(stat);		// wait for start or death
    38 	r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
    39 	server.Close();
    40 	return r;
    41 	}
    42 
    43 EXPORT_C TInt RMsgSession::Connect()
    44 	{
    45 	TInt retry=2;
    46 	for (;;)
    47 		{
    48 		TVersion version(KMsgServerVersionMajor, KMsgServerVersionMinor, KMsgServerVersionBuild);
    49 		TInt r=CreateSession(KMsgServerName, version);
    50 		if (r!=KErrNotFound && r!=KErrServerTerminated)
    51 			return r;
    52 		if (--retry==0)
    53 			return r;
    54 		r=StartServer();
    55 		if (r!=KErrNone && r!=KErrAlreadyExists)
    56 			return r;
    57 		}
    58 	}
    59 
    60 EXPORT_C void RMsgSession::SendMsg(const TDesC& aTo, const TDesC& aBody, TRequestStatus& aStatus) const
    61 /**
    62  Sends a message
    63  @param aTo		The recipient of the message.
    64  @param	aBody	The message body.	
    65  @param aStatus	The server completes this request object when it has finished handling the request. 
    66  */
    67 	{
    68 	aStatus = KRequestPending;
    69 	SendReceive(ESendMsg, TIpcArgs(&aTo, &aBody), aStatus);
    70 	}
    71 
    72 EXPORT_C void RMsgSession::CancelSendMsg() const
    73 /**
    74  Cancels an active call to SendMsg
    75  */
    76 	{
    77 	SendReceive(ECancelSendMsg);
    78 	}