services/terminalmodeservice/src/upnpiconfileservetransaction.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: CUpnpIconFileServeTransaction implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpiconfileservetransaction.h"
       
    20 #include <upnperrors.h>
       
    21 #include "OstTraceDefinitions.h"
       
    22 #ifdef OST_TRACE_COMPILER_IN_USE
       
    23 #include "upnpiconfileservetransactionTraces.h"
       
    24 #endif
       
    25 
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===================================
       
    28 
       
    29 // ---------------------------------------------------------------------------------
       
    30 // CUpnpIconFileServeTransaction::NewL
       
    31 // Two-phased constructor.
       
    32 // ---------------------------------------------------------------------------------
       
    33 //
       
    34 CUpnpIconFileServeTransaction* CUpnpIconFileServeTransaction::NewL( const TDesC& aOutFilePath,
       
    35                                                                        RFs& aIconFileSession )
       
    36        
       
    37     {
       
    38     OstTraceFunctionEntry0( CUPNPICONFILESERVETRANSACTION_NEWL_ENTRY );
       
    39     CUpnpIconFileServeTransaction* self = 
       
    40                      new (ELeave) CUpnpIconFileServeTransaction( aIconFileSession );
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL( aOutFilePath );
       
    43     CleanupStack::Pop( self );
       
    44     OstTraceFunctionExit0( CUPNPICONFILESERVETRANSACTION_NEWL_EXIT );
       
    45     return self;
       
    46     }    
       
    47     
       
    48 // ---------------------------------------------------------------------------------
       
    49 // CUpnpIconFileServeTransaction::ConstructL
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // ---------------------------------------------------------------------------------
       
    52 //
       
    53 void CUpnpIconFileServeTransaction::ConstructL( const TDesC& aOutFilePath )
       
    54     {
       
    55     OstTraceFunctionEntry0( CUPNPICONFILESERVETRANSACTION_CONSTRUCTL_ENTRY );
       
    56     iOutFilePath.CreateL( aOutFilePath );
       
    57     OstTraceFunctionExit0( CUPNPICONFILESERVETRANSACTION_CONSTRUCTL_EXIT );
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------------
       
    61 // CUpnpIconFileServeTransaction::CUpnpIconFileServeTransaction
       
    62 // C++ default constructor can NOT contain any code, that
       
    63 // might leave.
       
    64 // ---------------------------------------------------------------------------------
       
    65 //
       
    66 CUpnpIconFileServeTransaction::CUpnpIconFileServeTransaction( RFs& aIconFileSession )
       
    67     :iIconFileSession( aIconFileSession )
       
    68     { 
       
    69     
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------------
       
    73 // CUpnpIconFileServeTransaction::~CUpnpIconFileServeTransaction
       
    74 // Default Destructor
       
    75 // ---------------------------------------------------------------------------------
       
    76 //    
       
    77 CUpnpIconFileServeTransaction::~CUpnpIconFileServeTransaction()
       
    78     {
       
    79     OstTraceFunctionEntry0( CUPNPICONFILESERVETRANSACTION_CUPNPICONFILESERVETRANSACTION_ENTRY );
       
    80     iOutFilePath.Close();
       
    81     OstTraceFunctionExit0( CUPNPICONFILESERVETRANSACTION_CUPNPICONFILESERVETRANSACTION_EXIT );
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------------
       
    85 // CUpnpIconFileServeTransaction::OnCallbackL
       
    86 // Handler for transaction event.
       
    87 // Method is invoked when a particular event arrives.
       
    88 // In case of leave,it traps the error and returns the http error code.
       
    89 // @param aEvent Server event
       
    90 // ---------------------------------------------------------------------------------
       
    91 //    
       
    92 void CUpnpIconFileServeTransaction::OnCallbackL( TUpnpHttpServerEvent aEvent )
       
    93     {
       
    94     OstTraceFunctionEntry0( CUPNPICONFILESERVETRANSACTION_ONCALLBACKL_ENTRY );
       
    95     TRAPD( err, DoCallbackL( aEvent ) );
       
    96     if ( err != KErrNone )
       
    97         {
       
    98         SetHttpCode( err );
       
    99         }
       
   100     OstTraceFunctionExit0( CUPNPICONFILESERVETRANSACTION_ONCALLBACKL_EXIT );
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------------
       
   104 // CUpnpIconFileServeTransaction::DoCallbackL
       
   105 // Method is used to set the data source file and respective http error codes.
       
   106 // @param aEvent Server event
       
   107 // ---------------------------------------------------------------------------------
       
   108 //  
       
   109 void CUpnpIconFileServeTransaction::DoCallbackL( TUpnpHttpServerEvent aEvent )
       
   110     {
       
   111     OstTraceFunctionEntry0( CUPNPICONFILESERVETRANSACTION_DOCALLBACKL_ENTRY );
       
   112     switch ( aEvent )
       
   113         {
       
   114         case EOnRequestStart:
       
   115             { 
       
   116             RFile file;
       
   117             if ( file.Open( iIconFileSession,iOutFilePath,EFileShareReadersOnly | EFileRead ) == KErrNone ) 
       
   118                 {
       
   119                 CleanupClosePushL(file);
       
   120                 // Sets the file which have to be served in response to http request
       
   121                 SetDataSourceL(  file ); 
       
   122                 CleanupStack::Pop(&file);
       
   123                 }
       
   124             else
       
   125                 {
       
   126                 // if the error occurs set the error code in http response
       
   127                 SetHttpCode( -EHttpNotFound );
       
   128                 }                                  
       
   129             }break;
       
   130         case EOnComplete:
       
   131             break;  
       
   132         case EOnResponseStart:
       
   133             {
       
   134             SetHttpCode( KErrNone );
       
   135             } break;          
       
   136         default:
       
   137             break;
       
   138         }            
       
   139     OstTraceFunctionExit0( CUPNPICONFILESERVETRANSACTION_DOCALLBACKL_EXIT );
       
   140     }
       
   141 
       
   142 // End of File