dbgagents/trkagent/trklauncher/trklauncher.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 #include <e32debug.h>
       
    19 
       
    20 // system includes
       
    21 #include <e32std.h>
       
    22 #include <eikenv.h>
       
    23 
       
    24 // local includes
       
    25 #include "trkdummyrecognizer.h"
       
    26 #ifdef __UI_FRAMEWORKS_V2__
       
    27 #include <implementationproxy.h>
       
    28 #endif //__UI_FRAMEWORKS_V2__
       
    29 
       
    30 // constants
       
    31 _LIT(KTrkConsoleExe, "trkconsole.exe");
       
    32 
       
    33 const TUid KTrkConsoleExeUid={0x200159E2}; // 
       
    34 
       
    35 
       
    36 TBool IsAlreadyRunning()
       
    37 {
       
    38 	RDebug::Print(_L("TrkLauncher::IsAlreadyRunning()"));
       
    39 
       
    40 	_LIT(KTrkConsoleSearchPattern, "*TRKPROCESS*");
       
    41 	_LIT(KTrkConsoleProcessPattern, "*");
       
    42 	
       
    43 	TFindProcess finder;
       
    44 	TFullName fullName;
       
    45 	TBool found = EFalse;
       
    46 	finder.Find(KTrkConsoleProcessPattern);
       
    47 
       
    48 	while (!found && finder.Next(fullName) == KErrNone)
       
    49 	{
       
    50 		fullName.UpperCase();
       
    51 		
       
    52 		if (fullName.Match(KTrkConsoleSearchPattern) != KErrNotFound)
       
    53 		{
       
    54 			found = ETrue;
       
    55 			RDebug::Print(_L("process found Inside while"));
       
    56 			break;
       
    57 		}
       
    58 	}
       
    59 
       
    60 	if (found)
       
    61 	{
       
    62 		RDebug::Print(_L("TrkLauncher - Process found outside while"));
       
    63 	}
       
    64 	else
       
    65 	{
       
    66 		RDebug::Print(_L("TrkLauncher - Process was never found"));
       
    67 	}
       
    68 		
       
    69 	return found;
       
    70 }
       
    71 
       
    72 void HandleStart()
       
    73 {
       
    74 	RDebug::Print(_L("TrkLauncher::HandleStart()"));
       
    75 	
       
    76 	if (!IsAlreadyRunning())
       
    77 	{		
       
    78 		TInt result;		
       
    79 		RProcess p;
       
    80 		
       
    81 		//start TrkConsole	process
       
    82 		result = p.Create(KTrkConsoleExe, TPtr(NULL, 0), TUidType(KNullUid, KNullUid, KTrkConsoleExeUid));
       
    83 		if (result == KErrNone)
       
    84 		{
       
    85 			RDebug::Print(_L("TrkLauncher - Trk process resume"));
       
    86 			p.Resume();
       
    87 			RDebug::Print(_L("TrkLauncher - After Trk process resume"));
       
    88 			p.Close();
       
    89 			RDebug::Print(_L("TrkLauncher - After Trk process close"));
       
    90 		}
       
    91 		else
       
    92 		{
       
    93 			RDebug::Print(_L("TrkLauncher - Trk process not created with %d \n"),result);
       
    94 			RDebug::Print(_L("TrkLauncher - Returning without process creation"));
       
    95 		}
       
    96 			
       
    97 	}
       
    98 }
       
    99 	
       
   100 #ifdef __UI_FRAMEWORKS_V2__
       
   101 
       
   102 const TImplementationProxy ImplementationTable[]=
       
   103 {
       
   104     IMPLEMENTATION_PROXY_ENTRY(0x1020814D, CTrkDummyRecognizer::NewL)
       
   105 };
       
   106 
       
   107 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   108 {
       
   109     RDebug::Print(_L("TrkLauncher::ImplementationGroupProxy(aTableCount=%d)"), aTableCount);
       
   110     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   111     return ImplementationTable;
       
   112 }
       
   113 
       
   114 CApaDataRecognizerType* CTrkDummyRecognizer::NewL()
       
   115 {
       
   116 	RDebug::Print(_L("TrkLauncher::CTrkDummyRecognizer::NewL()"));
       
   117     CApaDataRecognizerType *recog = new CTrkDummyRecognizer(); // no (ELeave) as return NULL is OK
       
   118    
       
   119     RDebug::Print(_L("TrkLauncher - Before HandleSart()"));
       
   120     HandleStart(); 
       
   121     
       
   122     return recog;
       
   123 }
       
   124 
       
   125 #else
       
   126 	
       
   127 EXPORT_C CApaDataRecognizerType* CreateRecognizer()
       
   128 {
       
   129 	CApaDataRecognizerType* recog = new CTrkDummyRecognizer(); // no (ELeave) as return NULL is OK
       
   130 
       
   131 	HandleStart();
       
   132 
       
   133 	return recog;
       
   134 }
       
   135 #endif //__UI_FRAMEWORKS_V2__
       
   136 
       
   137 #ifndef EKA2
       
   138 
       
   139 GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
       
   140 {
       
   141 	RDebug::Print(_L("MCLauncher::E32Dll()"));
       
   142 	return KErrNone;
       
   143 }
       
   144 #endif // EKA2