kernel/eka/debug/securityServer/src/c_security_svr_async.cpp
changeset 245 647ab20fee2e
parent 244 a77889bee936
child 252 0a40b8675b23
equal deleted inserted replaced
244:a77889bee936 245:647ab20fee2e
     1 // Copyright (c) 2006-2009 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 // Asynchronous security server active object class.
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <e32base_private.h>
       
    20 
       
    21 #include "c_security_svr_async.h"
       
    22 #include "rm_debug_logging.h"
       
    23 
       
    24 using namespace Debug;
       
    25 
       
    26 // ctor
       
    27 CSecuritySvrAsync::CSecuritySvrAsync(CSecuritySvrSession* aSession, TProcessId aAgentId)
       
    28 	: CActive(CActive::EPriorityStandard),
       
    29 	iSession(aSession),
       
    30 	iProcessName(NULL),
       
    31 	iAgentId(aAgentId),
       
    32 	iEventBalance(0)
       
    33 	{
       
    34 	LOG_MSG("CSecuritySvrAsync::CSecuritySvrAsync()");
       
    35 	CActiveScheduler::Add(this);
       
    36 	}
       
    37 
       
    38 // returns a CSecuritySvrAsync active object associated with
       
    39 // the specified agent and debugged process.
       
    40 CSecuritySvrAsync* CSecuritySvrAsync::NewL(CSecuritySvrSession* aSession, const TDesC8& aProcessName, TProcessId aAgentId)
       
    41 	{
       
    42 	LOG_MSG("CSecuritySvrAsync::NewL()");
       
    43 	CSecuritySvrAsync* me = new (ELeave) CSecuritySvrAsync(aSession, aAgentId);
       
    44 
       
    45 	CleanupStack::PushL(me);
       
    46 
       
    47 	me->ConstructL(aProcessName);
       
    48 
       
    49 	CleanupStack::Pop(me);
       
    50 
       
    51 	return (me);
       
    52 	}
       
    53 
       
    54 // dtor
       
    55 CSecuritySvrAsync::~CSecuritySvrAsync()
       
    56 	{
       
    57 	LOG_MSG("CSecuritySvrAsync::~CSecuritySvrAsync()");
       
    58 
       
    59 	// NOTE: the Cancel() function calls DoCancel() which may rely on class members so be careful not
       
    60 	// to destroy/close data members before this call if they are needed
       
    61 	Cancel();
       
    62 	iProcessName.Close();
       
    63 	}
       
    64 
       
    65 // Associates the agent id and process name with the Active Object being constructed
       
    66 void CSecuritySvrAsync::ConstructL(const TDesC8& aProcessName)
       
    67 	{
       
    68 	LOG_MSG("CSecuritySvrAsync::ConstructL()");
       
    69 	iProcessName.CreateL(aProcessName.Length());
       
    70 	iProcessName.Copy(aProcessName);
       
    71 	}
       
    72 
       
    73 // RunL() completes a previously issued call (currently only GetEvent() completion)
       
    74 void CSecuritySvrAsync::RunL()
       
    75 	{
       
    76 
       
    77 	LOG_MSG3("CSecuritySvrAsync::RunL() &iInfo=0x%08x, iEventBalance=%d", (TUint8*)&iInfo, iEventBalance);
       
    78 
       
    79 	// Something bad happened in the driver
       
    80 	User::LeaveIfError(iStatus.Int());
       
    81 
       
    82 	// Write back the event data to the debug agent.
       
    83 	// For compatibility we need to check the size of the buffer that the
       
    84 	// client has passed in as the size of TEventInfo will increase over time.
       
    85 	// Clients can calculate the required size from the EApiConstantsTEventInfoSize entry 
       
    86 	// in the Debug Functionality block but may still pass in buffers which
       
    87 	// are smaller than the Debug Security Server's calculation of sizeof(TEventInfo), 
       
    88 	// returning KErrTooBig in this case would be
       
    89 	// inappropriate as we would break compatibility.
       
    90 	TInt dataLengthToReturn = sizeof(TEventInfo);
       
    91 	TInt maxLengthClientSide = iMessage.GetDesMaxLengthL(1);
       
    92 	if(maxLengthClientSide < dataLengthToReturn)
       
    93 		{
       
    94 		dataLengthToReturn = maxLengthClientSide;
       
    95 		}
       
    96 
       
    97 	TPtr8 data((TUint8*)&iInfo,dataLengthToReturn,dataLengthToReturn);
       
    98 
       
    99 	iMessage.WriteL(1,data,0);
       
   100 
       
   101 	iMessage.Complete(KErrNone);
       
   102 	--iEventBalance;
       
   103 	}
       
   104 
       
   105 // Cancels the oustanding GetEvent call. May cope with other async calls in future.
       
   106 void CSecuritySvrAsync::DoCancel()
       
   107 	{
       
   108 	LOG_MSG2("CSecuritySvrAsync::DoCancel() iEventBalance=%d", iEventBalance);
       
   109 	iSession->Server().iKernelDriver.CancelGetEvent(iProcessName,iAgentId.Id());
       
   110 
       
   111 	iMessage.Complete(KErrCancel);
       
   112 	iEventBalance=0;
       
   113 	}
       
   114 
       
   115 // Report any leave to the client if possible.
       
   116 TInt CSecuritySvrAsync::RunError(TInt aError)
       
   117 	{
       
   118 	LOG_MSG2("CSecuritySvrAsync::RunError()=%d", aError);
       
   119 	iMessage.Complete(aError);
       
   120 
       
   121 	return KErrNone;
       
   122 	}
       
   123 
       
   124 /*
       
   125  * Start an asynchronous GetEvent call to the debug driver
       
   126  * and activates this active object. 
       
   127  */
       
   128 void CSecuritySvrAsync::GetEvent(const RMessage2& aMessage)
       
   129 	{
       
   130 	iMessage = aMessage;
       
   131 
       
   132 	iEventBalance++;
       
   133 	LOG_MSG5("CSecuritySvrAsync::GetEvent() this = 0x%08x, iInfo=0x%08x, iStatus=0x%08x \
       
   134 		iEventBalance=%d : >SetActive() > GetEvent() ",
       
   135 		this, &iInfo, &iStatus, iEventBalance );
       
   136 
       
   137 	/* 
       
   138 	SetActive is called before sending the message to the driver so 
       
   139 	that we do not get stray signal panics, since the driver may complete immediately
       
   140  	*/
       
   141 	SetActive();
       
   142 	iSession->Server().iKernelDriver.GetEvent(iProcessName,iAgentId.Id(),iStatus,iInfo);
       
   143 	}
       
   144 
       
   145 // Used for identifying which AO is associated with a debugged process
       
   146 const TDesC8& CSecuritySvrAsync::ProcessName(void)
       
   147 	{
       
   148 	return iProcessName;
       
   149 	}
       
   150 
       
   151 // End of file - c_security_svr_async.cpp
       
   152