stif/TestServerStarter/src/TestServerStarter.cpp
changeset 0 a03f92240627
child 9 8a14024f954a
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     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("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 (moduleName);
       
    70 
       
    71     // Open start-up synchronization semaphore
       
    72     RSemaphore startup;
       
    73     RDebug::Print(_L(" Openingstart-up semaphore"));
       
    74     TName semaphoreName = _L("startupSemaphore");
       
    75     semaphoreName.Append( moduleName );
       
    76     
       
    77     TInt res = startup.OpenGlobal(semaphoreName);
       
    78     RDebug::Print(_L("Opening result %d"), res);    
       
    79 
       
    80 
       
    81     TFileName serverName;
       
    82     TInt r = StartNewServer ( moduleName, serverName, EFalse, startup);    
       
    83 
       
    84     if ( r ==   KErrAlreadyExists )
       
    85         {        
       
    86         // Ok, server was already started
       
    87         RDebug::Print(_L("Server already started, signaling semaphore and existing"));
       
    88         startup.Signal();        
       
    89 
       
    90         delete cmdLine;
       
    91 
       
    92         return KErrNone;
       
    93         }
       
    94     else
       
    95         {       
       
    96         RDebug::Print(_L("Server is finished, code %d"), r);
       
    97         }
       
    98 
       
    99     delete cmdLine;
       
   100     
       
   101     return r;
       
   102 
       
   103     }
       
   104 
       
   105 // End of File