omads/omadsextensions/adapters/mms/src/mmsdataprovider.cpp
changeset 40 b63e67867dcd
equal deleted inserted replaced
39:9905f7d46607 40:b63e67867dcd
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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:  Part of SyncML Data Synchronization Plug In Adapter
       
    15 *
       
    16 */
       
    17 
       
    18   
       
    19 #include <f32file.h>
       
    20 #include <msvstd.h>
       
    21 #include <msvapi.h>    
       
    22 #include <bautils.h>
       
    23 #include <barsc.h> 
       
    24 #include <stringpool.h> 
       
    25 #include <data_caging_path_literals.hrh>
       
    26 #include <mmsdatastore.rsg>
       
    27 #include <SmlDataFormat.h>
       
    28 #include <ecom/implementationproxy.h>
       
    29 #include "mmsdataprovider.h"
       
    30 #include "mmsdataproviderdefs.h"
       
    31 #include "mmsdatastore.h"
       
    32 #include "logger.h"
       
    33 
       
    34 
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CMmsDataProvider::CMmsDataProvider
       
    38 // C++ default constructor can NOT contain any code, that might leave
       
    39 // -----------------------------------------------------------------------------
       
    40 CMmsDataProvider::CMmsDataProvider() :
       
    41     iOwnStoreFormat(NULL),
       
    42     iFilters(1),
       
    43     iMsvSession(NULL)
       
    44     {
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CMmsDataProvider::ConstructL
       
    49 // Symbian 2nd phase constructor can leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 void CMmsDataProvider::ConstructL()
       
    52     {
       
    53     LOGGER_ENTERFN( "CMmsDataProvider::ConstructL" ); 
       
    54     
       
    55     iMsvSession = CMsvSession::OpenSyncL( *this );
       
    56     iRFs = iMsvSession->FileSession();
       
    57     iStringPool.OpenL();
       
    58 
       
    59     LOGGER_LEAVEFN( "CMmsDataProvider::ConstructL" )
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CMmsDataProvider::NewL
       
    64 // Two-phased constructor.
       
    65 // -----------------------------------------------------------------------------
       
    66 CMmsDataProvider* CMmsDataProvider::NewL()
       
    67     {
       
    68     LOGGER_ENTERFN("CMmsDataProvider::NewL()"); 
       
    69     
       
    70     CMmsDataProvider* self = new (ELeave) CMmsDataProvider;
       
    71    
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL();
       
    74     CleanupStack::Pop( self );
       
    75 
       
    76     LOGGER_LEAVEFN("CMmsDataProvider::NewL()"); 
       
    77     return self;  
       
    78     }
       
    79 
       
    80     
       
    81 // -----------------------------------------------------------------------------
       
    82 // CMmsDataProvider::~CMmsDataProvider
       
    83 // Destructor.
       
    84 // -----------------------------------------------------------------------------
       
    85 CMmsDataProvider::~CMmsDataProvider()
       
    86     {
       
    87     LOGGER_ENTERFN("CMmsDataProvider::~CMmsDataProvider()");
       
    88     
       
    89     delete iOwnStoreFormat; 
       
    90     delete iMsvSession;
       
    91     
       
    92     iStringPool.Close();
       
    93     
       
    94     iFilters.ResetAndDestroy();
       
    95     iFilters.Close();
       
    96     
       
    97     LOGGER_LEAVEFN("CMmsDataProvider::~CMmsDataProvider()");
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CMmsDataProvider::HandleSessionEventL
       
   102 // virtual function from MMsvSessionObserver, does nothing
       
   103 // -----------------------------------------------------------------------------
       
   104 void CMmsDataProvider::HandleSessionEventL(TMsvSessionEvent /*aEvent*/,
       
   105     TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/ )
       
   106     {
       
   107     LOGGER_ENTERFN("CMmsDataProvider::HandleSessionEventL()"); 
       
   108     LOGGER_LEAVEFN("CMmsDataProvider::HandleSessionEventL()"); 
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CMmsDataProvider::DoOnFrameworkEvent
       
   113 // Not used
       
   114 // -----------------------------------------------------------------------------
       
   115 void CMmsDataProvider::DoOnFrameworkEvent(TSmlFrameworkEvent, TInt /*aParam1*/, TInt /*aParam2*/)
       
   116     {
       
   117     LOGGER_ENTERFN("CMmsDataProvider::DoOnFrameworkEvent()"); 
       
   118     LOGGER_LEAVEFN("CMmsDataProvider::DoOnFrameworkEvent()"); 
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CMmsDataProvider::DoSupportsOperation
       
   123 // Checks whether data provider supports specific operation
       
   124 // -----------------------------------------------------------------------------
       
   125 TBool CMmsDataProvider::DoSupportsOperation(TUid /*aOpId*/) const 
       
   126     {
       
   127     LOGGER_ENTERFN("CMmsDataProvider::DoSupportsOperation()"); 
       
   128     LOGGER_LEAVEFN("CMmsDataProvider::DoSupportsOperation()"); 
       
   129     
       
   130     // Optional operations are not supported
       
   131     return EFalse;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CMmsDataProvider::DoStoreFormatL
       
   136 // Creates data store format
       
   137 // -----------------------------------------------------------------------------
       
   138 const CSmlDataStoreFormat& CMmsDataProvider::DoStoreFormatL()
       
   139     {
       
   140     LOGGER_ENTERFN("CMmsDataProvider::DoStoreFormatL()"); 
       
   141     
       
   142     if ( !iOwnStoreFormat )
       
   143         {
       
   144         iOwnStoreFormat = DoOwnStoreFormatL();
       
   145         }
       
   146     
       
   147     LOGGER_LEAVEFN("CMmsDataProvider::DoStoreFormatL()"); 
       
   148     
       
   149     return *iOwnStoreFormat;
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CMmsDataProvider::DoListStoresLC
       
   154 // Returns array fo data stores, not implemented because only single data store
       
   155 // is supported
       
   156 // -----------------------------------------------------------------------------
       
   157 CDesCArray* CMmsDataProvider::DoListStoresLC()
       
   158     {
       
   159     LOGGER_ENTERFN("CMmsDataProvider::DoListStoresLC()");
       
   160     
       
   161     CDesCArrayFlat* stores = new (ELeave) CDesCArrayFlat(1);
       
   162     CleanupStack::PushL( stores );
       
   163     stores->AppendL( KNSmlDefaultLocalDbName );   
       
   164     
       
   165     LOGGER_LEAVEFN("CMmsDataProvider::DoListStoresLC()");
       
   166     
       
   167     return stores;
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CMmsDataProvider::DoDefaultStoreL
       
   172 // Returns the name of the default data store
       
   173 // -----------------------------------------------------------------------------
       
   174 const TDesC& CMmsDataProvider::DoDefaultStoreL()
       
   175     {
       
   176     LOGGER_ENTERFN("CMmsDataProvider::DoDefaultStoreL()"); 
       
   177     LOGGER_LEAVEFN("CMmsDataProvider::DoDefaultStoreL()"); 
       
   178     return KNSmlDefaultLocalDbName;
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CMmsDataProvider::DoNewStoreInstanceLC
       
   183 // Creates a new data store object, which can be used for synchronization
       
   184 // ----------------------------------------------------------------------------- 
       
   185 CSmlDataStore* CMmsDataProvider::DoNewStoreInstanceLC()
       
   186     {
       
   187     LOGGER_ENTERFN("CMmsDataProvider::DoNewStoreInstanceLC");
       
   188     CMmsDataStore* newStore = CMmsDataStore::NewL( *iMsvSession );
       
   189     CleanupStack::PushL(newStore);
       
   190     LOGGER_LEAVEFN("CMmsDataProvider::DoNewStoreInstanceLC");
       
   191     return newStore;
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CMmsDataProvider::DoCheckSupportedServerFiltersL
       
   196 // Filters are not supported
       
   197 // ----------------------------------------------------------------------------- 
       
   198 void CMmsDataProvider::DoCheckSupportedServerFiltersL(
       
   199     const CSmlDataStoreFormat& /*aServerDataStoreFormat*/,
       
   200     RPointerArray<CSyncMLFilter>& /*aFilters*/,
       
   201     TSyncMLFilterChangeInfo& /*aChangeInfo*/ )
       
   202     {
       
   203     LOGGER_ENTERFN("CMmsDataProvider::DoCheckSupportedServerFiltersL()"); 
       
   204     User::Leave( KErrNotSupported );
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CMmsDataProvider::DoCheckServerFiltersL
       
   209 // Filters are not supported
       
   210 // ----------------------------------------------------------------------------- 
       
   211 void CMmsDataProvider::DoCheckServerFiltersL(
       
   212     RPointerArray<CSyncMLFilter>& /*aFilters*/,
       
   213     TSyncMLFilterChangeInfo& /*aChangeInfo*/)
       
   214     {
       
   215     LOGGER_ENTERFN("CMmsDataProvider::DoCheckServerFiltersL()"); 
       
   216     User::Leave( KErrNotSupported );
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CMmsDataProvider::DoSupportedServerFiltersL
       
   221 // Filters are not supported
       
   222 // ----------------------------------------------------------------------------- 
       
   223 const RPointerArray<CSyncMLFilter>& CMmsDataProvider::DoSupportedServerFiltersL()
       
   224     {
       
   225     LOGGER_ENTERFN("CMmsDataProvider::DoSupportedServerFiltersL()"); 
       
   226     LOGGER_LEAVEFN("CMmsDataProvider::DoSupportedServerFiltersL()"); 
       
   227     return iFilters; // empty array
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CMmsDataProvider::DoSupportsUserSelectableMatchType
       
   232 // Not supported
       
   233 // -----------------------------------------------------------------------------        
       
   234 TBool CMmsDataProvider::DoSupportsUserSelectableMatchType() const
       
   235     {
       
   236     LOGGER_ENTERFN("CMmsDataProvider::DoSupportsUserSelectableMatchType()"); 
       
   237     LOGGER_LEAVEFN("CMmsDataProvider::DoSupportsUserSelectableMatchType()"); 
       
   238     return EFalse;
       
   239     }           
       
   240     
       
   241 // -----------------------------------------------------------------------------
       
   242 // CMmsDataProvider::DoGenerateRecordFilterQueryLC
       
   243 // Filters are not supported
       
   244 // ----------------------------------------------------------------------------- 
       
   245 HBufC* CMmsDataProvider::DoGenerateRecordFilterQueryLC(
       
   246     const RPointerArray<CSyncMLFilter>& /*aFilters*/,
       
   247     TSyncMLFilterMatchType /*aMatch*/, TDes& /*aFilterMimeType*/,
       
   248     TSyncMLFilterType& /*aFilterType*/, TDesC& /*aStoreName*/ )
       
   249     {
       
   250     LOGGER_ENTERFN("CMmsDataProvider::DoGenerateRecordFilterQueryLC()"); 
       
   251     User::Leave( KErrNotSupported );
       
   252     return NULL;
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CMmsDataProvider::DoGenerateFieldFilterQueryL
       
   257 // Filters are not supported
       
   258 // ----------------------------------------------------------------------------- 
       
   259 void CMmsDataProvider::DoGenerateFieldFilterQueryL(
       
   260     const RPointerArray<CSyncMLFilter>& /*aFilters*/, TDes& /*aFilterMimeType*/,
       
   261     RPointerArray<CSmlDataProperty>& /*aProperties*/, TDesC& /*aStoreName*/)
       
   262     {
       
   263     LOGGER_ENTERFN("CMmsDataProvider::DoGenerateFieldFilterQueryL()"); 
       
   264     User::Leave( KErrNotSupported );
       
   265     }
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CMmsDataProvider::DoOwnStoreFormatL
       
   269 // Creates data store format
       
   270 // -----------------------------------------------------------------------------
       
   271 CSmlDataStoreFormat* CMmsDataProvider::DoOwnStoreFormatL()
       
   272     {
       
   273     LOGGER_ENTERFN("CMmsDataProvider::DoOwnStoreFormatL()"); 
       
   274     
       
   275     TParse* parse = new ( ELeave ) TParse();
       
   276     CleanupStack::PushL(parse);
       
   277     TFileName fileName;
       
   278     RResourceFile resourceFile;
       
   279     
       
   280     parse->Set( KMmsStoreFormatRscRom, &KDC_RESOURCE_FILES_DIR, NULL );
       
   281     fileName = parse->FullName();
       
   282     BaflUtils::NearestLanguageFile( iRFs, fileName );
       
   283     
       
   284     TRAPD( error, resourceFile.OpenL( iRFs, fileName ) );
       
   285     if ( error )
       
   286         {
       
   287         LOGGER_WRITE_1( "RResourceFile::OpenL leaved with %d - try again", error );
       
   288         parse->Set( KMmsStoreFormatRsc, &KDC_RESOURCE_FILES_DIR, NULL );
       
   289         fileName = parse->FullName();
       
   290         BaflUtils::NearestLanguageFile( iRFs, fileName );
       
   291         resourceFile.OpenL( iRFs, fileName );
       
   292         }
       
   293     CleanupClosePushL( resourceFile );
       
   294 
       
   295     HBufC8* buffer = resourceFile.AllocReadLC( MMS_DATA_STORE );
       
   296     
       
   297     TResourceReader reader;
       
   298     reader.SetBuffer( buffer );
       
   299 
       
   300     CSmlDataStoreFormat* dsFormat = NULL;
       
   301     dsFormat = CSmlDataStoreFormat::NewLC( iStringPool, reader );
       
   302     
       
   303     CleanupStack::Pop( dsFormat );
       
   304     CleanupStack::PopAndDestroy( buffer );
       
   305     CleanupStack::PopAndDestroy( &resourceFile );
       
   306     CleanupStack::PopAndDestroy( parse );
       
   307     
       
   308     LOGGER_LEAVEFN("CMmsDataProvider::DoOwnStoreFormatL()"); 
       
   309     
       
   310     return dsFormat;
       
   311     }
       
   312 
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // ImplementationTable
       
   316 // Required by ECom plugin interface, tells the entry point of the library
       
   317 // -----------------------------------------------------------------------------
       
   318 const TImplementationProxy ImplementationTable[] = 
       
   319     {
       
   320     IMPLEMENTATION_PROXY_ENTRY(KMmsDataProviderImplUid, CMmsDataProvider::NewL)
       
   321     };
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // ImplementationGroupProxy
       
   325 // Returns the implementation table, required by the ECom plugin interface
       
   326 // -----------------------------------------------------------------------------
       
   327 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   328     {
       
   329     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   330     return ImplementationTable;
       
   331     }