services/terminalmodeservice/src/upnptmserverdevicexmlparser.cpp
branchRCL_3
changeset 10 594d15129e2c
parent 9 5c72fd91570d
equal deleted inserted replaced
9:5c72fd91570d 10: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: CUpnpTmServerDeviceXmlParser class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // System Includes
       
    19 #include <xml/parserfeature.h>
       
    20 #include <xml/taginfo.h>
       
    21 
       
    22 // User Includes
       
    23 #include "upnptmserverdevicexmlparser.h"
       
    24 #include "upnpterminalmodeicon.h"
       
    25 #include "OstTraceDefinitions.h"
       
    26 #ifdef OST_TRACE_COMPILER_IN_USE
       
    27 #include "upnptmserverdevicexmlparserTraces.h"
       
    28 #endif
       
    29 
       
    30 
       
    31 //Literals
       
    32 _LIT8(KTextXml,           "text/xml");
       
    33 _LIT8(KRootDeviceXmlLead, "<?xml version=\"1.0\" encoding=\"utf-8\"?><root xmlns=\"urn:schemas-upnp-org:device-1-0\"><specVersion><major>1</major><minor>0</minor></specVersion><device><deviceType>urn:schemas-upnp-org:device:TmServerDevice:1</deviceType><friendlyName>S60</friendlyName><manufacturer /><manufacturerURL>http://www.nokia.com</manufacturerURL><modelName /><serialNumber /><UDN /><X_connectivity><bluetooth><btAddr /><startConnection /></bluetooth></X_connectivity>");
       
    34 _LIT8(KRootDeviceXmlTrail,"<serviceList><service><serviceType>urn:schemas-upnp-org:service:TmApplicationServer:1</serviceType><serviceId>urn:upnp-org:serviceId:TmApplicationServer1</serviceId><SCPDURL>/tmserverdevice1/tmapplicationserver1.xml</SCPDURL><controlURL>/tmserverdevice1/tmapplicationserver1/control</controlURL><eventSubURL>/tmserverdevice1/tmapplicationserver1/eventing</eventSubURL></service><service><serviceType>urn:schemas-upnp-org:service:TmClientProfile:1</serviceType>"
       
    35     "<serviceId>urn:upnp-org:serviceId:TmClientProfile1</serviceId><SCPDURL>/tmserverdevice1/tmclientprofile1.xml</SCPDURL><controlURL>/tmserverdevice1/tmclientprofile1/control</controlURL><eventSubURL>/tmserverdevice1/tmclientprofile1/eventing</eventSubURL></service></serviceList></device></root>");
       
    36 _LIT8(KAppServerSrvXml,   "<?xml version=\"1.0\" encoding=\"utf-8\"?><scpd xmlns=\"urn:schemas-upnp-org:service-1-0\"><specVersion><major>1</major> <minor>0</minor> </specVersion><actionList><action><name>GetApplicationList</name><argumentList><argument><name>AppListingFilter</name><direction>in</direction> <relatedStateVariable>A_ARG_TYPE_String</relatedStateVariable> </argument><argument><name>ProfileID</name><direction>in</direction> <relatedStateVariable>A_ARG_TYPE_ProfileID</relatedStateVariable> "
       
    37     "</argument><argument><name>AppListing</name><direction>out</direction><relatedStateVariable>A_ARG_TYPE_AppList</relatedStateVariable></argument></argumentList></action><action><name>LaunchApplication</name><argumentList><argument><name>AppID</name><direction>in</direction><relatedStateVariable>A_ARG_TYPE_AppID</relatedStateVariable></argument><argument><name>ProfileID</name><direction>in</direction><relatedStateVariable>A_ARG_TYPE_ProfileID</relatedStateVariable></argument><argument><name>AppURI</name>"
       
    38     "<direction>out</direction><relatedStateVariable>A_ARG_TYPE_URI</relatedStateVariable></argument></argumentList></action><action><name>TerminateApplication</name><argumentList><argument><name>AppID</name><direction>in</direction><relatedStateVariable>A_ARG_TYPE_AppID</relatedStateVariable></argument><argument><name>ProfileID</name><direction>in</direction><relatedStateVariable>A_ARG_TYPE_ProfileID</relatedStateVariable></argument><argument><name>TerminationResult</name><direction>out</direction>"
       
    39     "<relatedStateVariable>A_ARG_TYPE_Bool</relatedStateVariable></argument></argumentList></action><action><name>GetApplicationStatus</name><argumentList><argument><name>AppID</name><direction>in</direction><relatedStateVariable>A_ARG_TYPE_AppID</relatedStateVariable></argument><argument><name>AppStatus</name><direction>out</direction><relatedStateVariable>A_ARG_TYPE_AppStatus</relatedStateVariable></argument></argumentList></action></actionList><serviceStateTable><stateVariable sendEvents=\"yes\">"
       
    40     "<name>AppStatusUpdate</name> <dataType>string</dataType></stateVariable><stateVariable sendEvents=\"yes\"><name>AppListUpdate</name> <dataType>string</dataType></stateVariable><stateVariable sendEvents=\"no\"><name>A_ARG_TYPE_AppStatus</name> <dataType>string</dataType> </stateVariable><stateVariable sendEvents=\"no\"><name>A_ARG_TYPE_AppList</name><dataType>string</dataType></stateVariable><stateVariable sendEvents=\"no\"><name>A_ARG_TYPE_AppID</name><dataType>string</dataType></stateVariable>"
       
    41     "<stateVariable sendEvents=\"no\"><name>A_ARG_TYPE_ProfileID</name><dataType>ui4</dataType><defaultValue>0</defaultValue></stateVariable><stateVariable sendEvents=\"no\"><name>A_ARG_TYPE_URI</name> <dataType>uri</dataType> </stateVariable><stateVariable sendEvents=\"no\"><name>A_ARG_TYPE_String</name><dataType>string</dataType></stateVariable><stateVariable sendEvents=\"no\"><name>A_ARG_TYPE_Bool</name><dataType>string</dataType><defaultValue>false</defaultValue><allowedValueList><allowedValue>false</allowedValue>"
       
    42     "<allowedValue>true</allowedValue></allowedValueList></stateVariable></serviceStateTable></scpd>");
       
    43 _LIT8(KClientProfSrvXml,  "<?xml version=\"1.0\" encoding=\"utf-8\"?><scpd xmlns=\"urn:schemas-upnp-org:service-1-0\"><specVersion><major>1</major> <minor>0</minor> </specVersion><actionList><action><name>GetMaxNumProfiles</name><argumentList><argument><name>numProfilesAllowed</name><direction>out</direction> <relatedStateVariable>MaxNumProfiles</relatedStateVariable> </argument></argumentList></action><action><name>SetClientProfile</name><argumentList><argument><name>profileID</name><direction>in</direction>"
       
    44     "<relatedStateVariable>A_ARG_TYPE_ProfileID</relatedStateVariable></argument><argument><name>clientProfile</name><direction>in</direction><relatedStateVariable>A_ARG_TYPE_ClientProfile</relatedStateVariable></argument><argument><name>resultProfile</name><direction>out</direction><relatedStateVariable>A_ARG_TYPE_ClientProfile</relatedStateVariable></argument></argumentList></action><action><name>GetClientProfile</name><argumentList><argument><name>profileID</name><direction>in</direction>"
       
    45     "<relatedStateVariable>A_ARG_TYPE_ProfileID</relatedStateVariable></argument><argument><name>clientProfile</name><direction>out</direction><relatedStateVariable>A_ARG_TYPE_ClientProfile</relatedStateVariable></argument></argumentList></action></actionList><serviceStateTable><stateVariable sendEvents=\"yes\"><name>UnusedProfileIDs</name> <dataType>string</dataType></stateVariable><stateVariable sendEvents=\"no\"><name>A_ARG_TYPE_ClientProfile</name> <dataType>string</dataType></stateVariable>"
       
    46     "<stateVariable sendEvents=\"no\"><name>A_ARG_TYPE_ProfileID</name><dataType>ui4</dataType><defaultValue>0</defaultValue></stateVariable><stateVariable sendEvents=\"no\"><name>MaxNumProfiles</name> <dataType>ui2</dataType> <defaultValue>1</defaultValue> </stateVariable> </serviceStateTable></scpd>");
       
    47 _LIT8(KStartLine,         "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
       
    48 _LIT8(KRootAttrb,         " xmlns=\"urn:schemas-upnp-org:device-1-0\"");
       
    49 _LIT8(KScpdUrl,           "/tmserverdevice1/");
       
    50 _LIT8(KUpnpDeviceRoot,    "root" );
       
    51 _LIT8(KStartIconList,     "<iconList>" );
       
    52 _LIT8(KEndIconList,       "</iconList>" );
       
    53 _LIT8(KStartIcon,         "<icon>" );
       
    54 _LIT8(KEndIcon,           "</icon>" );
       
    55 _LIT8(KStartMimeType,     "<mimetype>" );
       
    56 _LIT8(KEndMimeType,       "</mimetype>" );
       
    57 _LIT8(KStartWidth,        "<width>" );
       
    58 _LIT8(KEndWidth,          "</width>" );
       
    59 _LIT8(KStartHeight,       "<height>" );
       
    60 _LIT8(KEndHeight,         "</height>" );
       
    61 _LIT8(KStartDepth,        "<depth>" );
       
    62 _LIT8(KEndDepth,          "</depth>" );
       
    63 _LIT8(KStartUrl,          "<url>" );
       
    64 _LIT8(KEndUrl,            "</url>" );
       
    65 _LIT8(KPhoneManufacturer, "manufacturer" );
       
    66 _LIT8(KPhoneModel,        "modelName" );
       
    67 _LIT8(KPhoneSerialNumber, "serialNumber" );
       
    68 _LIT8(KBtAddress,         "btAddr" );
       
    69 _LIT8(KStartConnection,   "startConnection" );
       
    70 _LIT8(KIconPath,          "icon/");
       
    71 _LIT8(KConnTrue,          "true");
       
    72 _LIT8(KConnFalse,         "false");
       
    73 _LIT(KPublicDevicePath,   "public\\TmServerDevice1\\");
       
    74 _LIT(KDeviceName,         "TmServerDevice1.xml");
       
    75 _LIT(KAppServerSrvName,   "TmApplicationServer1.xml");
       
    76 _LIT(KClientProfSrvName,  "TmClientProfile1.xml");
       
    77 _LIT(KIconDirectory,      "icon\\");
       
    78 
       
    79 
       
    80 // ============================ MEMBER FUNCTIONS ===================================
       
    81 
       
    82 // ---------------------------------------------------------------------------------
       
    83 // CUpnpTmServerDeviceXmlParser::NewL
       
    84 // Two-phased constructor.
       
    85 // ---------------------------------------------------------------------------------
       
    86 //
       
    87 CUpnpTmServerDeviceXmlParser* CUpnpTmServerDeviceXmlParser::NewL( CUpnpTmServerDeviceInfo& aDeviceInfo )
       
    88 	{
       
    89 	OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_NEWL_ENTRY );
       
    90 	CUpnpTmServerDeviceXmlParser* self = new (ELeave) CUpnpTmServerDeviceXmlParser( aDeviceInfo );
       
    91 	CleanupStack::PushL(self);
       
    92 	self->ConstructL();
       
    93 	CleanupStack::Pop(self);
       
    94 	OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_NEWL_EXIT );
       
    95 	return self;	
       
    96 	}
       
    97 
       
    98 // ---------------------------------------------------------------------------------
       
    99 // CUpnpTmServerDeviceXmlParser::~CUpnpTmServerDeviceXmlParser
       
   100 // Destructor
       
   101 // ---------------------------------------------------------------------------------
       
   102 //
       
   103 CUpnpTmServerDeviceXmlParser::~CUpnpTmServerDeviceXmlParser()	
       
   104 	{
       
   105 	OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_CUPNPTMSERVERDEVICEXMLPARSER_ENTRY );
       
   106 	DeleteDirectory();
       
   107 	iPhone.Close();
       
   108 	iEtelSrv.Close();
       
   109 	delete iParser;
       
   110 	iAppServerSrvDescription.Close();
       
   111 	iClientProfSrvDescription.Close();
       
   112 	iReadBuf.Close();
       
   113 	iDeviceDescription.Close();
       
   114 	iDescFilePath.Close();
       
   115 	iClientProfSrvFilePath.Close();
       
   116 	iAppServerSrvFilePath.Close();
       
   117 	iDescriptionUri.Close();
       
   118 	iFs.Close();
       
   119 	iDeviceDir.Close();
       
   120 	iIconDirectory.Close();
       
   121 	delete iFileMan;
       
   122 	OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_CUPNPTMSERVERDEVICEXMLPARSER_EXIT );
       
   123 	}
       
   124 
       
   125 // ---------------------------------------------------------------------------------
       
   126 // CUpnpTmServerDeviceXmlParser::DeleteDirectory
       
   127 // Deletes device and service description files and device icon files related to  
       
   128 // Terminal Mode Service located in the private directory.
       
   129 // ---------------------------------------------------------------------------------
       
   130 //
       
   131 void CUpnpTmServerDeviceXmlParser::DeleteDirectory()   
       
   132     {
       
   133     OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_DELETEDIRECTORY_ENTRY );
       
   134     iFs.Delete(iDescFilePath);
       
   135     iFs.Delete(iAppServerSrvFilePath);
       
   136     iFs.Delete(iClientProfSrvFilePath); 
       
   137     iFileMan->RmDir(iIconDirectory);
       
   138     OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_DELETEDIRECTORY_EXIT );
       
   139     }
       
   140 // ---------------------------------------------------------------------------------
       
   141 // CUpnpTmServerDeviceXmlParser::CUpnpTmServerDeviceXmlParser
       
   142 // C++ default constructor can NOT contain any code, that
       
   143 // might leave.
       
   144 // ---------------------------------------------------------------------------------
       
   145 //
       
   146 CUpnpTmServerDeviceXmlParser::CUpnpTmServerDeviceXmlParser( CUpnpTmServerDeviceInfo& aDeviceInfo )
       
   147     :iDeviceInfo(aDeviceInfo)
       
   148 	{		
       
   149 	}
       
   150 
       
   151 // ---------------------------------------------------------------------------------
       
   152 // CUpnpTmServerDeviceXmlParser::ConstructL
       
   153 // Symbian 2nd phase constructor can leave.
       
   154 // ---------------------------------------------------------------------------------
       
   155 //
       
   156 void CUpnpTmServerDeviceXmlParser::ConstructL( )
       
   157 	{
       
   158     OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_CONSTRUCTL_ENTRY );
       
   159     User::LeaveIfError(iEtelSrv.Connect());
       
   160     User::LeaveIfError(iEtelSrv.LoadPhoneModule( KMmTsyModuleName ));
       
   161     User::LeaveIfError(iPhone.Open( iEtelSrv, KMmTsyPhoneName ));
       
   162     TRequestStatus status;
       
   163     iPhone.GetPhoneId(status, iPhoneId); 
       
   164     User::WaitForRequest(status);
       
   165 	User::LeaveIfError(iFs.Connect());
       
   166     iAppServerSrvDescription.CreateL( KAppServerSrvXml() );
       
   167     iClientProfSrvDescription.CreateL( KClientProfSrvXml() );
       
   168 	iParser = CParser::NewL(KTextXml(), *this);
       
   169 	iParser->EnableFeature(ESendFullContentInOneChunk);
       
   170 	iReadBuf.CreateMaxL(KBufSize);
       
   171 	iDeviceDescription.CreateMaxL(KBufSize);
       
   172 	iDeviceDescription.SetLength(KErrNone);
       
   173 	OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_CONSTRUCTL_EXIT );
       
   174 	}
       
   175 
       
   176 // ---------------------------------------------------------------------------------
       
   177 // CUpnpTmServerDeviceXmlParser::OnStartDocumentL
       
   178 // Called when parser hits the start of the document
       
   179 // ---------------------------------------------------------------------------------
       
   180 //
       
   181 void CUpnpTmServerDeviceXmlParser::OnStartDocumentL(const RDocumentParameters& /*aDocParam*/,
       
   182                                                                              TInt aErrorCode )
       
   183 	{
       
   184 	OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_ONSTARTDOCUMENTL_ENTRY );
       
   185 	User::LeaveIfError(aErrorCode);
       
   186     
       
   187     TBuf<KMaxBufLength> tmpBuf(iDeviceDir);
       
   188     tmpBuf.Append(KDeviceName());
       
   189     iDescFilePath.CreateL(tmpBuf);
       
   190     tmpBuf.Zero();
       
   191     
       
   192     // Create TmAppServer service xml
       
   193     tmpBuf.Copy(iDeviceDir);
       
   194     tmpBuf.Append(KAppServerSrvName());
       
   195     RFile appServerSrvFile;
       
   196     CleanupClosePushL(appServerSrvFile);
       
   197     TInt err(KErrNone);
       
   198     err = appServerSrvFile.Create(iFs, tmpBuf, EFileWrite);
       
   199     if ( err == KErrAlreadyExists )
       
   200         {
       
   201         User::LeaveIfError(appServerSrvFile.Open(iFs, tmpBuf, EFileWrite));
       
   202         }
       
   203     else
       
   204         {
       
   205         User::LeaveIfError(err);
       
   206         }
       
   207     User::LeaveIfError(appServerSrvFile.Write(iAppServerSrvDescription));
       
   208     CleanupStack::PopAndDestroy( &appServerSrvFile );
       
   209     iAppServerSrvFilePath.CreateL(tmpBuf);
       
   210     tmpBuf.Zero();
       
   211     
       
   212     // Create TmClientProfile service xml
       
   213     tmpBuf.Copy(iDeviceDir);
       
   214     tmpBuf.Append(KClientProfSrvName());
       
   215     RFile clientProfSrvFile;
       
   216     CleanupClosePushL(clientProfSrvFile);
       
   217     err = clientProfSrvFile.Create(iFs, tmpBuf, EFileWrite);
       
   218     if ( err == KErrAlreadyExists )
       
   219         {
       
   220         User::LeaveIfError(clientProfSrvFile.Open(iFs, tmpBuf, EFileWrite));
       
   221         }
       
   222     else
       
   223         {
       
   224         User::LeaveIfError(err);
       
   225         }
       
   226     User::LeaveIfError(clientProfSrvFile.Write(iClientProfSrvDescription));
       
   227     CleanupStack::PopAndDestroy( &clientProfSrvFile );
       
   228     iClientProfSrvFilePath.CreateL(tmpBuf);
       
   229     
       
   230     iDeviceDescription.Append(KStartLine());
       
   231     iDescriptionUri.CreateMaxL(UpnpString::KDefaultStringLength);
       
   232     iDescriptionUri.SetLength(KErrNone);
       
   233     iDescriptionUri.Append(KScpdUrl());
       
   234     iDescriptionUri.Append(KDeviceName());
       
   235 	OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_ONSTARTDOCUMENTL_EXIT );
       
   236 	}
       
   237 
       
   238 // ---------------------------------------------------------------------------------
       
   239 // CUpnpTmServerDeviceXmlParser::OnEndDocumentL
       
   240 // Called when parser hits the end of the document
       
   241 // ---------------------------------------------------------------------------------
       
   242 //
       
   243 void CUpnpTmServerDeviceXmlParser::OnEndDocumentL(TInt aErrorCode)
       
   244 	{
       
   245 	OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_ONENDDOCUMENTL_ENTRY );
       
   246 	User::LeaveIfError(aErrorCode);
       
   247 	
       
   248 	RFile deviceFile;
       
   249 	CleanupClosePushL(deviceFile);
       
   250 	TInt err = deviceFile.Create(iFs, iDescFilePath, EFileWrite);
       
   251 	OstTrace1( TRACE_NORMAL, CUPNPTMSERVERDEVICEXMLPARSER_ONENDDOCUMENTL, "CUpnpTmServerDeviceXmlParser::OnEndDocumentL;err=%d", err );
       
   252     if ( err == KErrAlreadyExists )
       
   253         {
       
   254         User::LeaveIfError(deviceFile.Open(iFs, iDescFilePath, EFileWrite));
       
   255         }
       
   256     else
       
   257         {
       
   258         User::LeaveIfError(err);
       
   259         }
       
   260 	User::LeaveIfError(deviceFile.Write(iDeviceDescription));
       
   261 	CleanupStack::PopAndDestroy(&deviceFile);
       
   262 	OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_ONENDDOCUMENTL_EXIT );
       
   263 	}
       
   264 
       
   265 // ---------------------------------------------------------------------------------
       
   266 // CUpnpTmServerDeviceXmlParser::OnStartElementL
       
   267 // Called when parser hits the opening tag
       
   268 // ---------------------------------------------------------------------------------
       
   269 //
       
   270 void CUpnpTmServerDeviceXmlParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& /*aAttributes*/, TInt aErrorCode)
       
   271 	{
       
   272 	OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_ONSTARTELEMENTL_ENTRY );
       
   273 	User::LeaveIfError(aErrorCode);
       
   274 
       
   275 	iDeviceDescription.Append(UpnpCD::KKorp);
       
   276 	iDeviceDescription.Append(aElement.LocalName().DesC());
       
   277 	
       
   278     if(aElement.LocalName().DesC().Compare(KUpnpDeviceRoot) == 0)
       
   279         {
       
   280         iDeviceDescription.Append(KRootAttrb());    
       
   281         }       
       
   282     iDeviceDescription.Append(UpnpCD::KProk);
       
   283 
       
   284     if(aElement.LocalName().DesC().Compare(KPhoneManufacturer) == 0)
       
   285         {
       
   286         iDeviceDescription.Append(iPhoneId.iManufacturer);   
       
   287         }
       
   288 	else if(aElement.LocalName().DesC().Compare(KPhoneModel) == 0)
       
   289         {
       
   290         iDeviceDescription.Append(iPhoneId.iModel);   
       
   291         }
       
   292 	else if(aElement.LocalName().DesC().Compare(KPhoneSerialNumber) == 0)
       
   293         {
       
   294         iDeviceDescription.Append(iPhoneId.iSerialNumber);   
       
   295         }
       
   296     else if(aElement.LocalName().DesC().Compare(KBtAddress) == 0)
       
   297         {
       
   298         iDeviceDescription.Append(iDeviceInfo.BtAddress());   
       
   299         }
       
   300     else if(aElement.LocalName().DesC().Compare(KStartConnection) == 0)
       
   301         {
       
   302         if ( iDeviceInfo.StartConn() )
       
   303             {
       
   304             iDeviceDescription.Append(KConnTrue);    
       
   305             }
       
   306         else
       
   307             {
       
   308             iDeviceDescription.Append(KConnFalse);    
       
   309             }       
       
   310         }
       
   311 	OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_ONSTARTELEMENTL_EXIT );
       
   312 	}
       
   313 
       
   314 // ---------------------------------------------------------------------------------
       
   315 // CUpnpTmServerDeviceXmlParser::OnEndElementL
       
   316 // Called when parser hits the closing tag
       
   317 // ---------------------------------------------------------------------------------
       
   318 //
       
   319 void CUpnpTmServerDeviceXmlParser::OnEndElementL( const RTagInfo& aElement, TInt aErrorCode )
       
   320 	{
       
   321 	OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_ONENDELEMENTL_ENTRY );
       
   322 	User::LeaveIfError(aErrorCode);
       
   323 	
       
   324 	iDeviceDescription.Append( UpnpCD::KKorp );
       
   325 	iDeviceDescription.Append( UpnpString::KSlash );
       
   326 	iDeviceDescription.Append( aElement.LocalName().DesC() );
       
   327 	iDeviceDescription.Append( UpnpCD::KProk );
       
   328 	OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_ONENDELEMENTL_EXIT );
       
   329 	}
       
   330 
       
   331 // ---------------------------------------------------------------------------------
       
   332 // CUpnpTmServerDeviceXmlParser::OnContentL
       
   333 // Provides the content/value of the element/tag
       
   334 // ---------------------------------------------------------------------------------
       
   335 //	
       
   336 void CUpnpTmServerDeviceXmlParser::OnContentL( const TDesC8& aBytes, TInt aErrorCode )
       
   337 	{
       
   338 	User::LeaveIfError(aErrorCode);
       
   339 	iDeviceDescription.Append(aBytes);
       
   340 	}
       
   341 
       
   342 // ---------------------------------------------------------------------------------
       
   343 // CUpnpTmServerDeviceXmlParser::StartL
       
   344 // Method which inputs xml formatted buffer content to the XML Parser 
       
   345 // and invokes parsing
       
   346 // ---------------------------------------------------------------------------------
       
   347 // 
       
   348 void CUpnpTmServerDeviceXmlParser::StartL()
       
   349 	{
       
   350     OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_STARTL_ENTRY );
       
   351     TDriveNumber drive = RFs::GetSystemDrive();   //Find system's drive
       
   352     TBuf<UpnpString::KMaxFilenameLength> privatePath;  
       
   353     TInt err = iFs.PrivatePath(privatePath); //Find the application's private path
       
   354     // a) If the Private Path is not found (for whatever reasons),
       
   355     //      Create a private path in the System Drive
       
   356     if( err == KErrNotFound )
       
   357         {
       
   358         User::LeaveIfError( iFs.CreatePrivatePath(drive) );
       
   359         }
       
   360     // b) If Private Path is found but is a read-only or non-persistent drive
       
   361     //      Create a private path in the system drive else use it
       
   362     else if( err == KErrNone )
       
   363         {
       
   364         TDriveInfo driveInfo;
       
   365         User::LeaveIfError( iFs.Drive(driveInfo));
       
   366         TUint driveAttr = driveInfo.iDriveAtt;
       
   367         if ( driveAttr == KDriveAttRom )
       
   368             {
       
   369             User::LeaveIfError( iFs.CreatePrivatePath(drive) );
       
   370             }
       
   371         }
       
   372     else
       
   373         {
       
   374         OstTrace1( TRACE_ERROR, CUPNPTMSERVERDEVICEXMLPARSER_STARTL, "CUpnpTmServerDeviceXmlParser::StartL;err=%d", err );     
       
   375         User::Leave(err);
       
   376         }
       
   377     privatePath.Append(KPublicDevicePath());
       
   378     err = iFs.MkDirAll(privatePath);
       
   379     if( err && err != KErrAlreadyExists )
       
   380         {
       
   381         OstTrace1( TRACE_ERROR, DUP1_CUPNPTMSERVERDEVICEXMLPARSER_STARTL, "CUpnpTmServerDeviceXmlParser::StartL;err=%d", err );
       
   382         User::LeaveIfError(err);
       
   383         }
       
   384     iDeviceDir.CreateL(privatePath);
       
   385     RBuf8 rootDeviceBuf;
       
   386     CleanupClosePushL(rootDeviceBuf);
       
   387     rootDeviceBuf.CreateL(KBufSize);
       
   388     rootDeviceBuf.Append(KRootDeviceXmlLead());
       
   389     // Appends the device icon list to the device xml buffer
       
   390     const RPointerArray<CUpnpTerminalModeIcon>& deviceList = iDeviceInfo.DeviceIconList();
       
   391     TInt iconCount = deviceList.Count();
       
   392     if ( iconCount > KErrNone )
       
   393         {
       
   394         privatePath.Append(KIconDirectory());
       
   395         err = iFs.MkDir(privatePath);  // Creates icon directory 
       
   396         if( err && err != KErrAlreadyExists )
       
   397             {
       
   398             OstTrace1( TRACE_ERROR, DUP2_CUPNPTMSERVERDEVICEXMLPARSER_STARTL, "CUpnpTmServerDeviceXmlParser::StartL;err=%d", err );
       
   399             User::LeaveIfError(err);
       
   400             }
       
   401         iIconDirectory.CreateL(privatePath);
       
   402         OstTrace1( TRACE_ERROR, DUP3_CUPNPTMSERVERDEVICEXMLPARSER_STARTL, "CUpnpTmServerDeviceXmlParser::StartL;iconCount=%d", iconCount );
       
   403         rootDeviceBuf.Append(KStartIconList);
       
   404         for ( TInt i(0); i < iconCount; i++ )
       
   405             {
       
   406             rootDeviceBuf.Append(KStartIcon);
       
   407             rootDeviceBuf.Append(KStartMimeType);
       
   408             rootDeviceBuf.Append(deviceList[i]->MimeType());
       
   409             rootDeviceBuf.Append(KEndMimeType);
       
   410             rootDeviceBuf.Append(KStartWidth);
       
   411             rootDeviceBuf.AppendNum(deviceList[i]->Width());
       
   412             rootDeviceBuf.Append(KEndWidth);
       
   413             rootDeviceBuf.Append(KStartHeight);
       
   414             rootDeviceBuf.AppendNum(deviceList[i]->Height());
       
   415             rootDeviceBuf.Append(KEndHeight);
       
   416             rootDeviceBuf.Append(KStartDepth);
       
   417             rootDeviceBuf.AppendNum(deviceList[i]->Depth());
       
   418             rootDeviceBuf.Append(KEndDepth);
       
   419             rootDeviceBuf.Append(KStartUrl);
       
   420             
       
   421             TBuf8<KMaxPath> iconBuf;
       
   422             const TDesC& fileName = deviceList[i]->IconFilename();
       
   423             iconBuf.Copy(fileName);
       
   424             TBuf8<UpnpString::KDefaultStringLength> iconRelativeUrl(KScpdUrl());
       
   425             // Extracts the actual input filepath and creates the relative url for the icon
       
   426             // to be provided in the device xml file
       
   427             iconRelativeUrl.Append(KIconPath());
       
   428             // Extracts only filename and appends the same to url
       
   429             iconRelativeUrl.Append(iconBuf.Mid((iconBuf.LocateReverse(KDirectorySeparator))+1));
       
   430             rootDeviceBuf.Append(iconRelativeUrl);
       
   431             delete iFileMan;
       
   432             iFileMan = NULL;
       
   433             iFileMan = CFileMan::NewL(iFs) ;
       
   434             // copies icon files to the private device directory
       
   435             User::LeaveIfError(iFileMan->Copy(fileName,iIconDirectory));  
       
   436             rootDeviceBuf.Append(KEndUrl);
       
   437             rootDeviceBuf.Append(KEndIcon);
       
   438             }
       
   439         rootDeviceBuf.Append(KEndIconList);
       
   440         }
       
   441     rootDeviceBuf.Append( iDeviceInfo.DeviceInfo());
       
   442     rootDeviceBuf.Append( KRootDeviceXmlTrail() );
       
   443        
       
   444 	ParseL(*iParser, rootDeviceBuf );
       
   445 	CleanupStack::PopAndDestroy(&rootDeviceBuf);
       
   446 
       
   447 	OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_STARTL_EXIT );
       
   448 	}
       
   449 
       
   450 // ---------------------------------------------------------------------------------
       
   451 // CUpnpTmServerDeviceXmlParser::OnStartPrefixMappingL
       
   452 // ---------------------------------------------------------------------------------
       
   453 //  
       
   454 void CUpnpTmServerDeviceXmlParser::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, TInt aErrorCode)
       
   455     {
       
   456     OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_ONSTARTPREFIXMAPPINGL_ENTRY );
       
   457     User::LeaveIfError(aErrorCode);
       
   458     OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_ONSTARTPREFIXMAPPINGL_EXIT );
       
   459     }
       
   460 
       
   461 // ---------------------------------------------------------------------------------
       
   462 // CUpnpTmServerDeviceXmlParser::OnEndPrefixMappingL
       
   463 // ---------------------------------------------------------------------------------
       
   464 // 
       
   465 void CUpnpTmServerDeviceXmlParser::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt aErrorCode)
       
   466     {
       
   467     OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_ONENDPREFIXMAPPINGL_ENTRY );
       
   468     User::LeaveIfError(aErrorCode);
       
   469     OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_ONENDPREFIXMAPPINGL_EXIT );
       
   470     }
       
   471 
       
   472 // ---------------------------------------------------------------------------------
       
   473 // CUpnpTmServerDeviceXmlParser::OnIgnorableWhiteSpaceL
       
   474 // ---------------------------------------------------------------------------------
       
   475 // 
       
   476 void CUpnpTmServerDeviceXmlParser::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt aErrorCode)
       
   477     {
       
   478     OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_ONIGNORABLEWHITESPACEL_ENTRY );
       
   479     User::LeaveIfError(aErrorCode);
       
   480     OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_ONIGNORABLEWHITESPACEL_EXIT );
       
   481     }
       
   482 
       
   483 // ---------------------------------------------------------------------------------
       
   484 // CUpnpTmServerDeviceXmlParser::OnSkippedEntityL
       
   485 // ---------------------------------------------------------------------------------
       
   486 // 
       
   487 void CUpnpTmServerDeviceXmlParser::OnSkippedEntityL(const RString& /*aName*/, TInt aErrorCode)
       
   488     {
       
   489     OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_ONSKIPPEDENTITYL_ENTRY );
       
   490     User::LeaveIfError(aErrorCode);
       
   491     OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_ONSKIPPEDENTITYL_EXIT );
       
   492     }
       
   493 
       
   494 // ---------------------------------------------------------------------------------
       
   495 // CUpnpTmServerDeviceXmlParser::OnProcessingInstructionL
       
   496 // ---------------------------------------------------------------------------------
       
   497 // 
       
   498 void CUpnpTmServerDeviceXmlParser::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt aErrorCode)
       
   499     {
       
   500     OstTraceFunctionEntry0( CUPNPTMSERVERDEVICEXMLPARSER_ONPROCESSINGINSTRUCTIONL_ENTRY );
       
   501     User::LeaveIfError(aErrorCode);
       
   502     OstTraceFunctionExit0( CUPNPTMSERVERDEVICEXMLPARSER_ONPROCESSINGINSTRUCTIONL_EXIT );
       
   503     }
       
   504 
       
   505