xdmprotocols/LocalProtocol/src/LocalProtocol.cpp
branchRCL_3
changeset 35 fbd2e7cec7ef
parent 0 c8caa15ef882
equal deleted inserted replaced
34:2669f8761a99 35:fbd2e7cec7ef
       
     1 /*
       
     2 * Copyright (c) 2005 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: CLocalProtocol
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <hal.h>
       
    21 #include <f32file.h>
       
    22 #include <xdmlogwriter.h>
       
    23 #include <implementationproxy.h>
       
    24 #include "XdmXmlParser.h"
       
    25 #include "LocalProtocol.h"
       
    26 #include "LocalDocument.h"
       
    27 #include "LocalDocumentNode.h"
       
    28 #include "LocalDirectory.h"
       
    29 #include "XdmCredentials.h"
       
    30 #include "XdmProtocolInfo.h"
       
    31 #include "XdmOperationFactory.h"
       
    32 
       
    33 // ----------------------------------------------------------
       
    34 // CLocalProtocol::CLocalProtocol
       
    35 // 
       
    36 // ----------------------------------------------------------
       
    37 //
       
    38 CLocalProtocol::CLocalProtocol( const CXdmEngine& aXdmEngine,
       
    39                                 const CXdmProtocolInfo& aProtocolInfo ) :
       
    40                                 iTransferMediaOpen( EFalse ),
       
    41                                 iXdmEngine( CONST_CAST( CXdmEngine&, aXdmEngine ) ),
       
    42                                 iProtocolInfo( aProtocolInfo )
       
    43     {   
       
    44     }
       
    45     
       
    46 // ----------------------------------------------------------
       
    47 // CLocalProtocol::DeleteLogFileL
       
    48 // 
       
    49 // ----------------------------------------------------------
       
    50 //
       
    51 CLocalProtocol* CLocalProtocol::NewL( const TXdmProtocolParams& aProtocolParams )
       
    52     {
       
    53     CLocalProtocol* self = new ( ELeave ) CLocalProtocol( aProtocolParams.iXdmEngine,
       
    54                                                           aProtocolParams.iProtocolInfo );
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop();
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------
       
    62 // CLocalProtocol::DeleteLogFileL
       
    63 // 
       
    64 // ----------------------------------------------------------
       
    65 //
       
    66 CLocalProtocol::~CLocalProtocol()
       
    67     {
       
    68     #ifdef _DEBUG
       
    69         WriteToLog( _L8( "CLocalProtocol::~CLocalProtocol()" ) );  
       
    70     #endif
       
    71     delete iRootFolder;
       
    72     delete iXmlParser;
       
    73     delete iLogWriter;
       
    74     iFileSession.Close();
       
    75     Dll::FreeTls();
       
    76     }
       
    77         
       
    78 // ----------------------------------------------------------
       
    79 // CLocalProtocol::ConstructL
       
    80 // 
       
    81 // ----------------------------------------------------------
       
    82 //
       
    83 void CLocalProtocol::ConstructL()
       
    84     {
       
    85     #ifdef _DEBUG
       
    86         iLogWriter = CXdmLogWriter::NewL( KLocalEngLogFile );
       
    87         WriteToLog( _L8( "CLocalProtocol::ConstructL() " ) );  
       
    88     #endif
       
    89     iXmlParser = CXdmXmlParser::NewL();
       
    90     SetRootDirectoryL( iProtocolInfo.Root() ); 
       
    91     User::LeaveIfError( iFileSession.Connect() );
       
    92     Dll::SetTls( this );                                                                               
       
    93     }
       
    94 
       
    95 // ----------------------------------------------------------
       
    96 // CLocalProtocol::SetRootDirectoryL
       
    97 // 
       
    98 // ----------------------------------------------------------
       
    99 //
       
   100 void CLocalProtocol::SetRootDirectoryL( const TDesC& aRootPath )
       
   101     {
       
   102     TUid id = RProcess().Identity();
       
   103     TBuf<32> processId;
       
   104     processId.Zero();
       
   105     processId.Format( _L( "%x" ), id );
       
   106     #ifdef _DEBUG
       
   107         WriteToLog( _L8( "CLocalProtocol::SetRootDirectoryL()" ) );  
       
   108     #endif
       
   109     if( aRootPath.Length() > 0 )
       
   110         {
       
   111         iRootFolder = HBufC::NewL( aRootPath.Length() +
       
   112                                    processId.Length() + 
       
   113                                    TPtrC( KLocalEngPrivateRoot ).Length() + 4 );
       
   114         iRootFolder->Des().Copy( KLocalEngPrivateRoot );
       
   115         iRootFolder->Des().Append( processId );
       
   116         iRootFolder->Des().Append( _L( "\\" ) );
       
   117         iRootFolder->Des().Append( aRootPath );
       
   118         iRootFolder->Des().Append( _L( "\\" ) );
       
   119         }
       
   120     else
       
   121         {
       
   122         iRootFolder = HBufC::NewL( processId.Length() + 
       
   123                                    KLocalEngPrivateRoot().Length() + 2 );
       
   124         iRootFolder->Des().Copy( KLocalEngPrivateRoot );
       
   125         iRootFolder->Des().Append( processId );
       
   126         iRootFolder->Des().Append( _L( "\\" ) );
       
   127         }
       
   128     #ifdef _DEBUG
       
   129         TBuf8<256> eight;
       
   130         eight.Copy( iRootFolder->Des() );
       
   131         WriteToLog( _L8( "  Path: %S" ), &eight );  
       
   132     #endif
       
   133     }
       
   134 
       
   135 // ----------------------------------------------------------
       
   136 // CLocalProtocol::.WriteToLog
       
   137 // 
       
   138 // ----------------------------------------------------------
       
   139 //
       
   140 void CLocalProtocol::WriteToLog( TRefByValue<const TDesC8> aFmt,... ) const                                
       
   141     {
       
   142     VA_LIST list;
       
   143     VA_START( list, aFmt );
       
   144     TBuf8<KLogBufferMaxSize> buf;
       
   145     buf.FormatList( aFmt, list );
       
   146     iLogWriter->WriteToLog( buf );
       
   147     }
       
   148     
       
   149 // ----------------------------------------------------
       
   150 // CLocalProtocol::InitTransferMedia
       
   151 // 
       
   152 // ----------------------------------------------------
       
   153 //
       
   154 void CLocalProtocol::InitTransferMedium( TInt /*aIdleTimeout*/,
       
   155                                         TRequestStatus& aStatus )
       
   156     {
       
   157     TRequestStatus* status = &aStatus;
       
   158     User::RequestComplete( status, KErrNone );
       
   159     }
       
   160 
       
   161 // ----------------------------------------------------
       
   162 // CLocalProtocol::CancelTransferMediaInit
       
   163 // 
       
   164 // ----------------------------------------------------
       
   165 //
       
   166 void CLocalProtocol::CancelTransferMediumInit()
       
   167     {
       
   168     }
       
   169 
       
   170 // ----------------------------------------------------
       
   171 // CLocalProtocol::IsTransferAvailable
       
   172 // 
       
   173 // ----------------------------------------------------
       
   174 //
       
   175 TBool CLocalProtocol::IsTransferAvailable() const
       
   176     {
       
   177     return ETrue;
       
   178     }
       
   179             
       
   180 // ----------------------------------------------------
       
   181 // CLocalProtocol::RFSession
       
   182 // 
       
   183 // ----------------------------------------------------
       
   184 //
       
   185 RFs& CLocalProtocol::RFSession()
       
   186     {
       
   187     return iFileSession;
       
   188     }
       
   189 
       
   190 // ----------------------------------------------------
       
   191 // CLocalProtocol::Root
       
   192 // 
       
   193 // ----------------------------------------------------
       
   194 //
       
   195 TPtrC CLocalProtocol::Root()
       
   196     {
       
   197     return iRootFolder != NULL ? iRootFolder->Des() : TPtrC();
       
   198     }
       
   199     
       
   200 // ----------------------------------------------------------
       
   201 // void CXcapProtocol::DeleteLogFileL
       
   202 // 
       
   203 // ----------------------------------------------------------
       
   204 //
       
   205 EXPORT_C RFs& CLocalProtocol::FileSession()
       
   206     {
       
   207     TAny* ptr = Dll::Tls();
       
   208     CLocalProtocol* self = ( CLocalProtocol* )ptr;
       
   209     return self->RFSession();  
       
   210     }
       
   211     
       
   212 // ----------------------------------------------------
       
   213 // CLocalProtocol::RootFolder
       
   214 // 
       
   215 // ----------------------------------------------------
       
   216 //
       
   217 EXPORT_C TPtrC CLocalProtocol::RootFolder()
       
   218     {
       
   219     TAny* ptr = Dll::Tls();
       
   220     CLocalProtocol* self = ( CLocalProtocol* )ptr;
       
   221     return self->Root();
       
   222     }
       
   223 
       
   224 // ----------------------------------------------------
       
   225 // CLocalProtocol::CreateDocumentNodeL
       
   226 // 
       
   227 // ----------------------------------------------------
       
   228 //
       
   229 CXdmDocumentNode* CLocalProtocol::CreateDocumentNodeL()
       
   230     {
       
   231     return CLocalDocumentNode::NewL( iXdmEngine, *this );
       
   232     }
       
   233     
       
   234 // ----------------------------------------------------
       
   235 // CLocalProtocol::CreateDocumentL
       
   236 // 
       
   237 // ----------------------------------------------------
       
   238 //
       
   239 CXdmDocument* CLocalProtocol::CreateDocumentL( const TDesC& aDocumentName,
       
   240                                                const TXdmDocType /*aDocumentType*/ )
       
   241     {
       
   242     return CLocalDocument::NewL( iXdmEngine, aDocumentName, *this );
       
   243     }
       
   244 
       
   245 // ----------------------------------------------------
       
   246 // CLocalProtocol::CreateDirectoryL
       
   247 //
       
   248 // ----------------------------------------------------
       
   249 //
       
   250 CXdmDirectory* CLocalProtocol::CreateDirectoryL( const TDesC& aDirectoryPath )
       
   251     {
       
   252     TPtrC root = iRootFolder->Des();
       
   253     HBufC* fullName = HBufC::NewLC( root.Length() + aDirectoryPath.Length() );
       
   254     fullName->Des().Copy( root );
       
   255     fullName->Des().Append( aDirectoryPath );
       
   256     CXdmDirectory* dir = CLocalDirectory::NewL( fullName->Des(), iXdmEngine, *this );
       
   257     CleanupStack::PopAndDestroy();  //fullName
       
   258     return dir;
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------
       
   262 // Map the interface UIDs to implementation factory functions
       
   263 // 
       
   264 // ---------------------------------------------------------
       
   265 //
       
   266 const TImplementationProxy ImplementationTable[] = 
       
   267     {
       
   268     #ifdef __EABI__
       
   269         IMPLEMENTATION_PROXY_ENTRY( 0x10207424, CLocalProtocol::NewL )
       
   270     #else
       
   271         { { 0x10207424 }, CLocalProtocol::NewL }
       
   272     #endif
       
   273     };
       
   274 
       
   275 // ---------------------------------------------------------
       
   276 // Return the implementation table & number of implementations
       
   277 // 
       
   278 // ---------------------------------------------------------
       
   279 //
       
   280 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   281     {
       
   282     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   283     return ImplementationTable;
       
   284     }
       
   285     
       
   286 
       
   287 // End of File