dbgagents/trkagent/tcbclient/TrkTcbClientUtils.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     1 /*
       
     2 * Copyright (c) 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 "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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "TrkTcbClientUtils.h"
       
    20 
       
    21 // System includes
       
    22 #include <e32std.h>
       
    23 
       
    24 // User includes
       
    25 #include "TrkTcbClientDefs.h"
       
    26 
       
    27 // Type definitions
       
    28 
       
    29 // Constants
       
    30 
       
    31 // Enumerations
       
    32 
       
    33 
       
    34 //
       
    35 // TrkTcbClientUtils (source)
       
    36 //
       
    37 
       
    38 //
       
    39 // TrkTcbClientUtils::Panic()
       
    40 //
       
    41 // Panic the client
       
    42 //
       
    43 void TrkTcbClientUtils::Panic(TTrkTcbClientPanic aPanic)
       
    44 {
       
    45 	_LIT(KTrkTcbClientPanic, "TRKTCBCLI");
       
    46 	User::Panic(KTrkTcbClientPanic, aPanic);
       
    47 }
       
    48 
       
    49 //
       
    50 // TrkTcbClientUtils::Fault()
       
    51 //
       
    52 // Panic the client, indicating some form of logic error or terminal
       
    53 // fault.
       
    54 //
       
    55 void TrkTcbClientUtils::Fault(TTrkTcbClientFault aFault)
       
    56 {
       
    57 	_LIT(KTrkTcbClientFault, "TRKTCBCLIFAULT");
       
    58 	User::Panic(KTrkTcbClientFault, aFault);
       
    59 }
       
    60 
       
    61 //
       
    62 // TrkTcbClientUtils::StartTrkTcbServer()
       
    63 //
       
    64 // Starts the TrkTcb server.
       
    65 // @return KErrNone if successful, 
       
    66 //		   KErrAlreadyExists if the server is already running, otherwise a system-wide error.
       
    67 TInt TrkTcbClientUtils::StartTrkTcbServer()
       
    68 {
       
    69 
       
    70 	TInt ret = KErrNone;
       
    71 
       
    72 	//
       
    73 	// Create a new server process. Simultaneous launching
       
    74 	// of two such processes should be detected when the second one attempts to
       
    75 	// create the server object, failing with KErrAlreadyExists.
       
    76 	//
       
    77 	RProcess server;
       
    78 	ret = server.Create(TrkTcbClientDefs::ServerImageName(), KNullDesC, TrkTcbClientDefs::ServerUidType());
       
    79 
       
    80 	// Did we manage to create the thread/process?
       
    81 	if	(ret != KErrNone)
       
    82 		return ret;
       
    83 
       
    84 	// Wait to see if the thread/process died during construction
       
    85 	TRequestStatus serverDiedRequestStatus;
       
    86 #if defined(EKA2)
       
    87 	server.Rendezvous(serverDiedRequestStatus);
       
    88 #else
       
    89 	server.Logon(serverDiedRequestStatus);
       
    90 #endif
       
    91 	
       
    92 	if	(serverDiedRequestStatus != KRequestPending)
       
    93 	{
       
    94 		// Abort startup
       
    95 		server.Kill(KErrNone);
       
    96 	}
       
    97 	else
       
    98 	{
       
    99 		// Logon OK - start the server
       
   100 		server.Resume();
       
   101 	}
       
   102 	
       
   103 	User::WaitForRequest(serverDiedRequestStatus);
       
   104 
       
   105 	// we can't use the 'exit reason' if the server panicked as this
       
   106 	// is the panic 'reason' and may be '0' which cannot be distinguished
       
   107 	// from KErrNone
       
   108 	
       
   109 	ret = (server.ExitType() == EExitPanic) ? KErrGeneral : serverDiedRequestStatus.Int();
       
   110 	
       
   111 	server.Close();
       
   112 
       
   113 	return ret;
       
   114 }