meetingrequest/mrbcplugin/src/cmrbcpluginresourcereader.cpp
branchRCL_3
changeset 12 4ce476e64c59
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
       
     1 /*
       
     2 * Copyright (c) 2008 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: MBUtils ECOM definition
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cmrbcpluginresourcereader.h"
       
    19 #include "cmrbceventplugin.h"
       
    20 
       
    21 #include <coemain.h>
       
    22 #include <barsread.h>
       
    23 
       
    24 #include "emailtrace.h"
       
    25 
       
    26 namespace { //codescanner::namespace
       
    27 
       
    28 // BC Plugin resource file offset
       
    29 const TInt KMRBCPluginResourceFileOffset( 2 );
       
    30 
       
    31 } // namespace
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CMRBCPluginResourceReader::CMRBCPluginResourceReader
       
    35 // Static constructor for this class
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMRBCPluginResourceReader::CMRBCPluginResourceReader(
       
    39         MCalenServices& aCalenServices )
       
    40 :   iCalenServices( aCalenServices )
       
    41     {
       
    42     FUNC_LOG;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CMRBCPluginResourceReader::~CMRBCPluginResourceReader
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CMRBCPluginResourceReader::~CMRBCPluginResourceReader()
       
    50     {
       
    51     FUNC_LOG;
       
    52     
       
    53     iPluginCommands.Close();
       
    54     iBCPluginResourceFile.Close();
       
    55     delete iPlugin;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CMRBCPluginResourceReader::NewL
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CMRBCPluginResourceReader* CMRBCPluginResourceReader::NewL(
       
    63         MCalenServices& aCalenServices )
       
    64     {
       
    65     FUNC_LOG;
       
    66     
       
    67     CMRBCPluginResourceReader* self = 
       
    68             new (ELeave) CMRBCPluginResourceReader( aCalenServices );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74     
       
    75 // -----------------------------------------------------------------------------
       
    76 // CMRBCPluginResourceReader::ConstructL
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CMRBCPluginResourceReader::ConstructL()
       
    80     {  
       
    81     FUNC_LOG;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CMRBCPluginResourceReader::ReadFromResourceFileL
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CMRBCPluginResourceReader::ReadFromResourceFileL(
       
    89         TUid aUid,
       
    90         const TDesC& aResourceFile )
       
    91     {
       
    92     FUNC_LOG;
       
    93     
       
    94     CCoeEnv* coeEnv( CCoeEnv::Static() );
       
    95     
       
    96     iBCPluginResourceFile.Close();
       
    97     iBCPluginResourceFile.OpenL( coeEnv->FsSession(), aResourceFile );
       
    98     iBCPluginResourceFile.ConfirmSignatureL();
       
    99     
       
   100     iOffset = iBCPluginResourceFile.Offset() + KMRBCPluginResourceFileOffset;
       
   101     
       
   102     iPluginCommands.Reset();
       
   103     iSupportedEventTypes.ClearAll();
       
   104         
       
   105     HBufC8* resourceIdBuffer =
       
   106         iBCPluginResourceFile.AllocReadLC( iOffset );
       
   107     
       
   108     // Construct resource reader
       
   109     TResourceReader reader;
       
   110     reader.SetBuffer(resourceIdBuffer);
       
   111 
       
   112     iPluginImplementationUid = aUid;
       
   113     iVersion.iMajor = reader.ReadInt32();
       
   114     iSupportedEventTypes = reader.ReadUint32();
       
   115     
       
   116     TInt commandCount( reader.ReadInt16() );
       
   117     iPluginCommands.ReserveL( commandCount );
       
   118     
       
   119     for (TInt i(0); i < commandCount; ++i )
       
   120         {
       
   121         TMRBCPluginCommand pluginCommand;
       
   122         
       
   123         pluginCommand.iCommand = reader.ReadInt32();
       
   124         pluginCommand.iCheckEntryType = reader.ReadInt32();
       
   125         iPluginCommands.Append( pluginCommand  );
       
   126         }
       
   127 
       
   128     iBCPluginResourceFile.Close();
       
   129     CleanupStack::PopAndDestroy( resourceIdBuffer );
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CMRBCPluginResourceReader::Version
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 TVersion CMRBCPluginResourceReader::Version() const
       
   137     {
       
   138     FUNC_LOG;
       
   139     
       
   140     return iVersion;
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CMRBCPluginResourceReader::ReadFromResourceFileL
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 TBool CMRBCPluginResourceReader::SupportsType( 
       
   148         TBCPluginEventType aEventType ) const
       
   149     {
       
   150     FUNC_LOG;
       
   151     
       
   152     return iSupportedEventTypes.IsSet( aEventType );
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CMRBCPluginResourceReader::ReadFromResourceFileL
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 TBool CMRBCPluginResourceReader::SupportsCommand( 
       
   160         TInt aCommand ) const
       
   161     {
       
   162     FUNC_LOG;
       
   163     
       
   164     TInt pos( KErrNotFound );
       
   165     TInt commandCount( iPluginCommands.Count() );
       
   166     for ( TInt i(0); i < commandCount && KErrNotFound == pos; ++i )
       
   167         {
       
   168         if ( iPluginCommands[i].Command() == aCommand )
       
   169             {
       
   170             pos = i;
       
   171             }
       
   172         }
       
   173 
       
   174     return KErrNotFound != pos;
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CMRBCPluginResourceReader::CommandL
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 TInt CMRBCPluginResourceReader::Command( 
       
   182         TInt aCommand, 
       
   183         TMRBCPluginCommand& aPluginCommand ) const
       
   184     {
       
   185     FUNC_LOG;
       
   186     
       
   187     TInt retValue( KErrNotFound );
       
   188     TInt commandCount( iPluginCommands.Count() );
       
   189     for ( TInt i(0); i < commandCount && KErrNotFound == retValue; ++i )
       
   190         {
       
   191         if ( iPluginCommands[i].Command() == aCommand )
       
   192             {
       
   193             retValue = KErrNone;
       
   194             aPluginCommand = iPluginCommands[i];
       
   195             }
       
   196         }    
       
   197     
       
   198     return retValue;
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CMRBCPluginResourceReader::PluginImplUid
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 TUid CMRBCPluginResourceReader::PluginImplUid() const
       
   206     {
       
   207     FUNC_LOG;
       
   208     
       
   209     return iPluginImplementationUid;
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CMRBCPluginResourceReader::PluginImplUid
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 CMRBCEventPlugin& CMRBCPluginResourceReader::PluginL()
       
   217     {
       
   218     FUNC_LOG;
       
   219     
       
   220     if ( !iPlugin )
       
   221         {
       
   222         iPlugin = CMRBCEventPlugin::NewL(
       
   223                         iPluginImplementationUid,
       
   224                         iCalenServices );        
       
   225         }
       
   226     
       
   227     return *iPlugin;
       
   228     }
       
   229 
       
   230 // EOF