services/terminalmodeservice/src/upnptmserverimpl.cpp
branchRCL_3
changeset 30 594d15129e2c
parent 29 5c72fd91570d
equal deleted inserted replaced
29:5c72fd91570d 30:594d15129e2c
     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: CUpnpTmServerImpl class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // Includes
       
    19 #include "upnptmserverimpl.h"
       
    20 #include "upnpiconfileservetransaction.h"
       
    21 #include "OstTraceDefinitions.h"
       
    22 #ifdef OST_TRACE_COMPILER_IN_USE
       
    23 #include "upnptmserverimplTraces.h"
       
    24 #endif
       
    25 
       
    26 
       
    27 //Literals
       
    28 _LIT8(KAppListStart,             "<appList>");
       
    29 _LIT8(KAppListEnd,               "</appList>");
       
    30 _LIT8(KAppIdStart,               "<appID>");
       
    31 _LIT8(KAppIdEnd,                 "</appID>");
       
    32 _LIT8(KNameStart,                "<name>");
       
    33 _LIT8(KNameEnd,                  "</name>");
       
    34 _LIT8(KIconStart,                "<icon>");
       
    35 _LIT8(KIconEnd,                  "</icon>");
       
    36 _LIT8(KMimeTypeStart,            "<mimetype>");
       
    37 _LIT8(KMimeTypeEnd,              "</mimetype>");
       
    38 _LIT8(KWidthStart,               "<width>");
       
    39 _LIT8(KWidthEnd,                 "</width>");
       
    40 _LIT8(KHeightStart,              "<height>");
       
    41 _LIT8(KHeightEnd,                "</height>");
       
    42 _LIT8(KDepthStart,               "<depth>");
       
    43 _LIT8(KDepthEnd,                 "</depth>");
       
    44 _LIT8(KUrlStart,                 "<url>");
       
    45 _LIT8(KUrlEnd,                   "</url>");
       
    46 _LIT8(KAllowedProfileIdsStart,   "<allowedProfileIDs>");
       
    47 _LIT8(KAllowedProfileIdsEnd,     "</allowedProfileIDs>");
       
    48 _LIT8(KResourceStatusStart,      "<resourceStatus>");
       
    49 _LIT8(KResourceStatusEnd,        "</resourceStatus>");
       
    50 _LIT8(KAppStatusListStart,       "<appStatusList>");
       
    51 _LIT8(KAppStatusListEnd,         "</appStatusList>");
       
    52 _LIT8(KAppStatusStart,           "<appStatus>");
       
    53 _LIT8(KAppStatusEnd,             "</appStatus>");
       
    54 _LIT8(KStatusStart,              "<status>");
       
    55 _LIT8(KStatusEnd,                "</status>");
       
    56 _LIT8(KProfileIdStart,           "<profileID>");
       
    57 _LIT8(KProfileIdEnd,             "</profileID>");
       
    58 _LIT8(KStatusTypeStart,          "<statusType>");
       
    59 _LIT8(KStatusTypeEnd,            "</statusType>");
       
    60 _LIT8(KStartTagOpenBracket,      "<");
       
    61 _LIT8(KEndTagOpenBracket,        "</");
       
    62 _LIT8(KCloseBracket,             ">");
       
    63 
       
    64 
       
    65 // ================= MEMBER FUNCTIONS ==============================================
       
    66 
       
    67 // ---------------------------------------------------------------------------------
       
    68 // CUpnpTmServerImpl::NewL
       
    69 // Two-phased constructor.
       
    70 // ---------------------------------------------------------------------------------
       
    71 //
       
    72 CUpnpTmServerImpl* CUpnpTmServerImpl::NewL( CUpnpTmServerDeviceInfo& aDeviceInfo,
       
    73                                            MUpnpTmServerObserver& aTmServerObserver)
       
    74     {
       
    75     CUpnpTmServerImpl* self = new (ELeave) CUpnpTmServerImpl( aTmServerObserver );   
       
    76     CleanupStack::PushL(self);
       
    77     self->ConstructL( aDeviceInfo );
       
    78     CleanupStack::Pop(self);
       
    79     return self;    
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------------
       
    83 // CUpnpTmServerImpl::CUpnpTmServerImpl
       
    84 // C++ default constructor can NOT contain any code, that
       
    85 // might leave.
       
    86 // ---------------------------------------------------------------------------------
       
    87 //
       
    88 CUpnpTmServerImpl::CUpnpTmServerImpl( MUpnpTmServerObserver& aTmServerObserver )
       
    89       :iTmServerObserver(aTmServerObserver)
       
    90      {
       
    91 
       
    92      }
       
    93 
       
    94 // ---------------------------------------------------------------------------------
       
    95 // CUpnpTmServerImpl::ConstructL
       
    96 // Symbian 2nd phase constructor can leave.
       
    97 // ---------------------------------------------------------------------------------
       
    98 //
       
    99 void CUpnpTmServerImpl::ConstructL( CUpnpTmServerDeviceInfo& aDeviceInfo )
       
   100     {
       
   101     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_CONSTRUCTL_ENTRY );
       
   102     iIapSetting = CUpnpSettings::NewL( KCRUidUPnPStack );
       
   103     /**
       
   104      *  Retrieve the IAP ID which has been set by DLNA and store it so that 
       
   105      *  it can be reverted back to the same when Automotive Server has stopped 
       
   106      *  making use of TM Service.
       
   107      */
       
   108     iIapId = CUpnpSettings::GetIapL(); 
       
   109     //Fetch the IAP ID set by the Automotive Server
       
   110     TInt iapId = aDeviceInfo.IapId();
       
   111     OstTrace1( TRACE_NORMAL, CUPNPTMSERVERIMPL_CONSTRUCTL, "CUpnpTmServerImpl::ConstructL;iapId=%d", iapId );
       
   112     // writes the iap id to the cenrep
       
   113     User::LeaveIfError( iIapSetting->Set( CUpnpSettings::KUPnPStackIapId, iapId ) ); 
       
   114     iTmServerDevice = CUpnpTmServerDevice::NewL( aDeviceInfo, *this );
       
   115     iAppStore = CUpnpRemotableAppStore::NewL();
       
   116     iIconMapping = CUpnpTmIconMapping::NewL();
       
   117     User::LeaveIfError( iIconFileSession.Connect() );
       
   118     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_CONSTRUCTL_EXIT );
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------------
       
   122 // CUpnpTmServerImpl::~CUpnpTmServerImpl
       
   123 // Destructor
       
   124 // ---------------------------------------------------------------------------------
       
   125 //
       
   126 CUpnpTmServerImpl::~CUpnpTmServerImpl()
       
   127     {
       
   128     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_CUPNPTMSERVERIMPL_ENTRY );
       
   129     //Restore the IAP ID for DLNA use
       
   130     RestoreIap();
       
   131     delete iIapSetting;
       
   132     delete iFilteredAppList;
       
   133     iIconFileSession.Close();
       
   134     delete iAppStore;
       
   135     delete iIconMapping;
       
   136     iXmSignature.Close();
       
   137     iResponseBuf.Close();
       
   138     delete iTmServerDevice;
       
   139     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_CUPNPTMSERVERIMPL_EXIT );
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------------
       
   143 // CUpnpTmServerImpl::RestoreIap
       
   144 // Method is used to restore IAP ID which has been previously retreived so that
       
   145 // DLNA continues to make use of it.
       
   146 // This method is mainly provided to avoid codescanner tool error.
       
   147 // ---------------------------------------------------------------------------------
       
   148 //
       
   149 void CUpnpTmServerImpl::RestoreIap()
       
   150     {
       
   151     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_RESTOREIAP_ENTRY );
       
   152     OstTrace1( TRACE_NORMAL, CUPNPTMSERVERIMPL_RESTOREIAP, "CUpnpTmServerImpl::RestoreIap;iIapId=%d", iIapId );
       
   153     iIapSetting->Set( CUpnpSettings::KUPnPStackIapId, iIapId );    
       
   154     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_RESTOREIAP_EXIT );
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------------
       
   158 // CUpnpTmServerImpl::GetApplicationListL
       
   159 // Method to create soap repsonse for GetApplicationList action.
       
   160 // It generates a list of applications, which can be launched and terminated remotely.
       
   161 // @param aAppListFilter Application Listing Filter. This is an optional parameter 
       
   162 //                     used by the UPnP Control Point to limit the AppListing value to 
       
   163 //                               those applications which meet the filter parameters.
       
   164 // @param aProfileId  ProfileID of client profile whose parameter settings will be 
       
   165 //                    applied for generating the application list
       
   166 // @param aErr[out]   TerminalMode error code
       
   167 // @return Returns soap response buffer 
       
   168 // ---------------------------------------------------------------------------------
       
   169 //
       
   170 const TDesC8& CUpnpTmServerImpl::GetApplicationListL( const TDesC8& aAppListFilter,
       
   171                                      TUint aProfileId, TTerminalModeErrorCode& aErr )
       
   172     {
       
   173     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_GETAPPLICATIONLISTL_ENTRY );
       
   174     iResponseBuf.Close();
       
   175     iResponseBuf.CreateL(KActionBufferLength);
       
   176     aErr = iTmServerObserver.OnGetApplicationList( aProfileId );  
       
   177     if ( aErr == ETerminalModeSuccess )
       
   178         {
       
   179         // Check for availability of AppListingFilter input argument in the soap action
       
   180         TInt filterStringFound = aAppListFilter.Find(Keq);
       
   181         if ( filterStringFound != KErrNotFound )
       
   182             {
       
   183             delete iFilteredAppList;
       
   184             iFilteredAppList = NULL;
       
   185             
       
   186             // Constructs a filter object and parses the input filter string
       
   187             iFilteredAppList = CUpnpTmFilteredAppList::NewL(*this);
       
   188             iFilteredAppList->ParseAppFilterStringL( aAppListFilter, aErr );
       
   189             }
       
   190         if ( aErr == ETerminalModeSuccess )
       
   191             {
       
   192             iProfileId = aProfileId; // Stored for generating app icon path in the soap response
       
   193             AppendDataL(KAppListStart);
       
   194             for ( TInt i(0) ; i < iAppStore->AppIdArray().Count(); i++)
       
   195                  {
       
   196                  // There can be 2 conditions assoicated with this
       
   197                  // 1.  AppListingFilter is "*"
       
   198                  // 2.  AppListingFilter has some filter string set
       
   199                  const RArray<TUint>& profileIdList = iAppStore->FetchRemotableApp(i).AllowedProfileIdList();
       
   200                  if ( ( profileIdList.Find(aProfileId) != KErrNotFound ) ||
       
   201                                                     ( profileIdList.Count() == KErrNone ))
       
   202                      {
       
   203                     
       
   204                      // If the provided profileID is allowed profileID for the app
       
   205                      if (  filterStringFound == KErrNotFound )                 
       
   206                          {
       
   207                          // Constructs a non-filtered soap response
       
   208                          ConstructActionResponseBufferL(i);             
       
   209                          }   
       
   210                      else                            
       
   211                          {  
       
   212                          // Constructs a filtered soap response
       
   213                          iFilteredAppList->ConstructFilteredGetAppListResponseL(i);
       
   214                          }
       
   215                      }
       
   216                  }
       
   217             if ( ( filterStringFound == KErrNotFound ) || ( (iFilteredAppList->SignatureElement()).Length() != KErrNone ))
       
   218                 {
       
   219                 // Append the xml signature value to the response buffer if
       
   220                 // 1. Filter string contains the signature element
       
   221                 // 2. Filter value is '*'
       
   222                 AppendDataL(XmlSignature());
       
   223                 }
       
   224             AppendDataL(KAppListEnd);        
       
   225             }
       
   226         }
       
   227     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_GETAPPLICATIONLISTL_EXIT );
       
   228     return iResponseBuf;
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------------
       
   232 // CUpnpTmServerImpl::LaunchApp
       
   233 // Method to create soap repsonse for LaunchApp action
       
   234 // @param aAppId App ID of the application to be launched remotely
       
   235 // @param aProfileId  ProfileID of client profile 
       
   236 // @param aUrl[out] URI of the remote application where it is running
       
   237 // @return Returns Terminal Mode error code
       
   238 // ---------------------------------------------------------------------------------
       
   239 //
       
   240 TTerminalModeErrorCode CUpnpTmServerImpl::LaunchApp( TUint aAppId, TUint aProfileId, 
       
   241                                                                        RBuf8& aUrl )    
       
   242     {
       
   243     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_LAUNCHAPP_ENTRY );
       
   244     OstTrace1( TRACE_NORMAL, CUPNPTMSERVERIMPL_LAUNCHAPP, "CUpnpTmServerImpl::LaunchApp;aAppId=%d", aAppId );
       
   245     
       
   246     TTerminalModeErrorCode err = AuthorizeApp(aAppId);
       
   247     if ( err == ETerminalModeSuccess )
       
   248         {
       
   249         // Launching of the app succeeded
       
   250         err = iTmServerObserver.OnLaunchApp( aAppId,aUrl,aProfileId ); 
       
   251         }
       
   252     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_LAUNCHAPP_EXIT );
       
   253     return err;
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------------
       
   257 // CUpnpTmServerImpl::TerminateApp
       
   258 // Method to create soap repsonse for TerminateApp action
       
   259 // @param aAppId App ID of the application to be terminated
       
   260 // @param aProfileId  ProfileID of client profile 
       
   261 // @return Returns Terminal Mode error code
       
   262 // ---------------------------------------------------------------------------------
       
   263 //
       
   264 TTerminalModeErrorCode CUpnpTmServerImpl::TerminateApp( TUint aAppId, TUint aProfileId )
       
   265     {
       
   266     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_TERMINATEAPP_ENTRY );
       
   267     TTerminalModeErrorCode err = AuthorizeApp(aAppId);
       
   268     if ( err == ETerminalModeSuccess )
       
   269         {
       
   270         // Termination of the app succeeded
       
   271         err = iTmServerObserver.OnTerminateApp( aAppId, aProfileId );
       
   272         } 
       
   273     OstTrace1( TRACE_NORMAL, CUPNPTMSERVERIMPL_TERMINATEAPP, "CUpnpTmServerImpl::TerminateApp;err=%d", err );
       
   274     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_TERMINATEAPP_EXIT );
       
   275     return err;
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------------
       
   279 // CUpnpTmServerImpl::GetAppStatusL
       
   280 // Method to create soap repsonse for GetAppStatus action
       
   281 // @param aAppIdBuffer Buffer containing the appID or the wildcard character
       
   282 // @param aAppStatusResponse[out] soap response buffer 
       
   283 // @param aErr[out]  Terminal Mode error code
       
   284 // ---------------------------------------------------------------------------------
       
   285 //
       
   286 void CUpnpTmServerImpl::GetAppStatusL( const TDesC8& aAppIdBuffer,RBuf8& aAppStatusResponse,
       
   287                                                               TTerminalModeErrorCode& aErr )
       
   288     {
       
   289     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_GETAPPSTATUSL_ENTRY );
       
   290     RArray<TUint> registeredAppIdArray;
       
   291     CleanupClosePushL(registeredAppIdArray);
       
   292     if ( aAppIdBuffer.Compare( KWildCard()) != KErrNone )
       
   293         {
       
   294         // If the appID is not wildcard character(*)
       
   295         TInt appIdInt(0);
       
   296         TLex8 lex( aAppIdBuffer );
       
   297         lex.Val(appIdInt);  // No need to check the return code as it has been verified earlier
       
   298         aErr = AuthorizeApp( appIdInt );
       
   299         if ( aErr != ETerminalModeSuccess )
       
   300              {
       
   301              CleanupStack::PopAndDestroy(&registeredAppIdArray);
       
   302              OstTrace0( TRACE_ERROR, CUPNPTMSERVERIMPL_GETAPPSTATUSL, "CUpnpTmServerImpl::GetAppStatusL" );
       
   303              return;  // return if the requested appID is non-existent or un-authorized
       
   304              }    
       
   305         // add to the array for which get app status has to be retreived
       
   306         registeredAppIdArray.AppendL(appIdInt);   
       
   307         }
       
   308     else
       
   309         {
       
   310         // Fetch the list of registered apps from the App store
       
   311         for ( TInt i(0); i < iAppStore->AppIdArray().Count(); i++ )
       
   312             {
       
   313             registeredAppIdArray.AppendL(iAppStore->AppIdArray()[i]);       
       
   314             }
       
   315         }
       
   316     iResponseBuf.Close();
       
   317     iResponseBuf.CreateL(KActionBufferLength);
       
   318     AppendDataL(KAppStatusListStart);
       
   319     for ( TInt i(0); i < registeredAppIdArray.Count(); i++ )
       
   320         {
       
   321         CreateGetAppStatusResponseL( registeredAppIdArray[i], aErr );
       
   322         if ( aErr != ETerminalModeSuccess )
       
   323             {
       
   324             /* Should return an error code if it fails to retrieve the 
       
   325                status for even a single application */
       
   326             break;
       
   327             }         
       
   328         }
       
   329     AppendDataL(KAppStatusListEnd);
       
   330     aAppStatusResponse.CreateL(iResponseBuf);
       
   331     CleanupStack::PopAndDestroy(&registeredAppIdArray);
       
   332     OstTraceFunctionExit0( DUP2_CUPNPTMSERVERIMPL_GETAPPSTATUSL_EXIT );
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------------------------------
       
   336 // CUpnpTmServerImpl::CreateGetAppStatusResponseL
       
   337 // Helper method for GetApplicationStatus response buffer construction
       
   338 // @param aAppId AppID
       
   339 // @param aErr[out]  Terminal Mode error code
       
   340 // ---------------------------------------------------------------------------------
       
   341 //
       
   342 void CUpnpTmServerImpl::CreateGetAppStatusResponseL( TUint aAppId,TTerminalModeErrorCode& aErr )
       
   343     {
       
   344     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_CREATEGETAPPSTATUSRESPONSEL_ENTRY );
       
   345     // Get the app statuses of all the requested apps one by one
       
   346     TUint profileId;
       
   347     RBuf8 statusType;
       
   348     aErr = iTmServerObserver.OnGetAppStatus( aAppId, profileId, statusType);    
       
   349     if ( aErr == ETerminalModeSuccess )
       
   350        {
       
   351        /* Append the status to the buffer only if the fetching of the actual status of the 
       
   352           application from the Automotive Server is successful ,else just return the error */
       
   353        CleanupClosePushL(statusType);
       
   354        AppendDataL(KAppStatusStart);
       
   355        AppendDataL(KAppIdStart);
       
   356        AppendDataL(ConvertIntToDescriptor(aAppId));
       
   357        AppendDataL(KAppIdEnd);
       
   358        AppendDataL(KStatusStart);
       
   359        AppendDataL(KProfileIdStart);
       
   360        AppendDataL(ConvertIntToDescriptor(profileId));
       
   361        AppendDataL(KProfileIdEnd);
       
   362        AppendDataL(KStatusTypeStart);
       
   363        AppendDataL(statusType);
       
   364        AppendDataL(KStatusTypeEnd);
       
   365        AppendDataL(KStatusEnd);
       
   366        AppendDataL(KAppStatusEnd);
       
   367        CleanupStack::Pop(&statusType);
       
   368        }
       
   369     statusType.Close();
       
   370     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_CREATEGETAPPSTATUSRESPONSEL_EXIT );
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------------
       
   374 // CUpnpTmServerImpl::GetMaxNumProfiles
       
   375 // Method is used to return the value of the state variable MaxNumProfiles, 
       
   376 // which denotes the maximum number of client profiles that are supported 
       
   377 // simultaneously by the TmClientProfile service.
       
   378 // @param aNumMaxProfiles[out] Maximum number of client profiles that are supported 
       
   379 // @return Returns Terminal Mode error code
       
   380 // ---------------------------------------------------------------------------------
       
   381 //
       
   382 TTerminalModeErrorCode CUpnpTmServerImpl::GetMaxNumProfiles( TUint& aNumMaxProfiles )
       
   383     {
       
   384     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_GETMAXNUMPROFILES_ENTRY );
       
   385     return iTmServerObserver.OnGetMaxNumProfiles(aNumMaxProfiles);
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------------------------------
       
   389 // CUpnpTmServerImpl::SetClientProfile
       
   390 // Method to create soap repsonse for SetClientProfile action.
       
   391 // Method allows the control point to register a client profile and
       
   392 // notify the Terminal Mode device about its preferences, settings and capabilities.
       
   393 // @param aProfileId     The identifier of the profile record where the client
       
   394 //                       profile settings must be stored
       
   395 // @param aInputClientProfile[out]  Profile information about Terminal Mode client and
       
   396 //                    its capabilities which needs to be updated in the profile record
       
   397 // @param aResultProfile[out] The updated client profile.
       
   398 // @return Returns Terminal Mode error code
       
   399 // ---------------------------------------------------------------------------------
       
   400 //
       
   401 TTerminalModeErrorCode CUpnpTmServerImpl::SetClientProfile( TUint aProfileId, 
       
   402                         const TDesC8& aInputClientProfile, RBuf8& aResultProfile )
       
   403     {
       
   404     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_SETCLIENTPROFILE_ENTRY );
       
   405     return iTmServerObserver.OnSetClientProfile( aProfileId, aInputClientProfile,
       
   406                                                                 aResultProfile );
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------------------------------
       
   410 // CUpnpTmServerImpl::GetClientProfile
       
   411 // Method to create soap repsonse for GetClientProfile action.
       
   412 // Method allows the control point to access the contents of a client profile stored 
       
   413 // in the Terminal Mode device.
       
   414 // @param aProfileId  The identifier of the profile record where the client 
       
   415 //                     profile settings must be stored
       
   416 // @param aClientProfile[out] Client profile corresponding to the profileID input variable
       
   417 // @return Returns Terminal Mode error code
       
   418 // ---------------------------------------------------------------------------------
       
   419 //
       
   420 TTerminalModeErrorCode CUpnpTmServerImpl::GetClientProfile( TUint aProfileId, RBuf8& aClientProfile )
       
   421     {
       
   422     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_GETCLIENTPROFILE_ENTRY );
       
   423     return iTmServerObserver.OnGetClientProfile( aProfileId,aClientProfile );
       
   424     }
       
   425 
       
   426 // ---------------------------------------------------------------------------------
       
   427 // CUpnpTmServerImpl::GetIconInfoL
       
   428 // Method to fetch the icon file associated with the particular application. 
       
   429 // @param aUrl Relative URL of the application icon to be retreived
       
   430 // @param aResultTrans CUpnpHttpServerTransaction object
       
   431 // ---------------------------------------------------------------------------------
       
   432 //
       
   433 void CUpnpTmServerImpl::GetIconInfoL( const TDesC8& aUrl, CUpnpHttpServerTransaction*& aResultTrans )
       
   434     {
       
   435     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_GETICONINFOL_ENTRY );
       
   436     RBuf svgFilePath;   
       
   437     // Fetch the original file path which has been mapped to the requesting file.
       
   438     TInt fileIndex = iIconMapping->GetSvgIconPath( aUrl,svgFilePath );
       
   439     if ( fileIndex == KErrNotFound )
       
   440         {
       
   441         // In case the requested icon file is not available, should return EHttpNotFound(404). 
       
   442         // Sets the file source as an empty descriptor.
       
   443         aResultTrans = CUpnpIconFileServeTransaction::NewL( KNullDesC(), iIconFileSession );  
       
   444         svgFilePath.Close();
       
   445         OstTraceFunctionExit0( CUPNPTMSERVERIMPL_GETICONINFOL_EXIT );
       
   446         return;
       
   447         }
       
   448     CleanupClosePushL(svgFilePath);
       
   449     /* Extracts the profileID from the relative URL.
       
   450      * The relative URL will be of the form ( /<profileID>/<iconName> )
       
   451      */
       
   452     const TDesC8& urlWithoutLeadingSlash = aUrl.Mid((aUrl.Locate(KForwardSlash))+1);
       
   453     TInt secondSlashPos = urlWithoutLeadingSlash.Locate(KForwardSlash);
       
   454     User::LeaveIfError(secondSlashPos);
       
   455     const TDesC8& profileIdBuf = urlWithoutLeadingSlash.Left(secondSlashPos);
       
   456     // Converts descriptor to int
       
   457     TLex8 lex( profileIdBuf );
       
   458     TUint profileIdInt(KErrNone);
       
   459     lex.Val(profileIdInt);
       
   460     // Fetch the reference to client icon preference object from AutomotiveServer
       
   461     const CUpnpTmClientIconPref& clientIconPref = iTmServerObserver.GetClientIconPrefsL(profileIdInt);
       
   462     
       
   463     TInt servingIconWidth(KErrNone);
       
   464     TInt servingIconHeight(KErrNone);
       
   465     /* 
       
   466      * Checks whether the conversion of the icon file needed.
       
   467      * If conversion is required, it also determines the dimension(width and height) 
       
   468      * of the serving file.
       
   469      */ 
       
   470     TBool iconConversionNeeded = iIconMapping->IsConversionNeeded( fileIndex, clientIconPref, servingIconWidth,servingIconHeight );
       
   471     if ( iconConversionNeeded )
       
   472         {
       
   473         // Icon file conversion is needed( svg to bmp )
       
   474         CUpnpSvgImageConverter* decoder = CUpnpSvgImageConverter::NewL( servingIconWidth, servingIconHeight );
       
   475         CleanupStack::PushL(decoder);
       
   476         RBuf bitmapBuf;
       
   477         CleanupClosePushL(bitmapBuf);
       
   478         decoder->ConvertToBitmapL( svgFilePath, bitmapBuf );  // Method which in turn invokes the conversion
       
   479         aResultTrans = CUpnpIconFileServeTransaction::NewL( bitmapBuf, iIconFileSession ); /* Sets the data source( file ) 
       
   480                                                                                            which needs to be serverd*/
       
   481         CleanupStack::PopAndDestroy( 2,decoder);
       
   482         }
       
   483     else
       
   484         {
       
   485         // No icon file conversion needed ( svg icon is served )
       
   486         aResultTrans = CUpnpIconFileServeTransaction::NewL( svgFilePath, iIconFileSession );
       
   487         }
       
   488     CleanupStack::PopAndDestroy(&svgFilePath);
       
   489     OstTraceFunctionExit0( DUP1_CUPNPTMSERVERIMPL_GETICONINFOL_EXIT );
       
   490     }
       
   491 
       
   492 // ---------------------------------------------------------------------------------
       
   493 // CUpnpTmServerImpl::StartDeviceL
       
   494 // Method is used to start publishing the terminal mode server device and 
       
   495 // its services
       
   496 // ---------------------------------------------------------------------------------
       
   497 //
       
   498 void CUpnpTmServerImpl::StartDeviceL()
       
   499     {
       
   500     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_STARTDEVICEL_ENTRY );
       
   501     iTmServerDevice->StartTmServerDeviceL();
       
   502     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_STARTDEVICEL_EXIT );
       
   503     }
       
   504 
       
   505 // ---------------------------------------------------------------------------------
       
   506 // CUpnpTmServerImpl::StopDeviceL
       
   507 // Method is used to stop publishing the terminal mode server device and 
       
   508 // its services
       
   509 // ---------------------------------------------------------------------------------
       
   510 //
       
   511 void CUpnpTmServerImpl::StopDeviceL()
       
   512     {   
       
   513     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_STOPDEVICEL_ENTRY );
       
   514     iTmServerDevice->StopTmServerDeviceL();
       
   515     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_STOPDEVICEL_EXIT );
       
   516     }
       
   517 
       
   518 // ---------------------------------------------------------------------------------
       
   519 // CUpnpTmServerImpl::GetRemotableApp
       
   520 // Method is invoked by the Automotive Server to get the access to the particular
       
   521 // instance of the remotable app corresponding to the app ID provided.
       
   522 // This is needed in case AS wishes to modify any paramters of the already 
       
   523 // registered remotable app
       
   524 // @param aAppId App ID of the application whose access is needed
       
   525 // @param aErr[out]  Error code
       
   526 // @returns Returns reference to the Remotable App object
       
   527 // ---------------------------------------------------------------------------------
       
   528 //
       
   529 CUpnpRemotableApp& CUpnpTmServerImpl::GetRemotableApp( TUint aAppId, TInt& aErr )
       
   530     {
       
   531     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_GETREMOTABLEAPP_ENTRY );
       
   532     aErr = KErrNotFound;
       
   533     TInt appIndex = iAppStore->AppIdArray().Find(aAppId);
       
   534     CUpnpRemotableApp* remotableApp = NULL;
       
   535     if ( appIndex != KErrNotFound )
       
   536         {
       
   537         // The requested application is available
       
   538         aErr = KErrNone;    
       
   539         remotableApp = &(iAppStore->FetchRemotableApp(appIndex));  
       
   540         }
       
   541     OstTraceExt2( TRACE_NORMAL, CUPNPTMSERVERIMPL_GETREMOTABLEAPP, "CUpnpTmServerImpl::GetRemotableApp;aAppId=%d;aErr=%d", aAppId, aErr );
       
   542     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_GETREMOTABLEAPP_EXIT );
       
   543     return *remotableApp;
       
   544     }
       
   545 
       
   546 // ---------------------------------------------------------------------------------
       
   547 // Method is used to un-register the individual applications 
       
   548 // @param aRemotableApp  Pointer to Remotable app object which needs to 
       
   549  //                      be registered.Ownership is passed.
       
   550 // ---------------------------------------------------------------------------------
       
   551 //
       
   552 void CUpnpTmServerImpl::RegisterAppL( CUpnpRemotableApp* aRemotableApp )
       
   553     {   
       
   554     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_REGISTERAPPL_ENTRY );
       
   555     ASSERT( aRemotableApp );   
       
   556     iAppStore->AddRemotableAppL( aRemotableApp );
       
   557     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_REGISTERAPPL_EXIT );
       
   558     }
       
   559 
       
   560 // ---------------------------------------------------------------------------------
       
   561 // CUpnpTmServerImpl::RegisterAppsL
       
   562 // Method is used to register multiple applications in one go
       
   563 // @param aRemotableAppList Array of Remotable App objects which needs to be
       
   564 //                          registered. Ownership is passed.
       
   565 // ---------------------------------------------------------------------------------
       
   566 //
       
   567 void CUpnpTmServerImpl::RegisterAppsL( const RPointerArray<CUpnpRemotableApp>& aRemotableAppList )
       
   568     {
       
   569     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_REGISTERAPPSL_ENTRY );
       
   570     for ( TInt i(0); i < aRemotableAppList.Count(); i++ )
       
   571         {
       
   572         iAppStore->AddRemotableAppL( aRemotableAppList[i] );
       
   573         }
       
   574     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_REGISTERAPPSL_EXIT );
       
   575     }
       
   576 
       
   577 // ---------------------------------------------------------------------------------
       
   578 // CUpnpTmServerImpl::UnRegisterApp
       
   579 // Method is used to un-register the individual applications 
       
   580 // @param aAppId App ID which needs to be un-registered
       
   581 // ---------------------------------------------------------------------------------
       
   582 //
       
   583 TInt CUpnpTmServerImpl::UnRegisterApp( TUint aAppId )
       
   584     {
       
   585     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_UNREGISTERAPP_ENTRY );
       
   586     OstTrace1( TRACE_NORMAL, CUPNPTMSERVER_GETREMOTABLEAPP, "CUpnpTmServer::GetRemotableApp;aAppId=%u", aAppId );
       
   587     return iAppStore->RemoveRemotableApp(aAppId);
       
   588     }
       
   589 
       
   590 // ---------------------------------------------------------------------------------
       
   591 // CUpnpTmServerImpl::UnRegisterApps
       
   592 // Method is used to un-register multiple applications in one go 
       
   593 // param aAppIdArray an array of appIDs which needs to be un-registered
       
   594 // ---------------------------------------------------------------------------------
       
   595 //
       
   596 TInt CUpnpTmServerImpl::UnRegisterApps( const RArray<TUint>& aAppIdArray )
       
   597     {   
       
   598     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_UNREGISTERAPPS_ENTRY );
       
   599     /**
       
   600      * Create a copy of the array.
       
   601      * Only distinct and unique app IDs are copied into the array.
       
   602      */
       
   603     RArray<TUint> appIdList ;
       
   604     TInt i;
       
   605     for ( i = 0; i < aAppIdArray.Count(); i++ )
       
   606         {
       
   607         OstTrace1( TRACE_NORMAL, CUPNPTMSERVERIMPL_UNREGISTERAPPS, "CUpnpTmServerImpl::UnRegisterApps;aAppIdArray[i]=%d", aAppIdArray[i] );
       
   608         if ( appIdList.Find(aAppIdArray[i]) == KErrNotFound )
       
   609             {
       
   610             appIdList.Append(aAppIdArray[i]);
       
   611             }
       
   612         }
       
   613     for ( i = 0; i < appIdList.Count(); i++ )
       
   614         { 
       
   615         // Now remove the remotable app from the array one by one
       
   616         if ( ( iAppStore->RemoveRemotableApp( appIdList[i] )) == KErrNotFound )
       
   617             {
       
   618             /** 
       
   619               * Even if a single app from the requested array is unable 
       
   620               * to get un-registered the method should return KErrNotFound 
       
   621               */
       
   622             OstTrace1( TRACE_ERROR, DUP1_CUPNPTMSERVERIMPL_UNREGISTERAPPS, "CUpnpTmServerImpl::UnRegisterApps;appIdList[i]=%d", appIdList[i] );
       
   623             appIdList.Close();
       
   624             OstTraceFunctionExit0( CUPNPTMSERVERIMPL_UNREGISTERAPPS_EXIT );
       
   625             return KErrNotFound;
       
   626             }
       
   627         }  
       
   628     appIdList.Close();
       
   629     OstTraceFunctionExit0( DUP1_CUPNPTMSERVERIMPL_UNREGISTERAPPS_EXIT );
       
   630     return KErrNone;      
       
   631     }
       
   632 
       
   633 // ---------------------------------------------------------------------------------
       
   634 // CUpnpTmServerImpl::SetXmlSignatureL
       
   635 // Method is used to add xml formatted signature value to the list of remotable 
       
   636 // apps which is provided in response to the GetApplicationList action.
       
   637 // XML signature is applied over entire contents of the appList element
       
   638 // @param aSignature XML formatted signature value
       
   639 //                              objects
       
   640 // ---------------------------------------------------------------------------------
       
   641 //
       
   642 void CUpnpTmServerImpl::SetXmlSignatureL( const TDesC8& aSignature )
       
   643     {
       
   644     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_SETXMLSIGNATUREL_ENTRY );
       
   645     iXmSignature.Close();
       
   646     iXmSignature.CreateL(aSignature);
       
   647     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_SETXMLSIGNATUREL_EXIT );
       
   648     }
       
   649 
       
   650 // --------------------------------------------------------------------------------------------------------------------
       
   651 // CUpnpTmServerImpl::XmlSignature
       
   652 // Method is used to fetch xml formatted signature value 
       
   653 // @return Returns xml formatted signature buffer 
       
   654 // --------------------------------------------------------------------------------------------------------------------
       
   655 //
       
   656 const TDesC8& CUpnpTmServerImpl::XmlSignature( )const
       
   657     {
       
   658     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_XMLSIGNATURE_ENTRY );
       
   659     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_XMLSIGNATURE_EXIT );
       
   660     return iXmSignature;
       
   661     }
       
   662 
       
   663 // ---------------------------------------------------------------------------------
       
   664 // CUpnpTmServerImpl::UpdateAppStatusL
       
   665 // Method is used to update the status of applications which have undergone some 
       
   666 // change. This method is invoked by Automotive Server
       
   667 // @param aUpdatedAppIdList An array of app IDs corresponding to the applications
       
   668 //                          whose status have have undergone change
       
   669 // ---------------------------------------------------------------------------------
       
   670 //
       
   671 void CUpnpTmServerImpl::UpdateAppStatusL( const RArray<TUint>& aUpdatedAppIdList )
       
   672     {
       
   673     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_UPDATEAPPSTATUSL_ENTRY );
       
   674     CreateEventMessageL(aUpdatedAppIdList);
       
   675     iTmServerDevice->AppStatusUpdateL(iResponseBuf);
       
   676     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_UPDATEAPPSTATUSL_EXIT );
       
   677     }
       
   678 
       
   679 // ---------------------------------------------------------------------------------
       
   680 // CUpnpTmServerImpl::UpdateAppListL
       
   681 // Method is used to update the list of applications which have been either added,
       
   682 // removed or modified. This method is invoked by Automotive Server
       
   683 // @param aUpdatedAppIdList An array of app IDs corresponding to the applications
       
   684 //                          which have added, removed or modified to/from the list
       
   685 // ---------------------------------------------------------------------------------
       
   686 //
       
   687 void CUpnpTmServerImpl::UpdateAppListL( const RArray<TUint>& aUpdatedAppIdList )
       
   688     {
       
   689     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_UPDATEAPPLISTL_ENTRY );
       
   690     CreateEventMessageL(aUpdatedAppIdList);
       
   691     iTmServerDevice->AppListUpdateL(iResponseBuf);    
       
   692     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_UPDATEAPPLISTL_EXIT );
       
   693     }
       
   694 
       
   695 // ---------------------------------------------------------------------------------
       
   696 // CUpnpTmServerImpl::UpdateUnusedProfileIdsL
       
   697 // Method is used to update the list of profile IDs for profiles which are currently  
       
   698 // not being used by any Terminal Mode service hosted.on the Terminal Mode device
       
   699 // This method is invoked by Automotive Server
       
   700 // @param aUnusedProfileIdList List of profile IDs for profiles which are currently 
       
   701 //                             not being used
       
   702 //                             
       
   703 // ---------------------------------------------------------------------------------
       
   704 //
       
   705 void CUpnpTmServerImpl::UpdateUnusedProfileIdsL( const RArray<TUint>& aUnusedProfileIdList )
       
   706     {
       
   707     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_UPDATEUNUSEDPROFILEIDSL_ENTRY );
       
   708     CreateEventMessageL(aUnusedProfileIdList);
       
   709     iTmServerDevice->UnUsedProfileIdUpdateL(iResponseBuf);     
       
   710     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_UPDATEUNUSEDPROFILEIDSL_EXIT );
       
   711     }
       
   712 
       
   713 // ---------------------------------------------------------------------------------
       
   714 // CUpnpTmServerImpl::AuthorizeApp
       
   715 // This method is used to verify whether the requested appID exists and whether
       
   716 // the client is authorized to perform the oprations on that App ID
       
   717 // @param aAppID  appID which for which operation is requested
       
   718 // @return Returns ETerminalModeSuccess if appID is valid and authorized 
       
   719 //         else the error code
       
   720 // ---------------------------------------------------------------------------------
       
   721 //
       
   722 TTerminalModeErrorCode CUpnpTmServerImpl::AuthorizeApp( TUint aAppId )
       
   723     {
       
   724     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_AUTHORIZEAPP_ENTRY );
       
   725     OstTrace1( TRACE_NORMAL, DUP2_CUPNPTMSERVERIMPL_AUTHORIZEAPP, "CUpnpTmServerImpl::AuthorizeApp;aAppId=%u", aAppId );
       
   726     
       
   727     TTerminalModeErrorCode err;
       
   728     if ( iAppStore->AppIdArray().Find(aAppId) != KErrNotFound )
       
   729         {
       
   730         // requested appID is a valid one
       
   731         err = ETerminalModeSuccess;
       
   732         }
       
   733     else
       
   734         {
       
   735         // Requested appID does not exist
       
   736         err = ETerminalModeBadAppId;
       
   737         }
       
   738     OstTrace1( TRACE_NORMAL, CUPNPTMSERVERIMPL_AUTHORIZEAPP, "CUpnpTmServerImpl::AuthorizeApp;err=%d", err );
       
   739     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_AUTHORIZEAPP_EXIT );
       
   740     return err;
       
   741     }
       
   742 
       
   743 // ---------------------------------------------------------------------------------
       
   744 // CUpnpTmServerImpl::AppendDataL
       
   745 // Appends data to the buffer and also reallocates when needed
       
   746 // @param aData data to be appended to the buffer
       
   747 // ---------------------------------------------------------------------------------
       
   748 //
       
   749 void CUpnpTmServerImpl::AppendDataL( const TDesC8& aData )
       
   750     {
       
   751     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_APPENDDATAL_ENTRY );
       
   752     TInt actionBufMaxLen = iResponseBuf.MaxLength();
       
   753     TInt actionBufLen = iResponseBuf.Length();
       
   754     TInt dataLen = aData.Length();
       
   755     if ( actionBufMaxLen < ( actionBufLen + dataLen ) )
       
   756         {
       
   757         TInt lenToAllocate = (dataLen > KActionBufferLength) ? dataLen : KActionBufferLength;
       
   758         iResponseBuf.ReAllocL ( actionBufLen + lenToAllocate );
       
   759         }   
       
   760     iResponseBuf.Append( aData );
       
   761     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_APPENDDATAL_EXIT );
       
   762     }
       
   763 
       
   764 // ---------------------------------------------------------------------------------
       
   765 // CUpnpTmServerImpl::ConstructActionResponseBufferL
       
   766 // Constructs the actual soap response buffer
       
   767 // @param aAppIndex Index of the registered App
       
   768 // ---------------------------------------------------------------------------------
       
   769 //
       
   770 void CUpnpTmServerImpl::ConstructActionResponseBufferL( TInt aAppIndex )    
       
   771     {
       
   772     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_CONSTRUCTACTIONRESPONSEBUFFERL_ENTRY );
       
   773     ConstructLeadingSoapBufferL(aAppIndex);
       
   774     const TDesC8& appDesc = iAppStore->FetchRemotableApp(aAppIndex).AppDescription();
       
   775     if ( appDesc.Length() != KErrNone )
       
   776         {
       
   777         // Appends the application desciption
       
   778         AppendDataL(KStartNameDesc);
       
   779         AppendDataL(appDesc);
       
   780         AppendDataL(KEndNameDesc);   
       
   781         } 
       
   782     // Appends the optional icon information to the soap response buffer only 
       
   783     // if its available.
       
   784     const RPointerArray<CUpnpTerminalModeIcon>& iconList = iAppStore->FetchRemotableApp(aAppIndex).IconList();
       
   785     TInt iconCount = iconList.Count();
       
   786     if ( iconCount > KErrNone )
       
   787         {
       
   788         // Icon information is present
       
   789         AppendDataL(KStartIconList);                     
       
   790         for ( TInt j(0); j < iconCount; j++ )
       
   791             {
       
   792             // Adds all the icons associated with this app one by one
       
   793             SetRemotableAppIconInfoL( *iconList[j] );
       
   794             }
       
   795         AppendDataL(KEndIconList);
       
   796         }
       
   797     //Apends the allowedProfileIDs element
       
   798     SetAllowedProfileIdListL(aAppIndex);
       
   799     //Appends the different terminalmode info elements
       
   800     const RPointerArray<CUpnpTmInfoElement>& tmInfoElementList = 
       
   801                                  iAppStore->FetchRemotableApp(aAppIndex).TmInfoElementList();
       
   802     for ( TInt k(0); k < tmInfoElementList.Count(); k++)
       
   803         {
       
   804         // Called for each terminal mode element associated with the App
       
   805         SetTerminalModeInfoElementL( *tmInfoElementList[k] );
       
   806         }
       
   807     // Appends the resource status element for the app if it is available 
       
   808     SetResourceStatusL(aAppIndex);
       
   809     // End of an application
       
   810     AppendDataL(KEndApp);
       
   811     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_CONSTRUCTACTIONRESPONSEBUFFERL_EXIT );
       
   812     }
       
   813 
       
   814 // ---------------------------------------------------------------------------------
       
   815 // CUpnpTmServerImpl::ConstructLeadingSoapBufferL
       
   816 // Constructs leading soap buffer
       
   817 // It adds appID and appName to the soap response
       
   818 // @param aAppIndex Index of the remotable app
       
   819 // ---------------------------------------------------------------------------------
       
   820 //
       
   821 void CUpnpTmServerImpl::ConstructLeadingSoapBufferL( TInt aAppIndex )
       
   822     {
       
   823     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_CONSTRUCTLEADINGSOAPBUFFERL_ENTRY );
       
   824     AppendDataL(KStartApp);
       
   825     AppendDataL(KAppIdStart);
       
   826     AppendDataL(ConvertIntToDescriptor(iAppStore->FetchRemotableApp(aAppIndex).AppId()));
       
   827     AppendDataL(KAppIdEnd);
       
   828     AppendDataL(KNameStart);
       
   829     AppendDataL(iAppStore->FetchRemotableApp(aAppIndex).AppName());
       
   830     AppendDataL(KNameEnd);
       
   831     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_CONSTRUCTLEADINGSOAPBUFFERL_EXIT );
       
   832     }
       
   833 
       
   834 // ---------------------------------------------------------------------------------
       
   835 // CUpnpTmServerImpl::SetRemotableAppIconInfoL
       
   836 // Appends application icon information to the soap response buffer.
       
   837 // It stores the icon information in Tm Icon Mapping object for further reference.
       
   838 // @param aTmIcon  Reference to icon object 
       
   839 // @param aWidth   Width of the application icon.
       
   840 // @param aHeight  Height of the application icon.
       
   841 // ---------------------------------------------------------------------------------
       
   842 //
       
   843 void CUpnpTmServerImpl::SetRemotableAppIconInfoL( const CUpnpTerminalModeIcon& aTmIcon )
       
   844     {
       
   845     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_SETREMOTABLEAPPICONINFOL_ENTRY );
       
   846     AppendDataL(KIconStart);
       
   847     AppendDataL(KMimeTypeStart);
       
   848     AppendDataL(aTmIcon.MimeType());
       
   849     AppendDataL(KMimeTypeEnd);
       
   850     AppendDataL(KWidthStart);
       
   851     TInt width = aTmIcon.Width();
       
   852     AppendDataL(ConvertIntToDescriptor(width));
       
   853     AppendDataL(KWidthEnd);
       
   854     AppendDataL(KHeightStart);
       
   855     TInt height = aTmIcon.Height();
       
   856     AppendDataL(ConvertIntToDescriptor(height));
       
   857     AppendDataL(KHeightEnd);
       
   858     AppendDataL(KDepthStart);
       
   859     AppendDataL(ConvertIntToDescriptor(aTmIcon.Depth()));
       
   860     AppendDataL(KDepthEnd);
       
   861     //Application icon URL creation
       
   862     AppendDataL(KUrlStart);
       
   863     AppendDataL(UpnpHTTP::KHTTPUrl());        
       
   864     AppendDataL(iAddrBuf);  // Adds IP address
       
   865     AppendDataL(KColon);
       
   866     AppendDataL(iPortBuf);  // Adds port number
       
   867     
       
   868     // Fetch the icon file path
       
   869     const TDesC& filePath = aTmIcon.IconFilename();
       
   870     // Extract just filename from the complete file path
       
   871     const TDesC& fileName = filePath.Mid((filePath.LocateReverse(KDirectorySeparator))+1);
       
   872     TBuf8<UpnpString::KDefaultStringLength> fileName8;
       
   873     fileName8.Copy(fileName);  // 16-bit to 8-bit conversion( icon filename )
       
   874     
       
   875     TBuf8<UpnpString::KDefaultStringLength> iconRelativeUrl(UpnpString::KSlash);
       
   876     // Appends the client profileID
       
   877     iconRelativeUrl.Append(ConvertIntToDescriptor(iProfileId));
       
   878     iconRelativeUrl.Append(UpnpString::KSlash);   
       
   879     // Appends the icon filename and creates the relative url
       
   880     iconRelativeUrl.Append(fileName8);
       
   881     AppendDataL(iconRelativeUrl);
       
   882     /** Icon information is stored for making decision during http request for app icon file.
       
   883      *  Depth is not taken into consideration while deciding on the final icon dimension
       
   884      *  because it is not a requirement and playing with the depth of the icon may lead
       
   885      *  to a poorly converted image which may not be displayed properly in the car 
       
   886      *  kit screen.
       
   887      */
       
   888     iIconMapping->AddIconFileInfoL( iconRelativeUrl,filePath,width,height );
       
   889     AppendDataL(KUrlEnd);
       
   890     AppendDataL(KIconEnd);
       
   891     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_SETREMOTABLEAPPICONINFOL_EXIT );
       
   892     }
       
   893 
       
   894 // ---------------------------------------------------------------------------------
       
   895 // CUpnpTmServerImpl::SetAllowedProfileIdListL
       
   896 // Appends  the list of allowed profile IDs information to the soap response buffer
       
   897 // @param aAppIndex Index of the registered app
       
   898 // ---------------------------------------------------------------------------------
       
   899 //
       
   900 void CUpnpTmServerImpl::SetAllowedProfileIdListL( TInt aAppIndex )
       
   901     {
       
   902     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_SETALLOWEDPROFILEIDLISTL_ENTRY );
       
   903     const RArray<TUint>& profileIdList = iAppStore->FetchRemotableApp(aAppIndex).AllowedProfileIdList();
       
   904     TInt profileIdCount = profileIdList.Count();
       
   905     if ( profileIdCount > KErrNone )
       
   906         {
       
   907         AppendDataL(KAllowedProfileIdsStart);
       
   908         for ( TInt i(0); i < profileIdCount; i++ )
       
   909             {
       
   910             AppendDataL(ConvertIntToDescriptor(profileIdList[i]));
       
   911             if ( i < (profileIdCount-1) )
       
   912                 {
       
   913                 // Adds comma after each profile ID except last 
       
   914                 AppendDataL(UpnpString::KComa);
       
   915                 }
       
   916             }
       
   917         AppendDataL(KAllowedProfileIdsEnd);
       
   918         }
       
   919     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_SETALLOWEDPROFILEIDLISTL_EXIT );
       
   920     }
       
   921 
       
   922 // ---------------------------------------------------------------------------------
       
   923 // CUpnpTmServerImpl::SetTerminalModeInfoElementL
       
   924 // Appends terminal mode info elements to the soap buffer
       
   925 // @param aTmInfoElement Reference to CUpnpTmInfoElement object
       
   926 // ---------------------------------------------------------------------------------
       
   927 //
       
   928 void CUpnpTmServerImpl::SetTerminalModeInfoElementL( const CUpnpTmInfoElement&  aTmInfoElement )                                                              
       
   929     {  
       
   930     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_SETTERMINALMODEINFOELEMENTL_ENTRY );
       
   931     AppendDataL(KStartTagOpenBracket);
       
   932     AppendDataL(aTmInfoElement.TerminalModeInfoType());
       
   933     AppendDataL(KCloseBracket);
       
   934     for ( TInt i(0); i < aTmInfoElement.TmInfoElementCount(); i++ )
       
   935         {
       
   936         RBuf8 elementName;
       
   937         CleanupClosePushL(elementName);
       
   938         RBuf8 elementValue;
       
   939         CleanupClosePushL(elementValue);
       
   940         // Fetch the key-value pair
       
   941         aTmInfoElement.GetTmInfoElementL( elementName, elementValue, i );
       
   942         AppendDataL(KStartTagOpenBracket);
       
   943         AppendDataL(elementName);
       
   944         AppendDataL(KCloseBracket);
       
   945         AppendDataL(elementValue); 
       
   946         AppendDataL(KEndTagOpenBracket);
       
   947         AppendDataL(elementName);
       
   948         AppendDataL(KCloseBracket);
       
   949         CleanupStack::PopAndDestroy(2,&elementName);
       
   950         }   
       
   951     AppendDataL(KEndTagOpenBracket);
       
   952     AppendDataL(aTmInfoElement.TerminalModeInfoType());
       
   953     AppendDataL(KCloseBracket);
       
   954     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_SETTERMINALMODEINFOELEMENTL_EXIT );
       
   955     }
       
   956 
       
   957 // ---------------------------------------------------------------------------------
       
   958 // CUpnpTmServerImpl::SetResourceStatusL
       
   959 // Appends resource status element(optional element)to the soap response buffer.
       
   960 // Provides the status of the resource of the application.
       
   961 // @param aAppIndex Index of the registered app
       
   962 // --------------------------------------------------------------------------------- 
       
   963 //
       
   964 void CUpnpTmServerImpl::SetResourceStatusL( TInt aAppIndex )
       
   965     {  
       
   966     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_SETRESOURCESTATUSL_ENTRY );
       
   967     const TDesC8& rscStatus = iAppStore->FetchRemotableApp(aAppIndex).ResourceStatus();
       
   968     if ( rscStatus.Length() > KErrNone ) 
       
   969         {
       
   970         AppendDataL(KResourceStatusStart);
       
   971         AppendDataL(rscStatus);
       
   972         AppendDataL(KResourceStatusEnd);
       
   973         }
       
   974     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_SETRESOURCESTATUSL_EXIT );
       
   975     }
       
   976 
       
   977 // ---------------------------------------------------------------------------------
       
   978 // CUpnpTmServerImpl::GenerateUrlComponents
       
   979 // Utility method to generate Server's IP address and port number which is used 
       
   980 // in constructing the icon url in action responses
       
   981 // ---------------------------------------------------------------------------------
       
   982 //
       
   983 void CUpnpTmServerImpl::GenerateUrlComponents( CUpnpHttpServerSession& aHttpServerSession )   
       
   984    {
       
   985    OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_GENERATEURLCOMPONENTS_ENTRY );
       
   986    TInetAddr servAddr;
       
   987    servAddr.SetFamily(KAfInet);
       
   988    aHttpServerSession.GetAddress( servAddr );
       
   989    TBuf<UpnpString::KShortStringLength> addrBuf8;
       
   990    servAddr.Output( addrBuf8 );
       
   991    iAddrBuf.Copy(addrBuf8); //Sets the IP address of the server
       
   992    iPortBuf.Num(servAddr.Port()); //Sets the port number
       
   993    OstTraceFunctionExit0( CUPNPTMSERVERIMPL_GENERATEURLCOMPONENTS_EXIT );
       
   994    }
       
   995 
       
   996 // ---------------------------------------------------------------------------------
       
   997 // CUpnpTmServerImpl::CreateEventMessageL
       
   998 // Utility method to generate GENA notificatiion messages.
       
   999 // Its is called in case of updateapplist, updateappstatuslist and
       
  1000 // unusedprofileidlist events.
       
  1001 // @param aIdList Reference to the changed ID list. It could be appID list or 
       
  1002 //                profileID list.
       
  1003 // ---------------------------------------------------------------------------------
       
  1004 //
       
  1005 void CUpnpTmServerImpl::CreateEventMessageL( const RArray<TUint>& aIdList )   
       
  1006     {
       
  1007     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_CREATEEVENTMESSAGEL_ENTRY );
       
  1008     iResponseBuf.Close();
       
  1009     iResponseBuf.CreateL(KActionBufferLength);
       
  1010     /**
       
  1011      * Create a copy of the array.
       
  1012      * Only distinct and unique elements are copied into the array.
       
  1013      */
       
  1014     RArray<TUint> idList;
       
  1015     CleanupClosePushL(idList);
       
  1016     TInt i;
       
  1017     for ( i = 0; i < aIdList.Count(); i++ )
       
  1018         {
       
  1019         OstTrace1( TRACE_NORMAL, CUPNPTMSERVERIMPL_CREATEEVENTMESSAGEL, "CUpnpTmServerImpl::CreateEventMessageL;aIdList[i]=%d", aIdList[i] );
       
  1020         if ( idList.Find(aIdList[i]) == KErrNotFound )
       
  1021             {
       
  1022             idList.AppendL(aIdList[i]);
       
  1023             }
       
  1024         }
       
  1025     TInt idCount = idList.Count();
       
  1026     for ( i = 0; i < idCount; i++ )
       
  1027         {  
       
  1028         AppendDataL(ConvertIntToDescriptor( idList[i]));
       
  1029         if ( i < ( idCount-1) )
       
  1030             {
       
  1031             //Add comma(,) after each ID except the last
       
  1032             AppendDataL(UpnpString::KComa);
       
  1033             }
       
  1034     }
       
  1035    CleanupStack::PopAndDestroy(&idList);
       
  1036    OstTraceFunctionExit0( CUPNPTMSERVERIMPL_CREATEEVENTMESSAGEL_EXIT );
       
  1037    }
       
  1038 
       
  1039 // ---------------------------------------------------------------------------------
       
  1040 // CUpnpTmServerImpl::ConvertIntToDescriptor
       
  1041 // Utility method to convert integer to descriptor
       
  1042 // @param  aIntVal  Integer value
       
  1043 // @return  Returns corresponding descriptor value
       
  1044 // ---------------------------------------------------------------------------------
       
  1045 //
       
  1046 const TDesC8& CUpnpTmServerImpl::ConvertIntToDescriptor( TInt aIntVal )
       
  1047     {
       
  1048     OstTraceFunctionEntry0( CUPNPTMSERVERIMPL_CONVERTINTTODESCRIPTOR_ENTRY );
       
  1049     OstTrace1( TRACE_NORMAL, CUPNPTMSERVERIMPL_CONVERTINTTODESCRIPTOR, "CUpnpTmServerImpl::ConvertIntToDescriptor;aIntVal=%d", aIntVal );
       
  1050     iBufVal.Num( aIntVal );
       
  1051     OstTraceFunctionExit0( CUPNPTMSERVERIMPL_CONVERTINTTODESCRIPTOR_EXIT );
       
  1052     return iBufVal;
       
  1053     }
       
  1054 
       
  1055 //End of File