|
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 "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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <bluetooth/hcicommandqitem.h> |
|
22 #include "HciCmdQTimer.h" |
|
23 #include "HciCmdQUtil.h" |
|
24 |
|
25 #include <bluetooth/hci/hcicommandallocator.h> |
|
26 #include <bluetooth/hci/hciframe.h> |
|
27 #include <bluetooth/hcicmdqcontroller.h> |
|
28 #include <bluetooth/hci/command.h> |
|
29 #include <bluetooth/logger.h> |
|
30 |
|
31 #ifdef __FLOG_ACTIVE |
|
32 _LIT8(KLogComponent, LOG_COMPONENT_HCICMDQ); |
|
33 #endif |
|
34 |
|
35 /** |
|
36 Static factory method for HCI Command Queue items. |
|
37 |
|
38 @param aCommandAllocator the HCI commmand frame allocator. |
|
39 @param aCmdProgressRecipient the HCI event notification client. |
|
40 @param aCommand the HCI command to be processed. Ownership of the command is transferred to |
|
41 the created HCI Command Queue item object. |
|
42 @return ownership of a new HCI Command Queue item object |
|
43 */ |
|
44 EXPORT_C /*static*/ CHCICommandQItem* CHCICommandQItem::NewL(MHCICommandAllocator& aCommandAllocator, |
|
45 MHCICommandQueueClient& aCmdProgressRecipient, |
|
46 CHCICommandBase* aCommand) |
|
47 { |
|
48 LOG_STATIC_FUNC |
|
49 |
|
50 CleanupStack::PushL(aCommand); // Ensure we don't leak the command until ownership is taken. |
|
51 CHCICommandQItem* self = new (ELeave) CHCICommandQItem(aCmdProgressRecipient, aCommand); |
|
52 CleanupStack::Pop(aCommand); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(aCommandAllocator); |
|
55 CleanupStack::Pop(self); |
|
56 return self; |
|
57 } |
|
58 |
|
59 EXPORT_C CHCICommandQItem::~CHCICommandQItem() |
|
60 { |
|
61 LOG_FUNC |
|
62 |
|
63 iLink.Deque(); |
|
64 delete iCompletionTimer; |
|
65 delete iCommand; |
|
66 delete iCmdFrame; |
|
67 delete iQdpData; |
|
68 } |
|
69 |
|
70 /** |
|
71 Const getter for the Command encapsulated in the object. |
|
72 |
|
73 @return Reference to the CHCICommandBase instance holding the command parameters. |
|
74 */ |
|
75 EXPORT_C CHCICommandBase& CHCICommandQItem::Command() const |
|
76 { |
|
77 LOG_FUNC |
|
78 |
|
79 return *iCommand; |
|
80 } |
|
81 |
|
82 /** |
|
83 Getter for the client to be notified of the progress of the command |
|
84 |
|
85 @return Reference to the MHCICommandQueueClient instance to be notified |
|
86 of the progress of the command |
|
87 */ |
|
88 EXPORT_C MHCICommandQueueClient* CHCICommandQItem::Client() const |
|
89 { |
|
90 LOG_FUNC |
|
91 |
|
92 return iCmdProgressRecipient; |
|
93 } |
|
94 |
|
95 /** |
|
96 Getter for the pointer to the QDP specific data associated with the queue item. |
|
97 |
|
98 @return A pointer to an arbitrary data structure used by the QDP. |
|
99 */ |
|
100 EXPORT_C TAny* CHCICommandQItem::QdpData() const |
|
101 { |
|
102 LOG_FUNC |
|
103 |
|
104 return iQdpData; |
|
105 } |
|
106 |
|
107 /** |
|
108 Setter for the pointer to the QDP specific data associated with the queue item. |
|
109 |
|
110 @param aQdpData A pointer to some data used by the QDP to be associated with this queue item. |
|
111 */ |
|
112 EXPORT_C void CHCICommandQItem::SetQdpData(TAny* aQdpData) |
|
113 { |
|
114 LOG_FUNC |
|
115 __ASSERT_DEBUG(!iQdpData, PANIC(KHCICmdQPanic, EPossibleQdpDataLeak)); |
|
116 iQdpData = aQdpData; |
|
117 } |
|
118 |
|
119 /** |
|
120 Return if a Command Status event has been received that matches the command associated |
|
121 with this command queue item. |
|
122 |
|
123 @return whether this command has received a command status event. |
|
124 */ |
|
125 EXPORT_C TBool CHCICommandQItem::ReceivedCmdStatusEvent() const |
|
126 { |
|
127 LOG_FUNC |
|
128 return ((iCommandState & EReceivedCmdStatusEvent)); |
|
129 } |
|
130 |
|
131 /** |
|
132 Return if the command associated with this queue item was added to the command |
|
133 queue as an initialisation command. |
|
134 |
|
135 @return whether this command is an initialisation command. |
|
136 */ |
|
137 EXPORT_C TBool CHCICommandQItem::IsInitialisation() const |
|
138 { |
|
139 LOG_FUNC |
|
140 return ((iCommandState & EInitialisationCmd)); |
|
141 } |
|
142 |
|
143 /** |
|
144 Return if the command associated with this queue item is a Parent command, i.e. |
|
145 one that has pre and/or post child commands. |
|
146 |
|
147 @return whether this command is a Parent command. |
|
148 */ |
|
149 EXPORT_C TBool CHCICommandQItem::IsParent() const |
|
150 { |
|
151 LOG_FUNC |
|
152 return (iType == EParent); |
|
153 } |
|
154 |
|
155 /** |
|
156 Return if the command associated with this queue item is a Pre-Child command, i.e. |
|
157 one that has Parent command. |
|
158 |
|
159 @return whether this command is a Pre-Child command. |
|
160 */ |
|
161 EXPORT_C TBool CHCICommandQItem::IsPreChild() const |
|
162 { |
|
163 LOG_FUNC |
|
164 return (iType == EPreChild); |
|
165 } |
|
166 |
|
167 /** |
|
168 Return if the command associated with this queue item is a Post-Child command, i.e. |
|
169 one that has Parent command. |
|
170 |
|
171 @return whether this command is a Post-Child command. |
|
172 */ |
|
173 EXPORT_C TBool CHCICommandQItem::IsPostChild() const |
|
174 { |
|
175 LOG_FUNC |
|
176 return (iType == EPostChild); |
|
177 } |
|
178 |
|
179 /** |
|
180 Return if the command associated with this queue item is a Normal command, i.e. |
|
181 one that doesn't require a workaround and isn't itself a Child command. |
|
182 |
|
183 @return whether this command is a Normal command. |
|
184 */ |
|
185 EXPORT_C TBool CHCICommandQItem::IsNormal() const |
|
186 { |
|
187 LOG_FUNC |
|
188 return (iType == ENormal); |
|
189 } |
|
190 |
|
191 /** |
|
192 Return the total number of times the command associated with this queue item has |
|
193 been sent. |
|
194 |
|
195 @return Number of times this command has been sent. |
|
196 */ |
|
197 EXPORT_C TUint CHCICommandQItem::SentCount() const |
|
198 { |
|
199 LOG_FUNC |
|
200 return iSentCounter; |
|
201 } |
|
202 |
|
203 /** |
|
204 This isn't exported since only the CHCICmdQController will use the Frame. |
|
205 Getter for the command frame object that is associated with this queue item. |
|
206 @return A reference to the command frame that this queue item "has". |
|
207 */ |
|
208 CHctlCommandFrame& CHCICommandQItem::Frame() const |
|
209 { |
|
210 LOG_FUNC |
|
211 return *iCmdFrame; |
|
212 } |
|
213 |
|
214 /** |
|
215 This isn't exported since only the CHCICmdQController will use the ID. |
|
216 @return the command queue ID for this object |
|
217 */ |
|
218 TUint CHCICommandQItem::CommandQId() const |
|
219 { |
|
220 LOG_FUNC |
|
221 return iCommandQId; |
|
222 } |
|
223 |
|
224 /** |
|
225 This isn't exported since only the CHCICmdQController will use the ID. |
|
226 @param aId the command queue ID for this object |
|
227 */ |
|
228 void CHCICommandQItem::SetCommandQId(TUint aId) |
|
229 { |
|
230 LOG_FUNC |
|
231 iCommandQId = aId; |
|
232 } |
|
233 |
|
234 /** |
|
235 This isn't exported since only the CHCICmdQController will use the |
|
236 EReceivedCmdStatusEvent flag. |
|
237 */ |
|
238 void CHCICommandQItem::SetReceivedCmdStatusEvent(TBool aReceivedCmdStatusEvent) |
|
239 { |
|
240 LOG_FUNC |
|
241 |
|
242 if (aReceivedCmdStatusEvent) |
|
243 { |
|
244 iCommandState |= EReceivedCmdStatusEvent; |
|
245 } |
|
246 else |
|
247 { |
|
248 iCommandState &= ~EReceivedCmdStatusEvent; |
|
249 } |
|
250 } |
|
251 |
|
252 /** |
|
253 Marks the command item as being an initialisation command. |
|
254 */ |
|
255 void CHCICommandQItem::SetInitialisationCmd() |
|
256 { |
|
257 LOG_FUNC |
|
258 |
|
259 iCommandState |= EInitialisationCmd; |
|
260 } |
|
261 |
|
262 /** |
|
263 This isn't exported since only the CHCICmdQController will use the |
|
264 EDuplicatedOpcode flag. |
|
265 @return whether this object duplicates an item on the command queue. |
|
266 */ |
|
267 TBool CHCICommandQItem::DuplicatedOpcode() const |
|
268 { |
|
269 LOG_FUNC |
|
270 return ((iCommandState & EDuplicatedOpcode)); |
|
271 } |
|
272 |
|
273 |
|
274 /** |
|
275 This isn't exported since only the CHCICmdQController will use the |
|
276 EDuplicatedOpcode flag. |
|
277 */ |
|
278 void CHCICommandQItem::SetDuplicatedOpcode(TBool aDuplicatedOpcode) |
|
279 { |
|
280 LOG_FUNC |
|
281 |
|
282 if (aDuplicatedOpcode) |
|
283 { |
|
284 iCommandState |= EDuplicatedOpcode; |
|
285 } |
|
286 else |
|
287 { |
|
288 iCommandState &= ~EDuplicatedOpcode; |
|
289 } |
|
290 } |
|
291 |
|
292 /** |
|
293 Starts iCompletionTimer going. |
|
294 @param aMilliseconds the amount of time in milliseconds to run the timer for. |
|
295 @param aController the object to inform if the timer expires. |
|
296 */ |
|
297 void CHCICommandQItem::StartCompletionTimer(TUint aMilliseconds, CHCICmdQController& aController) |
|
298 { |
|
299 LOG_FUNC |
|
300 |
|
301 iCompletionTimer->Restart(aMilliseconds, CommandQId(), aController); |
|
302 } |
|
303 |
|
304 /** |
|
305 Cancels iCompletionTimer. |
|
306 */ |
|
307 void CHCICommandQItem::CancelCompletionTimer() |
|
308 { |
|
309 LOG_FUNC |
|
310 |
|
311 iCompletionTimer->Cancel(); |
|
312 } |
|
313 |
|
314 /** |
|
315 Instructs this object to format iCmdFrame with the parameters in iCommand. |
|
316 */ |
|
317 void CHCICommandQItem::FormatFrame() |
|
318 { |
|
319 LOG_FUNC |
|
320 |
|
321 iCommand->FormatCommand(*iCmdFrame); |
|
322 } |
|
323 |
|
324 /** |
|
325 Detaches the client callback interface from the command on the queue. |
|
326 */ |
|
327 void CHCICommandQItem::DetachClient() |
|
328 { |
|
329 LOG_FUNC |
|
330 |
|
331 iCmdProgressRecipient = NULL; |
|
332 } |
|
333 |
|
334 /** |
|
335 @return Type of the command item (child, parent, normal, etc) |
|
336 */ |
|
337 CHCICommandQItem::TType CHCICommandQItem::Type() const |
|
338 { |
|
339 LOG_FUNC |
|
340 |
|
341 return iType; |
|
342 } |
|
343 |
|
344 /** |
|
345 @param Type of the command item (child, parent, normal, etc) |
|
346 */ |
|
347 void CHCICommandQItem::SetType(CHCICommandQItem::TType aType) |
|
348 { |
|
349 LOG_FUNC |
|
350 |
|
351 iType = aType; |
|
352 } |
|
353 |
|
354 /** |
|
355 This isn't exported since only the CHCICmdQController will set the |
|
356 send status flags. |
|
357 */ |
|
358 void CHCICommandQItem::CommandSent() |
|
359 { |
|
360 LOG_FUNC |
|
361 iSentCounter++; |
|
362 } |
|
363 |
|
364 /** |
|
365 Constructor |
|
366 */ |
|
367 CHCICommandQItem::CHCICommandQItem(MHCICommandQueueClient& aCmdProgressRecipient, |
|
368 CHCICommandBase* aCommand) |
|
369 : iCommand(aCommand), |
|
370 iCmdProgressRecipient(&aCmdProgressRecipient) |
|
371 { |
|
372 LOG_FUNC |
|
373 } |
|
374 |
|
375 /** |
|
376 Constructor |
|
377 */ |
|
378 void CHCICommandQItem::ConstructL(MHCICommandAllocator& aCommandAllocator) |
|
379 { |
|
380 LOG_FUNC |
|
381 |
|
382 iCmdFrame = aCommandAllocator.MhcaNewFrameL(); |
|
383 iCompletionTimer = CHCICmdQCompletionTimer::NewL(); |
|
384 } |