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 
00064 class FileSyncSource : public SyncSource {
00065 
00066 protected:
00067 
00068     // The dir in which the files are and that are to be synced.
00069     char* dir;
00070 
00071     // The copy is protected
00072     FileSyncSource(SyncSource& s);
00073 
00074     // Return true if data correctly set: syncItem->getKey() contains
00075     // the file name relative to dir, copying its content into
00076     // the items data can be overriden by derived classes.
00077     virtual bool setItemData(SyncItem* syncItem);
00078 
00086     int addedItem(SyncItem& item, const WCHAR* key);
00087 
00088 public:
00089     FileSyncSource(const WCHAR* name, SyncSourceConfig* sc);
00090     virtual ~FileSyncSource();
00091 
00097     void setDir(const char* p);
00098     const char* getDir();
00099 
00110     void setFileNode(ManagementNode *mn) { fileNode = mn; }
00111     ManagementNode *getFileNode() { return fileNode; }
00112 
00113     /* SyncSource interface implementations follow */
00114 
00115     SyncItem* getFirstItem() { return getFirst(allItems); }
00116     SyncItem* getNextItem() { return getNext(allItems); }
00117     SyncItem* getFirstNewItem() { return getFirst(newItems); }
00118     SyncItem* getNextNewItem() { return getNext(newItems); }
00119     SyncItem* getFirstUpdatedItem() { return getFirst(updatedItems); }
00120     SyncItem* getNextUpdatedItem() { return getNext(updatedItems); }
00121     SyncItem* getFirstDeletedItem() { return getFirst(deletedItems, FALSE); }
00122     SyncItem* getNextDeletedItem() { return getNext(deletedItems, FALSE); }
00123     SyncItem* getFirstItemKey() { return getFirst(allItems, FALSE); }
00124     SyncItem* getNextItemKey() { return getNext(allItems, FALSE); }
00125     int addItem(SyncItem& item);
00126     int updateItem(SyncItem& item);
00127     int deleteItem(SyncItem& item);
00128     void setItemStatus(const WCHAR* key, int status);
00129     int beginSync();
00130     int endSync();
00131     void assign(FileSyncSource& s);
00132     ArrayElement* clone();
00133 
00134   private:
00135     // Lists of all, new, update and deleted items
00136     // together with the current index.
00137     struct ItemIteratorContainer {
00138         ArrayList items;
00139         int index;
00140     } allItems, newItems, updatedItems, deletedItems;
00141 
00142     // an optional node in which file dates are stored to track changes
00143     ManagementNode* fileNode;
00144 
00146     unsigned long getServerModTime(const char* keystr);
00147 
00148     SyncItem* getFirst(ItemIteratorContainer& container, BOOL getData = TRUE);
00149     SyncItem* getNext(ItemIteratorContainer& container, BOOL getData = TRUE);
00150 };
00151 
00154 #endif

Generated on Thu Mar 6 14:25:04 2008 for Funambol C++ Client Library by  doxygen 1.5.2