|
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 #include <mtp/mmtpconnection.h> |
|
17 #include <mtp/mmtpdataproviderframework.h> |
|
18 #include <mtp/mtpdataproviderapitypes.h> |
|
19 #include <mtp/tmtptyperequest.h> |
|
20 |
|
21 #include "cmtpproxydp.h" |
|
22 #include "cmtprequestprocessor.h" |
|
23 #include "mtpproxydppanic.h" |
|
24 #include "mtpproxydpprocessor.h" |
|
25 |
|
26 static const TInt KMTPProxyDpSessionGranularity = 3; |
|
27 |
|
28 __FLOG_STMT(_LIT8(KComponent,"CMTPProxyDataProvider");) |
|
29 |
|
30 /** |
|
31 Standard NewL method |
|
32 @param aParams The pointer to MMTPDataProviderFramework |
|
33 */ |
|
34 TAny* CMTPProxyDataProvider::NewL(TAny* aParams) |
|
35 { |
|
36 CMTPProxyDataProvider* self = new (ELeave) CMTPProxyDataProvider(aParams); |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop(self); |
|
40 return self; |
|
41 } |
|
42 |
|
43 |
|
44 void CMTPProxyDataProvider::ConstructL() |
|
45 { |
|
46 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
47 __FLOG(_L8("ConstructL - Entry")); |
|
48 iDpSingletons.OpenL(Framework()); |
|
49 iSingletons.OpenL(Framework()); |
|
50 __FLOG(_L8("ConstructL - Exit")); |
|
51 } |
|
52 |
|
53 /** |
|
54 Destructor |
|
55 */ |
|
56 CMTPProxyDataProvider::~CMTPProxyDataProvider() |
|
57 { |
|
58 TInt count = iActiveProcessors.Count(); |
|
59 while(count--) |
|
60 { |
|
61 iActiveProcessors[count]->Release(); |
|
62 } |
|
63 iActiveProcessors.Close(); |
|
64 iDpSingletons.Close(); |
|
65 iSingletons.Close(); |
|
66 __FLOG_CLOSE; |
|
67 } |
|
68 |
|
69 void CMTPProxyDataProvider::Cancel() |
|
70 { |
|
71 |
|
72 } |
|
73 |
|
74 /** |
|
75 Process the event from initiator |
|
76 @param aEvent The event to be processed |
|
77 @param aConnection The connection from which the event comes |
|
78 */ |
|
79 void CMTPProxyDataProvider::ProcessEventL(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection) |
|
80 { |
|
81 TInt index = LocateRequestProcessorL(aEvent, aConnection); |
|
82 if(index != KErrNotFound) |
|
83 { |
|
84 iActiveProcessors[index]->HandleEventL(aEvent); |
|
85 } |
|
86 } |
|
87 |
|
88 void CMTPProxyDataProvider::ProcessNotificationL(TMTPNotification aNotification, const TAny* aParams) |
|
89 { |
|
90 switch (aNotification) |
|
91 { |
|
92 case EMTPSessionClosed: |
|
93 SessionClosedL(*reinterpret_cast<const TMTPNotificationParamsSessionChange*>(aParams)); |
|
94 break; |
|
95 |
|
96 case EMTPSessionOpened: |
|
97 SessionOpenedL(*reinterpret_cast<const TMTPNotificationParamsSessionChange*>(aParams)); |
|
98 break; |
|
99 |
|
100 default: |
|
101 // Ignore all other notifications. |
|
102 break; |
|
103 } |
|
104 } |
|
105 |
|
106 /** |
|
107 Process the request from initiator. The method first searches if there is any matching active processor; |
|
108 if not, it creates a new processor. It deletes the processor once it finishes. |
|
109 @param aPhase The request transaction phase |
|
110 @param aRequest The request to be processed |
|
111 @param aConnection The connection from which the request comes |
|
112 */ |
|
113 void CMTPProxyDataProvider::ProcessRequestPhaseL(TMTPTransactionPhase aPhase, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) |
|
114 { |
|
115 TInt index = LocateRequestProcessorL(aRequest, aConnection); |
|
116 __ASSERT_DEBUG(index != KErrNotFound, Panic(EMTPNoMatchingProcessor)); |
|
117 MMTPRequestProcessor* processor = iActiveProcessors[index]; |
|
118 iActiveProcessor = index; |
|
119 iActiveProcessorRemoved = EFalse; |
|
120 TBool result = processor->HandleRequestL(aRequest, aPhase); |
|
121 if (iActiveProcessorRemoved) |
|
122 { |
|
123 processor->Release(); // destroy the processor |
|
124 } |
|
125 else if (result) |
|
126 { |
|
127 processor->Release(); |
|
128 iActiveProcessors.Remove(index); |
|
129 } |
|
130 iActiveProcessor = -1; |
|
131 |
|
132 } |
|
133 |
|
134 void CMTPProxyDataProvider::StartObjectEnumerationL(TUint32 aStorageId, TBool /*aPersistentFullEnumeration*/) |
|
135 { |
|
136 // The proxy data provider does not manage any data objects. |
|
137 Framework().ObjectEnumerationCompleteL(aStorageId); |
|
138 } |
|
139 |
|
140 void CMTPProxyDataProvider::StartStorageEnumerationL() |
|
141 { |
|
142 Framework().StorageEnumerationCompleteL(); |
|
143 } |
|
144 |
|
145 /** |
|
146 Append all the operations that are supported by the proxy data provider to |
|
147 the operations array. |
|
148 @param aCategory category of operations of interest |
|
149 @param aArray array to hold the operations |
|
150 */ |
|
151 void CMTPProxyDataProvider::Supported(TMTPSupportCategory aCategory, RArray<TUint>& /*aArray*/) const |
|
152 { |
|
153 |
|
154 __FLOG(_L8("Supported - Entry")); |
|
155 switch (aCategory) |
|
156 { |
|
157 case EEvents: |
|
158 break; |
|
159 |
|
160 case EObjectCaptureFormats: |
|
161 case EObjectPlaybackFormats: |
|
162 |
|
163 break; |
|
164 |
|
165 case EObjectProperties: |
|
166 break; |
|
167 |
|
168 case EOperations: |
|
169 break; |
|
170 |
|
171 case EStorageSystemTypes: |
|
172 break; |
|
173 |
|
174 default: |
|
175 |
|
176 // Unrecognised category, leave aArray unmodified. |
|
177 break; |
|
178 } |
|
179 __FLOG(_L8("Supported - Exit")); |
|
180 |
|
181 } |
|
182 |
|
183 |
|
184 void CMTPProxyDataProvider::SupportedL(TMTPSupportCategory /*aCategory*/, CDesCArray& /*aStrings*/) const |
|
185 { |
|
186 __FLOG(_L8("SupportedL - Entry")); |
|
187 __FLOG(_L8("SupportedL - Exit")); |
|
188 } |
|
189 |
|
190 |
|
191 /** |
|
192 Get the pointer to the extended interface |
|
193 @param aInterfaceUid The uid of the extended interface |
|
194 @return the pointer to the extended interface |
|
195 */ |
|
196 TAny* CMTPProxyDataProvider::GetExtendedInterface(TUid /*aInterfaceUid*/) |
|
197 { |
|
198 return NULL; |
|
199 } |
|
200 |
|
201 /** |
|
202 Standard c++ constructor |
|
203 */ |
|
204 CMTPProxyDataProvider::CMTPProxyDataProvider(TAny* aParams) |
|
205 :CMTPDataProviderPlugin(aParams), |
|
206 iActiveProcessors(KMTPProxyDpSessionGranularity), |
|
207 iActiveProcessor(-1) |
|
208 { |
|
209 } |
|
210 |
|
211 /** |
|
212 Find or create a request processor that can process the request |
|
213 @param aRequest The request to be processed |
|
214 @param aConnection The connection from which the request comes |
|
215 @return the index of the found/created request processor |
|
216 */ |
|
217 TInt CMTPProxyDataProvider::LocateRequestProcessorL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) |
|
218 { |
|
219 TInt index = KErrNotFound; |
|
220 TInt count = iActiveProcessors.Count(); |
|
221 for(TInt i = 0; i < count; i++) |
|
222 { |
|
223 if(iActiveProcessors[i]->Match(aRequest, aConnection)) |
|
224 { |
|
225 index = i; |
|
226 break; |
|
227 } |
|
228 } |
|
229 if(index == KErrNotFound) |
|
230 { |
|
231 MMTPRequestProcessor* processor = MTPProxyDpProcessor::CreateL(Framework(), aRequest, aConnection); |
|
232 __ASSERT_DEBUG(processor, Panic(EMTPNoMatchingProcessor)); |
|
233 CleanupReleasePushL(*processor); |
|
234 iActiveProcessors.AppendL(processor); |
|
235 CleanupStack::Pop(); |
|
236 index = count; |
|
237 } |
|
238 return index; |
|
239 |
|
240 } |
|
241 |
|
242 /** |
|
243 Find a request processor that can process the event |
|
244 @param aEvent The event to be processed |
|
245 @param aConnection The connection from which the request comes |
|
246 @return the index of the found request processor, KErrNotFound if not found |
|
247 */ |
|
248 TInt CMTPProxyDataProvider::LocateRequestProcessorL(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection) |
|
249 { |
|
250 TInt index = KErrNotFound; |
|
251 TInt count = iActiveProcessors.Count(); |
|
252 for(TInt i = 0; i < count; i++) |
|
253 { |
|
254 if(iActiveProcessors[i]->Match(aEvent, aConnection)) |
|
255 { |
|
256 index = i; |
|
257 break; |
|
258 } |
|
259 } |
|
260 return index; |
|
261 } |
|
262 |
|
263 void CMTPProxyDataProvider::SessionClosedL(const TMTPNotificationParamsSessionChange& aSession) |
|
264 { |
|
265 TInt count = iActiveProcessors.Count(); |
|
266 while(count--) |
|
267 { |
|
268 MMTPRequestProcessor* processor = iActiveProcessors[count]; |
|
269 TUint32 sessionId = processor->SessionId(); |
|
270 if((sessionId == aSession.iMTPId) && (processor->Connection().ConnectionId() == aSession.iConnection.ConnectionId())) |
|
271 { |
|
272 iActiveProcessors.Remove(count); |
|
273 if (count == iActiveProcessor) |
|
274 { |
|
275 iActiveProcessorRemoved = ETrue; |
|
276 } |
|
277 else |
|
278 { |
|
279 processor->Release(); |
|
280 } |
|
281 } |
|
282 } |
|
283 } |
|
284 |
|
285 /** |
|
286 Prepares for a newly-opened session. |
|
287 @param aSession notification parameter block |
|
288 */ |
|
289 #ifdef __FLOG_ACTIVE |
|
290 void CMTPProxyDataProvider::SessionOpenedL(const TMTPNotificationParamsSessionChange& /*aSession*/) |
|
291 #else |
|
292 void CMTPProxyDataProvider::SessionOpenedL(const TMTPNotificationParamsSessionChange& /*aSession*/) |
|
293 #endif |
|
294 { |
|
295 __FLOG(_L8("SessionOpenedL - Entry")); |
|
296 __FLOG(_L8("SessionOpenedL - Exit")); |
|
297 } |
|
298 |