|
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: Implements the CUpnpService class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "upnpcommonstructs.h" |
|
21 #include "upnpstring.h" |
|
22 |
|
23 #include "upnphttpmessage.h" |
|
24 #include "upnphttpmessagefactory.h" |
|
25 #include "upnpserviceimplementation.h" |
|
26 #include "upnpgenamessage.h" |
|
27 #include "upnpdevice.h" |
|
28 #include "upnpservice.h" |
|
29 #include "upnpfileutils.h" |
|
30 #include "upnpargument.h" |
|
31 |
|
32 //for sax |
|
33 |
|
34 #include "upnpcontenthandlerscontroller.h" |
|
35 |
|
36 using namespace UpnpFileUtil; |
|
37 |
|
38 static const TInt KMaxServiceDescriptionLength( 51200 ); |
|
39 |
|
40 |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
|
43 |
|
44 CUpnpService* CUpnpService::NewL( CUpnpDevice* aDevice ) |
|
45 { |
|
46 CUpnpService* self = new (ELeave) CUpnpService( *aDevice ); |
|
47 return self; |
|
48 } |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CUpnpService::AddAction |
|
51 // Add new action to action list |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CUpnpService::AddActionL( CUpnpAction& aAction ) |
|
55 { |
|
56 iActions.AppendL( &aAction ); |
|
57 } |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CUpnpService::CUpnpService |
|
60 // C++ default constructor can NOT contain any code, that |
|
61 // might leave. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C CUpnpService::CUpnpService( CUpnpDevice& aDevice ) |
|
65 : iParentDevice( aDevice ) |
|
66 { |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CUpnpService::ConstructL |
|
71 // Symbian 2nd phase constructor can leave. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C void CUpnpService::ConstructL( const TDesC8& aDescription, |
|
75 const TDesC8& /*aServiceType*/) |
|
76 { |
|
77 if ( aDescription.Length() > KMaxServiceDescriptionLength ) |
|
78 { |
|
79 User::Leave( KErrTooBig ); |
|
80 } |
|
81 CUpnpContentHandlersController* controller = |
|
82 CUpnpContentHandlersController::NewLC(); |
|
83 controller->ParseServiceL( aDescription, this ); |
|
84 CleanupStack::PopAndDestroy( controller ); |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CUpnpService::NewL |
|
89 // Two-phased constructor. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C CUpnpService* CUpnpService::NewL( const TDesC8& aDescription, |
|
93 const TDesC8& aServiceType, |
|
94 CUpnpDevice& aDevice ) |
|
95 { |
|
96 CUpnpService* self = new (ELeave) CUpnpService( aDevice ); |
|
97 |
|
98 CleanupStack::PushL( self ); |
|
99 self->ConstructL( aDescription, aServiceType ); |
|
100 CleanupStack::Pop( self ); |
|
101 |
|
102 return self; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CUpnpService::~CUpnpService |
|
107 // Destructor |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 EXPORT_C CUpnpService::~CUpnpService() |
|
111 { |
|
112 iActions.ResetAndDestroy(); |
|
113 iActions.Close(); |
|
114 iStateVariables.ResetAndDestroy(); |
|
115 iStateVariables.Close(); |
|
116 |
|
117 delete iType; |
|
118 delete iPath; |
|
119 delete iSubscriptionUrl; |
|
120 delete iControlUrl; |
|
121 delete iUrl; |
|
122 } |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CUpnpService::CreateActionLC |
|
125 // Creating an action by Control Point |
|
126 // (other items were commented in a header). |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 EXPORT_C CUpnpAction* CUpnpService::CreateActionLC( const TDesC8& aActionName ) |
|
130 { |
|
131 TInt index( 0 ); |
|
132 |
|
133 while ( index < iActions.Count() ) |
|
134 { |
|
135 CUpnpAction& action = *iActions[index]; |
|
136 |
|
137 if ( aActionName.Compare( action.Name() ) == KErrNone ) |
|
138 { |
|
139 CUpnpAction* act = CUpnpAction::NewLC( action, *this ); |
|
140 |
|
141 act->SetDestinationAddr( iParentDevice.Address() ); |
|
142 act->SetDestinationPathL( ControlUrl() ); |
|
143 |
|
144 return act; |
|
145 } |
|
146 |
|
147 index++; |
|
148 } |
|
149 |
|
150 return NULL; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CUpnpService::GetActionList |
|
155 // Build a list of actions provided by the CUpnpService. |
|
156 // (other items were commented in a header). |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 EXPORT_C void CUpnpService::GetActionList( RPointerArray<CUpnpAction>& aActionList ) |
|
160 { |
|
161 aActionList = iActions; |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CUpnpService::GetAction |
|
166 // Returns an Action with the given name |
|
167 // (other items were commented in a header). |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 |
|
171 EXPORT_C TBool CUpnpService::GetAction( CUpnpAction*& aAction, |
|
172 const TDesC8& aActionName ) |
|
173 { |
|
174 TBool result = EFalse; |
|
175 aAction = NULL; |
|
176 |
|
177 for ( TInt i=0; i<iActions.Count(); i++ ) |
|
178 { |
|
179 if ( iActions[i]->Name().Compare( aActionName ) == 0 ) |
|
180 { |
|
181 result = ETrue; |
|
182 aAction = iActions[i]; |
|
183 break; |
|
184 } |
|
185 } |
|
186 |
|
187 return result; |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CUpnpService::StateVariableList |
|
192 // |
|
193 // (other items were commented in a header). |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C RPointerArray<CUpnpStateVariable> CUpnpService::StateVariableList() const |
|
197 { |
|
198 return iStateVariables; |
|
199 } |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CUpnpService::AddStateVariableL |
|
202 // Add new state to state list |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 EXPORT_C void CUpnpService::AddStateVariableL( CUpnpStateVariable* aStateVariable ) |
|
206 { |
|
207 iStateVariables.AppendL( aStateVariable ); |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CUpnpService::SetStateVariableL |
|
212 // |
|
213 // (other items were commented in a header). |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C void CUpnpService::SetStateVariableL( const TDesC8& aName, |
|
217 const TDesC8& aValue ) |
|
218 { |
|
219 |
|
220 TInt i( 0 ); |
|
221 |
|
222 for ( i=0; i < iStateVariables.Count() && |
|
223 iStateVariables[i]->Name() != aName; i++ ) |
|
224 { |
|
225 } |
|
226 |
|
227 if ( i != iStateVariables.Count() ) |
|
228 { |
|
229 iStateVariables[i]->SetValueL( aValue ); |
|
230 } |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CUpnpService::StateVariable |
|
235 // |
|
236 // (other items were commented in a header). |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 EXPORT_C CUpnpStateVariable* CUpnpService::StateVariable( const TDesC8& aName ) |
|
240 { |
|
241 TInt index = 0; |
|
242 |
|
243 while ( index < iStateVariables.Count() ) |
|
244 { |
|
245 CUpnpStateVariable* var = iStateVariables[index]; |
|
246 |
|
247 if ( aName.Compare( var->Name() ) == KErrNone ) |
|
248 { |
|
249 return var; |
|
250 } |
|
251 |
|
252 index++; |
|
253 } |
|
254 |
|
255 return NULL; |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CUpnpService::ServiceType |
|
260 // |
|
261 // (other items were commented in a header). |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 EXPORT_C const TDesC8& CUpnpService::ServiceType() |
|
265 { |
|
266 if (iType) |
|
267 { |
|
268 return *iType; |
|
269 } |
|
270 else |
|
271 { |
|
272 return KNullDesC8; |
|
273 } |
|
274 } |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CUpnpService::SetServiceTypeL |
|
277 // Get service type of this (local or remote) service |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 void CUpnpService::SetServiceTypeL( const TDesC8& aServiceType ) |
|
281 { |
|
282 HBufC8* tmp = aServiceType.AllocL(); |
|
283 delete iType; |
|
284 iType = tmp; |
|
285 } |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CUpnpService::Path |
|
288 // |
|
289 // (other items were commented in a header). |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 EXPORT_C const TDesC8& CUpnpService::Path() |
|
293 { |
|
294 return *iPath; |
|
295 } |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CUpnpService::SetPathL |
|
298 // Get message dispatching path. For internal use only |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CUpnpService::SetPathL( const TDesC8& aPath ) |
|
302 { |
|
303 HBufC8* tmp = aPath.AllocL(); |
|
304 delete iPath; |
|
305 iPath = tmp; |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CUpnpService::Address |
|
310 // |
|
311 // (other items were commented in a header). |
|
312 // ----------------------------------------------------------------------------- |
|
313 // |
|
314 EXPORT_C TInetAddr CUpnpService::Address() |
|
315 { |
|
316 return iParentDevice.Address(); |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CUpnpService::SubscriptionUrl |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 EXPORT_C const TPtrC8 CUpnpService::SubscriptionUrl() |
|
324 { |
|
325 if ( iSubscriptionUrl ) |
|
326 { |
|
327 return *iSubscriptionUrl; |
|
328 } |
|
329 else |
|
330 { |
|
331 return KNullDesC8(); |
|
332 } |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CUpnpService::SetSubscriptionUrl |
|
337 // ----------------------------------------------------------------------------- |
|
338 // |
|
339 EXPORT_C void CUpnpService::SetSubscriptionUrl( HBufC8* aUrl ) |
|
340 { |
|
341 iSubscriptionUrl = aUrl; |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CUpnpService::ControlUrl |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 EXPORT_C const TPtrC8 CUpnpService::ControlUrl() |
|
349 { |
|
350 if (iControlUrl) |
|
351 { |
|
352 return *iControlUrl; |
|
353 } |
|
354 else |
|
355 { |
|
356 return KNullDesC8(); |
|
357 } |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CUpnpService::SetControlUrl |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 EXPORT_C void CUpnpService::SetControlUrl( HBufC8* aUrl ) |
|
365 { |
|
366 iControlUrl = aUrl; |
|
367 } |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CUpnpService::SetServiceUrl |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 EXPORT_C void CUpnpService::SetServiceDescriptionUrl( HBufC8* aUrl ) |
|
373 { |
|
374 iUrl = aUrl; |
|
375 } |
|
376 // ----------------------------------------------------------------------------- |
|
377 // CUpnpService::ControlUrl |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 EXPORT_C const TPtrC8 CUpnpService::ServiceDescriptionUrl() |
|
381 { |
|
382 if ( iUrl ) |
|
383 { |
|
384 return *iUrl; |
|
385 } |
|
386 else |
|
387 { |
|
388 return KNullDesC8(); |
|
389 } |
|
390 } |
|
391 // ----------------------------------------------------------------------------- |
|
392 // CUpnpService::Device |
|
393 // Gets parent device |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 EXPORT_C CUpnpDevice& CUpnpService::Device() |
|
397 { |
|
398 return iParentDevice; |
|
399 } |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // CUpnpService::SetArgumentTypes |
|
403 // Sets argument types |
|
404 // ----------------------------------------------------------------------------- |
|
405 // |
|
406 void CUpnpService::SetArgumentTypes() |
|
407 { |
|
408 for ( TInt actionIndex(0); actionIndex < iActions.Count() ; actionIndex++ ) |
|
409 { |
|
410 CUpnpAction* action = iActions[ actionIndex ]; |
|
411 TInt actCount = action->ArgumentList().Count(); |
|
412 for ( TInt argumentIndex(0); argumentIndex < actCount; argumentIndex++ ) |
|
413 { |
|
414 CUpnpArgument* argument = action->ArgumentList()[ argumentIndex ]; |
|
415 CUpnpStateVariable* stateVariable = |
|
416 StateVariable( argument->RelatedStateVariable() ); |
|
417 if ( stateVariable ) |
|
418 { |
|
419 argument->SetType( stateVariable->Type() ); |
|
420 } |
|
421 else |
|
422 argument->SetType( EUnknown ); |
|
423 } |
|
424 } |
|
425 } |
|
426 // ----------------------------------------------------------------------------- |
|
427 // CUpnpService::Added |
|
428 // Set true value |
|
429 // ----------------------------------------------------------------------------- |
|
430 // |
|
431 void CUpnpService::Added() |
|
432 { |
|
433 iIsAdded = ETrue; |
|
434 } |
|
435 // ----------------------------------------------------------------------------- |
|
436 // CUpnpService::IsAdded |
|
437 // Get boolean value if added |
|
438 // ----------------------------------------------------------------------------- |
|
439 // |
|
440 EXPORT_C TBool CUpnpService::IsAdded() |
|
441 { |
|
442 return iIsAdded; |
|
443 } |
|
444 // ----------------------------------------------------------------------------- |
|
445 // CUpnpService::IsComplete |
|
446 // Get boolean value if complete |
|
447 // ----------------------------------------------------------------------------- |
|
448 // |
|
449 TBool CUpnpService::IsComplete() |
|
450 { |
|
451 return iComplete; |
|
452 } |
|
453 // End of File |