|
1 /* |
|
2 * Copyright (c) 2008-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 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include "eventqueue.h" |
|
24 #include "eventhandler.h" |
|
25 #include "msmmserver.h" |
|
26 #include "msmmnodebase.h" |
|
27 #include "msmmengine.h" |
|
28 #include <usb/hostms/msmmpolicypluginbase.h> |
|
29 #include <usb/usblogger.h> |
|
30 |
|
31 #ifdef __FLOG_ACTIVE |
|
32 _LIT8(KLogComponent, "UsbHostMsmmServer"); |
|
33 #endif |
|
34 |
|
35 // Public member functions |
|
36 CDeviceEventQueue::~CDeviceEventQueue( ) |
|
37 { |
|
38 LOG_FUNC |
|
39 Cancel(); |
|
40 delete iHandler; |
|
41 iEventArray.Close(); |
|
42 } |
|
43 |
|
44 CDeviceEventQueue* CDeviceEventQueue::NewL(MMsmmSrvProxy& aServer) |
|
45 { |
|
46 LOG_STATIC_FUNC_ENTRY |
|
47 CDeviceEventQueue* self = CDeviceEventQueue::NewLC(aServer); |
|
48 CleanupStack::Pop(self); |
|
49 |
|
50 return self; |
|
51 } |
|
52 CDeviceEventQueue* CDeviceEventQueue::NewLC(MMsmmSrvProxy& aServer) |
|
53 { |
|
54 LOG_STATIC_FUNC_ENTRY |
|
55 CDeviceEventQueue* self = new (ELeave) CDeviceEventQueue(aServer); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(); |
|
58 |
|
59 return self; |
|
60 } |
|
61 |
|
62 void CDeviceEventQueue::PushL(const TDeviceEvent& aEvent) |
|
63 { |
|
64 LOG_FUNC |
|
65 |
|
66 // Perform optimization for remove device event |
|
67 AppendAndOptimizeL(aEvent); |
|
68 |
|
69 // Start handling first event in queue |
|
70 StartL(); |
|
71 } |
|
72 |
|
73 void CDeviceEventQueue::Finalize() |
|
74 { |
|
75 TInt index(0); |
|
76 while(index < iEventArray.Count()) |
|
77 { |
|
78 if (EDeviceEventAddFunction == iEventArray[index].iEvent) |
|
79 { |
|
80 iEventArray.Remove(index); |
|
81 } |
|
82 else |
|
83 { |
|
84 index ++; |
|
85 } |
|
86 }; |
|
87 |
|
88 if (EDeviceEventAddFunction == iHandler->Event().iEvent) |
|
89 { |
|
90 iHandler->Cancel(); |
|
91 } |
|
92 } |
|
93 |
|
94 |
|
95 // Protected member functions |
|
96 void CDeviceEventQueue::DoCancel() |
|
97 { |
|
98 LOG_FUNC |
|
99 iEventArray.Reset(); |
|
100 iHandler->Cancel(); |
|
101 } |
|
102 |
|
103 void CDeviceEventQueue::RunL() |
|
104 { |
|
105 LOG_FUNC |
|
106 // Check the completion code from CDeviceEventHandler. If there |
|
107 // is some error occured. We need issue error notification here. |
|
108 TInt err = iStatus.Int(); |
|
109 if ((KErrNone != err) && (KErrCancel != err)) |
|
110 { |
|
111 iServer.PolicyPlugin()-> |
|
112 SendErrorNotificationL(iHandler->ErrNotiData()); |
|
113 } |
|
114 iHandler->ResetHandler(); |
|
115 if (IsEventAvailable()) |
|
116 { |
|
117 SendEventL(); |
|
118 } |
|
119 } |
|
120 |
|
121 TInt CDeviceEventQueue::RunError(TInt aError) |
|
122 { |
|
123 LOG_FUNC |
|
124 THostMsErrData errData; |
|
125 switch (aError) |
|
126 { |
|
127 case KErrNoMemory: |
|
128 errData.iError = EHostMsErrOutOfMemory; |
|
129 break; |
|
130 case KErrArgument: |
|
131 errData.iError = EHostMsErrInvalidParameter; |
|
132 break; |
|
133 default: |
|
134 errData.iError = EHostMsErrGeneral; |
|
135 } |
|
136 errData.iE32Error = aError; |
|
137 TUsbMsDevice* deviceNode = |
|
138 iServer.Engine().SearchDevice(iHandler->Event().iDeviceId); |
|
139 if (deviceNode) |
|
140 { |
|
141 errData.iManufacturerString.Copy(deviceNode->iDevice.iManufacturerString); |
|
142 errData.iProductString.Copy(deviceNode->iDevice.iProductString); |
|
143 } |
|
144 errData.iDriveName = 0x0; |
|
145 TInt err(KErrNone); |
|
146 TRAP(err, iServer.PolicyPlugin()->SendErrorNotificationL(errData)); |
|
147 return KErrNone; |
|
148 } |
|
149 |
|
150 // Private member functions |
|
151 CDeviceEventQueue::CDeviceEventQueue(MMsmmSrvProxy& aServer): |
|
152 CActive(EPriorityStandard), |
|
153 iServer(aServer) |
|
154 { |
|
155 LOG_FUNC |
|
156 CActiveScheduler::Add(this); |
|
157 } |
|
158 |
|
159 void CDeviceEventQueue::ConstructL() |
|
160 { |
|
161 LOG_FUNC |
|
162 iHandler = CDeviceEventHandler::NewL(iServer); |
|
163 } |
|
164 |
|
165 void CDeviceEventQueue::AppendAndOptimizeL(const TDeviceEvent& aEvent) |
|
166 { |
|
167 LOG_FUNC |
|
168 if (EDeviceEventRemoveDevice == aEvent.iEvent) |
|
169 { |
|
170 // Scan the event queue to discard all pending related adding |
|
171 // function events. |
|
172 TInt index(0); |
|
173 while(index < iEventArray.Count()) |
|
174 { |
|
175 if (aEvent.iDeviceId == iEventArray[index].iDeviceId) |
|
176 { |
|
177 iEventArray.Remove(index); |
|
178 } |
|
179 else |
|
180 { |
|
181 index ++; |
|
182 } |
|
183 }; |
|
184 |
|
185 switch (iHandler->Event().iEvent) |
|
186 { |
|
187 case EDeviceEventAddFunction: |
|
188 // If a related adding interface event is being handled currently, |
|
189 // CDeviceEventQueue shall cancel it first. |
|
190 if (aEvent.iDeviceId == iHandler->Event().iDeviceId) |
|
191 { |
|
192 iHandler->Cancel(); |
|
193 } |
|
194 break; |
|
195 case EDeviceEventRemoveDevice: |
|
196 if (aEvent.iDeviceId == iHandler->Event().iDeviceId && IsActive()) |
|
197 { |
|
198 // Discard duplicated removing event. |
|
199 return; |
|
200 } |
|
201 break; |
|
202 } |
|
203 } |
|
204 iEventArray.AppendL(aEvent); |
|
205 } |
|
206 |
|
207 void CDeviceEventQueue::StartL() |
|
208 { |
|
209 LOG_FUNC |
|
210 if (IsActive()) |
|
211 { |
|
212 return; |
|
213 } |
|
214 |
|
215 if (IsEventAvailable()) |
|
216 { |
|
217 SendEventL(); |
|
218 } |
|
219 } |
|
220 |
|
221 void CDeviceEventQueue::SendEventL() |
|
222 { |
|
223 LOG_FUNC |
|
224 // If the handler is available, sending oldest event to it |
|
225 iHandler->HandleEventL(iStatus, Pop()); |
|
226 |
|
227 // Activiate the manager again to wait for the handler |
|
228 // finish current event |
|
229 SetActive(); |
|
230 } |
|
231 |
|
232 TDeviceEvent CDeviceEventQueue::Pop() |
|
233 { |
|
234 LOG_FUNC |
|
235 TDeviceEvent event = iEventArray[0]; |
|
236 iEventArray.Remove(0); |
|
237 return event; |
|
238 } |
|
239 |
|
240 // End of file |