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