|
1 // Copyright (c) 2004-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/logger.h> |
|
22 #include <e32base.h> |
|
23 #include <remcon/remconextapi1.h> |
|
24 #include <remcontrackinfocontroller.h> |
|
25 #include <remcontrackinfocontrollerobserver.h> |
|
26 #include <remconinterfaceselector.h> |
|
27 |
|
28 #ifdef __FLOG_ACTIVE |
|
29 _LIT8(KLogComponent, LOG_COMPONENT_REMCON_EXTAPI1); |
|
30 #endif |
|
31 |
|
32 // Used to pad over the results field in the operation-specific data. |
|
33 _LIT8(KResultsPad, " "); |
|
34 |
|
35 EXPORT_C CRemConTrackInfoController* CRemConTrackInfoController::NewL(CRemConInterfaceSelector& aInterfaceSelector, |
|
36 MRemConTrackInfoControllerObserver& aObserver) |
|
37 { |
|
38 LOG_STATIC_FUNC |
|
39 |
|
40 CRemConTrackInfoController* self = new(ELeave) CRemConTrackInfoController(aInterfaceSelector, aObserver); |
|
41 CleanupStack::PushL(self); |
|
42 self->BaseConstructL(); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CRemConTrackInfoController::CRemConTrackInfoController(CRemConInterfaceSelector& aInterfaceSelector, |
|
48 MRemConTrackInfoControllerObserver& aObserver) |
|
49 : CRemConInterfaceBase(TUid::Uid(KRemConTrackInfoApiUid), |
|
50 KMaxName, |
|
51 aInterfaceSelector, |
|
52 ERemConClientTypeController), |
|
53 iObserver(aObserver) |
|
54 { |
|
55 } |
|
56 |
|
57 EXPORT_C CRemConTrackInfoController::~CRemConTrackInfoController() |
|
58 { |
|
59 LOG_FUNC |
|
60 } |
|
61 |
|
62 TAny* CRemConTrackInfoController::GetInterfaceIf(TUid aUid) |
|
63 { |
|
64 TAny* ret = NULL; |
|
65 if ( aUid == TUid::Uid(KRemConInterfaceIf1) ) |
|
66 { |
|
67 ret = reinterpret_cast<TAny*>( |
|
68 static_cast<MRemConInterfaceIf*>(this) |
|
69 ); |
|
70 } |
|
71 |
|
72 return ret; |
|
73 } |
|
74 |
|
75 void CRemConTrackInfoController::MrcibNewMessage(TUint aOperationId, const TDesC8& aData) |
|
76 { |
|
77 LOG_FUNC |
|
78 LOG1(_L("\taOperationId = 0x%02x"), aOperationId); |
|
79 LOG1(_L("\taData.Length = %d"), aData.Length()); |
|
80 |
|
81 // Get the response error out of aData. |
|
82 if ( aData.Length() < KRemConExtApi1MinimumDataLength ) |
|
83 { |
|
84 return; // ditch malformed messages |
|
85 } |
|
86 |
|
87 TInt err = static_cast<TInt>(aData.Ptr()[0]); |
|
88 |
|
89 switch ( aOperationId ) |
|
90 { |
|
91 case ERemConSetTrackName: |
|
92 iObserver.MrcticoSetTrackNameResponse(err); |
|
93 break; |
|
94 |
|
95 //Only used in the pan-shared back to back test builds. |
|
96 #ifdef SYMBIAN_ENABLE_TRACKINFO_BACKTOBACK_TEST_FUNCT |
|
97 case ERemConGetTrackName: |
|
98 HandleGetTrackNameResponse(err, aData); |
|
99 break; |
|
100 case ERemConGetArtist: |
|
101 HandleGetArtistResponse(err, aData); |
|
102 break; |
|
103 case ERemConGetTrackDuration: |
|
104 HandleGetTrackDurationResponse(err, aData); |
|
105 break; |
|
106 #endif //SYMBIAN_ENABLE_TRACKINFO_BACKTOBACK_TEST_FUNCT |
|
107 |
|
108 default: |
|
109 break; |
|
110 } |
|
111 } |
|
112 |
|
113 EXPORT_C void CRemConTrackInfoController::SetTrackName(TRequestStatus& aStatus, const TDesC& aTrackName, TUint& aNumRemotes) |
|
114 { |
|
115 LOG_FUNC |
|
116 |
|
117 // First copy aTrackName into a specific descriptor type to |
|
118 // nail down the structure as we don't know what type of |
|
119 // descriptor has been passed in. |
|
120 |
|
121 // TBuf is restricted to 58 characters, this relates to the |
|
122 // amount of available space in iOutData. |
|
123 TBuf<58> temp; |
|
124 temp.Copy(aTrackName); |
|
125 |
|
126 iOutData.Copy(KResultsPad()); //leaves 124 bytes of space |
|
127 |
|
128 TPckgBuf<TName> buf(temp); |
|
129 |
|
130 //Set buf to minimum required length |
|
131 //Size of iLength + Size of iMaxLength + Size of aTrackName |
|
132 // 4 Bytes + 4 Bytes +(Max. 58x2) 116 Bytes |
|
133 // = 124 Bytes Max Size |
|
134 buf.SetLength(sizeof(TUint) + sizeof(TUint) + temp.Size()); |
|
135 iOutData.Append(buf); |
|
136 |
|
137 InterfaceSelector().Send(aStatus, |
|
138 TUid::Uid(KRemConTrackInfoApiUid), |
|
139 (TUint)ERemConSetTrackName, |
|
140 aNumRemotes, |
|
141 ERemConCommand, |
|
142 iOutData); |
|
143 } |
|
144 |
|
145 |
|
146 //Included for internal testing purposes only. Should never be in a released product. |
|
147 #ifdef SYMBIAN_ENABLE_TRACKINFO_BACKTOBACK_TEST_FUNCT |
|
148 /** |
|
149 Sends a 'get track name' command. |
|
150 |
|
151 @param aStatus Used by RemCon to indicate completion of the send request. |
|
152 @param aNumRemotes On success, will contain the number of remotes the |
|
153 command was sent to. |
|
154 */ |
|
155 EXPORT_C void CRemConTrackInfoController::GetTrackName(TRequestStatus& aStatus, TUint& aNumRemotes) |
|
156 { |
|
157 LOG_FUNC |
|
158 |
|
159 iOutData.Zero(); |
|
160 |
|
161 InterfaceSelector().Send(aStatus, |
|
162 TUid::Uid(KRemConTrackInfoApiUid), |
|
163 (TUint)ERemConGetTrackName, |
|
164 aNumRemotes, |
|
165 ERemConCommand, |
|
166 iOutData); |
|
167 } |
|
168 |
|
169 /** |
|
170 Sends a 'get artist' command. |
|
171 |
|
172 @param aStatus Used by RemCon to indicate completion of the send request. |
|
173 @param aNumRemotes On success, will contain the number of remotes the |
|
174 command was sent to. |
|
175 */ |
|
176 EXPORT_C void CRemConTrackInfoController::GetArtist(TRequestStatus& aStatus, TUint& aNumRemotes) |
|
177 { |
|
178 LOG_FUNC |
|
179 |
|
180 iOutData.Zero(); |
|
181 |
|
182 InterfaceSelector().Send(aStatus, |
|
183 TUid::Uid(KRemConTrackInfoApiUid), |
|
184 (TUint)ERemConGetArtist, |
|
185 aNumRemotes, |
|
186 ERemConCommand, |
|
187 iOutData); |
|
188 } |
|
189 |
|
190 /** |
|
191 Sends a 'get track duration' command. |
|
192 |
|
193 @param aStatus Used by RemCon to indicate completion of the send request. |
|
194 @param aNumRemotes On success, will contain the number of remotes the |
|
195 command was sent to. |
|
196 */ |
|
197 EXPORT_C void CRemConTrackInfoController::GetTrackDuration(TRequestStatus& aStatus, TUint& aNumRemotes) |
|
198 { |
|
199 LOG_FUNC |
|
200 |
|
201 iOutData.Zero(); |
|
202 |
|
203 InterfaceSelector().Send(aStatus, |
|
204 TUid::Uid(KRemConTrackInfoApiUid), |
|
205 (TUint)ERemConGetTrackDuration, |
|
206 aNumRemotes, |
|
207 ERemConCommand, |
|
208 iOutData); |
|
209 } |
|
210 |
|
211 /** |
|
212 Extracts the track name from the 'get track name' response data and calls |
|
213 the relevant mixin function on the observer. |
|
214 |
|
215 @param The data passed with the response. |
|
216 */ |
|
217 void CRemConTrackInfoController::HandleGetTrackNameResponse(TInt aError, const TDesC8& aData) |
|
218 { |
|
219 LOG_FUNC |
|
220 |
|
221 TPckgBuf<TName> buf; |
|
222 buf.Copy((aData.Mid(KRemConExtApi1ResultDataLength))); |
|
223 iObserver.MrcticoGetTrackNameResponse(aError, buf()); |
|
224 } |
|
225 |
|
226 /** |
|
227 Extracts the artist from the 'get artist' response data and calls |
|
228 the relevant mixin function on the observer. |
|
229 |
|
230 @param The data passed with the response. |
|
231 */ |
|
232 void CRemConTrackInfoController::HandleGetArtistResponse(TInt aError, const TDesC8& aData) |
|
233 { |
|
234 LOG_FUNC |
|
235 |
|
236 TPckgBuf<TName> buf; |
|
237 buf.Copy((aData.Mid(KRemConExtApi1ResultDataLength))); |
|
238 iObserver.MrcticoGetArtistResponse(aError, buf()); |
|
239 } |
|
240 |
|
241 /** |
|
242 Extracts the track duration from the 'get track duration' response data and calls |
|
243 the relevant mixin function on the observer. |
|
244 |
|
245 @param The data passed with the response. |
|
246 */ |
|
247 void CRemConTrackInfoController::HandleGetTrackDurationResponse(TInt aError, const TDesC8& aData) |
|
248 { |
|
249 LOG_FUNC |
|
250 |
|
251 TPckgBuf<TInt64> buf; |
|
252 buf.Copy((aData.Mid(KRemConExtApi1ResultDataLength))); |
|
253 TTime duration(buf()); |
|
254 iObserver.MrcticoGetTrackDurationResponse(aError, duration); |
|
255 } |
|
256 |
|
257 #pragma message ("The remote control Track Info extension API is being built with the extra back to back test code functionality included. This should only happen in DEBUG build and never be released.") |
|
258 |
|
259 #endif //SYMBIAN_ENABLE_TRACKINFO_BACKTOBACK_TEST_FUNCT |