|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: The header of content server main scheduler class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #ifndef __UPNPCONTENTSERVERHANDLER_H__ |
|
23 #define __UPNPCONTENTSERVERHANDLER_H__ |
|
24 |
|
25 // INCLUDES |
|
26 #include <e32base.h> |
|
27 #include <e32property.h> |
|
28 |
|
29 #include "upnpcontentserverdefs.h" |
|
30 #include "upnpcontentserverclient.h" |
|
31 #include "upnpcontentsharingao.h" |
|
32 #include "upnpcontentsharingobserver.h" |
|
33 #include "upnpsharingcallback.h" |
|
34 #include "upnpsharingrequest.h" |
|
35 |
|
36 #include "upnpmetadataobserver.h" |
|
37 #include "upnpcontainercheckerao.h" |
|
38 #include "upnpunsharerao.h" |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 |
|
42 class CUpnpSelectionReader; |
|
43 class CUpnpContentMetadataUtility; |
|
44 class CUpnpContentSharingAo; |
|
45 class CUpnpSharingRequest; |
|
46 class CUpnpContentServer; |
|
47 class CUPnPPeriodic; |
|
48 |
|
49 |
|
50 /** |
|
51 * A class to schedule the active objects in server |
|
52 * |
|
53 * @since S60 3.1 |
|
54 */ |
|
55 class CUpnpContentServerHandler : public CBase, |
|
56 public MUpnpSharingCallback, |
|
57 public MUpnpMetadataObserver |
|
58 { |
|
59 /** |
|
60 * Indicates internal state of the CUpnpContentServerHandler |
|
61 */ |
|
62 enum THandlerState |
|
63 { |
|
64 ESchedulingSharing, |
|
65 EWaitingUploads, |
|
66 EProcessingUploads, |
|
67 ENotActive |
|
68 }; |
|
69 |
|
70 /** |
|
71 * Indicates which active object is running |
|
72 */ |
|
73 enum TSharingPhase |
|
74 { |
|
75 ESharingInActive, |
|
76 ECheckDefaults, |
|
77 EUnshare, |
|
78 EShare |
|
79 }; |
|
80 |
|
81 public: |
|
82 |
|
83 /** |
|
84 * 2-phased constructor. |
|
85 */ |
|
86 static CUpnpContentServerHandler* NewL( CUpnpContentServer* aServer ); |
|
87 |
|
88 /** |
|
89 * C++ destructor. |
|
90 */ |
|
91 virtual ~CUpnpContentServerHandler(); |
|
92 |
|
93 /** |
|
94 * Sets the observer to session class |
|
95 * @since S60 3.1 |
|
96 * @param aObserver Pointer to observer in session class |
|
97 */ |
|
98 void SetContentSharingObserverL( MUpnpContentSharingObserver* aObserver ); |
|
99 |
|
100 /** |
|
101 * Start the media server upload listener, leave if error |
|
102 * @since S60 3.1 |
|
103 */ |
|
104 void StartUploadListenerL(); |
|
105 |
|
106 /** |
|
107 * Stop the media server upload listener, leave if error |
|
108 * @since S60 3.1 |
|
109 */ |
|
110 void StopUploadListenerL(); |
|
111 |
|
112 /** |
|
113 * Get the strings for the UI |
|
114 * @since S60 3.1 |
|
115 * @param aContainerType Type of the content requested |
|
116 */ |
|
117 void GetSelectionContentL( const TInt& aContainerType ); |
|
118 |
|
119 /** |
|
120 * Get the selected items for the UI |
|
121 * @since S60 3.1 |
|
122 * @param aMarkedItems Array of previous sharing selections |
|
123 * @param aType Type of selections to request |
|
124 */ |
|
125 void GetSelectionIndexesL( RArray<TInt>& aMarkedItems, |
|
126 const TInt aType ); |
|
127 |
|
128 /** |
|
129 * Start sharing |
|
130 * @since S60 3.1 |
|
131 * @param aMarkedItems The new sharing selections |
|
132 * @param aType Type of sharing selections |
|
133 */ |
|
134 void ChangeShareContentL( const RArray<TInt>& aMarkedItems, |
|
135 const TInt aType ); |
|
136 |
|
137 /** |
|
138 * First read the selections then refresh. |
|
139 * Leaves with KErrServerBusy if sharing is ongoing |
|
140 * @since S60 3.1 |
|
141 * @param aType Type of refresh requested |
|
142 */ |
|
143 void RefreshShareContentL( |
|
144 TInt aType ); |
|
145 |
|
146 /** |
|
147 * Determines if it is possible to stop the server |
|
148 * @since S60 3.1 |
|
149 */ |
|
150 TBool CanStop() const; |
|
151 |
|
152 /** |
|
153 * Callback from metadatautility to inform that refresh is completed |
|
154 * @since S60 3.1 |
|
155 */ |
|
156 void RefreshDoneL(); |
|
157 |
|
158 /** |
|
159 * Switch media server offline, change internal states accordingly |
|
160 * @since S60 3.1 |
|
161 */ |
|
162 TBool ConnectionLostL(); |
|
163 |
|
164 // from MUpnpSharingCallback |
|
165 // |
|
166 |
|
167 /** |
|
168 * The CUpnpContentSharingAo uses this to indicate it has done sharing |
|
169 * @since S60 3.1 |
|
170 * @param aErr Error code |
|
171 * @param aType Type of sharing completed |
|
172 */ |
|
173 void CompleteSharingOperationL( |
|
174 const TInt& aErr, const TInt& aType ); |
|
175 /** |
|
176 * Cancel the current sharing operation |
|
177 * @since S60 3.1 |
|
178 * @param aErr Error code |
|
179 */ |
|
180 void CancelSharingOperationL( |
|
181 const TInt& aErr ); |
|
182 |
|
183 /** |
|
184 * Update the progress PubSub key |
|
185 * @since S60 3.1 |
|
186 * @param aProgress Progress to update |
|
187 */ |
|
188 void SetProgressL( |
|
189 const TInt& aProgress ); |
|
190 |
|
191 /** |
|
192 * Cancel the current sharing operation |
|
193 * @since S60 3.1 |
|
194 * @param aErr Error code |
|
195 */ |
|
196 void ValidateDefaultContainersL(); |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 private: |
|
202 /** |
|
203 * C++ constructor. |
|
204 * @since S60 3.1 |
|
205 */ |
|
206 CUpnpContentServerHandler( CUpnpContentServer* aServer ); |
|
207 |
|
208 /** |
|
209 * The main sharing loop |
|
210 * @since S60 3.1 |
|
211 */ |
|
212 void DoShareL( ); |
|
213 |
|
214 /** |
|
215 * Cleanup resources, also state variables are cleaned |
|
216 * @since S60 3.1 |
|
217 */ |
|
218 void Cleanup(); |
|
219 |
|
220 /** |
|
221 * 2nd phase constructor. |
|
222 * @since S60 3.1 |
|
223 */ |
|
224 void ConstructL(); |
|
225 |
|
226 /** |
|
227 * Get id of the default container determined by aType |
|
228 * @since S60 3.1 |
|
229 * @param aType Determines which container id is returned |
|
230 */ |
|
231 TInt GetContainerId( const TInt aType ) const; |
|
232 |
|
233 /** |
|
234 * Fill the progress info for aType |
|
235 * @since S60 3.1 |
|
236 * @param aArr Array to store progress information |
|
237 * @param aType Determines which container id is returned |
|
238 */ |
|
239 void FillProgressInfoL( |
|
240 RArray<TUpnpProgressInfo>& aArr, |
|
241 const TInt aType ); |
|
242 |
|
243 /** |
|
244 * Set the values of the iImageVideoSharingReq or iMusicSharingReq |
|
245 * depending of aType |
|
246 * @since S60 3.1 |
|
247 * @param aMarkedItems The new sharing selections |
|
248 * @param aType Type of sharing selections |
|
249 */ |
|
250 void SetSharingRequestL( |
|
251 const RArray<TInt>& aMarkedItems, |
|
252 const TInt aType ); |
|
253 |
|
254 /** |
|
255 * Handle errors from active objects |
|
256 * @since S60 3.1 |
|
257 * @param aError Error code |
|
258 */ |
|
259 void HandleError( TInt aError ); |
|
260 |
|
261 /** |
|
262 * Perform CLF refresh in background |
|
263 * @param aPtr Pointer to CUpnpContentServerHandler instance |
|
264 * @return EFalse |
|
265 */ |
|
266 static TInt RefreshClfL( TAny* aPtr ); |
|
267 |
|
268 |
|
269 private: |
|
270 /** |
|
271 * Pointer to server process, used for stopping it |
|
272 * Not owned |
|
273 */ |
|
274 CUpnpContentServer* iServer; |
|
275 |
|
276 /** |
|
277 * Pointer to CLF interface |
|
278 * owned |
|
279 */ |
|
280 CUpnpContentMetadataUtility* iMetadata; |
|
281 |
|
282 /** |
|
283 * The sharing engine |
|
284 * owned |
|
285 */ |
|
286 CUpnpContentSharingAo* iAo; |
|
287 |
|
288 /** |
|
289 * Pointer to corresponding session observer for returning results |
|
290 * not owned |
|
291 */ |
|
292 MUpnpContentSharingObserver* iContentSharingObserver; |
|
293 |
|
294 /** |
|
295 * Gets the albums/playlists to UI |
|
296 * owned |
|
297 */ |
|
298 CUpnpSelectionReader* iReader; |
|
299 |
|
300 /** |
|
301 * Used to wait CLF refresh |
|
302 */ |
|
303 CActiveSchedulerWait iWait; |
|
304 |
|
305 /** |
|
306 * Handlers current state |
|
307 */ |
|
308 TInt iHandlerState; |
|
309 |
|
310 /** |
|
311 * Currently processed request index |
|
312 */ |
|
313 TInt iBufferPosition; |
|
314 |
|
315 /** |
|
316 * The buffer for image and video sharing requests |
|
317 * owned |
|
318 */ |
|
319 CUpnpSharingRequest* iVisualSharingReq; |
|
320 |
|
321 /** |
|
322 * The buffer for music sharing requests |
|
323 * owned |
|
324 */ |
|
325 CUpnpSharingRequest* iMusicSharingReq; |
|
326 |
|
327 /** |
|
328 * The buffer for any sharing request which is not yet scheduled to run |
|
329 * owned |
|
330 */ |
|
331 CUpnpSharingRequest* iPendingSharingReq; |
|
332 |
|
333 /** |
|
334 * Ongoing sharing operation. See TSharingPhase |
|
335 */ |
|
336 TInt iSharingPhase; |
|
337 |
|
338 /** |
|
339 * Active object checking the file structure of the media server |
|
340 */ |
|
341 CUpnpContainerCheckerAo* iContainerChecker; |
|
342 |
|
343 /** |
|
344 * Active object handling the unsharing of items and containers |
|
345 */ |
|
346 CUpnpUnsharerAo* iUnsharer; |
|
347 |
|
348 /** |
|
349 * Storage for ids of default containers |
|
350 */ |
|
351 RArray<TInt> iDefaultContainerIds; |
|
352 |
|
353 /** |
|
354 * MediaServer Handle |
|
355 * Owned |
|
356 */ |
|
357 RUpnpMediaServerClient* iMediaServer; |
|
358 |
|
359 /** |
|
360 * Error code, reset after transferred to client |
|
361 */ |
|
362 TInt iErrorToClient; |
|
363 |
|
364 /** |
|
365 * Flag to indicate if the iContainerChecker is created in |
|
366 * staring sharing context |
|
367 */ |
|
368 TBool iStartupCleaning; |
|
369 |
|
370 /** |
|
371 * The Publish subscribe key to deliver progress infromation about sharing |
|
372 */ |
|
373 RProperty iProgressProperty; |
|
374 |
|
375 CUPnPPeriodic* iIdle; |
|
376 |
|
377 }; |
|
378 |
|
379 #endif // __UPNPCONTENTSERVERHANDLER_H__ |