|
1 /** |
|
2 * Copyright (c) 2010 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: CUpnpTmAppServerService class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System includes |
|
20 #include <upnpdevice.h> |
|
21 #include <upnpservice.h> |
|
22 |
|
23 //User includes |
|
24 #include "upnptmappserverservice.h" |
|
25 #include "upnptmserverdevice.h" |
|
26 #include "upnptmserverimpl.h" |
|
27 #include "OstTraceDefinitions.h" |
|
28 #ifdef OST_TRACE_COMPILER_IN_USE |
|
29 #include "upnptmappserverserviceTraces.h" |
|
30 #endif |
|
31 |
|
32 |
|
33 //Defines different action names ,their arguments and their related state variables |
|
34 _LIT8(KGetApplicationList, "GetApplicationList"); |
|
35 _LIT8(KLaunchApp, "LaunchApplication"); |
|
36 _LIT8(KTerminateApp, "TerminateApplication"); |
|
37 _LIT8(KGetAppStatus, "GetApplicationStatus"); |
|
38 _LIT8(KAppFilter, "AppListingFilter"); |
|
39 _LIT8(KProfileId, "ProfileID"); |
|
40 _LIT8(KAppListing, "AppListing"); |
|
41 _LIT8(KAppId , "AppID"); |
|
42 _LIT8(KAppStatus, "AppStatus"); |
|
43 _LIT8(KAppLaunchUri, "AppURI"); |
|
44 _LIT8(KAppTerminateResult, "TerminationResult"); |
|
45 _LIT8(KArgTypeAppList, "A_ARG_TYPE_AppList"); |
|
46 _LIT8(KArgTypeAppStatus, "A_ARG_TYPE_AppStatus"); |
|
47 _LIT8(KArgTypeAppStatusUpdate, "AppStatusUpdate"); |
|
48 _LIT8(KArgTypeAppListUpdate, "AppListUpdate"); |
|
49 _LIT8(KStatusTrue, "True"); |
|
50 _LIT8(KStatusFalse, "False"); |
|
51 |
|
52 |
|
53 // ================= MEMBER FUNCTIONS ============================================== |
|
54 |
|
55 // --------------------------------------------------------------------------------- |
|
56 // CUpnpTmAppServerService::CUpnpTmAppServerService |
|
57 // C++ default constructor can NOT contain any code, that |
|
58 // might leave. |
|
59 // --------------------------------------------------------------------------------- |
|
60 // |
|
61 CUpnpTmAppServerService::CUpnpTmAppServerService( CUpnpDevice& aUpnpDevice,CUpnpTmServerImpl& aTmServerImpl ): |
|
62 CUpnpServiceImplementation(aUpnpDevice),iUpnpDevice(aUpnpDevice), iTmServerImpl(aTmServerImpl) |
|
63 { |
|
64 |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------------- |
|
68 // CUpnpTmAppServerService::~CUpnpTmAppServerService |
|
69 // C++ default destructor |
|
70 // --------------------------------------------------------------------------------- |
|
71 // |
|
72 CUpnpTmAppServerService::~CUpnpTmAppServerService() |
|
73 { |
|
74 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_CUPNPTMAPPSERVERSERVICE_ENTRY ); |
|
75 if ( iHttpServerSession ) |
|
76 { |
|
77 iHttpServerSession->Stop(); |
|
78 } |
|
79 delete iHttpServerSession; |
|
80 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_CUPNPTMAPPSERVERSERVICE_EXIT ); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------------- |
|
84 // CUpnpTmAppServerService::ConstructL |
|
85 // Two-phased constructor. |
|
86 // Initialize variables, set parent service and create XML reader. |
|
87 // --------------------------------------------------------------------------------- |
|
88 // |
|
89 void CUpnpTmAppServerService::ConstructL( const TDesC& aDescriptionPath ) |
|
90 { |
|
91 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_CONSTRUCTL_ENTRY ); |
|
92 _LIT8( KServiceType, "TmApplicationServer:1" ); |
|
93 BaseConstructL( aDescriptionPath, KServiceType); |
|
94 |
|
95 SetStateVariableL( KArgTypeAppList, KEmptyString, EFalse ); |
|
96 SetStateVariableL( KArgTypeAppStatus, KEmptyString, EFalse ); |
|
97 SetStateVariableL( KArgTypeAppStatusUpdate, KEmptyString, EFalse ); |
|
98 SetStateVariableL( KArgTypeAppListUpdate, KEmptyString, EFalse ); |
|
99 ConstructHttpL( ); |
|
100 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_CONSTRUCTL_EXIT ); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------------- |
|
104 // CUpnpTmAppServerService::ConstructHttpL |
|
105 // Method is used to start the HTTP Server |
|
106 // --------------------------------------------------------------------------------- |
|
107 // |
|
108 void CUpnpTmAppServerService::ConstructHttpL( ) |
|
109 { |
|
110 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_CONSTRUCTHTTPL_ENTRY ); |
|
111 iHttpServerSession = CUpnpHttpServerSession::NewL( CUpnpSettings::GetIapL(),*this ); |
|
112 iHttpServerSession->DefaultRuntime().SetCreator( *this ); |
|
113 iHttpServerSession->StartL(); |
|
114 iTmServerImpl.GenerateUrlComponents(*iHttpServerSession); |
|
115 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_CONSTRUCTHTTPL_EXIT ); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------------- |
|
119 // CUpnpTmAppServerService::NewL |
|
120 // Two-phased constructor. |
|
121 // --------------------------------------------------------------------------------- |
|
122 // |
|
123 CUpnpTmAppServerService* CUpnpTmAppServerService::NewL(CUpnpDevice& aUpnpDevice, const TDesC& aDescriptionPath, |
|
124 CUpnpTmServerImpl& aTmServerImp ) |
|
125 { |
|
126 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_NEWL_ENTRY ); |
|
127 CUpnpTmAppServerService* appServerService = new (ELeave) CUpnpTmAppServerService(aUpnpDevice, aTmServerImp); |
|
128 CleanupStack::PushL( appServerService ); |
|
129 appServerService->ConstructL( aDescriptionPath ); |
|
130 CleanupStack::Pop( appServerService ); |
|
131 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_NEWL_EXIT ); |
|
132 return appServerService; |
|
133 } |
|
134 |
|
135 // ---------------------------------------------------------------------------------------------- |
|
136 // CUpnpTmAppServerService::ActionReceivedLD |
|
137 // @param aAction action received from the client |
|
138 // ---------------------------------------------------------------------------------------------- |
|
139 // |
|
140 void CUpnpTmAppServerService::ActionReceivedLD( CUpnpAction* aAction ) |
|
141 { |
|
142 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_ACTIONRECEIVEDLD_ENTRY ); |
|
143 if ( !aAction ) |
|
144 { |
|
145 User::Leave( KErrNotFound ); |
|
146 } |
|
147 CleanupStack::PushL( aAction ); |
|
148 TUpnpErrorCode eCode = EHttpOk; |
|
149 |
|
150 // Get the name, saves calls in the if-else statements |
|
151 TPtrC8 name( aAction->Name() ); |
|
152 // Verify the action and do the operation(s) |
|
153 if ( name.Compare( KGetApplicationList ) == 0 ) |
|
154 { |
|
155 eCode = GetAppListActionL( aAction ); |
|
156 } |
|
157 else if ( name.Compare( KLaunchApp ) == 0 ) |
|
158 { |
|
159 eCode = LaunchAppActionL( aAction ); |
|
160 } |
|
161 else if ( name.Compare( KTerminateApp ) == 0 ) |
|
162 { |
|
163 eCode = TerminateAppActionL ( aAction ); |
|
164 } |
|
165 else if ( name.Compare( KGetAppStatus) == 0 ) |
|
166 { |
|
167 eCode = GetAppStatusActionL( aAction ); |
|
168 } |
|
169 else |
|
170 { |
|
171 eCode = EInvalidAction; |
|
172 } |
|
173 SendL( aAction, eCode ); |
|
174 CleanupStack::PopAndDestroy( aAction ); |
|
175 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_ACTIONRECEIVEDLD_EXIT ); |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------------- |
|
179 // CUpnpTmAppServerService::GetAppListActionL |
|
180 // @param aAction pointer to upnp action object |
|
181 // @return Returns upnp error code |
|
182 // --------------------------------------------------------------------------------- |
|
183 // |
|
184 TUpnpErrorCode CUpnpTmAppServerService::GetAppListActionL( CUpnpAction* aAction ) |
|
185 { |
|
186 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_GETAPPLISTACTIONL_ENTRY ); |
|
187 // Fetch the value for app listing filter argument |
|
188 const TDesC8& filter = aAction->ArgumentValue(KAppFilter); |
|
189 // Validate the AppListing filter string |
|
190 // AppListingFilter input argument can contain wither wildcard(*) or |
|
191 // a well formatted string |
|
192 if ( ( filter.Compare(KWildCard ) != KErrNone ) && ( filter.Find(Keq) == KErrNotFound )) |
|
193 { |
|
194 // The filter string is having neither wildcard(*) nor a proper string( =" is missing ) |
|
195 OstTrace0( TRACE_ERROR, DUP2_CUPNPTMAPPSERVERSERVICE_GETAPPLISTACTIONL, "CUpnpTmAppServerService::GetAppListActionL" ); |
|
196 return EInvalidArgs; // invalid AppListingFilter argument |
|
197 } |
|
198 |
|
199 // Fetch the value for profile ID argument |
|
200 TUint profileIdInt; |
|
201 ConvertDescriptorToInt( aAction->ArgumentValue(KProfileId), profileIdInt ); |
|
202 OstTrace1( TRACE_NORMAL, CUPNPTMAPPSERVERSERVICE_GETAPPLISTACTIONL, "CUpnpTmAppServerService::GetAppListActionL;profileIdInt=%u", profileIdInt ); |
|
203 |
|
204 TTerminalModeErrorCode ret; |
|
205 const TDesC8& appList = iTmServerImpl.GetApplicationListL( filter,profileIdInt,ret ); |
|
206 if ( ret != ETerminalModeSuccess ) |
|
207 { |
|
208 OstTrace1( TRACE_ERROR, DUP1_CUPNPTMAPPSERVERSERVICE_GETAPPLISTACTIONL, "CUpnpTmAppServerService::GetAppListActionL;ret=%d", ret ); |
|
209 return TUpnpErrorCode( ret ); |
|
210 } |
|
211 aAction->SetArgumentL( KAppListing, appList ); |
|
212 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_GETAPPLISTACTIONL_EXIT ); |
|
213 return EHttpOk; |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------------- |
|
217 // CUpnpTmAppServerService::LaunchAppActionL |
|
218 // @param aAction pointer to upnp action object |
|
219 // @return Returns upnp error code |
|
220 // --------------------------------------------------------------------------------- |
|
221 // |
|
222 TUpnpErrorCode CUpnpTmAppServerService::LaunchAppActionL( CUpnpAction* aAction ) |
|
223 { |
|
224 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_LAUNCHAPPACTIONL_ENTRY ); |
|
225 TUint appIdInt; |
|
226 TUint profileIdInt; |
|
227 // Validates the input parameters |
|
228 if ( ( ConvertDescriptorToInt( aAction->ArgumentValue(KAppId), appIdInt ) != KErrNone ) |
|
229 || ( ConvertDescriptorToInt( aAction->ArgumentValue(KProfileId), profileIdInt ) != KErrNone )) |
|
230 { |
|
231 OstTraceExt2( TRACE_ERROR, CUPNPTMAPPSERVERSERVICE_LAUNCHAPPACTIONL, "CUpnpTmAppServerService::LaunchAppActionL;appIdInt=%u;profileIdInt=%u", appIdInt, profileIdInt ); |
|
232 return EInvalidArgs; // either invalid app ID or invalid profile ID |
|
233 } |
|
234 |
|
235 RBuf8 launchUrl; |
|
236 TTerminalModeErrorCode ret = iTmServerImpl.LaunchApp( appIdInt,profileIdInt,launchUrl ); |
|
237 |
|
238 if ( ret != ETerminalModeSuccess ) |
|
239 { |
|
240 // Error is returned |
|
241 launchUrl.Close(); |
|
242 OstTrace0( TRACE_ERROR, DUP1_CUPNPTMAPPSERVERSERVICE_LAUNCHAPPACTIONL, "CUpnpTmAppServerService::LaunchAppActionL" ); |
|
243 return TUpnpErrorCode( ret ); |
|
244 } |
|
245 CleanupClosePushL(launchUrl); |
|
246 aAction->SetArgumentL( KAppLaunchUri , launchUrl ); |
|
247 |
|
248 CleanupStack::PopAndDestroy(&launchUrl); |
|
249 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_LAUNCHAPPACTIONL_EXIT ); |
|
250 return EHttpOk; |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------------------------------- |
|
254 // CUpnpTmAppServerService::TerminateAppActionL |
|
255 // @param aAction pointer to upnp action object |
|
256 // @return Returns upnp error code |
|
257 // --------------------------------------------------------------------------------- |
|
258 // |
|
259 TUpnpErrorCode CUpnpTmAppServerService::TerminateAppActionL( CUpnpAction* aAction ) |
|
260 { |
|
261 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_TERMINATEAPPACTIONL_ENTRY ); |
|
262 // Validates the input parameters |
|
263 TUint appIdInt; |
|
264 TUint profileIdInt; |
|
265 if ( ( ConvertDescriptorToInt( aAction->ArgumentValue(KAppId), appIdInt ) != KErrNone ) |
|
266 || ( ConvertDescriptorToInt( aAction->ArgumentValue(KProfileId), profileIdInt ) != KErrNone )) |
|
267 { |
|
268 OstTraceExt2( TRACE_ERROR, CUPNPTMAPPSERVERSERVICE_TERMINATEAPPACTIONL, "CUpnpTmAppServerService::TerminateAppActionL;appIdInt=%u;profileIdInt=%u", appIdInt, profileIdInt ); |
|
269 return EInvalidArgs; // either invalid app ID or invalid profile ID |
|
270 } |
|
271 |
|
272 TTerminalModeErrorCode ret = iTmServerImpl.TerminateApp( appIdInt,profileIdInt ); |
|
273 if ( ret != ETerminalModeSuccess ) |
|
274 { |
|
275 // Error is returned |
|
276 aAction->SetArgumentL( KAppTerminateResult,KStatusFalse ); |
|
277 OstTrace0( TRACE_ERROR, DUP1_CUPNPTMAPPSERVERSERVICE_TERMINATEAPPACTIONL, "CUpnpTmAppServerService::TerminateAppActionL" ); |
|
278 return TUpnpErrorCode( ret ); |
|
279 } |
|
280 aAction->SetArgumentL( KAppTerminateResult,KStatusTrue); |
|
281 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_TERMINATEAPPACTIONL_EXIT ); |
|
282 return EHttpOk; |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------------- |
|
286 // CUpnpTmAppServerService::GetAppStatusActionL |
|
287 // @param aAction Pointer to upnp action object |
|
288 // @return Returns upnp error code |
|
289 // --------------------------------------------------------------------------------- |
|
290 // |
|
291 TUpnpErrorCode CUpnpTmAppServerService::GetAppStatusActionL( CUpnpAction* aAction ) |
|
292 { |
|
293 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_GETAPPSTATUSACTIONL_ENTRY ); |
|
294 const TDesC8& appId= aAction->ArgumentValue(KAppId); |
|
295 // Check if the appID argument has either wildcard character(*) |
|
296 // or a valid integer as its value |
|
297 TUint appIdInt; |
|
298 if ( (( appId.Compare( KWildCard ) != KErrNone ) && |
|
299 ( ConvertDescriptorToInt( appId, appIdInt ) != KErrNone )) ) |
|
300 { |
|
301 OstTrace1( TRACE_ERROR, CUPNPTMAPPSERVERSERVICE_GETAPPSTATUSACTIONL, "CUpnpTmAppServerService::GetAppStatusActionL;appIdInt=%u", appIdInt ); |
|
302 return EInvalidArgs; // invalid input argument |
|
303 } |
|
304 RBuf8 appStatusBuf; |
|
305 CleanupClosePushL(appStatusBuf); |
|
306 TTerminalModeErrorCode ret; |
|
307 iTmServerImpl.GetAppStatusL( appId, appStatusBuf, ret); |
|
308 |
|
309 if ( ret != ETerminalModeSuccess ) |
|
310 { |
|
311 CleanupStack::PopAndDestroy(&appStatusBuf); |
|
312 OstTrace0( TRACE_ERROR, DUP1_CUPNPTMAPPSERVERSERVICE_GETAPPSTATUSACTIONL, "CUpnpTmAppServerService::GetAppStatusActionL" ); |
|
313 return TUpnpErrorCode( ret ); |
|
314 } |
|
315 aAction->SetArgumentL( KAppStatus, appStatusBuf ); |
|
316 |
|
317 CleanupStack::PopAndDestroy(&appStatusBuf); |
|
318 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_GETAPPSTATUSACTIONL_EXIT ); |
|
319 return EHttpOk; |
|
320 } |
|
321 |
|
322 // --------------------------------------------------------------------------------- |
|
323 // CUpnpTmAppServerService::NewTransactionL |
|
324 // This method is invoked whenever http request related to icon file transfer |
|
325 // arrives to http server from remote client |
|
326 // @param aMethod Http message method ( GET, HEAD or POST ) |
|
327 // @param aUri Http message request uri |
|
328 // @param aSender IP address of the Http message sender |
|
329 // @param[out] aTrans Returns newly created transaction object |
|
330 // --------------------------------------------------------------------------------- |
|
331 // |
|
332 void CUpnpTmAppServerService::NewTransactionL( const TDesC8& aMethod, const TDesC8& aUri, |
|
333 const TInetAddr& /*aSender*/, CUpnpHttpServerTransaction*& aResultTrans ) |
|
334 { |
|
335 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_NEWTRANSACTIONL_ENTRY ); |
|
336 if ( aMethod != KHttpPost() ) |
|
337 { |
|
338 iTmServerImpl.GetIconInfoL(aUri, aResultTrans); |
|
339 } |
|
340 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_NEWTRANSACTIONL_EXIT ); |
|
341 } |
|
342 |
|
343 // --------------------------------------------------------------------------------- |
|
344 // CUpnpTmAppServerService::HttpEventLD |
|
345 // Provides file transfer completion status |
|
346 // Notifies about the HTTP events, errors. |
|
347 // Handling of http events is not provided in Terminal Mode Service |
|
348 // @param aMessage the HTTP message |
|
349 // --------------------------------------------------------------------------------- |
|
350 // |
|
351 void CUpnpTmAppServerService::HttpEventLD( CUpnpHttpMessage* /*aMessage*/ ) |
|
352 { |
|
353 |
|
354 } |
|
355 |
|
356 // --------------------------------------------------------------------------------- |
|
357 // CUpnpTmAppServerService::AppStatusUpdateEventL |
|
358 // Notifies the client about the status updates. |
|
359 // @param aStatusUpdateBuffer Buffer holding the update status information. |
|
360 // --------------------------------------------------------------------------------- |
|
361 // |
|
362 void CUpnpTmAppServerService::AppStatusUpdateEventL( const TDesC8& aStatusUpdateBuffer ) |
|
363 { |
|
364 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_APPSTATUSUPDATEEVENTL_ENTRY ); |
|
365 SetStateVariableL( KArgTypeAppStatusUpdate, aStatusUpdateBuffer, EFalse ); |
|
366 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_APPSTATUSUPDATEEVENTL_EXIT ); |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------------------------------- |
|
370 // CUpnpTmAppServerService::AppListUpdateEventL |
|
371 // Notifies the client about the app list updates. |
|
372 // @param aListUpdateBuffer Buffer holding the update app list information. |
|
373 // --------------------------------------------------------------------------------- |
|
374 // |
|
375 void CUpnpTmAppServerService::AppListUpdateEventL( const TDesC8& aListUpdateBuffer ) |
|
376 { |
|
377 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_APPLISTUPDATEEVENTL_ENTRY ); |
|
378 SetStateVariableL( KArgTypeAppListUpdate, aListUpdateBuffer, EFalse ); |
|
379 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_APPLISTUPDATEEVENTL_EXIT ); |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------------------------------- |
|
383 // CUpnpTmAppServerService::ConvertDescriptorToInt |
|
384 // Utility method to convert descriptor's data to integer |
|
385 // @param aDes Descriptor whose integer equivalent have to be calculated |
|
386 // @param aIntVal[out] Integer value |
|
387 // @return Returns error code |
|
388 // --------------------------------------------------------------------------------- |
|
389 // |
|
390 TInt CUpnpTmAppServerService::ConvertDescriptorToInt( const TDesC8& aDes, TUint& aIntVal ) |
|
391 { |
|
392 OstTraceFunctionEntry0( CUPNPTMAPPSERVERSERVICE_CONVERTDESCRIPTORTOINT_ENTRY ); |
|
393 aIntVal = KErrNone; |
|
394 TLex8 lex( aDes ); |
|
395 OstTrace1( TRACE_NORMAL, CUPNPTMAPPSERVERSERVICE_CONVERTDESCRIPTORTOINT, "CUpnpTmAppServerService::ConvertDescriptorToInt;aIntVal=%u", aIntVal ); |
|
396 OstTraceFunctionExit0( CUPNPTMAPPSERVERSERVICE_CONVERTDESCRIPTORTOINT_EXIT ); |
|
397 return lex.Val(aIntVal); |
|
398 } |
|
399 |
|
400 //End of File |