|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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: Media server device |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CUPNPMEDIASERVER_H |
|
20 #define C_CUPNPMEDIASERVER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <in_sock.h> |
|
24 #include <upnpnetworkeventobserver.h> |
|
25 #include "upnpmediaserver.pan" |
|
26 #include "upnpmediaserversettings.h" |
|
27 #include "upnpmediaservereventhandler.h" |
|
28 #include "upnpnotifytimer.h" |
|
29 #include "upnpsymbianserverbase.h" |
|
30 #include "upnpmediaserverclient.h" |
|
31 |
|
32 |
|
33 // CONSTANTS |
|
34 _LIT(KMSPublicAccessedDir,"public"); |
|
35 _LIT(KMSMediaDir,"Media"); |
|
36 _LIT(KMSDeviceXmlDescDir,"MediaServer1"); |
|
37 _LIT(KMSDeviceXmlDescFile,"MediaServer1.xml"); |
|
38 _LIT(KCDXmlDescFile,"ContentDirectory1.xml"); |
|
39 _LIT(KCMXmlDescFile,"ConnectionManager1.xml"); |
|
40 _LIT(KIconDirectory, "icon"); |
|
41 _LIT(KBackupSuffix,".bak"); |
|
42 _LIT(KDescTemplateDrive,"Z:"); |
|
43 // |
|
44 const TUint KMSDescriptionMaxSize = 204800; |
|
45 |
|
46 //note that this value should be less than upnp server process shutdown timeout value |
|
47 const TInt KStopAVMediaServerDelay = 1500000; |
|
48 |
|
49 // FORWARD DECLARATIONS |
|
50 class CUpnpContentDirectoryService; |
|
51 class CUpnpContainerList; |
|
52 class CUpnpItem; |
|
53 class CUpnpContainer; |
|
54 class CUpnpCM; |
|
55 class CUpnpSecurityManager; |
|
56 class CUpnpDeviceImplementation; |
|
57 class CUpnpIconManager; |
|
58 class CUpnpDiskRemoveDetector; |
|
59 class CUpnpDeviceDescriptionStore; |
|
60 |
|
61 class CUpnpConnectionManagerNetworkEventProvider; |
|
62 class CUpnpMediaServerDescriptionProvider; |
|
63 |
|
64 |
|
65 |
|
66 // CLASS DECLARATION |
|
67 |
|
68 /** |
|
69 * UPnP Media Server container. |
|
70 * Provides interface for Media Server maintanace purposes. |
|
71 * |
|
72 * @since Series 60 3.1 |
|
73 */ |
|
74 class CUpnpMediaServer : public CUpnpSymbianServerBase, MUpnpSettingObserver, |
|
75 MUpnpContentDirectoryEventObserver, MUpnpNetworkEventObserver |
|
76 { |
|
77 public: |
|
78 // Constructors and destructor |
|
79 |
|
80 /** |
|
81 * Two-phased constructor. |
|
82 */ |
|
83 static CUpnpSymbianServerBase* NewLC(); |
|
84 |
|
85 /** |
|
86 * Destructor. |
|
87 */ |
|
88 virtual ~CUpnpMediaServer(); |
|
89 |
|
90 public: |
|
91 // New functions |
|
92 void GetSharedItemListL( TInt aContId, |
|
93 CUpnpBrowseCriteria* aBrowseCriteria, TInt* TotalMatches, |
|
94 CUpnpItemList* aItemList ); |
|
95 void GetSharedContainerListL( TInt aContId, |
|
96 CUpnpBrowseCriteria* aBrowseCriteria, TInt* TotalMatches, |
|
97 CUpnpContainerList* aContainerList ); |
|
98 void UnshareItemListL( RArray<TInt>& aItemList, TInt* aExecutionStatus ); |
|
99 CUpnpItem* GetSharedItemL( TInt aItem ); |
|
100 CUpnpContainer* GetSingleContainerL( TInt aContainerId ); |
|
101 void UnshareRootL(); |
|
102 void UnshareItemL( TInt aId ); |
|
103 void UnshareContainerL( TInt aId ); |
|
104 |
|
105 /** |
|
106 * Shares new item |
|
107 */ |
|
108 void ShareObjectL( CUpnpObject* aItem ); |
|
109 |
|
110 /** |
|
111 * Shares new items |
|
112 */ |
|
113 void ShareItemListL( CUpnpItemList* aItemList, TInt* aStatus ); |
|
114 |
|
115 /** |
|
116 * Creates a new reference |
|
117 */ |
|
118 void ShareReferenceL( CUpnpItem* aItem ); |
|
119 |
|
120 /** |
|
121 * Shares new 'reference item' list |
|
122 */ |
|
123 void ShareReferenceListL( CUpnpItemList* aItemList, TInt* aStatus ); |
|
124 |
|
125 /** |
|
126 * Starts AV Media Server - Device, Service, ContentDirecory, ConnectionManager |
|
127 */ |
|
128 void StartAVMediaServerL(); |
|
129 |
|
130 /** |
|
131 * Starts AV Media Server in offline mode |
|
132 */ |
|
133 void StartAVMediaServerOfflineL(); |
|
134 |
|
135 /** |
|
136 * Stops AV Media Server - Device, ContentDirecory, ConnectionManager |
|
137 * Starts timeout timer |
|
138 */ |
|
139 void StopAVMediaServer( TBool aSilent ); |
|
140 |
|
141 /** |
|
142 * Restarts AV Media Server - Device, ContentDirecory, ConnectionManager |
|
143 */ |
|
144 void RestartAVMediaServerL(); |
|
145 |
|
146 /** |
|
147 * Check status of AV Media Server |
|
148 */ |
|
149 RUpnpMediaServerClient::TServerStatus Status() const; |
|
150 |
|
151 /** |
|
152 * Sets description properties for device, changes are available after restarting |
|
153 * the server. |
|
154 * Values are read from Central Repository |
|
155 * @param aDevice device to change |
|
156 */ |
|
157 void SetDescriptionSettingsL( CUpnpDeviceImplementation* aDevice ); |
|
158 |
|
159 /** |
|
160 * Adds icon to public\MediaServer1\icon and adds icon element |
|
161 * to device description xml |
|
162 * @param aProperty device to change |
|
163 */ |
|
164 void AddIconL( const TDesC8& aProperty ); |
|
165 |
|
166 /** |
|
167 * Updates icon in public\MediaServer1\icon and updates icon element |
|
168 * in device description xml |
|
169 * @param aProperty |
|
170 * @param aUrl icon url |
|
171 */ |
|
172 void UpdateIconL( const TDesC8& aProperty, const TDesC8& aUrl ); |
|
173 |
|
174 /** |
|
175 * Removes icon from public\MediaServer1\icon and removes icon element |
|
176 * from device description xml |
|
177 * @param aUrl icon url |
|
178 */ |
|
179 void RemoveIconL( const TDesC8& aUrl ); |
|
180 |
|
181 /** |
|
182 * Removes all icons from public\MediaServer1\icon and removes icon elements |
|
183 * from device description xml |
|
184 */ |
|
185 void RemoveIconsL(); |
|
186 |
|
187 /** |
|
188 * Sets description property for device, changes are available after restarting |
|
189 * the server. |
|
190 * Value is read from Central Repository |
|
191 * @param aDevice device to change |
|
192 * @param aKey Central Repository property key |
|
193 * @param aName property name (XML) |
|
194 */ |
|
195 void SetDescriptionPropertyL( CUpnpDeviceImplementation* aDevice, |
|
196 TInt aKey, const TDesC8& aName ); |
|
197 |
|
198 /** |
|
199 * Sets description required property for device, changes are available after restarting |
|
200 * the server. |
|
201 * Value is read from Central Repository |
|
202 * @param aDevice device to change |
|
203 * @param aKey Central Repository required property key |
|
204 * @param aName property name (XML) |
|
205 */ |
|
206 void SetDescriptionRequiredPropertyL( CUpnpDeviceImplementation* aDevice, |
|
207 TInt aKey, const TDesC8& aName ); |
|
208 |
|
209 /** |
|
210 * Removes white characters from input descriptor |
|
211 * @param aString to change |
|
212 */ |
|
213 void RemoveWhiteSpaces( TDes8& aString ); |
|
214 |
|
215 /** |
|
216 * Initialize Media Server files in private directory. |
|
217 * @param aOverwrite indicate whether files should be overwrite if exist |
|
218 */ |
|
219 void InitializeL( TBool aOverwrite ); |
|
220 |
|
221 /** |
|
222 * Reset Content Directory DB |
|
223 * It means that it rename original file adding suffix KBackupSuffix, |
|
224 * s during next running Content Directory will create new DB file. |
|
225 */ |
|
226 void ResetDbL(); |
|
227 |
|
228 /** |
|
229 * Delete Content Directory DB |
|
230 * It means that it deletes database file |
|
231 */ |
|
232 void DeleteDbL(); |
|
233 |
|
234 /** |
|
235 * Subscribe events, adds observer to the list |
|
236 * @param aObserver event observer |
|
237 */ |
|
238 void SubscribeEvents( MUpnpContentDirectoryEventObserver* aObserver ); |
|
239 |
|
240 /** |
|
241 * Unsubscribe events, removes observer from list |
|
242 * @param aObserver event observer |
|
243 */ |
|
244 void UnsubscribeEvents( MUpnpContentDirectoryEventObserver* aObserver ); |
|
245 |
|
246 TInetAddr GetAddress(); |
|
247 |
|
248 /** |
|
249 * Set the download and thumbnail path in CD according to the value of the upload directory. |
|
250 * @param aContentDirectory |
|
251 * @return full name of description file |
|
252 */ |
|
253 void SetUploadDirToCDL( const TDesC& aPath ); |
|
254 |
|
255 /** |
|
256 * Cancels scheduled shutdown of MS |
|
257 */ |
|
258 void CancelAVMediaServerStop(); |
|
259 |
|
260 /** |
|
261 * Set the upload and thumbnail path in CD and in central repository. |
|
262 * @param aPath new path |
|
263 */ |
|
264 void SetUploadDirL( const TDesC& aPath ); |
|
265 |
|
266 public: |
|
267 // From MUpnpContentDirectoryEventObserver |
|
268 /** |
|
269 * Called when transfer event happens |
|
270 * @param aTransferEvent transfer event |
|
271 */ |
|
272 virtual void FileTransferEvent( CUpnpFileTransferEvent *aTransferEvent ); |
|
273 |
|
274 /** |
|
275 * Checks if interface is up |
|
276 * @result return ETrue if started in online mode |
|
277 */ |
|
278 TBool IsInterfaceUp(); |
|
279 |
|
280 // From MUpnpSettingObserver |
|
281 /** |
|
282 * Function notify when setting will change |
|
283 */ |
|
284 virtual void SettingChangedL(); |
|
285 |
|
286 private: |
|
287 // New methods |
|
288 |
|
289 /** |
|
290 * Constructor |
|
291 */ |
|
292 CUpnpMediaServer(); |
|
293 |
|
294 /** |
|
295 * Perform the second phase construction of a CUpnpMessageHandler object |
|
296 */ |
|
297 void ConstructL(); |
|
298 |
|
299 /** |
|
300 * Init Media Server directory structure in private directory. |
|
301 * @param aFs handle to RFs |
|
302 * @return a updateId of container |
|
303 */ |
|
304 void InitPrivateDirL( RFs &aFs ); |
|
305 |
|
306 /** |
|
307 * Checks is description file exists. If not creates it from teplate stored on Z: |
|
308 * If parameter aOverwrite |
|
309 * @param aFs handle to RFs |
|
310 * @param aTempleteDescFile xml description file name |
|
311 * @param aOverwrite indicate whether file should be overwrite if exists |
|
312 * @return full name of description file |
|
313 */ |
|
314 HBufC* InitDescFileL( RFs &aFs, const TDesC& aTempleteDescFile, |
|
315 TBool aOverwrite ); |
|
316 |
|
317 /** |
|
318 * Create full name using drive MS directory structure and file name. |
|
319 * @param aFs handle to RFs |
|
320 * @param aDrive drive |
|
321 * @param aName file name |
|
322 * @return full name of description file |
|
323 */ |
|
324 HBufC* CreateFullNameL( RFs &aFs, const TDesC& aDrive, |
|
325 const TDesC& aName ); |
|
326 |
|
327 private: |
|
328 /** |
|
329 * Stops MS immediatly |
|
330 */ |
|
331 void StopAVMediaServerImmediately( TBool aSilent, TBool aWlanLost ); |
|
332 |
|
333 private://from CUpnpSymbianServerBase |
|
334 |
|
335 /** |
|
336 * Create a time server session, and return a pointer to the created object |
|
337 * @param aMessage client message |
|
338 * @result pointer to new session |
|
339 */ |
|
340 CSession2* NewSessionL( const RMessage2& aMessage ) const; |
|
341 |
|
342 /** |
|
343 * @return ETrue when media server is in state that it can be stopped |
|
344 */ |
|
345 TBool CanBeStopped() const; |
|
346 |
|
347 /** |
|
348 * Returns version that is supported by this server. |
|
349 */ |
|
350 TVersion SupportedVersion() const; |
|
351 |
|
352 /** |
|
353 * Returns server name |
|
354 */ |
|
355 const TDesC& ServerName() const; |
|
356 |
|
357 /** |
|
358 * Change media server status |
|
359 */ |
|
360 void SetStatus( RUpnpMediaServerClient::TServerStatus aStatus ); |
|
361 |
|
362 /** |
|
363 * Method should be invoked to notify all subscribed clients about |
|
364 * media server change. It is invoked if after RunL method status |
|
365 * is changed, and in every case that server change its status |
|
366 * without user request (eq. wlan lost) |
|
367 */ |
|
368 void NotifyStatusChanged(); |
|
369 |
|
370 private: // from MUpnpNetworkEventObserver |
|
371 |
|
372 /** |
|
373 * It is called from bottom layer when network event occurs [callback method] |
|
374 * @result None |
|
375 */ |
|
376 void NetworkEvent( CUpnpNetworkEventBase* aEvent ); |
|
377 |
|
378 private: // from CUpnpSymbianServerBase |
|
379 virtual void RunL(); |
|
380 |
|
381 private: |
|
382 /** |
|
383 * Callback if timer expires |
|
384 */ |
|
385 void TimerEventL( CUpnpNotifyTimer* aTimer ); |
|
386 |
|
387 private: |
|
388 |
|
389 /*! @var iDevice Media Server Device */ |
|
390 CUpnpDeviceImplementation* iDevice; |
|
391 /*! @var iContentDirecory Content Directory */ |
|
392 CUpnpContentDirectoryService* iContentDirecory; |
|
393 /*! @var iCm Connection Manager */ |
|
394 CUpnpCM* iCm; |
|
395 /*! @var iIconManager Icon Manager */ |
|
396 CUpnpIconManager* iIconManager; |
|
397 |
|
398 /*! @var iMsName Media Server Device description file full name */ |
|
399 HBufC* iMsName; |
|
400 /*! @var iCdName Content Directory Service description file full name */ |
|
401 HBufC* iCdName; |
|
402 /*! @var iCmName Connection Manager Service description file full name */ |
|
403 HBufC* iCmName; |
|
404 |
|
405 /*! @var iMsStatus Media Server operational status - started/started offline/stopped */ |
|
406 RUpnpMediaServerClient::TServerStatus iMsStatus; |
|
407 |
|
408 /*! @var interface for reading and setting Media Server settings */ |
|
409 CUpnpMediaServerSettings* iSettings; |
|
410 |
|
411 /*! @var security manager pointer */ |
|
412 CUpnpSecurityManager* iManager; |
|
413 |
|
414 /*! @var list of event observers (subscribed sessions) */ |
|
415 RPointerArray<MUpnpContentDirectoryEventObserver> iObserverList; |
|
416 |
|
417 // memory card remove watcher |
|
418 CUpnpDiskRemoveDetector* iDiskDetector; |
|
419 |
|
420 // flag that stores shut down type |
|
421 TBool iIsSilentShutdown; |
|
422 |
|
423 //please note that it only stops media server as UPnP entity (sends bye bye etc.) |
|
424 //not symbian server object |
|
425 CUpnpNotifyTimer* iStopAVMediaServerTimer; |
|
426 |
|
427 // Network events provider used for WLAN lost and address change |
|
428 CUpnpConnectionManagerNetworkEventProvider* iConnectionManagerNetworkEventProvider; |
|
429 |
|
430 // Provides files for description part |
|
431 CUpnpMediaServerDescriptionProvider* iDescriptionProvider; |
|
432 |
|
433 // Services device description |
|
434 CUpnpDeviceDescriptionStore* iDescriptionStore; |
|
435 }; |
|
436 |
|
437 #endif // C_CUPNPMEDIASERVER_H |