sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Example Code sl@0: * No changes necessary to support User Prompt Service sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include "tmsgclient.h" sl@0: sl@0: static TInt StartServer() sl@0: { sl@0: const TUidType serverUid(KNullUid,KNullUid,KMsgServerUid3); sl@0: RProcess server; sl@0: TInt r=server.Create(KMsgServerImg,KNullDesC,serverUid); sl@0: if (r!=KErrNone) sl@0: return r; sl@0: TRequestStatus stat; sl@0: server.Rendezvous(stat); sl@0: if (stat!=KRequestPending) sl@0: server.Kill(0); // abort startup sl@0: else sl@0: server.Resume(); // logon OK - start the server sl@0: User::WaitForRequest(stat); // wait for start or death sl@0: r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); sl@0: server.Close(); sl@0: return r; sl@0: } sl@0: sl@0: EXPORT_C TInt RMsgSession::Connect() sl@0: { sl@0: TInt retry=2; sl@0: for (;;) sl@0: { sl@0: TVersion version(KMsgServerVersionMajor, KMsgServerVersionMinor, KMsgServerVersionBuild); sl@0: TInt r=CreateSession(KMsgServerName, version); sl@0: if (r!=KErrNotFound && r!=KErrServerTerminated) sl@0: return r; sl@0: if (--retry==0) sl@0: return r; sl@0: r=StartServer(); sl@0: if (r!=KErrNone && r!=KErrAlreadyExists) sl@0: return r; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void RMsgSession::SendMsg(const TDesC& aTo, const TDesC& aBody, TRequestStatus& aStatus) const sl@0: /** sl@0: Sends a message sl@0: @param aTo The recipient of the message. sl@0: @param aBody The message body. sl@0: @param aStatus The server completes this request object when it has finished handling the request. sl@0: */ sl@0: { sl@0: aStatus = KRequestPending; sl@0: SendReceive(ESendMsg, TIpcArgs(&aTo, &aBody), aStatus); sl@0: } sl@0: sl@0: EXPORT_C void RMsgSession::CancelSendMsg() const sl@0: /** sl@0: Cancels an active call to SendMsg sl@0: */ sl@0: { sl@0: SendReceive(ECancelSendMsg); sl@0: }