sdkcreationmw/sdkconnectivityfw/emuconnectserver/CmdLauncher/src/EcmtLauncher.cpp
changeset 0 b26acd06ea60
equal deleted inserted replaced
-1:000000000000 0:b26acd06ea60
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Standalone .exe that launces Ecmt framework without emulator
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <f32file.h>
       
    23 
       
    24 // MODULE DATA STRUCTURES
       
    25 typedef TInt (*ExeEntryPoint)();
       
    26 
       
    27 // CONSTANTS
       
    28 const TInt KDefaultMinHeapSize=0x10000; // !! for now
       
    29 const TInt KDefaultMaxHeapSize=0x1000000; // !! for now
       
    30 _LIT( KEcmtCoreFileName, "Z:\\Sys\\bin\\ECMTCORE.EXE" );
       
    31 
       
    32 // ============================= LOCAL FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // ExeThreadStartFunction .
       
    36 // Generic thread entry point that calls the first export of the library
       
    37 // given as parameter.
       
    38 // -----------------------------------------------------------------------------
       
    39 
       
    40 TInt ExeThreadStartFunction(TAny* aParam)
       
    41 	{
       
    42 	const TDesC& libraryName=(*(const TDesC*)aParam);
       
    43 	RLibrary lib;
       
    44 	TInt err=lib.Load(libraryName);
       
    45 	User::Free(aParam);
       
    46 	if (!err)
       
    47 		{
       
    48 		ExeEntryPoint exeFunc=(ExeEntryPoint)lib.Lookup(1);
       
    49 		if (!exeFunc)
       
    50 			err=KErrBadLibraryEntryPoint;
       
    51 		else
       
    52 			err=(*exeFunc)();
       
    53 		}
       
    54 	return(err);
       
    55 	}
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // LaunchEcmtCoreL
       
    59 // 
       
    60 // -----------------------------------------------------------------------------
       
    61 
       
    62 void LaunchEcmtCoreL()
       
    63 	{
       
    64 	RFs fs;
       
    65 	fs.Connect();
       
    66 	TFindFile findExe( fs );
       
    67 
       
    68 	TInt err = findExe.FindByPath( KEcmtCoreFileName, NULL );
       
    69 	User::LeaveIfError( err );
       
    70 
       
    71 	TParse fileName;
       
    72 	TThreadId threadId;
       
    73 	User::LeaveIfError(fileName.Set(KEcmtCoreFileName, NULL, NULL));
       
    74 	
       
    75 /* RThread process;
       
    76 
       
    77 	TBuf<KMaxFileName> threadName;
       
    78 	TPtrC baseName=fileName.Name();
       
    79 
       
    80 	TInt num=0;
       
    81 	_LIT(KThreadFormat,"%S%02d");
       
    82 	do
       
    83 		{
       
    84 		threadName.Format(KThreadFormat,&baseName,num++);
       
    85 		err=process.Create(threadName,ExeThreadStartFunction,KDefaultStackSize,KDefaultMinHeapSize,KDefaultMaxHeapSize,NULL);
       
    86 		} while(err==KErrAlreadyExists);
       
    87 
       
    88 	User::LeaveIfError(err);
       
    89 	RHeap* heap=process.Heap();
       
    90 	RHeap* originalHeap=User::SwitchHeap(heap);
       
    91 	HBufC* commandLine=fileName.FullName().Alloc();
       
    92 	User::SwitchHeap(originalHeap);
       
    93 	if (!commandLine)
       
    94 		{
       
    95 		process.Close();
       
    96 		User::LeaveNoMemory();
       
    97 		}
       
    98 	process.SetInitialParameter(commandLine);
       
    99 	threadId = process.Id();
       
   100 
       
   101 	process.Resume();
       
   102 	process.Close();
       
   103 */	
       
   104 
       
   105 	RProcess process;
       
   106 
       
   107 	TBuf<KMaxFileName> processName;
       
   108 	TPtrC baseName=fileName.Name();
       
   109 
       
   110 	HBufC* commandLine=fileName.FullName().Alloc();
       
   111 	if (!commandLine)
       
   112 		{
       
   113 		User::LeaveNoMemory();
       
   114 		}
       
   115 
       
   116 	TInt num=0;
       
   117 	_LIT(KProcessFormat,"%S%02d");
       
   118 	do
       
   119 		{
       
   120 		processName.Format(KProcessFormat,&baseName,num++);
       
   121 //		err=process.Create(processName,ExeThreadStartFunction,KDefaultStackSize,KDefaultMinHeapSize,KDefaultMaxHeapSize,NULL); 
       
   122 		err = process.Create( processName, commandLine->Des() );
       
   123 		} while ( err == KErrAlreadyExists );
       
   124 
       
   125 	process.Resume();
       
   126 	process.Close();
       
   127 	}
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // E32Main
       
   131 // Entry point called by system
       
   132 // -----------------------------------------------------------------------------
       
   133 
       
   134 GLDEF_C TInt E32Main()
       
   135     {
       
   136 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   137 	TRAPD(error, LaunchEcmtCoreL() );
       
   138 	delete cleanup;
       
   139 
       
   140 	RThread self;
       
   141 	self.Suspend();
       
   142 	return 0;
       
   143     }