src/include/common/client/FileSyncSource.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_FILE_SYNC_SOURCE
00037 #define INCL_FILE_SYNC_SOURCE
00038 
00042 #include "base/fscapi.h"
00043 #include "spds/constants.h"
00044 #include "spds/SyncItem.h"
00045 #include "spds/SyncMap.h"
00046 #include "spds/SyncStatus.h"
00047 #include "spds/SyncSource.h"
00048 #include "spdm/ManagementNode.h"
00049 #include "base/util/ItemContainer.h"
00050 
00051 
00052 #define ERR_FILE_SYSTEM             1
00053 #define ERR_NO_FILES_TO_SYNC        2
00054 #define ERR_BAD_FILE_CONTENT        3
00055 #include "base/globalsdef.h"
00056 
00057 BEGIN_NAMESPACE
00058 
00067 class FileSyncSource : public SyncSource {
00068 
00069 protected:
00070     
00071     // The dir in which the files are and that are to be synced.
00072     char* dir;
00073 
00074     // The copy is protected
00075     FileSyncSource(SyncSource& s);
00076     
00077     // Return true if data correctly set: syncItem->getKey() contains
00078     // the file name relative to dir, copying its content into
00079     // the items data can be overriden by derived classes.
00080     virtual bool setItemData(SyncItem* syncItem);
00081 
00089     int addedItem(SyncItem& item, const WCHAR* key);
00090       
00091 public:
00092     FileSyncSource(const WCHAR* name, AbstractSyncSourceConfig* sc);
00093     virtual ~FileSyncSource();
00094     
00100     void setDir(const char* p);
00101     const char* getDir();
00102     
00113     void setFileNode(ManagementNode *mn) { fileNode = mn; }
00114     ManagementNode *getFileNode() { return fileNode; }
00115 
00116     /* SyncSource interface implementations follow */
00117 
00118     SyncItem* getFirstItem() { return getFirst(allItems); }
00119     SyncItem* getNextItem() { return getNext(allItems); }
00120     SyncItem* getFirstNewItem() { return getFirst(newItems); }
00121     SyncItem* getNextNewItem() { return getNext(newItems); }
00122     SyncItem* getFirstUpdatedItem() { return getFirst(updatedItems); }
00123     SyncItem* getNextUpdatedItem() { return getNext(updatedItems); }
00124     SyncItem* getFirstDeletedItem() { return getFirst(deletedItems, false); }
00125     SyncItem* getNextDeletedItem() { return getNext(deletedItems, false); }
00126     SyncItem* getFirstItemKey() { return getFirst(allItems, false); }
00127     SyncItem* getNextItemKey() { return getNext(allItems, false); }
00128     int addItem(SyncItem& item);
00129     int updateItem(SyncItem& item);
00130     int deleteItem(SyncItem& item);
00131     void setItemStatus(const WCHAR* key, int status);
00132     int removeAllItems();
00133     int beginSync();
00134     int endSync();
00135     void assign(FileSyncSource& s);
00136 
00137   private:
00138     // Lists of all, new, update and deleted items
00139     // together with the current index.
00140     struct ItemIteratorContainer {
00141         ArrayList items;
00142         int index;
00143     } allItems, newItems, updatedItems, deletedItems;
00144     
00145     // an optional node in which file dates are stored to track changes
00146     ManagementNode* fileNode;
00147     
00149     unsigned long getServerModTime(const char* keystr);
00150 
00151     SyncItem* getFirst(ItemIteratorContainer& container, bool getData = true);
00152     SyncItem* getNext(ItemIteratorContainer& container, bool getData = true);
00153 };
00154 
00155 
00156 END_NAMESPACE
00157 
00160 #endif

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