|
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 #include "mediabrowse.h" |
|
17 #include "avrcputils.h" |
|
18 #include "commandhandlerinterface.h" |
|
19 #include "internalcommand.h" |
|
20 #include "mediabrowse.h" |
|
21 #include "playerstatewatcher.h" |
|
22 #include "remconcommandinterface.h" |
|
23 #include "avrcplog.h" |
|
24 #include "playerinformation.h" |
|
25 |
|
26 CPlayerWatcherBase::CPlayerWatcherBase(MRemConCommandInterface& aCommandInterface) |
|
27 : iCommandInterface(aCommandInterface), iCommands() |
|
28 { |
|
29 LOG_FUNC; |
|
30 } |
|
31 |
|
32 CPlayerWatcherBase::~CPlayerWatcherBase() |
|
33 { |
|
34 LOG_FUNC; |
|
35 } |
|
36 |
|
37 void CPlayerWatcherBase::StopWatchingPlayer(TRemConClientId aClientId) |
|
38 { |
|
39 LOG_FUNC; |
|
40 CInternalCommand* command = *iCommands.Find(aClientId); |
|
41 __ASSERT_DEBUG(command, AVRCP_PANIC(ENotWatchingPlayer)); |
|
42 |
|
43 iCommands.Remove(aClientId); |
|
44 command->DecrementUsers(); |
|
45 } |
|
46 |
|
47 void CPlayerWatcherBase::MessageSent(CAvrcpCommand& /*aCommand*/, TInt /*aSendResult*/) |
|
48 { |
|
49 LOG_FUNC; |
|
50 __DEBUG_ONLY(AVRCP_PANIC(ELowerInterfaceUsedOnInternalHandler)); |
|
51 } |
|
52 |
|
53 void CPlayerWatcherBase::MaxPacketSize(TInt /*aMtu*/) |
|
54 { |
|
55 LOG_FUNC; |
|
56 __DEBUG_ONLY(AVRCP_PANIC(ELowerInterfaceUsedOnInternalHandler)); |
|
57 } |
|
58 |
|
59 void CPlayerWatcherBase::ReceiveCommandL(const TDesC8& /*aMessageInformation*/, SymbianAvctp::TTransactionLabel /*aTransLabel*/, const TBTDevAddr& /*aAddr*/) |
|
60 { |
|
61 LOG_FUNC; |
|
62 __DEBUG_ONLY(AVRCP_PANIC(ELowerInterfaceUsedOnInternalHandler)); |
|
63 } |
|
64 |
|
65 CInternalCommand& CPlayerWatcherBase::FindCommand(TUid __DEBUG_ONLY(aInterfaceUid), |
|
66 TUint aTransactionId, TRemConClientId& aFoundClientId) |
|
67 { |
|
68 __ASSERT_DEBUG(aInterfaceUid == TUid::Uid(KRemConPlayerInformationUid) || aInterfaceUid == TUid::Uid(KRemConMediaBrowseApiUid), AVRCP_PANIC(EResponseForWrongInterface)); |
|
69 THashMapIter<TRemConClientId, CInternalCommand*> commandIter(iCommands); |
|
70 |
|
71 CInternalCommand* command = NULL; |
|
72 while(commandIter.NextValue()) |
|
73 { |
|
74 command = *commandIter.CurrentValue(); |
|
75 if(command->RemConCommandId() == aTransactionId) |
|
76 { |
|
77 aFoundClientId = *commandIter.CurrentKey(); |
|
78 break; |
|
79 } |
|
80 } |
|
81 |
|
82 // If command is NULL we reached the end of our iter without finding the match |
|
83 __ASSERT_DEBUG(command, AVRCP_PANIC(EUnmatchedResponseFromRemCon)); |
|
84 |
|
85 return *command; |
|
86 } |
|
87 |
|
88 TInt CPlayerWatcherBase::SendRemConResponse(TUid aInterfaceUid, TUint aTransactionId, RBuf8& aData) |
|
89 { |
|
90 LOG_FUNC; |
|
91 |
|
92 TRemConClientId clientId; |
|
93 CInternalCommand& command = FindCommand(aInterfaceUid, aTransactionId, clientId); |
|
94 |
|
95 ReceiveUpdate(command, clientId, aData); |
|
96 |
|
97 return KErrNone; |
|
98 } |
|
99 |
|
100 void CPlayerWatcherBase::SendReject(TUid aInterfaceUid, TUint aTransactionId) |
|
101 { |
|
102 TRemConClientId clientId; |
|
103 (void)FindCommand(aInterfaceUid, aTransactionId, clientId); |
|
104 |
|
105 ReceiveReject(clientId); |
|
106 } |
|
107 |
|
108 void CPlayerWatcherBase::Disconnect() |
|
109 { |
|
110 LOG_FUNC; |
|
111 } |
|
112 |
|
113 CPlayStatusWatcher* CPlayStatusWatcher::NewL(MPlayStatusObserver& aObserver, MRemConCommandInterface& aCommandInterface) |
|
114 { |
|
115 LOG_STATIC_FUNC; |
|
116 CPlayStatusWatcher* watcher = new(ELeave)CPlayStatusWatcher(aObserver, aCommandInterface); |
|
117 return watcher; |
|
118 } |
|
119 |
|
120 CPlayStatusWatcher::CPlayStatusWatcher(MPlayStatusObserver& aObserver, |
|
121 MRemConCommandInterface& aCommandInterface) |
|
122 : CPlayerWatcherBase(aCommandInterface), iObserver(aObserver) |
|
123 { |
|
124 LOG_FUNC; |
|
125 } |
|
126 |
|
127 CPlayStatusWatcher::~CPlayStatusWatcher() |
|
128 { |
|
129 LOG_FUNC; |
|
130 } |
|
131 |
|
132 void CPlayStatusWatcher::StartWatchingPlayerL(TRemConClientId aClientId) |
|
133 { |
|
134 LOG_FUNC; |
|
135 __ASSERT_DEBUG(!iCommands.Find(aClientId), AVRCP_PANIC(EAlreadyWatchingPlayer)); |
|
136 |
|
137 CInternalCommand* command = CInternalCommand::NewL(TUid::Uid(KRemConPlayerInformationUid), |
|
138 0, |
|
139 EGetPlayStatusUpdate, |
|
140 KNullDesC8); |
|
141 |
|
142 CleanupStack::PushL(command); |
|
143 iCommands.InsertL(aClientId, command); |
|
144 CleanupStack::Pop(command); |
|
145 command->IncrementUsers(); |
|
146 |
|
147 // Initially request uid notification relative to stopped |
|
148 SendPlayStatusUpdateRequest(*command, aClientId, MPlayerEventsObserver::EStopped); |
|
149 } |
|
150 |
|
151 void CPlayStatusWatcher::SendPlayStatusUpdateRequest(CInternalCommand& aCommand, TRemConClientId& aClientId, MPlayerEventsObserver::TPlaybackStatus aPlaybackStatus) |
|
152 { |
|
153 LOG_FUNC; |
|
154 |
|
155 RRemConPlayerInformationGetPlayStatusUpdateRequest request; |
|
156 request.iStatus = aPlaybackStatus; |
|
157 |
|
158 TBuf8<sizeof(MPlayerEventsObserver::TPlaybackStatus)> buf; |
|
159 TRAPD(err, request.WriteL(buf)); |
|
160 |
|
161 // We know how big the request is so this should never fail |
|
162 __ASSERT_DEBUG(err == KErrNone, AVRCP_PANIC(EUidUpdateRequestWriteFailure)); |
|
163 |
|
164 TUint transId = iCommandInterface.MrcciNewTransactionId(); |
|
165 TRAP(err, aCommand.ResetL(transId, buf)); |
|
166 |
|
167 if(err == KErrNone) |
|
168 { |
|
169 iCommandInterface.MrcciNewCommand(aCommand, aClientId); |
|
170 } |
|
171 else |
|
172 { |
|
173 // Doom |
|
174 iObserver.MpsoError(aClientId); |
|
175 } |
|
176 } |
|
177 |
|
178 void CPlayStatusWatcher::ReceiveUpdate(CInternalCommand& aCommand, TRemConClientId aClientId, RBuf8& aData) |
|
179 { |
|
180 LOG_FUNC; |
|
181 |
|
182 // Read 4 byte Big-Endian error code before the payload |
|
183 RAvrcpIPCError errorResponse; |
|
184 TRAPD(err, errorResponse.ReadL(aData)); |
|
185 err = err ? err : errorResponse.iError; |
|
186 |
|
187 RRemConPlayerInformationGetPlayStatusUpdateResponse response; |
|
188 if(!err) |
|
189 { |
|
190 // Parse the rest of the response (minus error code) |
|
191 TRAP(err, response.ReadL(aData.RightTPtr(aData.Length() - KLengthErrorResponse))); |
|
192 } |
|
193 |
|
194 aData.Close(); // data has been used now |
|
195 |
|
196 if(!err) |
|
197 { |
|
198 iObserver.MpsoPlayStatusChanged(aClientId, response.iStatus); |
|
199 SendPlayStatusUpdateRequest(aCommand, aClientId, response.iStatus); |
|
200 } |
|
201 else |
|
202 { |
|
203 // Should never get here with a valid player. This client is |
|
204 // sending us junk. |
|
205 iObserver.MpsoError(aClientId); |
|
206 } |
|
207 } |
|
208 |
|
209 void CPlayStatusWatcher::ReceiveReject(TRemConClientId aClientId) |
|
210 { |
|
211 LOG_FUNC; |
|
212 iObserver.MpsoError(aClientId); |
|
213 } |
|
214 |
|
215 CUidWatcher* CUidWatcher::NewL(MUidObserver& aObserver, |
|
216 MRemConCommandInterface& aCommandInterface) |
|
217 { |
|
218 LOG_STATIC_FUNC; |
|
219 CUidWatcher* watcher = new(ELeave)CUidWatcher(aObserver, aCommandInterface); |
|
220 return watcher; |
|
221 } |
|
222 |
|
223 CUidWatcher::CUidWatcher(MUidObserver& aObserver, |
|
224 MRemConCommandInterface& aCommandInterface) |
|
225 : CPlayerWatcherBase(aCommandInterface), iObserver(aObserver) |
|
226 { |
|
227 LOG_FUNC; |
|
228 } |
|
229 |
|
230 CUidWatcher::~CUidWatcher() |
|
231 { |
|
232 LOG_FUNC; |
|
233 } |
|
234 |
|
235 void CUidWatcher::StartWatchingPlayerL(TRemConClientId aClientId) |
|
236 { |
|
237 LOG_FUNC; |
|
238 __ASSERT_DEBUG(!iCommands.Find(aClientId), AVRCP_PANIC(EAlreadyWatchingPlayer)); |
|
239 |
|
240 CInternalCommand* command = CInternalCommand::NewL(TUid::Uid(KRemConMediaBrowseApiUid), |
|
241 0, |
|
242 EMediaLibraryStateCookieUpdateOperationId, |
|
243 KNullDesC8); |
|
244 |
|
245 CleanupStack::PushL(command); |
|
246 iCommands.InsertL(aClientId, command); |
|
247 CleanupStack::Pop(command); |
|
248 command->IncrementUsers(); |
|
249 |
|
250 // Initially request uid notification relative to 0 uid counter |
|
251 SendUidUpdateRequest(*command, aClientId, 0); |
|
252 } |
|
253 |
|
254 void CUidWatcher::SendUidUpdateRequest(CInternalCommand& aCommand, TRemConClientId& aClientId, TUint16 aUidCounter) |
|
255 { |
|
256 LOG_FUNC; |
|
257 RRemConUidsChangedRequest request; |
|
258 request.iInitialUidCounter = aUidCounter; |
|
259 TBuf8<sizeof(TUint16)> buf; |
|
260 TRAPD(err, request.WriteL(buf)); |
|
261 // We know how big the request is so this should never fail |
|
262 __ASSERT_DEBUG(err == KErrNone, AVRCP_PANIC(EUidUpdateRequestWriteFailure)); |
|
263 |
|
264 TUint transId = iCommandInterface.MrcciNewTransactionId(); |
|
265 TRAP(err, aCommand.ResetL(transId, buf)); |
|
266 |
|
267 if(err == KErrNone) |
|
268 { |
|
269 iCommandInterface.MrcciNewCommand(aCommand, aClientId); |
|
270 } |
|
271 else |
|
272 { |
|
273 // Doom |
|
274 iObserver.MuoError(aClientId); |
|
275 } |
|
276 } |
|
277 |
|
278 void CUidWatcher::ReceiveUpdate(CInternalCommand& aCommand, TRemConClientId aClientId, RBuf8& aData) |
|
279 { |
|
280 LOG_FUNC; |
|
281 RRemConUidsChangedResponse response; |
|
282 TRAPD(err, response.ReadL(aData)); |
|
283 aData.Close(); // data has been used now |
|
284 |
|
285 if(!err) |
|
286 { |
|
287 iObserver.MuoUidChanged(aClientId, response.iUidCounter); |
|
288 SendUidUpdateRequest(aCommand, aClientId, response.iUidCounter); |
|
289 } |
|
290 else |
|
291 { |
|
292 // Should never get here with a valid player. This client is |
|
293 // sending us junk. |
|
294 iObserver.MuoError(aClientId); |
|
295 } |
|
296 } |
|
297 |
|
298 void CUidWatcher::ReceiveReject(TRemConClientId aClientId) |
|
299 { |
|
300 LOG_FUNC; |
|
301 iObserver.MuoError(aClientId); |
|
302 } |
|
303 |
|
304 |
|
305 |