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/util/ArrayElement.h"
00044 #include "spds/constants.h"
00045 #include "spds/SyncItem.h"
00046 #include "spds/AbstractSyncSourceConfig.h"
00047 #include "spds/SyncSourceReport.h"
00048 #include "spds/SyncSource.h"
00049 #include "syncml/core/TagNames.h"
00050 #include "base/util/Enumeration.h"
00051 #include "base/util/KeyValueStore.h"
00052 #include "base/util/KeyValuePair.h"
00053 
00054 BEGIN_NAMESPACE
00055 
00085 class CacheSyncSource : public SyncSource {
00086 
00087 private:
00088          
00100     KeyValueStore* cache; 
00101        
00105     Enumeration*   newKeys;
00106 
00110     Enumeration*   updatedKeys;
00111 
00115     Enumeration*   deletedKeys;       
00116     
00121     Enumeration* allKeys;
00122 
00127     SyncItem* fillSyncItem(StringBuffer* key);       
00128 
00138     bool fillItemModifications();
00139 
00148     void getKeyAndSignature(SyncItem& item, KeyValuePair& kvp);
00149 
00150 protected:
00151   
00156     int saveCache();
00157   
00167     int addItem(SyncItem& item);
00168 
00176     int updateItem(SyncItem& item);
00177 
00186     int deleteItem(SyncItem& item);
00187 
00195     int updateInCache(KeyValuePair& k, const char* action = REPLACE);
00196         
00200     int insertInCache(KeyValuePair& k) {
00201         return updateInCache(k, ADD);
00202     }
00203     
00207     int removeFromCache(KeyValuePair& k) {
00208         return updateInCache(k, DEL);
00209     }    
00210     
00214     int clearCache() {
00215         return (cache->removeAllProperties() || saveCache());
00216     }
00217 
00218 public:
00219 
00238     CacheSyncSource(const WCHAR* name, AbstractSyncSourceConfig* sc, 
00239                         KeyValueStore* cache = NULL);
00240         
00241     // Destructor
00242     virtual ~CacheSyncSource();         
00243                                
00255     void setItemStatus(const WCHAR* key, int status, const char* command);       
00256     
00263     SyncItem* getFirstItemKey() { return NULL; };
00264 
00271     SyncItem* getNextItemKey() { return NULL; };
00272 
00278     SyncItem* getFirstItem();
00279 
00285     SyncItem* getNextItem();
00286 
00291     SyncItem* getFirstNewItem();
00292 
00297     SyncItem* getNextNewItem();
00298 
00303     SyncItem* getFirstUpdatedItem();
00304 
00309     SyncItem* getNextUpdatedItem();
00310 
00315     SyncItem* getFirstDeletedItem();
00316 
00321     SyncItem* getNextDeletedItem();
00322     
00329     void serverStatusPackageEnded() {};    
00330     
00338     void clientStatusPackageEnded() {};        
00339 
00343     virtual int beginSync();
00344 
00350     virtual int endSync();       
00351     
00362     virtual StringBuffer getItemSignature(StringBuffer& key);
00363 
00371     virtual void* getItemContent(StringBuffer& key, size_t* size) = 0;
00372     
00373             
00386     virtual Enumeration* getAllItemList() = 0;      
00387     
00398     virtual int insertItem(SyncItem& item) = 0;
00399 
00407     virtual int modifyItem(SyncItem& item) = 0;
00408 
00417     virtual int removeItem(SyncItem& item) = 0;
00418     
00419 };
00420 
00421 END_NAMESPACE
00422 
00425 #endif

Generated on Wed Jan 14 17:15:36 2009 for Funambol C++ Client Library by  doxygen 1.5.2