services/terminalmodeservice/src/upnptmserverdescriptionprovider.cpp
author hgs
Fri, 03 Sep 2010 09:13:04 +0300
changeset 31 b51a6f4f15ba
parent 24 e9457ebcc4df
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
hgs
parents:
diff changeset
     1
/**
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: CUpnpTmServerDescriptionProvider class implementation.
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "upnptmserverdescriptionprovider.h"
hgs
parents:
diff changeset
    19
#include <utf.h>
hgs
parents:
diff changeset
    20
#include "OstTraceDefinitions.h"
hgs
parents:
diff changeset
    21
#ifdef OST_TRACE_COMPILER_IN_USE
hgs
parents:
diff changeset
    22
#include "upnptmserverdescriptionproviderTraces.h"
hgs
parents:
diff changeset
    23
#endif
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
_LIT(KPublic,   "public\\");
hgs
parents:
diff changeset
    27
_LIT(KIconPath, "icon");
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    30
//  CUpnpTmServerDescriptionProvider::NewL
hgs
parents:
diff changeset
    31
//
hgs
parents:
diff changeset
    32
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    33
//
hgs
parents:
diff changeset
    34
CUpnpTmServerDescriptionProvider* CUpnpTmServerDescriptionProvider::NewL()
hgs
parents:
diff changeset
    35
    {
hgs
parents:
diff changeset
    36
    OstTraceFunctionEntry0( CUPNPTMSERVERDESCRIPTIONPROVIDER_NEWL_ENTRY );
hgs
parents:
diff changeset
    37
    CUpnpTmServerDescriptionProvider* self = new (ELeave) CUpnpTmServerDescriptionProvider();           
hgs
parents:
diff changeset
    38
    CleanupStack::PushL(self);
hgs
parents:
diff changeset
    39
    self->ConstructL();
hgs
parents:
diff changeset
    40
    CleanupStack::Pop(self); 
hgs
parents:
diff changeset
    41
    OstTraceFunctionExit0( CUPNPTMSERVERDESCRIPTIONPROVIDER_NEWL_EXIT );
hgs
parents:
diff changeset
    42
    return self;
hgs
parents:
diff changeset
    43
    }
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    46
//  CUpnpTmServerDescriptionProvider::CUpnpTmServerDescriptionProvider
hgs
parents:
diff changeset
    47
//
hgs
parents:
diff changeset
    48
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    49
//
hgs
parents:
diff changeset
    50
CUpnpTmServerDescriptionProvider::CUpnpTmServerDescriptionProvider()
hgs
parents:
diff changeset
    51
    {
hgs
parents:
diff changeset
    52
    // No implementation required
hgs
parents:
diff changeset
    53
    }
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    56
//  CUpnpTmServerDescriptionProvider::~CUpnpTmServerDescriptionProvider
hgs
parents:
diff changeset
    57
//
hgs
parents:
diff changeset
    58
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    59
//
hgs
parents:
diff changeset
    60
CUpnpTmServerDescriptionProvider::~CUpnpTmServerDescriptionProvider()
hgs
parents:
diff changeset
    61
    {
hgs
parents:
diff changeset
    62
    OstTraceFunctionEntry0( CUPNPTMSERVERDESCRIPTIONPROVIDER_CUPNPTMSERVERDESCRIPTIONPROVIDER_ENTRY );
hgs
parents:
diff changeset
    63
    iFs.Close();
hgs
parents:
diff changeset
    64
    OstTraceFunctionExit0( CUPNPTMSERVERDESCRIPTIONPROVIDER_CUPNPTMSERVERDESCRIPTIONPROVIDER_EXIT );
hgs
parents:
diff changeset
    65
    }
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    68
//  CUpnpTmServerDescriptionProvider::ConstructL
hgs
parents:
diff changeset
    69
//
hgs
parents:
diff changeset
    70
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    71
//
hgs
parents:
diff changeset
    72
void CUpnpTmServerDescriptionProvider::ConstructL()
hgs
parents:
diff changeset
    73
    {
hgs
parents:
diff changeset
    74
    OstTraceFunctionEntry0( CUPNPTMSERVERDESCRIPTIONPROVIDER_CONSTRUCTL_ENTRY );
hgs
parents:
diff changeset
    75
    User::LeaveIfError( iFs.Connect() );        
hgs
parents:
diff changeset
    76
    OstTraceFunctionExit0( CUPNPTMSERVERDESCRIPTIONPROVIDER_CONSTRUCTL_EXIT );
hgs
parents:
diff changeset
    77
    }
hgs
parents:
diff changeset
    78
hgs
parents:
diff changeset
    79
hgs
parents:
diff changeset
    80
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    81
//  CUpnpTmServerDescriptionProvider::OnDeviceDescription
hgs
parents:
diff changeset
    82
//
hgs
parents:
diff changeset
    83
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    84
//
hgs
parents:
diff changeset
    85
TInt CUpnpTmServerDescriptionProvider::OnDeviceDescription( 
hgs
parents:
diff changeset
    86
                                       CUpnpDeviceDescriptionRequest& aRequest )
hgs
parents:
diff changeset
    87
    {
hgs
parents:
diff changeset
    88
    OstTraceFunctionEntry0( CUPNPTMSERVERDESCRIPTIONPROVIDER_ONDEVICEDESCRIPTION_ENTRY );
hgs
parents:
diff changeset
    89
    return OnRequest( aRequest );
hgs
parents:
diff changeset
    90
    }
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    93
//  CUpnpTmServerDescriptionProvider::OnServiceDescription
hgs
parents:
diff changeset
    94
//
hgs
parents:
diff changeset
    95
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
    96
//
hgs
parents:
diff changeset
    97
TInt CUpnpTmServerDescriptionProvider::OnServiceDescription( 
hgs
parents:
diff changeset
    98
                                        CUpnpDeviceDescriptionRequest& aRequest )
hgs
parents:
diff changeset
    99
    {
hgs
parents:
diff changeset
   100
    OstTraceFunctionEntry0( CUPNPTMSERVERDESCRIPTIONPROVIDER_ONSERVICEDESCRIPTION_ENTRY );
hgs
parents:
diff changeset
   101
    return OnRequest( aRequest );
hgs
parents:
diff changeset
   102
    }
hgs
parents:
diff changeset
   103
hgs
parents:
diff changeset
   104
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   105
//  CUpnpTmServerDescriptionProvider::OnIcon
hgs
parents:
diff changeset
   106
//
hgs
parents:
diff changeset
   107
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   108
//
hgs
parents:
diff changeset
   109
TInt CUpnpTmServerDescriptionProvider::OnIcon( CUpnpDeviceDescriptionRequest& aRequest )
hgs
parents:
diff changeset
   110
    {
hgs
parents:
diff changeset
   111
    OstTraceFunctionEntry0( CUPNPTMSERVERDESCRIPTIONPROVIDER_ONICON_ENTRY );
hgs
parents:
diff changeset
   112
    return OnRequest( aRequest );
hgs
parents:
diff changeset
   113
    }
hgs
parents:
diff changeset
   114
hgs
parents:
diff changeset
   115
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   116
//  CUpnpTmServerDescriptionProvider::GetFile
hgs
parents:
diff changeset
   117
//
hgs
parents:
diff changeset
   118
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   119
//
hgs
parents:
diff changeset
   120
TInt CUpnpTmServerDescriptionProvider::GetFile( const TDesC8& /*aUri*/, RFile& aFile )
hgs
parents:
diff changeset
   121
    {
hgs
parents:
diff changeset
   122
    OstTraceFunctionEntry0( CUPNPTMSERVERDESCRIPTIONPROVIDER_GETFILE_ENTRY );
hgs
parents:
diff changeset
   123
    return ( aFile.Open( iFs, iFilePath, EFileShareReadersOnly | EFileRead ));  
hgs
parents:
diff changeset
   124
    }
hgs
parents:
diff changeset
   125
hgs
parents:
diff changeset
   126
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   127
//  CUpnpTmServerDescriptionProvider::OnRequest
hgs
parents:
diff changeset
   128
//
hgs
parents:
diff changeset
   129
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   130
//
hgs
parents:
diff changeset
   131
TInt CUpnpTmServerDescriptionProvider::OnRequest( CUpnpDeviceDescriptionRequest& aRequest )
hgs
parents:
diff changeset
   132
    {
hgs
parents:
diff changeset
   133
    OstTraceFunctionEntry0( CUPNPTMSERVERDESCRIPTIONPROVIDER_ONREQUEST_ENTRY );
hgs
parents:
diff changeset
   134
    TPtrC8 fileName;
hgs
parents:
diff changeset
   135
    TInt error(KErrNone);
hgs
parents:
diff changeset
   136
    TPtrC8 urlPath = UpnpFileUtil::ExtractUrlPath( aRequest.Uri(), fileName, error );
hgs
parents:
diff changeset
   137
    if( error == KErrNone)
hgs
parents:
diff changeset
   138
        {    
hgs
parents:
diff changeset
   139
        TRAP( error, OnRequestL( urlPath,fileName ) );
hgs
parents:
diff changeset
   140
        }
hgs
parents:
diff changeset
   141
    OstTraceFunctionExit0( CUPNPTMSERVERDESCRIPTIONPROVIDER_ONREQUEST_EXIT );
hgs
parents:
diff changeset
   142
    return error;
hgs
parents:
diff changeset
   143
    }
hgs
parents:
diff changeset
   144
hgs
parents:
diff changeset
   145
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   146
//  CUpnpTmServerDescriptionProvider::OnRequestL
hgs
parents:
diff changeset
   147
//  @param aUrlPath   URL 
hgs
parents:
diff changeset
   148
//  @param aFileName  FileName 
hgs
parents:
diff changeset
   149
// ---------------------------------------------------------------------------------
hgs
parents:
diff changeset
   150
//
hgs
parents:
diff changeset
   151
void CUpnpTmServerDescriptionProvider::OnRequestL( const TDesC8& aUrlPath, 
hgs
parents:
diff changeset
   152
                                                              const TDesC8& aFileName )
hgs
parents:
diff changeset
   153
    {
hgs
parents:
diff changeset
   154
    OstTraceFunctionEntry0( CUPNPTMSERVERDESCRIPTIONPROVIDER_ONREQUESTL_ENTRY );
hgs
parents:
diff changeset
   155
    // 8-bit to 16-bit conversion of URL path and file path
hgs
parents:
diff changeset
   156
    TBuf<UpnpString::KMaxFilenameLength> urlPath;  
hgs
parents:
diff changeset
   157
    urlPath.Copy(aUrlPath);
hgs
parents:
diff changeset
   158
    TBuf<UpnpString::KMaxFilenameLength> fileName;  
hgs
parents:
diff changeset
   159
    fileName.Copy(aFileName);
hgs
parents:
diff changeset
   160
    
hgs
parents:
diff changeset
   161
    // Fetches the private directory
hgs
parents:
diff changeset
   162
    User::LeaveIfError( iFs.PrivatePath( iFilePath ) );
hgs
parents:
diff changeset
   163
    iFilePath.Append(KPublic());
hgs
parents:
diff changeset
   164
    /** 
hgs
parents:
diff changeset
   165
     * Appends the filename to the file path.
hgs
parents:
diff changeset
   166
     * 1. In case of icon file, it first appends icon directory and then appends the filename.
hgs
parents:
diff changeset
   167
     * 2. In case of device and service xml files, it merely appends filename to the file path.
hgs
parents:
diff changeset
   168
     */
hgs
parents:
diff changeset
   169
    if ( urlPath.Find(KIconPath()) != KErrNotFound )
hgs
parents:
diff changeset
   170
        {
hgs
parents:
diff changeset
   171
        // The request is for icon file
hgs
parents:
diff changeset
   172
        iFilePath.Append(urlPath.Left(urlPath.Locate(KForwardSlash))); 
hgs
parents:
diff changeset
   173
        iFilePath.Append(UpnpString::KDoubleBackSlash16());    
hgs
parents:
diff changeset
   174
        iFilePath.Append(KIconPath());
hgs
parents:
diff changeset
   175
        }
hgs
parents:
diff changeset
   176
    else
hgs
parents:
diff changeset
   177
        {
hgs
parents:
diff changeset
   178
        iFilePath.Append(urlPath);   
hgs
parents:
diff changeset
   179
        }
hgs
parents:
diff changeset
   180
    iFilePath.Append(UpnpString::KDoubleBackSlash16());
hgs
parents:
diff changeset
   181
    // Appends filename to the file path.
hgs
parents:
diff changeset
   182
    iFilePath.Append(fileName);
hgs
parents:
diff changeset
   183
    OstTraceFunctionExit0( CUPNPTMSERVERDESCRIPTIONPROVIDER_ONREQUESTL_EXIT );
hgs
parents:
diff changeset
   184
    }
hgs
parents:
diff changeset
   185