|
1 // Copyright (c) 2008-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 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 @released |
|
22 */ |
|
23 |
|
24 #include <remconaddress.h> |
|
25 #include <remconbeareravrcp.h> |
|
26 #include <remcon/remconbearerbulkobserver.h> |
|
27 |
|
28 #include "avrcpbrowsingcommandhandler.h" |
|
29 #include "avrcprouter.h" |
|
30 #include "avrcputils.h" |
|
31 #include "browsecommand.h" |
|
32 #include "bulkbearer.h" |
|
33 #include "playerstatewatcher.h" |
|
34 |
|
35 #include "avrcplog.h" |
|
36 |
|
37 #ifdef _DEBUG |
|
38 PANICCATEGORY("avrcpbulk"); |
|
39 #endif // _DEBUG |
|
40 |
|
41 CAvrcpBulkBearer* CAvrcpBulkBearer::NewL(RAvctp& aAvctp, CAvrcpPlayerInfoManager& aPlayerInfoManager) |
|
42 { |
|
43 LOG_STATIC_FUNC |
|
44 CAvrcpBulkBearer* bulkBearer = new(ELeave) CAvrcpBulkBearer(aPlayerInfoManager, aAvctp); |
|
45 return bulkBearer; |
|
46 } |
|
47 |
|
48 CAvrcpBulkBearer::~CAvrcpBulkBearer() |
|
49 { |
|
50 LOG_FUNC |
|
51 ASSERT_DEBUG(!iRouter); // Should already be stopped... |
|
52 } |
|
53 |
|
54 CAvrcpBulkBearer::CAvrcpBulkBearer(CAvrcpPlayerInfoManager& aPlayerInfoManager, RAvctp& aAvctp) |
|
55 : iPlayerInfoManager(aPlayerInfoManager) |
|
56 , iAvctp(aAvctp) |
|
57 , iReadyBrowseCommands(_FOFF(CAvrcpCommand, iReadyLink)) |
|
58 { |
|
59 LOG_FUNC |
|
60 } |
|
61 |
|
62 MIncomingCommandHandler* CAvrcpBulkBearer::IncomingHandler(const TBTDevAddr& aAddr) |
|
63 { |
|
64 LOG_FUNC |
|
65 |
|
66 MIncomingCommandHandler* handler = NULL; |
|
67 TInt ix = iBrowseHandlers.Find(aAddr, CAvrcpBulkBearer::CompareBrowsingCommandHandlerByBDAddr); |
|
68 if(ix >= 0) |
|
69 { |
|
70 handler = iBrowseHandlers[ix]; |
|
71 } |
|
72 |
|
73 return handler; |
|
74 } |
|
75 |
|
76 MOutgoingCommandHandler* CAvrcpBulkBearer::OutgoingHandler(const TBTDevAddr& /*aAddr*/) |
|
77 { |
|
78 LOG_FUNC |
|
79 // We've received a response, but we haven't sent a command. Naughty remote, |
|
80 // just ignore it. |
|
81 return NULL; |
|
82 } |
|
83 |
|
84 void CAvrcpBulkBearer::DoConnectIndicateL(const TBTDevAddr& aBTDevice) |
|
85 { |
|
86 LOG_FUNC |
|
87 ASSERT_BULK_THREAD; |
|
88 |
|
89 ASSERT_DEBUG(Operational()); |
|
90 |
|
91 CRcpBrowsingCommandHandler* handler = CRcpBrowsingCommandHandler::NewL(*this, *iRouter, iPlayerInfoManager, aBTDevice); |
|
92 CleanupStack::PushL(handler); |
|
93 |
|
94 iBrowseHandlers.AppendL(handler); |
|
95 |
|
96 CleanupStack::Pop(handler); |
|
97 } |
|
98 |
|
99 void CAvrcpBulkBearer::ConnectIndicate(const TBTDevAddr& aBTDevice) |
|
100 { |
|
101 LOG_FUNC |
|
102 // If we failed to allocate a handler for this connection the router will |
|
103 // not be able to find it when it checks, and will tell AVCTP that we're |
|
104 // not interested in this connection. |
|
105 TRAP_IGNORE(DoConnectIndicateL(aBTDevice)); |
|
106 } |
|
107 |
|
108 void CAvrcpBulkBearer::ConnectConfirm(const TBTDevAddr& IF_FLOGGING(aBTDevice), TInt IF_FLOGGING(aError)) |
|
109 { |
|
110 LOG_FUNC |
|
111 LOGBTDEVADDR(aBTDevice); |
|
112 LOG1(_L("\taError = %d"), aError); |
|
113 |
|
114 // Outlandish! We did not ask for this! |
|
115 __ASSERT_DEBUG(EFalse, AVRCP_PANIC(EAvrcpConnectConfirmOnBrowseChannel)); |
|
116 } |
|
117 |
|
118 void CAvrcpBulkBearer::DisconnectIndicate(const TBTDevAddr& aBTDevice) |
|
119 { |
|
120 LOG_FUNC |
|
121 ASSERT_BULK_THREAD; |
|
122 |
|
123 CRcpBrowsingCommandHandler* handler = NULL; |
|
124 TInt ix = iBrowseHandlers.Find(aBTDevice, CAvrcpBulkBearer::CompareBrowsingCommandHandlerByBDAddr); |
|
125 if(ix >= 0) |
|
126 { |
|
127 handler = iBrowseHandlers[ix]; |
|
128 delete handler; |
|
129 iBrowseHandlers.Remove(ix); |
|
130 } |
|
131 else |
|
132 { |
|
133 ASSERT_DEBUG(EFalse); |
|
134 } |
|
135 } |
|
136 |
|
137 void CAvrcpBulkBearer::DisconnectConfirm(const TBTDevAddr& IF_FLOGGING(aBTDevice), TInt IF_FLOGGING(aError)) |
|
138 { |
|
139 LOG_FUNC |
|
140 LOGBTDEVADDR(aBTDevice); |
|
141 LOG1(_L("\taError = %d"), aError); |
|
142 |
|
143 // Also outlandish! Connections on browse channel are all passive. |
|
144 __ASSERT_DEBUG(EFalse, AVRCP_PANIC(EAvrcpDisconnectConfirmOnBrowseChannel)); |
|
145 } |
|
146 |
|
147 void CAvrcpBulkBearer::MrcciNewCommand(CAvrcpCommand& aCommand) |
|
148 { |
|
149 LOG_FUNC |
|
150 |
|
151 DoNewCommand(aCommand, KNullClientId); |
|
152 } |
|
153 |
|
154 // This overload is used when we want to address a stateless command that may |
|
155 // be interleaved with commands from other controllers. The only command |
|
156 // this is currently used for is the internal UidCounterUpdate command. |
|
157 void CAvrcpBulkBearer::MrcciNewCommand(CAvrcpCommand& aCommand, const TRemConClientId& aClientId) |
|
158 { |
|
159 LOG_FUNC |
|
160 // Verify that it's an internal command |
|
161 __ASSERT_DEBUG(aCommand.RemoteAddress() == TBTDevAddr(0), AvrcpUtils::Panic(ESpecificAddressUsedForBrowsingCommand)); |
|
162 |
|
163 DoNewCommand(aCommand, aClientId); |
|
164 } |
|
165 |
|
166 void CAvrcpBulkBearer::DoNewCommand(CAvrcpCommand& aCommand, const TRemConClientId& aClientId) |
|
167 { |
|
168 LOG_FUNC |
|
169 |
|
170 // Need to put the command on the queue straight |
|
171 // away in case RemCon collects it synchronously |
|
172 iReadyBrowseCommands.AddLast(aCommand); |
|
173 aCommand.IncrementUsers(); |
|
174 |
|
175 TRemConAddress remAddr; |
|
176 AvrcpUtils::BTToRemConAddr(aCommand.RemoteAddress(), remAddr); |
|
177 |
|
178 TInt err = (aClientId == KNullClientId) ? iObserver->NewCommand(remAddr) : iObserver->NewCommand(remAddr, aClientId); |
|
179 |
|
180 if(err != KErrNone) |
|
181 { |
|
182 TUid interfaceUid; |
|
183 TUint remconId, operationId; |
|
184 RBuf8 commandData; |
|
185 TBTDevAddr btAddr; |
|
186 |
|
187 // Calling GetCommandInfo transfers ownership of the command data. |
|
188 aCommand.GetCommandInfo(interfaceUid, remconId, operationId, commandData, btAddr); |
|
189 MrcbbiSendReject(interfaceUid, operationId, remconId, remAddr); |
|
190 commandData.Close(); |
|
191 |
|
192 // RemCon is not going to pick this command up |
|
193 aCommand.iReadyLink.Deque(); |
|
194 aCommand.DecrementUsers(); |
|
195 } |
|
196 } |
|
197 |
|
198 TUint CAvrcpBulkBearer::MrcciNewTransactionId() |
|
199 { |
|
200 LOG_FUNC |
|
201 return iObserver->NewTransactionId(); |
|
202 } |
|
203 |
|
204 TInt CAvrcpBulkBearer::MrcbciSetAddressedClient(const TRemConAddress& aAddr, const TRemConClientId& aClient) |
|
205 { |
|
206 LOG_FUNC |
|
207 return iObserver->SetAddressedClient(aAddr, aClient); |
|
208 } |
|
209 |
|
210 void CAvrcpBulkBearer::MrcbciRemoveAddressing(const TRemConAddress& aAddr) |
|
211 { |
|
212 LOG_FUNC |
|
213 iObserver->RemoveAddressing(aAddr); |
|
214 } |
|
215 |
|
216 TInt CAvrcpBulkBearer::MrcbbiGetCommand(TUid& aInterfaceUid, |
|
217 TUint& aTransactionId, |
|
218 TUint& aOperationId, |
|
219 RBuf8& aData, |
|
220 TRemConAddress& aAddr) |
|
221 { |
|
222 LOG_FUNC |
|
223 TInt result = KErrNotFound; |
|
224 |
|
225 if(!iReadyBrowseCommands.IsEmpty()) |
|
226 { |
|
227 CAvrcpCommand* command = iReadyBrowseCommands.First(); |
|
228 |
|
229 // Calling GetCommandInfo transfers the command data to RemCon. This means |
|
230 // once we have called it we are committed to returning KErrNone. |
|
231 TBTDevAddr btAddr; |
|
232 command->GetCommandInfo(aInterfaceUid, aTransactionId, aOperationId, aData, btAddr); |
|
233 AvrcpUtils::BTToRemConAddr(btAddr, aAddr); |
|
234 |
|
235 // Remove command from queue first because calling |
|
236 // DecrementUsers() may delete command |
|
237 command->iReadyLink.Deque(); |
|
238 command->DecrementUsers(); |
|
239 result = KErrNone; |
|
240 } |
|
241 else |
|
242 { |
|
243 __DEBUGGER(); |
|
244 } |
|
245 |
|
246 return result; |
|
247 } |
|
248 |
|
249 TInt CAvrcpBulkBearer::MrcbbiSendResponse(TUid aInterfaceUid, |
|
250 TUint /*aOperationId*/, |
|
251 TUint aTransactionId, |
|
252 RBuf8& aData, |
|
253 const TRemConAddress& aAddr) |
|
254 { |
|
255 LOG_FUNC |
|
256 TBTDevAddr btAddr; |
|
257 TInt err = KErrNone; |
|
258 |
|
259 err = AvrcpUtils::RemConToBTAddr(aAddr, btAddr); |
|
260 __ASSERT_DEBUG(err == KErrNone, AvrcpUtils::Panic(EInvalidBtAddrInResponse)); |
|
261 |
|
262 if(btAddr != TBTDevAddr(0)) |
|
263 { |
|
264 MIncomingCommandHandler* handler = IncomingHandler(btAddr); |
|
265 __ASSERT_ALWAYS(handler, AVRCP_PANIC(EAvrcpNotConnected)); |
|
266 |
|
267 err = handler->SendRemConResponse(aInterfaceUid, aTransactionId, aData); |
|
268 } |
|
269 else |
|
270 { |
|
271 err = iInternalHandler->SendRemConResponse(aInterfaceUid, aTransactionId, aData); |
|
272 } |
|
273 |
|
274 return err; |
|
275 } |
|
276 |
|
277 void CAvrcpBulkBearer::MrcbbiSendReject(TUid aInterfaceUid, |
|
278 TUint /*aOperationId*/, |
|
279 TUint aTransactionId, |
|
280 const TRemConAddress& aAddr) |
|
281 { |
|
282 LOG_FUNC |
|
283 |
|
284 TBTDevAddr btAddr; |
|
285 TInt err = AvrcpUtils::RemConToBTAddr(aAddr, btAddr); |
|
286 __ASSERT_DEBUG(err == KErrNone, AvrcpUtils::Panic(EInvalidBtAddrInResponse)); |
|
287 |
|
288 if(btAddr != TBTDevAddr(0)) |
|
289 { |
|
290 IncomingHandler(btAddr)->SendReject(aInterfaceUid, aTransactionId); |
|
291 } |
|
292 else |
|
293 { |
|
294 iInternalHandler->SendReject(aInterfaceUid, aTransactionId); |
|
295 } |
|
296 } |
|
297 |
|
298 TInt CAvrcpBulkBearer::MrcbbiStartBulk(MRemConBearerBulkObserver& aObserver) |
|
299 { |
|
300 LOG_FUNC |
|
301 iObserver = &aObserver; |
|
302 TRAPD(err, DoStartBulkL()); |
|
303 if(err != KErrNone) |
|
304 { |
|
305 MrcbbiStopBulk(); |
|
306 } |
|
307 return err; |
|
308 } |
|
309 |
|
310 void CAvrcpBulkBearer::DoStartBulkL() |
|
311 { |
|
312 LOG_FUNC |
|
313 LEAVEIFERRORL(Dll::SetTls(reinterpret_cast<TAny*>(EBulkThread))); |
|
314 iInternalHandler = iPlayerInfoManager.BulkStartedL(*this); |
|
315 iRouter = CBulkRouter::NewL(iAvctp, *this); |
|
316 } |
|
317 |
|
318 void CAvrcpBulkBearer::MrcbbiStopBulk() |
|
319 { |
|
320 LOG_FUNC |
|
321 WEAK_ASSERT_BULK_THREAD; |
|
322 |
|
323 iPlayerInfoManager.BulkStopped(); |
|
324 iInternalHandler = NULL; |
|
325 |
|
326 delete iRouter; |
|
327 iRouter = NULL; |
|
328 |
|
329 iBrowseHandlers.ResetAndDestroy(); |
|
330 |
|
331 iObserver = NULL; // the observer is no longer valid. |
|
332 |
|
333 Dll::FreeTls(); |
|
334 } |
|
335 |
|
336 TBool CAvrcpBulkBearer::Operational() const |
|
337 { |
|
338 LOG_FUNC |
|
339 ASSERT_DEBUG(!iRouter == !iObserver); // internal consistency check |
|
340 return !!iRouter; |
|
341 } |
|
342 |
|
343 void CAvrcpBulkBearer::MrcbbiBulkClientAvailable(const TRemConClientId& aId) |
|
344 { |
|
345 LOG_FUNC |
|
346 iPlayerInfoManager.BulkClientAvailable(aId); |
|
347 } |
|
348 |
|
349 void CAvrcpBulkBearer::MrcbbiBulkClientNotAvailable(const TRemConClientId& aId) |
|
350 { |
|
351 LOG_FUNC |
|
352 iPlayerInfoManager.BulkClientNotAvailable(aId); |
|
353 } |
|
354 |
|
355 |
|
356 TBool CAvrcpBulkBearer::CompareBrowsingCommandHandlerByBDAddr(const TBTDevAddr* aKey, const CRcpBrowsingCommandHandler& aHandler) |
|
357 { |
|
358 LOG_STATIC_FUNC |
|
359 return aKey && aHandler.BtAddr() == *aKey; |
|
360 } |
|
361 |
|
362 |
|
363 |