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