traceservices/commsdebugutility/SSVR/comsdbgthrd.cpp
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implements the FLogger server process startup
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <comms-infras/commsdebugutility.h>
       
    24 #include "comsdbgstd.h"
       
    25 
       
    26 const TInt KFLoggerServerUid=0x10004ee0;
       
    27 
       
    28 _LIT(KFLoggerServerExecutable,"COMSDBGSVR");           ///< Filename of flogger server executable
       
    29 
       
    30 
       
    31 // only needed for EKA1:
       
    32 // END EKA1
       
    33 
       
    34 
       
    35 
       
    36 EXPORT_C TInt FLogger::Start()
       
    37 /**
       
    38  * Start the FLOGGER server - called by a hopeful client when they first connect.
       
    39  * @return TInt of (KErrorNone) if the server startup was successful, otherwise
       
    40  *         an error code.
       
    41  */
       
    42 	{
       
    43 
       
    44 	TRequestStatus stat;
       
    45 
       
    46 
       
    47 	TInt ret;
       
    48 // Different approaches for EKA1/EKA2:
       
    49 	//
       
    50 	// Target and EKA2 is easy, we just create a new server process. Simultaneous
       
    51 	// launching of two such processes should be detected when the second one
       
    52 	// attempts to create the server object, failing with KErrAlreadyExists.
       
    53 	//
       
    54 	RProcess server;
       
    55 	ret = server.Create(KFLoggerServerExecutable,KNullDesC,TUidType(KNullUid,KNullUid,TUid::Uid(KFLoggerServerUid)));
       
    56 // END EKA1/EKA2
       
    57 	
       
    58 	if (ret!=KErrNone)
       
    59 		{
       
    60 		return ret;
       
    61 		}
       
    62 
       
    63 	server.SetPriority(EPriorityHigh);
       
    64 
       
    65 	server.Rendezvous(stat);
       
    66 
       
    67 	server.Resume();
       
    68 	
       
    69 	// setting the server process priority is really just a formality since
       
    70 	// we set the server's thread priorities to absolute values later anyway.
       
    71 	server.Close();
       
    72 
       
    73 	User::WaitForRequest(stat);
       
    74 
       
    75 	return stat.Int();
       
    76 	}
       
    77 
       
    78 EXPORT_C TInt FLogger::Run()
       
    79 /**
       
    80  * Start the active scheduler and create the server. This is called from the DLL entry code.
       
    81  * @return TInt of (KErrorNone) if the server startup was successful, otherwise
       
    82  *         an error code.
       
    83 @internalComponent
       
    84  */
       
    85 	{
       
    86 
       
    87 	__UHEAP_MARK;
       
    88 	
       
    89 	RThread self;
       
    90 	self.SetPriority(EPriorityAbsoluteHigh); // was EPriorityMore
       
    91 	self.Close();
       
    92 	
       
    93 	TInt ret = KErrNone;
       
    94 
       
    95 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    96 	if (cleanup==NULL)
       
    97 		ret=KErrNoMemory;
       
    98 
       
    99 	CActiveScheduler* scheduler = NULL;
       
   100 	CFileLoggerServer* server = NULL;
       
   101 	if (ret==KErrNone)
       
   102 		{
       
   103 		scheduler = new CActiveScheduler;
       
   104 		if (scheduler == NULL)
       
   105 			ret = KErrNoMemory;
       
   106 		else
       
   107 			{
       
   108 			CActiveScheduler::Install(scheduler);
       
   109 			TRAP(ret, server = CFileLoggerServer::NewL());
       
   110 			}
       
   111 		}
       
   112 
       
   113 	RProcess::Rendezvous(ret);
       
   114 
       
   115 	if (ret==KErrNone)
       
   116 		CActiveScheduler::Start();
       
   117 
       
   118 	delete server;
       
   119 	delete scheduler;
       
   120 	delete cleanup;
       
   121 
       
   122 	__UHEAP_MARKEND;
       
   123 
       
   124 	return ret;
       
   125 	}
       
   126 
       
   127 
       
   128