1 /* |
1 /* |
2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
25 #include "msmmserver.h" |
25 #include "msmmserver.h" |
26 #include "msmmnodebase.h" |
26 #include "msmmnodebase.h" |
27 #include "msmmengine.h" |
27 #include "msmmengine.h" |
28 #include <usb/hostms/msmmpolicypluginbase.h> |
28 #include <usb/hostms/msmmpolicypluginbase.h> |
29 #include <usb/usblogger.h> |
29 #include <usb/usblogger.h> |
30 #include "OstTraceDefinitions.h" |
30 |
31 #ifdef OST_TRACE_COMPILER_IN_USE |
31 #ifdef __FLOG_ACTIVE |
32 #include "eventqueueTraces.h" |
32 _LIT8(KLogComponent, "UsbHostMsmmServer"); |
33 #endif |
33 #endif |
34 |
|
35 |
34 |
36 // Public member functions |
35 // Public member functions |
37 CDeviceEventQueue::~CDeviceEventQueue( ) |
36 CDeviceEventQueue::~CDeviceEventQueue( ) |
38 { |
37 { |
39 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_CDEVICEEVENTQUEUE_DES_ENTRY ); |
38 LOG_FUNC |
40 |
|
41 Cancel(); |
39 Cancel(); |
42 delete iHandler; |
40 delete iHandler; |
43 iEventArray.Close(); |
41 iEventArray.Close(); |
44 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_CDEVICEEVENTQUEUE_DES_EXIT ); |
|
45 } |
42 } |
46 |
43 |
47 CDeviceEventQueue* CDeviceEventQueue::NewL(MMsmmSrvProxy& aServer) |
44 CDeviceEventQueue* CDeviceEventQueue::NewL(MMsmmSrvProxy& aServer) |
48 { |
45 { |
49 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_NEWL_ENTRY ); |
46 LOG_STATIC_FUNC_ENTRY |
50 |
|
51 CDeviceEventQueue* self = CDeviceEventQueue::NewLC(aServer); |
47 CDeviceEventQueue* self = CDeviceEventQueue::NewLC(aServer); |
52 CleanupStack::Pop(self); |
48 CleanupStack::Pop(self); |
53 |
49 |
54 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_NEWL_EXIT ); |
|
55 return self; |
50 return self; |
56 } |
51 } |
57 CDeviceEventQueue* CDeviceEventQueue::NewLC(MMsmmSrvProxy& aServer) |
52 CDeviceEventQueue* CDeviceEventQueue::NewLC(MMsmmSrvProxy& aServer) |
58 { |
53 { |
59 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_NEWLC_ENTRY ); |
54 LOG_STATIC_FUNC_ENTRY |
60 |
|
61 CDeviceEventQueue* self = new (ELeave) CDeviceEventQueue(aServer); |
55 CDeviceEventQueue* self = new (ELeave) CDeviceEventQueue(aServer); |
62 CleanupStack::PushL(self); |
56 CleanupStack::PushL(self); |
63 self->ConstructL(); |
57 self->ConstructL(); |
64 |
58 |
65 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_NEWLC_EXIT ); |
|
66 return self; |
59 return self; |
67 } |
60 } |
68 |
61 |
69 void CDeviceEventQueue::PushL(const TDeviceEvent& aEvent) |
62 void CDeviceEventQueue::PushL(const TDeviceEvent& aEvent) |
70 { |
63 { |
71 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_PUSHL_ENTRY ); |
64 LOG_FUNC |
72 |
65 |
73 // Perform optimization for remove device event |
66 // Perform optimization for remove device event |
74 AppendAndOptimizeL(aEvent); |
67 AppendAndOptimizeL(aEvent); |
75 |
68 |
76 // Start handling first event in queue |
69 // Start handling first event in queue |
77 StartL(); |
70 StartL(); |
78 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_PUSHL_EXIT ); |
|
79 } |
71 } |
80 |
72 |
81 void CDeviceEventQueue::Finalize() |
73 void CDeviceEventQueue::Finalize() |
82 { |
74 { |
83 TInt index(0); |
75 TInt index(0); |
101 |
93 |
102 |
94 |
103 // Protected member functions |
95 // Protected member functions |
104 void CDeviceEventQueue::DoCancel() |
96 void CDeviceEventQueue::DoCancel() |
105 { |
97 { |
106 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_DOCANCEL_ENTRY ); |
98 LOG_FUNC |
107 |
|
108 iEventArray.Reset(); |
99 iEventArray.Reset(); |
109 iHandler->Cancel(); |
100 iHandler->Cancel(); |
110 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_DOCANCEL_EXIT ); |
|
111 } |
101 } |
112 |
102 |
113 void CDeviceEventQueue::RunL() |
103 void CDeviceEventQueue::RunL() |
114 { |
104 { |
115 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_RUNL_ENTRY ); |
105 LOG_FUNC |
116 |
|
117 // Check the completion code from CDeviceEventHandler. If there |
106 // Check the completion code from CDeviceEventHandler. If there |
118 // is some error occured. We need issue error notification here. |
107 // is some error occured. We need issue error notification here. |
119 TInt err = iStatus.Int(); |
108 TInt err = iStatus.Int(); |
120 if ((KErrNone != err) && (KErrCancel != err)) |
109 if ((KErrNone != err) && (KErrCancel != err)) |
121 { |
110 { |
125 iHandler->ResetHandler(); |
114 iHandler->ResetHandler(); |
126 if (IsEventAvailable()) |
115 if (IsEventAvailable()) |
127 { |
116 { |
128 SendEventL(); |
117 SendEventL(); |
129 } |
118 } |
130 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_RUNL_EXIT ); |
|
131 } |
119 } |
132 |
120 |
133 TInt CDeviceEventQueue::RunError(TInt aError) |
121 TInt CDeviceEventQueue::RunError(TInt aError) |
134 { |
122 { |
135 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_RUNERROR_ENTRY ); |
123 LOG_FUNC |
136 |
|
137 THostMsErrData errData; |
124 THostMsErrData errData; |
138 switch (aError) |
125 switch (aError) |
139 { |
126 { |
140 case KErrNoMemory: |
127 case KErrNoMemory: |
141 errData.iError = EHostMsErrOutOfMemory; |
128 errData.iError = EHostMsErrOutOfMemory; |
155 errData.iProductString.Copy(deviceNode->iDevice.iProductString); |
142 errData.iProductString.Copy(deviceNode->iDevice.iProductString); |
156 } |
143 } |
157 errData.iDriveName = 0x0; |
144 errData.iDriveName = 0x0; |
158 TInt err(KErrNone); |
145 TInt err(KErrNone); |
159 TRAP(err, iServer.PolicyPlugin()->SendErrorNotificationL(errData)); |
146 TRAP(err, iServer.PolicyPlugin()->SendErrorNotificationL(errData)); |
160 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_RUNERROR_EXIT ); |
|
161 return KErrNone; |
147 return KErrNone; |
162 } |
148 } |
163 |
149 |
164 // Private member functions |
150 // Private member functions |
165 CDeviceEventQueue::CDeviceEventQueue(MMsmmSrvProxy& aServer): |
151 CDeviceEventQueue::CDeviceEventQueue(MMsmmSrvProxy& aServer): |
166 CActive(EPriorityStandard), |
152 CActive(EPriorityStandard), |
167 iServer(aServer) |
153 iServer(aServer) |
168 { |
154 { |
169 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_CDEVICEEVENTQUEUE_CONS_ENTRY ); |
155 LOG_FUNC |
170 |
|
171 CActiveScheduler::Add(this); |
156 CActiveScheduler::Add(this); |
172 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_CDEVICEEVENTQUEUE_CONS_EXIT ); |
|
173 } |
157 } |
174 |
158 |
175 void CDeviceEventQueue::ConstructL() |
159 void CDeviceEventQueue::ConstructL() |
176 { |
160 { |
177 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_CONSTRUCTL_ENTRY ); |
161 LOG_FUNC |
178 |
|
179 iHandler = CDeviceEventHandler::NewL(iServer); |
162 iHandler = CDeviceEventHandler::NewL(iServer); |
180 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_CONSTRUCTL_EXIT ); |
|
181 } |
163 } |
182 |
164 |
183 void CDeviceEventQueue::AppendAndOptimizeL(const TDeviceEvent& aEvent) |
165 void CDeviceEventQueue::AppendAndOptimizeL(const TDeviceEvent& aEvent) |
184 { |
166 { |
185 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_APPENDANDOPTIMIZEL_ENTRY ); |
167 LOG_FUNC |
186 |
|
187 if (EDeviceEventRemoveDevice == aEvent.iEvent) |
168 if (EDeviceEventRemoveDevice == aEvent.iEvent) |
188 { |
169 { |
189 // Scan the event queue to discard all pending related adding |
170 // Scan the event queue to discard all pending related adding |
190 // function events. |
171 // function events. |
191 TInt index(0); |
172 TInt index(0); |
213 break; |
194 break; |
214 case EDeviceEventRemoveDevice: |
195 case EDeviceEventRemoveDevice: |
215 if (aEvent.iDeviceId == iHandler->Event().iDeviceId && IsActive()) |
196 if (aEvent.iDeviceId == iHandler->Event().iDeviceId && IsActive()) |
216 { |
197 { |
217 // Discard duplicated removing event. |
198 // Discard duplicated removing event. |
218 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_APPENDANDOPTIMIZEL_EXIT ); |
|
219 return; |
199 return; |
220 } |
200 } |
221 break; |
201 break; |
222 } |
202 } |
223 } |
203 } |
224 iEventArray.AppendL(aEvent); |
204 iEventArray.AppendL(aEvent); |
225 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_APPENDANDOPTIMIZEL_EXIT_DUP1 ); |
|
226 } |
205 } |
227 |
206 |
228 void CDeviceEventQueue::StartL() |
207 void CDeviceEventQueue::StartL() |
229 { |
208 { |
230 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_STARTL_ENTRY ); |
209 LOG_FUNC |
231 |
|
232 if (IsActive()) |
210 if (IsActive()) |
233 { |
211 { |
234 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_STARTL_EXIT ); |
|
235 return; |
212 return; |
236 } |
213 } |
237 |
214 |
238 if (IsEventAvailable()) |
215 if (IsEventAvailable()) |
239 { |
216 { |
240 SendEventL(); |
217 SendEventL(); |
241 } |
218 } |
242 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_STARTL_EXIT_DUP1 ); |
|
243 } |
219 } |
244 |
220 |
245 void CDeviceEventQueue::SendEventL() |
221 void CDeviceEventQueue::SendEventL() |
246 { |
222 { |
247 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_SENDEVENTL_ENTRY ); |
223 LOG_FUNC |
248 |
|
249 // If the handler is available, sending oldest event to it |
224 // If the handler is available, sending oldest event to it |
250 iHandler->HandleEventL(iStatus, Pop()); |
225 iHandler->HandleEventL(iStatus, Pop()); |
251 |
226 |
252 // Activiate the manager again to wait for the handler |
227 // Activiate the manager again to wait for the handler |
253 // finish current event |
228 // finish current event |
254 SetActive(); |
229 SetActive(); |
255 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_SENDEVENTL_EXIT ); |
|
256 } |
230 } |
257 |
231 |
258 TDeviceEvent CDeviceEventQueue::Pop() |
232 TDeviceEvent CDeviceEventQueue::Pop() |
259 { |
233 { |
260 OstTraceFunctionEntry0( CDEVICEEVENTQUEUE_POP_ENTRY ); |
234 LOG_FUNC |
261 |
|
262 TDeviceEvent event = iEventArray[0]; |
235 TDeviceEvent event = iEventArray[0]; |
263 iEventArray.Remove(0); |
236 iEventArray.Remove(0); |
264 OstTraceFunctionExit0( CDEVICEEVENTQUEUE_POP_EXIT ); |
|
265 return event; |
237 return event; |
266 } |
238 } |
267 |
239 |
268 // End of file |
240 // End of file |