src/include/common/client/CacheSyncSource.h

00001 /*
00002  * Funambol is a mobile platform developed by Funambol, Inc. 
00003  * Copyright (C) 2003 - 2007 Funambol, Inc.
00004  * 
00005  * This program is free software; you can redistribute it and/or modify it under
00006  * the terms of the GNU Affero General Public License version 3 as published by
00007  * the Free Software Foundation with the addition of the following permission 
00008  * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
00009  * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
00010  * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  * 
00017  * You should have received a copy of the GNU Affero General Public License 
00018  * along with this program; if not, see http://www.gnu.org/licenses or write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00020  * MA 02110-1301 USA.
00021  * 
00022  * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
00023  * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
00024  * 
00025  * The interactive user interfaces in modified source and object code versions
00026  * of this program must display Appropriate Legal Notices, as required under
00027  * Section 5 of the GNU Affero General Public License version 3.
00028  * 
00029  * In accordance with Section 7(b) of the GNU Affero General Public License
00030  * version 3, these Appropriate Legal Notices must retain the display of the
00031  * "Powered by Funambol" logo. If the display of the logo is not reasonably 
00032  * feasible for technical reasons, the Appropriate Legal Notices must display
00033  * the words "Powered by Funambol".
00034  */
00035 
00036 #ifndef INCL_CACHE_SYNC_SOURCE
00037 #define INCL_CACHE_SYNC_SOURCE
00038 
00042 #include "base/fscapi.h"
00043 #include "base/ErrorHandler.h"
00044 #include "base/util/ArrayElement.h"
00045 #include "filter/SourceFilter.h"
00046 #include "spds/constants.h"
00047 #include "spds/SyncItem.h"
00048 #include "spds/SyncStatus.h"
00049 #include "spds/AbstractSyncSourceConfig.h"
00050 #include "spds/SyncSourceReport.h"
00051 #include "spds/SyncSource.h"
00052 #include "syncml/core/TagNames.h"
00053 #include "base/util/Enumeration.h"
00054 #include "base/util/KeyValueStore.h"
00055 #include "base/util/KeyValuePair.h"
00056 
00057 BEGIN_NAMESPACE
00058 
00059 #define CACHE_FILE_NAME     "cache_items.dat"
00060 
00066 class CacheSyncSource : public SyncSource {
00067 
00068 private:
00069          
00081     KeyValueStore* cache; 
00082        
00086     Enumeration*   newKeys;
00090     Enumeration*   updatedKeys;
00094     Enumeration*   deletedKeys;       
00095     
00100     Enumeration* allKeys;
00101 
00106     SyncItem* fillSyncItem(StringBuffer* key);       
00107 
00117     bool fillItemModifications();
00118 
00127     void getKeyAndSignature(SyncItem& item, KeyValuePair& kvp);
00128 
00129 protected:
00130   
00134     int saveCache();
00135   
00141     int addItem(SyncItem& item);
00142 
00150     int updateItem(SyncItem& item);
00151 
00159     int deleteItem(SyncItem& item);
00160 
00168     int updateInCache(KeyValuePair& k, const char* action = REPLACE);
00169         
00173     int insertInCache(KeyValuePair& k) {
00174         return updateInCache(k, ADD);
00175     }
00176     
00180     int removeFromCache(KeyValuePair& k) {
00181         return updateInCache(k, DEL);
00182     }    
00183 
00184 public:
00185 
00204     CacheSyncSource(const WCHAR* name, AbstractSyncSourceConfig* sc, 
00205                         KeyValueStore* cache = NULL);
00206         
00207     // Destructor
00208     virtual ~CacheSyncSource();         
00209                                
00221     void setItemStatus(const WCHAR* key, int status, const char* command);       
00222     
00229     SyncItem* getFirstItemKey() { return NULL; };
00230 
00237     SyncItem* getNextItemKey() { return NULL; };
00238 
00244     SyncItem* getFirstItem();
00245 
00251     SyncItem* getNextItem();
00252 
00257     SyncItem* getFirstNewItem();
00258 
00263     SyncItem* getNextNewItem();
00264 
00269     SyncItem* getFirstUpdatedItem();
00270 
00275     SyncItem* getNextUpdatedItem();
00276 
00281     SyncItem* getFirstDeletedItem();
00282 
00287     SyncItem* getNextDeletedItem();
00288     
00295     void serverStatusPackageEnded() {};    
00296     
00304     void clientStatusPackageEnded() {};        
00305 
00311     int endSync();       
00312     
00323     virtual StringBuffer getItemSignature(StringBuffer& key);
00324 
00332     virtual void* getItemContent(StringBuffer& key, size_t* size) = 0;
00333     
00334             
00342     virtual Enumeration* getAllItemList() = 0;      
00343     
00354     virtual int insertItem(SyncItem& item) = 0;
00355 
00363     virtual int modifyItem(SyncItem& item) = 0;
00364 
00372     virtual int removeItem(SyncItem& item) = 0;
00373    
00374    
00375 };
00376 
00377 END_NAMESPACE
00378 
00381 #endif

Generated on Tue Jun 10 17:20:21 2008 for Funambol C++ Client Library by  doxygen 1.5.2