voipplugins/voipadapters/provisioningfile/src/WPOMAMsgHandler.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Used by ProvisioningFile to read provisioning messages.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "WPOMAMsgHandler.h"
       
    21 #include    "wpprovisioningfiledebug.h"
       
    22 
       
    23 #include    <e32std.h>
       
    24 #include    <f32file.h>
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CWPOMAMsgHandler::CWPOMAMsgHandler
       
    30 // C++ default constructor can NOT contain any code, that
       
    31 // might leave.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CWPOMAMsgHandler::CWPOMAMsgHandler()
       
    35     : iProvData( NULL, 0 )
       
    36     {
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CWPOMAMsgHandler::ConstructL
       
    41 // Symbian 2nd phase constructor can leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void CWPOMAMsgHandler::ConstructL()
       
    45     {
       
    46     FLOG( "[ProvisioningFile] CWPOMAMsgHandler::ConstructL" );
       
    47     User::LeaveIfError( iFs.Connect() );
       
    48     iProvisioningDoc = HBufC8::NewL( 0 );
       
    49     }
       
    50     
       
    51 // -----------------------------------------------------------------------------
       
    52 // CWPOMAMsgHandler::NewL
       
    53 // Two-phased constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CWPOMAMsgHandler* CWPOMAMsgHandler::NewL()
       
    57     {
       
    58     CWPOMAMsgHandler* self = CWPOMAMsgHandler::NewLC();
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CWPOMAMsgHandler::NewLC
       
    65 // Two-phased constructor.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CWPOMAMsgHandler* CWPOMAMsgHandler::NewLC()
       
    69     {
       
    70     CWPOMAMsgHandler* self = new( ELeave ) CWPOMAMsgHandler;    
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL();
       
    73     return self;
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CWPOMAMsgHandler::~CWPOMAMsgHandler
       
    78 // Destructor
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CWPOMAMsgHandler::~CWPOMAMsgHandler()
       
    82     {
       
    83     if ( iProvisioningDoc )
       
    84         {
       
    85         delete iProvisioningDoc;
       
    86         iProvisioningDoc = NULL;
       
    87         }
       
    88     
       
    89     iFs.Close();
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CWPOMAMsgHandler::ReadProvFileL
       
    94 //
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CWPOMAMsgHandler::ReadProvFileL( TFileName aConfig )
       
    98     {
       
    99     FLOG( "[ProvisioningFile] CWPOMAMsgHandler::ReadProvFileL" );
       
   100 
       
   101     TInt fileSize( 0 );
       
   102 
       
   103     iFileName = aConfig;
       
   104     User::LeaveIfError( GetFileSize( fileSize ) );
       
   105       
       
   106     if ( fileSize )
       
   107         {
       
   108         delete iProvisioningDoc;
       
   109         iProvisioningDoc = NULL;
       
   110         iProvisioningDoc = HBufC8::NewL( fileSize );
       
   111         iProvData.Set( iProvisioningDoc->Des() );
       
   112         
       
   113 	    User::LeaveIfError( iFile.Open( iFs, iFileName, EFileShareReadersOnly ) );
       
   114 	    User::LeaveIfError( iFile.Read( iProvData ) );
       
   115 	    iFile.Close();
       
   116         }
       
   117 	}
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CWPOMAMsgHandler::DocL
       
   121 //
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 HBufC8* CWPOMAMsgHandler::DocL()
       
   125     {
       
   126     FLOG( "[ProvisioningFile] CWPOMAMsgHandler::DocL" );
       
   127     
       
   128     if( iProvisioningDoc )
       
   129         {
       
   130         return iProvisioningDoc->AllocL();
       
   131         }
       
   132     else
       
   133         {
       
   134         return NULL;
       
   135         }
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CWPOMAMsgHandler::GetFileSize
       
   140 // 
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 TInt CWPOMAMsgHandler::GetFileSize( TInt& aSize )
       
   144     {
       
   145     FLOG( "[ProvisioningFile] CWPOMAMsgHandler::GetFileSize" );
       
   146     
       
   147     TInt err( iFile.Open( iFs, iFileName , EFileShareReadersOnly ) );
       
   148     if ( KErrNone == err )
       
   149         {
       
   150         err = iFile.Size( aSize );
       
   151         iFile.Close();
       
   152         }
       
   153     return err;
       
   154     }
       
   155 
       
   156 //  End of File