|
1 // Copyright (c) 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 <mtp/tmtptyperequest.h> |
|
17 #include <mtp/cmtpstoragemetadata.h> |
|
18 #include <mtp/mmtpconnection.h> |
|
19 #include <mtp/mmtpdataproviderframework.h> |
|
20 #include <mtp/mtpdataproviderapitypes.h> |
|
21 #include <mtp/mtpprotocolconstants.h> |
|
22 #include "cmtppictbridgedp.h" |
|
23 #include "cptpserver.h" |
|
24 #include "mtppictbridgedpconst.h" |
|
25 #include "mtppictbridgedppanic.h" |
|
26 #include "mtppictbridgedpprocessor.h" |
|
27 #include "cmtppictbridgeenumerator.h" |
|
28 #include "ptpdef.h" |
|
29 |
|
30 LOCAL_D const TInt KArrayGranularity = 3; |
|
31 |
|
32 // -------------------------------------------------------------------------- |
|
33 // PictBridge data provider factory method. |
|
34 // @return A pointer to a pictbridge data provider object. Ownership is transfered. |
|
35 // @leave One of the system wide error codes, if a processing failure occurs. |
|
36 // -------------------------------------------------------------------------- |
|
37 // |
|
38 TAny* CMTPPictBridgeDataProvider::NewL(TAny* aParams) |
|
39 { |
|
40 CMTPPictBridgeDataProvider* self = new (ELeave) CMTPPictBridgeDataProvider(aParams); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 // -------------------------------------------------------------------------- |
|
47 // Constructor |
|
48 // -------------------------------------------------------------------------- |
|
49 // |
|
50 CMTPPictBridgeDataProvider::CMTPPictBridgeDataProvider(TAny* aParams): |
|
51 CMTPDataProviderPlugin(aParams), |
|
52 iActiveProcessors(KArrayGranularity) |
|
53 { |
|
54 } |
|
55 |
|
56 // -------------------------------------------------------------------------- |
|
57 // second phase constructor |
|
58 // -------------------------------------------------------------------------- |
|
59 // |
|
60 void CMTPPictBridgeDataProvider::ConstructL() |
|
61 { |
|
62 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
63 __FLOG(_L8(">> CMTPPictBridgeDataProvider::ConstructL")); |
|
64 iPictBridgeEnumeratorP = CMTPPictBridgeEnumerator::NewL(Framework(), *this); |
|
65 iServerP = CPtpServer::NewL(Framework(), *this); |
|
66 __FLOG(_L8("<< CMTPPictBridgeDataProvider::ConstructL")); |
|
67 } |
|
68 // -------------------------------------------------------------------------- |
|
69 // Destructor |
|
70 // -------------------------------------------------------------------------- |
|
71 // |
|
72 CMTPPictBridgeDataProvider::~CMTPPictBridgeDataProvider() |
|
73 { |
|
74 __FLOG(_L8(">> ~CMTPPictBridgeDataProvider")); |
|
75 |
|
76 TUint count(iActiveProcessors.Count()); |
|
77 while (count--) |
|
78 { |
|
79 iActiveProcessors[count]->Release(); |
|
80 } |
|
81 iActiveProcessors.Close(); |
|
82 |
|
83 delete iPictBridgeEnumeratorP; |
|
84 delete iServerP; |
|
85 |
|
86 __FLOG(_L8("<< ~CMTPPictBridgeDataProvider")); |
|
87 __FLOG_CLOSE; |
|
88 } |
|
89 |
|
90 // -------------------------------------------------------------------------- |
|
91 // Cancel |
|
92 // -------------------------------------------------------------------------- |
|
93 // |
|
94 void CMTPPictBridgeDataProvider::Cancel() |
|
95 { |
|
96 __FLOG(_L8(">> CMTPPictBridgeDataProvider::Cancel")); |
|
97 // nothing to cancel |
|
98 __FLOG(_L8("<< CMTPPictBridgeDataProvider::Cancel")); |
|
99 } |
|
100 // -------------------------------------------------------------------------- |
|
101 // |
|
102 // -------------------------------------------------------------------------- |
|
103 // |
|
104 void CMTPPictBridgeDataProvider::ProcessEventL(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection) |
|
105 { |
|
106 __FLOG(_L8(">> CMTPPictBridgeDataProvider::ProcessEventL")); |
|
107 |
|
108 TInt idx = LocateRequestProcessorL(aEvent, aConnection); |
|
109 |
|
110 if (idx != KErrNotFound) |
|
111 { |
|
112 iActiveProcessors[idx]->HandleEventL(aEvent); |
|
113 } |
|
114 |
|
115 __FLOG(_L8("<< CMTPPictBridgeDataProvider::ProcessEventL")); |
|
116 } |
|
117 // -------------------------------------------------------------------------- |
|
118 // Process notifications from the initiator |
|
119 // -------------------------------------------------------------------------- |
|
120 // |
|
121 void CMTPPictBridgeDataProvider::ProcessNotificationL(TMTPNotification aNotification, const TAny* aParams) |
|
122 { |
|
123 __FLOG(_L8(">> CMTPPictBridgeDataProvider::ProcessNotificationL")); |
|
124 |
|
125 switch (aNotification) |
|
126 { |
|
127 case EMTPSessionClosed: |
|
128 SessionClosedL(*reinterpret_cast<const TMTPNotificationParamsSessionChange*>(aParams)); |
|
129 break; |
|
130 |
|
131 case EMTPSessionOpened: |
|
132 SessionOpenedL(*reinterpret_cast<const TMTPNotificationParamsSessionChange*>(aParams)); |
|
133 break; |
|
134 |
|
135 default: |
|
136 // Ignore all other notifications. |
|
137 break; |
|
138 } |
|
139 |
|
140 __FLOG(_L8("<< CMTPPictBridgeDataProvider::ProcessNotificationL")); |
|
141 } |
|
142 // -------------------------------------------------------------------------- |
|
143 // Process requests from the initiator |
|
144 // -------------------------------------------------------------------------- |
|
145 // |
|
146 void CMTPPictBridgeDataProvider::ProcessRequestPhaseL(TMTPTransactionPhase aPhase, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) |
|
147 { |
|
148 __FLOG(_L8(">> CMTPPictBridgeDataProvider::ProcessRequestPhaseL")); |
|
149 |
|
150 TInt idx = LocateRequestProcessorL(aRequest, aConnection); |
|
151 __ASSERT_DEBUG((idx != KErrNotFound), Panic(EMTPPictBridgeDpNoMatchingProcessor)); |
|
152 MMTPRequestProcessor* processorP(iActiveProcessors[idx]); |
|
153 TBool result(processorP->HandleRequestL(aRequest, aPhase)); |
|
154 if (result) //destroy the processor |
|
155 { |
|
156 processorP->Release(); |
|
157 iActiveProcessors.Remove(idx); |
|
158 } |
|
159 |
|
160 __FLOG_VA((_L8("<< CMTPPictBridgeDataProvider::ProcessRequestPhaseL result=%d"), result)); |
|
161 } |
|
162 |
|
163 // -------------------------------------------------------------------------- |
|
164 // Starts the object enumeration |
|
165 // -------------------------------------------------------------------------- |
|
166 // |
|
167 void CMTPPictBridgeDataProvider::StartObjectEnumerationL(TUint32 aStorageId, TBool /*aPersistentFullEnumeration*/) |
|
168 { |
|
169 __FLOG(_L8(">> CMTPPictBridgeDataProvider::StartObjectEnumerationL")); |
|
170 |
|
171 iPictBridgeEnumeratorP->EnumerateObjectsL(aStorageId); |
|
172 |
|
173 __FLOG(_L8("<< CMTPPictBridgeDataProvider::StartObjectEnumerationL")); |
|
174 } |
|
175 |
|
176 // -------------------------------------------------------------------------- |
|
177 // Storage enumeration is not needed, just declared complete |
|
178 // -------------------------------------------------------------------------- |
|
179 // |
|
180 void CMTPPictBridgeDataProvider::StartStorageEnumerationL() |
|
181 { |
|
182 __FLOG(_L8(">> CMTPPictBridgeDataProvider::StartStorageEnumerationL")); |
|
183 iPictBridgeEnumeratorP->EnumerateStoragesL(); |
|
184 __FLOG(_L8("<< CMTPPictBridgeDataProvider::StartStorageEnumerationL")); |
|
185 } |
|
186 // -------------------------------------------------------------------------- |
|
187 // |
|
188 // -------------------------------------------------------------------------- |
|
189 // |
|
190 void CMTPPictBridgeDataProvider::Supported(TMTPSupportCategory aCategory, RArray<TUint>& aArray) const |
|
191 { |
|
192 __FLOG_VA((_L8(">> CMTPPictBridgeDataProvider::Supported %d"), aCategory)); |
|
193 switch (aCategory) |
|
194 { |
|
195 case EEvents: |
|
196 aArray.Append(EMTPEventCodeRequestObjectTransfer); |
|
197 break; |
|
198 case EObjectPlaybackFormats: |
|
199 case EObjectCaptureFormats: |
|
200 break; |
|
201 case EObjectProperties: |
|
202 { |
|
203 TInt count(sizeof(KMTPPictBridgeDpSupportedProperties) / sizeof(KMTPPictBridgeDpSupportedProperties[0])); |
|
204 for (TInt i = 0; i < count; i++ ) |
|
205 { |
|
206 aArray.Append( KMTPPictBridgeDpSupportedProperties[i] ); |
|
207 } |
|
208 } |
|
209 break; |
|
210 |
|
211 case EOperations: |
|
212 { |
|
213 TInt count(sizeof(KMTPPictBridgeDpSupportedOperations) / sizeof(KMTPPictBridgeDpSupportedOperations[0])); |
|
214 for (TInt i = 0; (i < count); i++) |
|
215 { |
|
216 aArray.Append(KMTPPictBridgeDpSupportedOperations[i]); |
|
217 } |
|
218 } |
|
219 break; |
|
220 |
|
221 case EStorageSystemTypes: |
|
222 aArray.Append(CMTPStorageMetaData::ESystemTypeDefaultFileSystem); |
|
223 break; |
|
224 |
|
225 default: |
|
226 // Unrecognised category, leave aArray unmodified. |
|
227 break; |
|
228 } |
|
229 __FLOG(_L8("<< CMTPPictBridgeDataProvider::Supported")); |
|
230 } |
|
231 |
|
232 void CMTPPictBridgeDataProvider::SupportedL(TMTPSupportCategory aCategory, CDesCArray& /*aStrings*/) const |
|
233 { |
|
234 switch (aCategory) |
|
235 { |
|
236 case EFolderExclusionSets: |
|
237 break; |
|
238 case EFormatExtensionSets: |
|
239 break; |
|
240 default: |
|
241 break; |
|
242 } |
|
243 } |
|
244 |
|
245 |
|
246 // -------------------------------------------------------------------------- |
|
247 // CMTPPictBridgeDataProvider::NotifyStorageEnumerationCompleteL() |
|
248 // -------------------------------------------------------------------------- |
|
249 // |
|
250 void CMTPPictBridgeDataProvider::NotifyStorageEnumerationCompleteL() |
|
251 { |
|
252 __FLOG(_L8(">> CMTPPictBridgeDataProvider::NotifyStorageEnumerationCompleteL")); |
|
253 Framework().StorageEnumerationCompleteL(); |
|
254 __FLOG(_L8("<< CMTPPictBridgeDataProvider::NotifyStorageEnumerationCompleteL")); |
|
255 } |
|
256 |
|
257 // -------------------------------------------------------------------------- |
|
258 // |
|
259 // -------------------------------------------------------------------------- |
|
260 // |
|
261 #ifdef __FLOG_ACTIVE |
|
262 void CMTPPictBridgeDataProvider::NotifyEnumerationCompleteL(TUint32 aStorageId, TInt aErr ) |
|
263 #else |
|
264 void CMTPPictBridgeDataProvider::NotifyEnumerationCompleteL(TUint32 aStorageId, TInt /* aErr*/ ) |
|
265 #endif |
|
266 { |
|
267 __FLOG_VA((_L8(">> CMTPPictBridgeDataProvider::NotifyEnumerationCompletedL storage 0x%08X status %d"), aStorageId, aErr )); |
|
268 Framework().ObjectEnumerationCompleteL(aStorageId); |
|
269 __FLOG(_L8("<< CMTPPictBridgeDataProvider::NotifyEnumerationCompletedL")); |
|
270 } |
|
271 |
|
272 |
|
273 // -------------------------------------------------------------------------- |
|
274 // Find or create a request processor that can process the specified request. |
|
275 // @param aRequest The request to be processed |
|
276 // @param aConnection The connection from which the request comes |
|
277 // @return the idx of the found/created request processor |
|
278 // -------------------------------------------------------------------------- |
|
279 // |
|
280 TInt CMTPPictBridgeDataProvider::LocateRequestProcessorL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) |
|
281 { |
|
282 __FLOG(_L8(">> CMTPPictBridgeDataProvider::LocateRequestProcessorL")); |
|
283 |
|
284 TInt idx(KErrNotFound); |
|
285 TInt count(iActiveProcessors.Count()); |
|
286 for (TInt i = 0; (i < count); i++) |
|
287 { |
|
288 if (iActiveProcessors[i]->Match(aRequest, aConnection)) |
|
289 { |
|
290 idx = i; |
|
291 break; |
|
292 } |
|
293 } |
|
294 |
|
295 if (idx == KErrNotFound) |
|
296 { |
|
297 MMTPRequestProcessor* processorP = MTPPictBridgeDpProcessor::CreateL(Framework(), aRequest, aConnection, *this); |
|
298 CleanupReleasePushL(*processorP); |
|
299 iActiveProcessors.AppendL(processorP); |
|
300 CleanupStack::Pop(); |
|
301 idx = count; |
|
302 } |
|
303 |
|
304 __FLOG(_L8("<< CMTPPictBridgeDataProvider::LocateRequestProcessorL")); |
|
305 return idx; |
|
306 } |
|
307 |
|
308 // -------------------------------------------------------------------------- |
|
309 // Find or create a request processor that can process the specified event. |
|
310 // @param aEvent The event to be processed |
|
311 // @param aConnection The connection from which the request comes |
|
312 // @return the idx of the found request processor, KErrNotFound if not found |
|
313 // -------------------------------------------------------------------------- |
|
314 // |
|
315 TInt CMTPPictBridgeDataProvider::LocateRequestProcessorL(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection) |
|
316 { |
|
317 __FLOG(_L8(">> CMTPPictBridgeDataProvider::LocateRequestProcessorL (event)")); |
|
318 |
|
319 TInt idx(KErrNotFound); |
|
320 TInt count(iActiveProcessors.Count()); |
|
321 for (TInt i = 0; (i < count); i++) |
|
322 { |
|
323 if (iActiveProcessors[i]->Match(aEvent, aConnection)) |
|
324 { |
|
325 idx = i; |
|
326 break; |
|
327 } |
|
328 } |
|
329 __FLOG(_L8("<< CMTPPictBridgeDataProvider::LocateRequestProcessorL (event)")); |
|
330 return idx; |
|
331 } |
|
332 |
|
333 // -------------------------------------------------------------------------- |
|
334 // Cleans up outstanding request processors when a session is closed. |
|
335 // @param aSession notification parameter block |
|
336 // -------------------------------------------------------------------------- |
|
337 // |
|
338 void CMTPPictBridgeDataProvider::SessionClosedL(const TMTPNotificationParamsSessionChange& aSession) |
|
339 { |
|
340 __FLOG_VA((_L8(">> CMTPPictBridgeDataProvider::SessionClosedL SessionID = %d"), aSession.iMTPId)); |
|
341 |
|
342 TInt count = iActiveProcessors.Count(); |
|
343 while(count--) |
|
344 { |
|
345 MMTPRequestProcessor* processorP = iActiveProcessors[count]; |
|
346 TUint32 sessionId = processorP->SessionId(); |
|
347 if((sessionId == aSession.iMTPId) && (processorP->Connection().ConnectionId() == aSession.iConnection.ConnectionId())) |
|
348 { |
|
349 processorP->Release(); |
|
350 iActiveProcessors.Remove(count); |
|
351 } |
|
352 } |
|
353 |
|
354 iServerP->MtpSessionClosed(); |
|
355 __FLOG(_L8("<< CMTPPictBridgeDataProvider::SessionClosedL")); |
|
356 } |
|
357 |
|
358 // -------------------------------------------------------------------------- |
|
359 // Prepares for a newly-opened session. |
|
360 // @param aSession notification parameter block |
|
361 // -------------------------------------------------------------------------- |
|
362 // |
|
363 #ifdef __FLOG_ACTIVE |
|
364 void CMTPPictBridgeDataProvider::SessionOpenedL(const TMTPNotificationParamsSessionChange& aSession ) |
|
365 #else |
|
366 void CMTPPictBridgeDataProvider::SessionOpenedL(const TMTPNotificationParamsSessionChange& /*aSession*/ ) |
|
367 #endif |
|
368 { |
|
369 __FLOG_VA((_L8(" CMTPPictBridgeDataProvider::SessionOpenedL SessionID = %d"), aSession.iMTPId)); |
|
370 iServerP->MtpSessionOpened(); |
|
371 } |
|
372 |
|
373 TUint32 CMTPPictBridgeDataProvider::DeviceDiscoveryHandle() const |
|
374 { |
|
375 return iPictBridgeEnumeratorP->DeviceDiscoveryHandle(); |
|
376 } |
|
377 |