|
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: Declares main application class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef C_CUPNPDEVICELIBRARY_H |
|
21 #define C_CUPNPDEVICELIBRARY_H |
|
22 |
|
23 // INCLUDES |
|
24 #include "upnpdevicelibraryelement.h" |
|
25 |
|
26 // CONSTANTS |
|
27 static const TInt KDeviceTimeout=120; |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class TBufferIndex; |
|
31 class CUpnpSsdpMessage; |
|
32 |
|
33 // CLASS DECLARATION |
|
34 |
|
35 /** |
|
36 * An interface from device library to Message Handler. |
|
37 * This interface class presents two pure virtual functions that are required |
|
38 * by device library. |
|
39 * |
|
40 * @since Series60 2.0 |
|
41 */ |
|
42 class MUpnpDeviceLibraryObserver |
|
43 { |
|
44 public: // New functions |
|
45 |
|
46 /** |
|
47 * A pure virtual function. |
|
48 * Advertise a device (advertisement type |
|
49 * selected depending on parameter aLive) |
|
50 * @since Series60 2.0 |
|
51 * @param aLive Expresses the advertisement type |
|
52 * (ssdp:alive or ssdp:byebye) |
|
53 * @param anElement The device to be advertised |
|
54 */ |
|
55 virtual void AdvertiseDeviceL(TInt aLive, CUpnpDeviceLibraryElement& anElement) = 0; |
|
56 |
|
57 /** |
|
58 * A pure virtual function. Advertises the device list has changed. |
|
59 * @since Series60 2.0 |
|
60 */ |
|
61 virtual void DeviceListChangedL() = 0; |
|
62 }; |
|
63 |
|
64 // CLASS DECLARATION |
|
65 |
|
66 /** |
|
67 * The device library main class. |
|
68 * This class contains an array of device library elements |
|
69 * (of type CUpnpDeviceLibraryElement). |
|
70 * This list is maintained up-to-date by reading received SSDP messages. |
|
71 * Every element in the library has a timeout, and remote devices are removed |
|
72 * from the library after the timeout. |
|
73 * |
|
74 * @since Series60 2.0 |
|
75 */ |
|
76 class CUpnpDeviceLibrary : public CBase, public MUpnpTimeoutElementParent |
|
77 { |
|
78 public: |
|
79 |
|
80 /** |
|
81 * Two-phased constructor. |
|
82 * @param aObserver The observer of the library. |
|
83 * @param aHandle the thread log handle |
|
84 * @return The new instance. |
|
85 */ |
|
86 IMPORT_C static CUpnpDeviceLibrary* NewL( |
|
87 MUpnpDeviceLibraryObserver& aObserver, |
|
88 TInt aHandle ); |
|
89 |
|
90 /** |
|
91 * Destructor. |
|
92 */ |
|
93 IMPORT_C ~CUpnpDeviceLibrary(); |
|
94 |
|
95 /** |
|
96 * Adds the data of the local device to the library. |
|
97 * @since Series60 2.0 |
|
98 * @param aIndex An indexing structure to parse the actual data |
|
99 * @param aBuffer A buffer containing the actual data |
|
100 * @param aLocalAddr Local address |
|
101 */ |
|
102 IMPORT_C void AddInfoL( const TUpnpAddLocalDevice* aIndex, |
|
103 const TDesC8& aBuffer, |
|
104 const TInetAddr& aLocalAddr); |
|
105 |
|
106 /** |
|
107 * Adds the data of the local device to the library. |
|
108 * @since Series60 2.0 |
|
109 * @param aIndex An indexing structure to parse the actual data |
|
110 * @param aBuffer A buffer containing the actual data |
|
111 */ |
|
112 IMPORT_C void AddInfoL( const TUpnpAddLocalDevice* aIndex, |
|
113 const TDesC8& aBuffer); |
|
114 |
|
115 /** |
|
116 * Adds the data of the SSDP message to the library. |
|
117 * @since Series60 2.0 |
|
118 * @param aMessage A SSDP message containing data |
|
119 */ |
|
120 IMPORT_C void AddInfoL( CUpnpSsdpMessage* aMessage ); |
|
121 |
|
122 /** |
|
123 * Returns the index of an element with matching UUID. |
|
124 * @since Series60 2.0 |
|
125 * @param aUuid The UUID of searched device |
|
126 * @return The index of the found element; if not found, -1 |
|
127 */ |
|
128 IMPORT_C TInt Find( const TDesC8& aUuid ); |
|
129 |
|
130 /** |
|
131 * Returns an array containing pointers to the library elements |
|
132 * @since Series60 2.0 |
|
133 * @return An array containing pointers to the library elements |
|
134 */ |
|
135 IMPORT_C RPointerArray<CUpnpDeviceLibraryElement>& DeviceList(); |
|
136 |
|
137 /** |
|
138 * Removes an element from the library. |
|
139 * @since Series60 2.0 |
|
140 * @param aUuid The UUID of the element to be removed |
|
141 */ |
|
142 IMPORT_C void RemoveL( const TDesC8& aUuid ); |
|
143 |
|
144 /** |
|
145 * Removes an element from the library. |
|
146 * @since Series60 2.0 |
|
147 * @param aUuid The UUID of the element to be removed |
|
148 */ |
|
149 IMPORT_C void RemoveSilentL( const TDesC8& aUuid ); |
|
150 /** |
|
151 * Prepare for shutdown. |
|
152 * @since Series60 2.0 |
|
153 */ |
|
154 IMPORT_C void PrepareShutdown(); |
|
155 |
|
156 /** |
|
157 * ?member_description. |
|
158 * @since Series60 2.0 |
|
159 * @param aUpdateId |
|
160 * @param aDevices |
|
161 * @param aServices |
|
162 * @param aDeviceCount |
|
163 * @param aServiceCount |
|
164 */ |
|
165 IMPORT_C void GetUpdate( TInt& aUpdateId, |
|
166 TUpnpDevice*& aDevices, |
|
167 TUpnpService*& aServices, |
|
168 TInt& aDeviceCount, |
|
169 TInt& aServiceCount ); |
|
170 |
|
171 |
|
172 /** |
|
173 * Removes all remote devices from the device library, |
|
174 * used for ip address changes |
|
175 * @since Series60 3.1 |
|
176 */ |
|
177 IMPORT_C void RemoveAllDevicesL(); |
|
178 |
|
179 /** |
|
180 * Set device notification filtering |
|
181 * @since Series60 3.2 |
|
182 * @param aUuid Device Uuid |
|
183 */ |
|
184 IMPORT_C void StopFilteringDeviceL( const TDesC8& aUuid ); |
|
185 |
|
186 private: // Functions from base classes |
|
187 |
|
188 /** |
|
189 * From MUpnpTimeoutElementParent Callback function. |
|
190 * Implementation of MUpnpTimeoutElementParent::TimeoutExpired. |
|
191 * If the element is local, it is advertised and new timeout is set. |
|
192 * If the element describes a remote device, the device is removed |
|
193 * from the library and observer is informed about the disappearing. |
|
194 * @since Series60 2.0 |
|
195 * @param aElement The element whose timeout has ran out |
|
196 */ |
|
197 void TimeoutExpiredL( CUpnpTimeoutElement* aElement ); |
|
198 |
|
199 protected: // New functions |
|
200 |
|
201 /** |
|
202 * Remove Device. |
|
203 * @since Series60 2.0 |
|
204 * @param aMessage |
|
205 */ |
|
206 void RemoveDeviceL( CUpnpSsdpMessage* aMessage ); |
|
207 |
|
208 private: // New functions |
|
209 |
|
210 /** |
|
211 * Return element. |
|
212 * @since Series60 2.0 |
|
213 * @param aUUID |
|
214 * @return CUpnpDeviceLibraryElement pointer |
|
215 */ |
|
216 CUpnpDeviceLibraryElement* Element( TDesC8& aUUID ); |
|
217 |
|
218 /** |
|
219 * Add device. |
|
220 * @since Series60 2.0 |
|
221 * @param aMessage |
|
222 * @return TBool |
|
223 */ |
|
224 TBool AddDeviceL( CUpnpSsdpMessage* aMessage ); |
|
225 /** |
|
226 * Creates and appends local device. |
|
227 * @param aIndex descriptiors positions structure |
|
228 needed by deserialization algorithm |
|
229 * @param aBuffer aBuffer CUpnpDeviceLibraryElement object in serialized form |
|
230 * @param aLocalAddr local address of device being added |
|
231 */ |
|
232 void AppendLocalDeviceL( const TUpnpAddLocalDevice* aIndex, |
|
233 const TDesC8& aBuffer, |
|
234 const TInetAddr& aLocalAddr ); |
|
235 |
|
236 /** |
|
237 * Invalidates non local device with the same UID as |
|
238 * local device being added |
|
239 * @param aElem |
|
240 */ |
|
241 void InvalidateNonLocalDevice( CUpnpDeviceLibraryElement& aElem ); |
|
242 |
|
243 private: |
|
244 |
|
245 /** |
|
246 * C++ default constructor. |
|
247 * @param aObserver The observer of the library. |
|
248 * @param aHandle the thread log handle |
|
249 */ |
|
250 CUpnpDeviceLibrary( MUpnpDeviceLibraryObserver& aObserver, TInt aHandle ); |
|
251 |
|
252 /** |
|
253 * By default Symbian 2nd phase constructor is private. |
|
254 */ |
|
255 void ConstructL(); |
|
256 |
|
257 protected: |
|
258 |
|
259 TInt iUpdateId; |
|
260 |
|
261 private: |
|
262 |
|
263 MUpnpDeviceLibraryObserver& iObserver; |
|
264 |
|
265 RPointerArray<CUpnpDeviceLibraryElement> iElementArray; |
|
266 |
|
267 // for logging into right thread log |
|
268 TInt iHandle; |
|
269 |
|
270 }; |
|
271 |
|
272 |
|
273 #endif // DEVICELIBRARY_H |
|
274 |
|
275 // End of File |