|
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: CUpnpAction |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "upnpaction.h" |
|
20 #include "upnpargument.h" |
|
21 #include "upnpstring.h" |
|
22 #include "upnpsoapmessage.h" |
|
23 #include "upnpservice.h" |
|
24 #define KLogFile _L("UPnPStack.txt") |
|
25 #include "upnpcustomlog.h" |
|
26 |
|
27 // ============================= LOCAL FUNCTIONS =============================== |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CUpnpAction::CUpnpAction |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 |
|
38 CUpnpAction::CUpnpAction( CUpnpService& aParentService ) : |
|
39 iParentService( aParentService ) |
|
40 { |
|
41 iError = KErrNone; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CUpnpAction::ConstructL |
|
46 // Symbian 2nd phase constructor can leave. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void CUpnpAction::ConstructL( CUpnpAction& aAction ) |
|
50 { |
|
51 RPointerArray<CUpnpArgument>& argumentList = aAction.ArgumentList(); |
|
52 |
|
53 for ( TInt index = 0; index < argumentList.Count(); index++ ) |
|
54 { |
|
55 CUpnpArgument* arg = CUpnpArgument::NewL( *argumentList[index], |
|
56 iParentService ); |
|
57 CleanupStack::PushL( arg ); |
|
58 iArguments.AppendL( arg ); |
|
59 CleanupStack::Pop( arg ); |
|
60 } |
|
61 |
|
62 iName = aAction.Name().AllocL(); |
|
63 iDestinationPath = HBufC8::NewL( 0 ); |
|
64 |
|
65 iSessionId = CUpnpHttpMessage::NewSessionIdL(); |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CUpnpAction::NewLC |
|
70 // Two-phased constructor. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C CUpnpAction* CUpnpAction::NewLC( CUpnpAction& aAction, |
|
74 CUpnpService& aParentService ) |
|
75 { |
|
76 CUpnpAction* self = new (ELeave) CUpnpAction( aParentService ); |
|
77 |
|
78 CleanupStack::PushL( self ); |
|
79 self->ConstructL( aAction ); |
|
80 |
|
81 return self; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CUpnpAction::~CUpnpAction |
|
86 // Destructor |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C CUpnpAction::~CUpnpAction() |
|
90 { |
|
91 iArguments.ResetAndDestroy(); |
|
92 iArguments.Close(); |
|
93 |
|
94 delete iName; |
|
95 delete iDestinationPath; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CUpnpAction::SetArgumentL |
|
100 // |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C TInt CUpnpAction::SetArgumentL( const TDesC8& aName, |
|
104 const TDesC8& aValue ) |
|
105 { |
|
106 for ( TInt i = 0; i < iArguments.Count(); i++ ) |
|
107 { |
|
108 CUpnpArgument* arg = iArguments[i]; |
|
109 |
|
110 if ( aName.Compare( arg->Name() ) == 0 ) |
|
111 { |
|
112 arg->SetValueL( aValue ); |
|
113 return KErrNone; |
|
114 } |
|
115 } |
|
116 return KErrBadName; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CUpnpAction::ArgumentValue |
|
121 // |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 EXPORT_C const TDesC8& CUpnpAction::ArgumentValue( const TDesC8& aName ) |
|
125 { |
|
126 for ( TInt i = 0; i < iArguments.Count(); i++ ) |
|
127 { |
|
128 CUpnpArgument* arg = iArguments[i]; |
|
129 |
|
130 if ( aName.Compare( arg->Name() ) == 0 ) |
|
131 { |
|
132 return arg->Value(); |
|
133 } |
|
134 } |
|
135 return KNullDesC8(); |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CUpnpAction::Argument |
|
140 // |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 EXPORT_C CUpnpArgument* CUpnpAction::Argument( const TDesC8& aName ) |
|
144 { |
|
145 for ( TInt i = 0; i < iArguments.Count(); i++ ) |
|
146 { |
|
147 CUpnpArgument* arg = iArguments[i]; |
|
148 |
|
149 if ( aName.Compare( arg->Name() ) == 0 ) |
|
150 { |
|
151 return arg; |
|
152 } |
|
153 } |
|
154 return NULL; |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CUpnpAction::SetDestinationPathL |
|
159 // |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 EXPORT_C void CUpnpAction::SetDestinationPathL( const TDesC8& aDestination ) |
|
163 { |
|
164 delete iDestinationPath; |
|
165 iDestinationPath = NULL; |
|
166 iDestinationPath = aDestination.AllocL(); |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CUpnpAction::DestinationPath |
|
171 // |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 EXPORT_C const TDesC8& CUpnpAction::DestinationPath() |
|
175 { |
|
176 return *iDestinationPath; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CUpnpAction::SetSender |
|
181 // |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 EXPORT_C void CUpnpAction::SetSender( const TInetAddr & aSender ) |
|
185 { |
|
186 iSender = aSender; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CUpnpAction::Sender |
|
191 // |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C TInetAddr& CUpnpAction::Sender() |
|
195 { |
|
196 return iSender; |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CUpnpAction::Name |
|
201 // |
|
202 // ----------------------------------------------------------------------------- |
|
203 // |
|
204 EXPORT_C TDesC8& CUpnpAction::Name() |
|
205 { |
|
206 return *iName; |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CUpnpAction::ArgumentList |
|
211 // |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 EXPORT_C RPointerArray<CUpnpArgument>& CUpnpAction::ArgumentList() |
|
215 { |
|
216 return iArguments; |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CUpnpAction::DestinationAddr |
|
221 // |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 EXPORT_C TInetAddr CUpnpAction::DestinationAddr() const |
|
225 { |
|
226 return iDestinationAddr; |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CUpnpAction::ArgumentType |
|
231 // |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 EXPORT_C TInt CUpnpAction::ArgumentType( const TDesC8 &aArgumentName ) |
|
235 { |
|
236 for ( TInt i = 0; i < iArguments.Count(); i++ ) |
|
237 { |
|
238 CUpnpArgument* arg = iArguments[i]; |
|
239 |
|
240 if ( aArgumentName.Compare( arg->Name() ) == 0 ) |
|
241 { |
|
242 return arg->Type(); |
|
243 } |
|
244 } |
|
245 |
|
246 return EUndefined; |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CUpnpAction::ServiceType |
|
251 // |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 EXPORT_C TDesC8& CUpnpAction::ServiceType() |
|
255 { |
|
256 return const_cast<TDesC8&>( iParentService.ServiceType() ); |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CUpnpAction::SessionId |
|
261 // |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 EXPORT_C TInt CUpnpAction::SessionId() const |
|
265 { |
|
266 return iSessionId; |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CUpnpAction::SessionId |
|
271 // |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 void CUpnpAction::SetSessionId( TInt aId ) |
|
275 { |
|
276 iSessionId = aId; |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CUpnpAction::SetDestinationAddr |
|
281 // |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 EXPORT_C void CUpnpAction::SetDestinationAddr( const TInetAddr & aAddr ) |
|
285 { |
|
286 iDestinationAddr = aAddr; |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CUpnpAction::Error |
|
291 // |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 EXPORT_C TInt CUpnpAction::Error() const |
|
295 { |
|
296 return iError; |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CUpnpAction::Service |
|
301 // |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 EXPORT_C CUpnpService& CUpnpAction::Service() |
|
305 { |
|
306 return iParentService; |
|
307 } |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // CUpnpAction::SetError |
|
311 // |
|
312 // ----------------------------------------------------------------------------- |
|
313 // |
|
314 EXPORT_C void CUpnpAction::SetError( TInt aError ) |
|
315 { |
|
316 iError = aError; |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CUpnpAction::Local |
|
321 // |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 EXPORT_C TBool CUpnpAction::Local() const |
|
325 { |
|
326 return iLocal; |
|
327 } |
|
328 |
|
329 // ----------------------------------------------------------------------------- |
|
330 // CUpnpAction::SetLocal |
|
331 // |
|
332 // ----------------------------------------------------------------------------- |
|
333 // |
|
334 EXPORT_C void CUpnpAction::SetLocal( TBool aLocal ) |
|
335 { |
|
336 iLocal = aLocal; |
|
337 } |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CUpnpAction::NewL |
|
341 // for TESTS only |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 EXPORT_C CUpnpAction* CUpnpAction::NewL( const TDesC8& aActionName ) |
|
345 { |
|
346 CUpnpAction* self = new (ELeave) CUpnpAction(); |
|
347 CleanupStack::PushL( self ); |
|
348 self->SetNameL( aActionName ); |
|
349 CleanupStack::Pop( self ); |
|
350 return self; |
|
351 } |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // CUpnpAction::NewL |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 CUpnpAction* CUpnpAction::NewL( CUpnpService& aParentService ) |
|
358 { |
|
359 CUpnpAction* self = new (ELeave) CUpnpAction( aParentService ); |
|
360 CleanupStack::PushL( self ); |
|
361 self->ConstructL(); |
|
362 CleanupStack::Pop( self ); |
|
363 return self; |
|
364 } |
|
365 |
|
366 // ----------------------------------------------------------------------------- |
|
367 // CUpnpAction::NewL |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 void CUpnpAction::SetNameL( const TDesC8& aName ) |
|
371 { |
|
372 HBufC8* tmp = aName.AllocL(); |
|
373 delete iName; |
|
374 iName = tmp; |
|
375 } |
|
376 |
|
377 // ----------------------------------------------------------------------------- |
|
378 // CUpnpAction::NewL |
|
379 // ----------------------------------------------------------------------------- |
|
380 // |
|
381 void CUpnpAction::AddArgumentL( CUpnpArgument& aAction ) |
|
382 { |
|
383 iArguments.AppendL( &aAction ); |
|
384 } |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // ConstructL |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 void CUpnpAction::ConstructL() |
|
391 { |
|
392 iSessionId = CUpnpHttpMessage::NewSessionIdL(); |
|
393 iDestinationPath = HBufC8::NewL( 0 ); |
|
394 iName = HBufC8::NewL( 0 ); |
|
395 } |
|
396 |
|
397 // ----------------------------------------------------------------------------- |
|
398 // CUpnpAction::CUpnpAction |
|
399 // for TESTS only. Object isn't completely valid. |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 CUpnpAction::CUpnpAction() |
|
403 : iParentService(*(CUpnpService*)1)//tests only iParentService shouldn't be used |
|
404 { |
|
405 } |
|
406 |
|
407 // End of File |