testexecfw/stf/stffw/testsrvstarter/src/TestServerStarter.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     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: This file contains TestServerStarter implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32base.h>
       
    20 #include <e32svr.h>
       
    21 #include <stifinternal/TestServerClient.h>
       
    22 // EXTERNAL DATA STRUCTURES
       
    23 
       
    24 // EXTERNAL FUNCTION PROTOTYPES  
       
    25 
       
    26 
       
    27 // ================= OTHER EXPORTED FUNCTIONS =================================
       
    28 
       
    29 
       
    30 /*
       
    31 -------------------------------------------------------------------------------
       
    32 
       
    33     Class: -
       
    34 
       
    35     Method: E32Main
       
    36 
       
    37     Description: 
       
    38 
       
    39     Parameters: None
       
    40 
       
    41     Return Values: TInt                             Error code
       
    42 
       
    43     Errors/Exceptions: None
       
    44 
       
    45     Status: Draft
       
    46 
       
    47 -------------------------------------------------------------------------------
       
    48 */
       
    49 
       
    50 GLDEF_C TInt E32Main()
       
    51     {
       
    52 
       
    53     RDebug::Print(_L("STF: New process starting"));
       
    54 
       
    55     // Get module name from command line
       
    56 	const TInt length = User().CommandLineLength();
       
    57 
       
    58     HBufC* cmdLine = HBufC::New( length );
       
    59     
       
    60     if ( cmdLine == NULL )
       
    61         {
       
    62         return KErrNoMemory;
       
    63         }
       
    64 
       
    65     TPtr moduleName = cmdLine->Des();
       
    66 
       
    67 	User().CommandLine( moduleName );
       
    68 
       
    69     RDebug::Print(_L("STF: Received data [%S]"), &moduleName);
       
    70 
       
    71     // Extract semaphore name passed in data
       
    72     TInt index = moduleName.Find(_L(" "));
       
    73     RDebug::Print(_L("STF: Space separator found at position [%d]"), index);
       
    74     TPtrC semaphoreName = moduleName.Mid(index + 1);
       
    75     moduleName = moduleName.Left(index);
       
    76 
       
    77     RDebug::Print(_L("STF: Extracted module name [%S] and sempahore name [%S]"), &moduleName, &semaphoreName);
       
    78 
       
    79     // Open start-up synchronization semaphore
       
    80     RSemaphore startup;
       
    81     RDebug::Print(_L(" Openingstart-up semaphore"));
       
    82     //TName semaphoreName = _L("startupSemaphore");
       
    83     //semaphoreName.Append( moduleName );
       
    84     
       
    85     TInt res = startup.OpenGlobal(semaphoreName);
       
    86     RDebug::Print(_L("Opening result %d"), res);    
       
    87 
       
    88 
       
    89     TFileName serverName;
       
    90     TInt r = StartNewServer ( moduleName, serverName, EFalse, startup);    
       
    91 
       
    92     if ( r ==   KErrAlreadyExists )
       
    93         {        
       
    94         // Ok, server was already started
       
    95         RDebug::Print(_L("Server already started, signaling semaphore and existing"));
       
    96         startup.Signal();        
       
    97 
       
    98         delete cmdLine;
       
    99 
       
   100         return KErrNone;
       
   101         }
       
   102     else
       
   103         {       
       
   104         RDebug::Print(_L("Server is finished, code %d"), r);
       
   105         }
       
   106 
       
   107     delete cmdLine;
       
   108     
       
   109     return r;
       
   110 
       
   111     }
       
   112 
       
   113 // End of File