|
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 #ifndef C_CUPNPSSDPSERVER_H |
|
19 #define C_CUPNPSSDPSERVER_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <es_sock.h> |
|
24 #include <in_sock.h> |
|
25 #include "upnpudpserver.h" |
|
26 #include "upnpssdpmessagefactory.h" |
|
27 #include "upnpssdpserverobserver.h" |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class CUpnpMessageHandler; |
|
31 class CUpnpSsdpMessage; |
|
32 class CUpnpDeviceLibraryElement; |
|
33 |
|
34 // CLASS DECLARATION |
|
35 |
|
36 /** |
|
37 * CUpnpSsdpServer is used to send and receive SSDP messages. |
|
38 * |
|
39 * @since Series60 2.0 |
|
40 */ |
|
41 NONSHARABLE_CLASS(CUpnpSsdpServer) : public CUpnpUdpServer, |
|
42 public MUpnpUdpServerObserver |
|
43 { |
|
44 public: |
|
45 // Constructors and destructor |
|
46 /** |
|
47 * Two-phased constructor. |
|
48 * @param aSsdpServerObserver Pointer that is used for callbacks. |
|
49 * @param aSocketServ Pointer to used Socket Server. |
|
50 * @param aListeningPort Port that server is listening to. |
|
51 * @return A new CUpnpSsdpServer instance. |
|
52 */ |
|
53 IMPORT_C static CUpnpSsdpServer* NewL( |
|
54 MUpnpSsdpServerObserver* aSsdpServerObserver, |
|
55 RSocketServ* aSocketServ, TInt aListeningPort ); |
|
56 |
|
57 /** |
|
58 * Two-phased constructor. |
|
59 * @param aSsdpServerObserver Pointer that is used for callbacks. |
|
60 * @param aSocketServ Pointer to used Socket Server. |
|
61 * @param aListeningPort Port that server is listening to. |
|
62 * @param aMasterServer Pointer to master server that generates the responses |
|
63 for multicast messages. |
|
64 * @return A new CUpnpSsdpServer instance. |
|
65 */ |
|
66 IMPORT_C static CUpnpSsdpServer* NewL( |
|
67 MUpnpSsdpServerObserver* aSsdpServerObserver, |
|
68 RSocketServ* aSocketServ, TInt aListeningPort, |
|
69 CUpnpSsdpServer* aMasterServer ); |
|
70 |
|
71 /** |
|
72 * Destructor. |
|
73 */ |
|
74 IMPORT_C virtual ~CUpnpSsdpServer(); |
|
75 |
|
76 public: |
|
77 // New functions |
|
78 |
|
79 /** |
|
80 * Starts the CUpnpSsdpServer. |
|
81 * @since Series60 2.0 |
|
82 * @return None |
|
83 */ |
|
84 IMPORT_C void StartL(); |
|
85 |
|
86 /** |
|
87 * Stops the CUpnpSsdpServer. |
|
88 * @since Series60 2.0 |
|
89 * @return None |
|
90 */ |
|
91 IMPORT_C void Stop(); |
|
92 |
|
93 public: |
|
94 // public functions for SSDP advertising and searching |
|
95 |
|
96 /** |
|
97 * Advertises element aDev in CUpnpDeviceLibrary. |
|
98 * @since Series60 2.0 |
|
99 * @param aDev Pointer to advertised device. |
|
100 * @return None |
|
101 */ |
|
102 /** |
|
103 Advertises element aDev in CUpnpDeviceLibrary. |
|
104 @param aDev Pointer to advertised device. |
|
105 @return None. |
|
106 */ |
|
107 IMPORT_C void AdvertiseAliveL( CUpnpDeviceLibraryElement& aDev ); |
|
108 |
|
109 /** |
|
110 * Advertises ByeBye for element aDev in CUpnpDeviceLibrary. |
|
111 * @since Series60 2.0 |
|
112 * @param aDev Pointer to advertised device. |
|
113 * @return None |
|
114 */ |
|
115 /** |
|
116 Advertises ByeBye for element aDev in CUpnpDeviceLibrary. |
|
117 @param aDev Pointer to advertised device. |
|
118 @return None. |
|
119 */ |
|
120 IMPORT_C void AdvertiseByebyeL( CUpnpDeviceLibraryElement& aDev ); |
|
121 |
|
122 /** |
|
123 * Sends a SSDP search, searching for aTarget. |
|
124 * @since Series60 2.0 |
|
125 * @param aTarget Search String. |
|
126 * @return None |
|
127 */ |
|
128 IMPORT_C void SearchL( TDesC8& aTarget ); |
|
129 |
|
130 /** |
|
131 * Sends a SSDP search, searching for aTarget. |
|
132 * @since Series60 2.0 |
|
133 * @param aTarget Search String. |
|
134 * @param aMaximumWaitTime Value of the MX-header. |
|
135 * @return None |
|
136 */ |
|
137 IMPORT_C void SearchL( TDesC8& aTarget, TDesC8& aMaximumWaitTime ); |
|
138 |
|
139 /** |
|
140 * Master server is receiving messages sent to multicast \ |
|
141 * address via this function and generates the response. |
|
142 * @since Series60 2.0 |
|
143 * @param aMessage Received message |
|
144 */ |
|
145 void MessageFromMulticastL( CUpnpSsdpMessage* aMessage ); |
|
146 |
|
147 private: |
|
148 |
|
149 /** |
|
150 * C++ default constructor. |
|
151 */ |
|
152 CUpnpSsdpServer( MUpnpSsdpServerObserver* aSsdpServerObserver, |
|
153 RSocketServ* aSocketServ, TInt aListeningPort ); |
|
154 |
|
155 /** |
|
156 * C++ default constructor. |
|
157 */ |
|
158 CUpnpSsdpServer( MUpnpSsdpServerObserver* aSsdpServerObserver, |
|
159 RSocketServ* aSocketServ, TInt aListeningPort, |
|
160 CUpnpSsdpServer* aMasterServer ); |
|
161 |
|
162 /** |
|
163 * By default Symbian 2nd phase constructor is private. |
|
164 */ |
|
165 void ConstructL(); |
|
166 |
|
167 private: |
|
168 // private ssdp:alive functions |
|
169 |
|
170 /** |
|
171 * Sends a single alive message to network using given paramaters. |
|
172 * @since Series60 2.0 |
|
173 * @param aNt Value of NT header |
|
174 * @param aUsn Value of USN header |
|
175 * @param aLoc Value of LOCATION header |
|
176 */ |
|
177 void SendAdvertiseAliveL( TDesC8& aNt, TDesC8& aUsn, TDesC8& aLoc ); |
|
178 |
|
179 /** |
|
180 * Advertises a device in device library. |
|
181 * @since Series60 2.0 |
|
182 * @param aDev Reference to device that is to be advertised. |
|
183 */ |
|
184 void SingleDeviceAdvertiseAliveL( CUpnpDeviceLibraryElement& aDev ); |
|
185 |
|
186 private: |
|
187 // private ssdp:byebye functions |
|
188 |
|
189 /** |
|
190 * Sends a BYEBYE message to network using given paramaters. |
|
191 * @since Series60 2.0 |
|
192 * @param aNt Value of NT header |
|
193 * @param aUsn Value of USN header |
|
194 * @return ?description |
|
195 */ |
|
196 void SendAdvertiseByebyeL( TDesC8& aNt, TDesC8& aUsn ); |
|
197 |
|
198 /** |
|
199 * Sends a single device BYEBYE advertisement |
|
200 * @since Series60 2.0 |
|
201 * @param aDev Device to be advertised. |
|
202 */ |
|
203 void SingleDeviceAdvertiseByebyeL( CUpnpDeviceLibraryElement& aDev ); |
|
204 |
|
205 private: |
|
206 // private ssdp response generating functions |
|
207 |
|
208 /** |
|
209 * Function that is used to determine what kind of response is |
|
210 * required to be sent. |
|
211 * @since Series60 2.0 |
|
212 * @param aMsg Message that contains the search request. |
|
213 */ |
|
214 void ResponseL( CUpnpSsdpMessage* aMsg ); |
|
215 |
|
216 /** |
|
217 * Sends a search response with given parameters. |
|
218 * @since Series60 2.0 |
|
219 * @param aDest Address of remote host |
|
220 * @param aSt Value of ST header |
|
221 * @param aUsn Value of USN header |
|
222 * @param aLoc Value of LOCATION header. |
|
223 */ |
|
224 void SendResponseL( TInetAddr& aDest, TDesC8& aSt, TDesC8& aUsn, |
|
225 TDesC8& aLoc ); |
|
226 |
|
227 /** |
|
228 * Creates a search response to given search message. |
|
229 * This advertises only the device. |
|
230 * @since Series60 2.0 |
|
231 * @param aDevice Device that needs to be advertised. |
|
232 * @param aMsg Search request message. |
|
233 * @return ?description |
|
234 */ |
|
235 void SingleDeviceResponseL( CUpnpDeviceLibraryElement* aDevice, |
|
236 CUpnpSsdpMessage* aMsg ); |
|
237 |
|
238 /** |
|
239 * Creates a response to search message aMsg from device aDevice. |
|
240 * This response concerns about aDevices certain service, aServiceType |
|
241 * @since Series60 2.0 |
|
242 * @param aDevice Device that sends the response. |
|
243 * @param aServiceType Service that resides in aDevice. |
|
244 * @param aMsg Message that requires the response to be sent (request) |
|
245 */ |
|
246 void SingleServiceResponseL( CUpnpDeviceLibraryElement* aDevice, |
|
247 const TDesC8& aServiceType, CUpnpSsdpMessage* aMsg ); |
|
248 |
|
249 private: |
|
250 |
|
251 /** |
|
252 * Callback function from CUpnpUdpServer. |
|
253 * @since Series60 2.0 |
|
254 * @param aMessage Message that was received thru CUpnpUdpServer. |
|
255 * @return None |
|
256 */ |
|
257 void UdpMessageReceivedL( CUdpMessage* aMessage ); |
|
258 |
|
259 private: |
|
260 // Data |
|
261 |
|
262 // SSDP server observer |
|
263 MUpnpSsdpServerObserver* iSsdpServerObserver; |
|
264 |
|
265 // SSDP master server |
|
266 CUpnpSsdpServer* iMasterServer; |
|
267 |
|
268 // value foro SERVER header in SSDP messages |
|
269 HBufC8* iServerDescription; |
|
270 |
|
271 }; |
|
272 |
|
273 #endif // C_CUPNPSSDPSERVER_H |
|
274 // End of File |