eventsui/eventshandlerui/eventshandler/src/evthandlerclient.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2008 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 "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:  Client for Events Handler Server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "evthandlerclientserver.h"
       
    20 #include "evthandlerclient.h"
       
    21 #include "evthandlerserverconsts.h"
       
    22 #include "evtdebug.h"
       
    23 
       
    24 // ----------------------------------------------------------------------------
       
    25 // StartServer()
       
    26 // ----------------------------------------------------------------------------
       
    27 //
       
    28 static TInt StartServer()
       
    29 /*
       
    30  * Start the server process. Simultaneous launching
       
    31  * of two such processes should be detected when the second one attempts to
       
    32  * create the server object, failing with KErrAlreadyExists.
       
    33  */
       
    34 	{
       
    35 	EVTUIDEBUG("+ StartServer()");
       
    36 	const TUidType serverUid( KNullUid, KNullUid, KServerUid3);
       
    37 	RProcess server;
       
    38 	TInt r = server.Create( KEvtHandlerServerImg, KNullDesC, serverUid );
       
    39 	if (r != KErrNone)
       
    40 		return r;
       
    41 	TRequestStatus stat;
       
    42 	server.Rendezvous(stat);
       
    43 	if (stat != KRequestPending)
       
    44 		server.Kill( 0 );		// abort startup
       
    45 	else
       
    46 		server.Resume();	// logon OK - start the server
       
    47 	User::WaitForRequest( stat );		// wait for start or death
       
    48 	// we can't use the 'exit reason' if the server panicked as this
       
    49 	// is the panic 'reason' and may be '0' which cannot be distinguished
       
    50 	// from KErrNone
       
    51 	r = ( server.ExitType() == EExitPanic ) ? KErrGeneral : stat.Int();
       
    52 	server.Close();
       
    53 	EVTUIDEBUG("- StartServer()");
       
    54 	return r;
       
    55 	}
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // REvtHandlerSession::Connect()
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C TInt REvtHandlerSession::Connect()
       
    62 /*
       
    63  * Connect to the server, attempting to start it if necessary
       
    64  */
       
    65 	{
       
    66 	EVTUIDEBUG("+ REvtHandlerSession::Connect()");
       
    67 	TInt retry = 2;
       
    68 	for (;;)
       
    69 		{
       
    70 		TInt r = CreateSession( KEvtHandlerServerName, TVersion( 0, 0, 0), 1 );
       
    71 		if ( r != KErrNotFound && r != KErrServerTerminated )
       
    72 			return r;
       
    73 
       
    74 		if ( --retry == 0 )
       
    75 			return r;
       
    76 
       
    77 		r = StartServer();
       
    78 		if ( r !=KErrNone && r != KErrAlreadyExists )
       
    79 			return r;
       
    80 		}
       
    81 	}
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // REvtHandlerSession::SendEventId()
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C TInt REvtHandlerSession::SendEventId( const TDesC& aMessage, const TInt aAccuracy )
       
    88 	{
       
    89 	EVTUIDEBUG("+ REvtHandlerSession::SendEventId()");
       
    90 
       
    91 	if ( aMessage.Length() > KMaxEvtHandlerMessage )
       
    92 		return KErrArgument;
       
    93 	return SendReceive( ESendEventId, TIpcArgs( &aMessage, aAccuracy )  );
       
    94 	}