src/include/common/client/FileSyncSource.h

00001 /*
00002 * Copyright (C) 2003-2007 Funambol
00003 *
00004 * This program is free software; you can redistribute it and/or modify
00005 * it under the terms of the GNU General Public License as published by
00006 * the Free Software Foundation; either version 2 of the License, or
00007 * (at your option) any later version.
00008 *
00009 * This program is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 * GNU General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 */
00018 
00019 #ifndef INCL_FILE_SYNC_SOURCE
00020 #define INCL_FILE_SYNC_SOURCE
00021 
00025 #include "base/fscapi.h"
00026 #include "spds/constants.h"
00027 #include "spds/SyncItem.h"
00028 #include "spds/SyncMap.h"
00029 #include "spds/SyncStatus.h"
00030 #include "spds/SyncSource.h"
00031 #include "spdm/ManagementNode.h"
00032 #include "base/util/ItemContainer.h"
00033 
00034 
00035 #define ERR_FILE_SYSTEM             1
00036 #define ERR_NO_FILES_TO_SYNC        2
00037 #define ERR_BAD_FILE_CONTENT        3
00038 
00047 class FileSyncSource : public SyncSource {
00048 
00049 protected:
00050 
00051     // The dir in which the files are and that are to be synced.
00052     char* dir;
00053 
00054     // The copy is protected
00055     FileSyncSource(SyncSource& s);
00056 
00057     // Return true if data correctly set: syncItem->getKey() contains
00058     // the file name relative to dir, copying its content into
00059     // the items data can be overriden by derived classes.
00060     virtual bool setItemData(SyncItem* syncItem);
00061 
00069     int addedItem(SyncItem& item, const WCHAR* key);
00070 
00071 public:
00072     FileSyncSource(const WCHAR* name, SyncSourceConfig* sc);
00073     virtual ~FileSyncSource();
00074 
00080     void setDir(const char* p);
00081     const char* getDir();
00082 
00093     void setFileNode(ManagementNode *mn) { fileNode = mn; }
00094     ManagementNode *getFileNode() { return fileNode; }
00095 
00096     /* SyncSource interface implementations follow */
00097     
00098     SyncItem* getFirstItem() { return getFirst(allItems); }
00099     SyncItem* getNextItem() { return getNext(allItems); }
00100     SyncItem* getFirstNewItem() { return getFirst(newItems); }
00101     SyncItem* getNextNewItem() { return getNext(newItems); }
00102     SyncItem* getFirstUpdatedItem() { return getFirst(updatedItems); }
00103     SyncItem* getNextUpdatedItem() { return getNext(updatedItems); }
00104     SyncItem* getFirstDeletedItem() { return getFirst(deletedItems, FALSE); }
00105     SyncItem* getNextDeletedItem() { return getNext(deletedItems, FALSE); }
00106     SyncItem* getFirstItemKey() { return getFirst(allItems, FALSE); }
00107     SyncItem* getNextItemKey() { return getNext(allItems, FALSE); }
00108     int addItem(SyncItem& item);
00109     int updateItem(SyncItem& item);
00110     int deleteItem(SyncItem& item);
00111     void setItemStatus(const WCHAR* key, int status);
00112     int beginSync();
00113     int endSync();
00114     void assign(FileSyncSource& s);
00115     ArrayElement* clone();
00116 
00117   private:
00118     // Lists of all, new, update and deleted items
00119     // together with the current index.
00120     struct ItemIteratorContainer {
00121         ArrayList items;
00122         int index;
00123     } allItems, newItems, updatedItems, deletedItems;
00124 
00125     // an optional node in which file dates are stored to track changes
00126     ManagementNode* fileNode;
00127 
00129     unsigned long getServerModTime(const char* keystr);
00130             
00131     SyncItem* getFirst(ItemIteratorContainer& container, BOOL getData = TRUE);
00132     SyncItem* getNext(ItemIteratorContainer& container, BOOL getData = TRUE);
00133 };
00134 
00137 #endif

Generated on Fri Apr 27 12:29:18 2007 for Funambol C++ Client Library by  doxygen 1.5.2