|
1 // Copyright (c) 2006-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 // 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 __ASSERT_COMPILE(_FOFF(TEventInfo, iEventType) == 20); // Checking that adding iActionTaken hasn't resized the class |
|
27 |
|
28 CSecuritySvrAsync::CSecuritySvrAsync(CSecuritySvrSession* aSession, TProcessId aAgentId) |
|
29 : CActive(CActive::EPriorityStandard), |
|
30 iSession(aSession), |
|
31 iProcessName(NULL), |
|
32 iAgentId(aAgentId) |
|
33 { |
|
34 LOG_MSG2("CSecuritySvrAsync::CSecuritySvrAsync(aAgentId=0x%x)", TUint(aAgentId.Id())); |
|
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 CSecuritySvrAsync* me = new (ELeave) CSecuritySvrAsync(aSession, aAgentId); |
|
43 |
|
44 CleanupStack::PushL(me); |
|
45 |
|
46 me->ConstructL(aProcessName); |
|
47 |
|
48 CleanupStack::Pop(me); |
|
49 LOG_MSG2("CSecuritySvrAsync::NewL() obj addr=0x%x", me); |
|
50 return (me); |
|
51 } |
|
52 |
|
53 // dtor |
|
54 CSecuritySvrAsync::~CSecuritySvrAsync() |
|
55 { |
|
56 LOG_MSG("CSecuritySvrAsync::~CSecuritySvrAsync()"); |
|
57 |
|
58 // NOTE: the Cancel() function calls DoCancel() which may rely on class members so be careful not |
|
59 // to destroy/close data members before this call if they are needed |
|
60 Cancel(); |
|
61 iProcessName.Close(); |
|
62 } |
|
63 |
|
64 // Associates the agent id and process name with the Active Object being constructed |
|
65 void CSecuritySvrAsync::ConstructL(const TDesC8& aProcessName) |
|
66 { |
|
67 LOG_MSG("CSecuritySvrAsync::ConstructL()"); |
|
68 iProcessName.CreateL(aProcessName.Length()); |
|
69 iProcessName.Copy(aProcessName); |
|
70 } |
|
71 |
|
72 // RunL() completes a previously issued call (currently only GetEvent() completion) |
|
73 void CSecuritySvrAsync::RunL() |
|
74 { |
|
75 |
|
76 LOG_MSG4("CSecuritySvrAsync::RunL() &iInfo=0x%08x, iAgentId.Id()=0x%x, iEventType=%d", |
|
77 (TUint8*)&iInfo, iAgentId.Id(), iInfo.iEventType); |
|
78 LOG_MSG5(" RunL() : iProcessIdValid=%d, iThreadId=0x%x, iProcessId=0x%x, &iStatus=0x%x", |
|
79 iInfo.iProcessIdValid, TUint(iInfo.iThreadId) , TUint(iInfo.iProcessId), &iStatus ); |
|
80 |
|
81 // Something bad happened in the driver |
|
82 User::LeaveIfError(iStatus.Int()); |
|
83 |
|
84 // Write back the event data to the debug agent. |
|
85 // For compatibility we need to check the size of the buffer that the |
|
86 // client has passed in as the size of TEventInfo will increase over time. |
|
87 // Clients can calculate the required size from the EApiConstantsTEventInfoSize entry |
|
88 // in the Debug Functionality block but may still pass in buffers which |
|
89 // are smaller than the Debug Security Server's calculation of sizeof(TEventInfo), |
|
90 // returning KErrTooBig in this case would be |
|
91 // inappropriate as we would break compatibility. |
|
92 TInt dataLengthToReturn = sizeof(TEventInfo); |
|
93 TInt maxLengthClientSide = iMessage.GetDesMaxLengthL(1); |
|
94 if(maxLengthClientSide < dataLengthToReturn) |
|
95 { |
|
96 dataLengthToReturn = maxLengthClientSide; |
|
97 } |
|
98 |
|
99 |
|
100 TPtr8 data((TUint8*)&iInfo, dataLengthToReturn, dataLengthToReturn); |
|
101 iMessage.WriteL(1, data, 0); |
|
102 iMessage.Complete(KErrNone); |
|
103 } |
|
104 |
|
105 // Cancels the oustanding GetEvent call. May cope with other async calls in future. |
|
106 void CSecuritySvrAsync::DoCancel() |
|
107 { |
|
108 LOG_MSG("CSecuritySvrAsync::DoCancel()"); |
|
109 iSession->Server().iKernelDriver.CancelGetEvent(iProcessName,iAgentId.Id()); |
|
110 |
|
111 iMessage.Complete(KErrCancel); |
|
112 } |
|
113 |
|
114 // Report any leave to the client if possible. |
|
115 TInt CSecuritySvrAsync::RunError(TInt aError) |
|
116 { |
|
117 LOG_MSG2("CSecuritySvrAsync::RunError()=%d", aError); |
|
118 iMessage.Complete(aError); |
|
119 |
|
120 return KErrNone; |
|
121 } |
|
122 |
|
123 /** |
|
124 * Start an asynchronous GetEvent call to the debug driver |
|
125 * and activates this active object. |
|
126 * If active object already active, completes the message with error KErrInUse |
|
127 * and takes no further action. |
|
128 */ |
|
129 void CSecuritySvrAsync::GetEvent(const RMessage2& aMessage) |
|
130 { |
|
131 if( !IsActive() ) |
|
132 { |
|
133 iMessage = aMessage; |
|
134 LOG_MSG4("CSecuritySvrAsync::GetEvent() this = 0x%08x, iInfo=0x%08x, iStatus=0x%08x", this, &iInfo, &iStatus); |
|
135 |
|
136 SetActive(); |
|
137 iSession->Server().iKernelDriver.GetEvent(iProcessName,iAgentId.Id(),iStatus,iInfo); |
|
138 } |
|
139 else |
|
140 { |
|
141 LOG_MSG2("CSecuritySvrAsync::GetEvent() this = 0x%08x: ! Warning: ActiveObject is active. Returning with no effect", |
|
142 this ); |
|
143 aMessage.Complete( KErrInUse ); |
|
144 } |
|
145 } |
|
146 |
|
147 // Used for identifying which AO is associated with a debugged process |
|
148 const TDesC8& CSecuritySvrAsync::ProcessName(void) |
|
149 { |
|
150 return iProcessName; |
|
151 } |
|
152 |
|
153 // End of file - c_security_svr_async.cpp |
|
154 |