debugsrv/runmodedebug/rmdebug_test/rm_debug/multi_agent_tests/t_agent_eventhandler.cpp
changeset 56 aa2539c91954
parent 54 a151135b0cf9
child 60 e54443a6878c
child 62 1c2bb2fc7c87
equal deleted inserted replaced
54:a151135b0cf9 56:aa2539c91954
     1 // Copyright (c) 2007-2010 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 the License "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 handling of run mode events for a particular target executable
       
    15 // 
       
    16 
       
    17 #include <e32base.h>
       
    18 #include <e32property.h>
       
    19 #include <e32test.h>
       
    20 
       
    21 #include "t_rmdebug_app.h"
       
    22 #include "t_agent_eventhandler.h"
       
    23 #include "t_multi_agent.h"
       
    24 #include "t_debug_logging.h" 
       
    25 
       
    26 using namespace Debug;
       
    27 
       
    28 CAgentAsyncEvent::CAgentAsyncEvent(CMultiAgent& aDriver, const TDesC& aExeName, const TDesC& aExeConfig):
       
    29 	CActive(EPriorityStandard), iDriver(aDriver)
       
    30 	{
       
    31 	}
       
    32 
       
    33 CAgentAsyncEvent* CAgentAsyncEvent::NewLC(CMultiAgent& aDriver, const TDesC& aExeName, const TDesC& aExeConfig)
       
    34 	{
       
    35 	CAgentAsyncEvent* self = new(ELeave) CAgentAsyncEvent(aDriver, aExeName, aExeConfig);
       
    36 	CleanupStack::PushL(self);
       
    37 	self->ConstructL(aExeName, aExeConfig);
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 CAgentAsyncEvent* CAgentAsyncEvent::NewL(CMultiAgent& aDriver, const TDesC& aExeName, const TDesC& aExeConfig)
       
    42 	{
       
    43 	CAgentAsyncEvent* self = CAgentAsyncEvent::NewLC(aDriver, aExeName, aExeConfig);
       
    44 	CleanupStack::Pop(); // self
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 void CAgentAsyncEvent::ConstructL(const TDesC& aExeName, const TDesC& aExeConfig)
       
    49 	{
       
    50 	iExeName.CreateL(aExeName);
       
    51 	iExeConfig.CreateL(aExeConfig);
       
    52 	CActiveScheduler::Add(this);
       
    53 	}
       
    54 
       
    55 CAgentAsyncEvent::~CAgentAsyncEvent()
       
    56 	{
       
    57 	LOG_MSG2("~CAgentAsyncEvent(), this = 0x%08x", this);
       
    58 
       
    59 	iSEventInfo.iEventInfoBuf.Delete(0, sizeof(TEventInfo));
       
    60 	iExeName.Close();
       
    61 	iExeConfig.Close();
       
    62 	iProc.Close();
       
    63 	Cancel(); // Cancel any request, if outstanding
       
    64 	}
       
    65 
       
    66 /*
       
    67  * Issue request to DSS and notify the active scheduler
       
    68  */
       
    69 void CAgentAsyncEvent::Watch()
       
    70 	{
       
    71 	LOG_MSG2("ENTER: CAgentAsyncEvent::Watch, this = 0x%08x", this);
       
    72 	iDriver.DebugDriver().GetEvent(GetExecutable(), iStatus, iSEventInfo.iEventInfoBuf);
       
    73 
       
    74 	if (!IsActive())
       
    75 		{
       
    76 		LOG_MSG("CAgentAsyncEvent::Watch(): SetActive()");
       
    77 		SetActive();
       
    78 		}
       
    79 
       
    80 	LOG_MSG("EXIT: CAgentAsyncEvent::Watch");
       
    81 	}
       
    82 
       
    83 void CAgentAsyncEvent::RunL()
       
    84 	{
       
    85 	LOG_MSG4("ENTER: CAgentAsyncEvent::RunL iDebugType=%d, iStatus.Int() %d, this 0x%x08", 
       
    86 			 iSEventInfo.iEventInfo.iEventType, iStatus.Int(), this);
       
    87 	
       
    88     LOG_MSG2("%S", &TPtr8((TUint8*)GetExecutable().Ptr(), 2*GetExecutable().Length(), 2*GetExecutable().Length()));	
       
    89 	iDriver.HandleEvent(iSEventInfo.iEventInfo);
       
    90 
       
    91 	LOG_MSG2("iDriver.GetNumApps() %d: ", iDriver.GetNumApps());
       
    92 	LOG_MSG2("iDriver.iLaunchCompleted  %d: ", iDriver.GetLaunchCompleted());
       
    93 
       
    94 	if (iDriver.GetLaunchCompleted() < iDriver.GetNumApps())
       
    95 		{
       
    96 		// Do not call Watch() if target has run to completion but test is still on going
       
    97 		if (iSEventInfo.iEventInfo.iEventType != EEventsRemoveProcess)
       
    98 			{
       
    99 			LOG_MSG("CAgentAsyncEvent::RunL Setting Watch()");
       
   100 			Watch();
       
   101 			}
       
   102 		}
       
   103 	else
       
   104 		{
       
   105 		// Stop event handling for all targets
       
   106 		LOG_MSG("CAgentAsyncEvent::RunL CActiveScheduler::Stop() & Cancel");
       
   107 		CActiveScheduler::Stop();
       
   108 		}
       
   109 
       
   110 	LOG_MSG2("EXIT: CAgentAsyncEvent::RunL", KNullDesC);
       
   111 	}
       
   112 
       
   113 void CAgentAsyncEvent::DoCancel()
       
   114 	{
       
   115 	LOG_MSG("CAgentAsyncEvent::DoCancel");
       
   116 	}
       
   117 
       
   118 TInt CAgentAsyncEvent::RunError(TInt aError)
       
   119 	{
       
   120 	LOG_MSG3(" RunL() has left with error %d, this 0x%08X", aError, this);
       
   121 	return aError; 
       
   122 	// Can we handle this error? Not at the moment!
       
   123 	}
       
   124