OpenAB  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
OneWaySync.hpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5  */
10 #ifndef ONE_WAY_SYNC_HPP
11 #define ONE_WAY_SYNC_HPP
12 
13 
14 #include <pthread.h>
15 #include "plugin/sync/Sync.hpp"
16 
104 {
105  std::string input_plugin;
107  std::string ab_plugin;
110  enum SyncType
111  {
115  } sync_type;
117  unsigned int batch_size;
118 };
119 
124 {
125  public:
127  ~OneWaySync();
128 
130 
131  void synchronize();
132 
134 
136 
138 
139  void getStats(unsigned int& locallyAdded,
140  unsigned int& locallyModified,
141  unsigned int& locallyRemoved,
142  unsigned int& remotelyAdded,
143  unsigned int& remotelyModified,
144  unsigned int& remotelyRemoved);
145 
146  private:
150  OneWaySync(OneWaySync const &other);
151 
155  OneWaySync& operator=(OneWaySync const &other);
156 
157  void updateIndexDB();
158  void processItems(unsigned int phaseNum);
159  void cleanStorage();
160 
161  void addItem(const OpenAB::SmartPtr<OpenAB::PIMItem> & item);
162  void modifyItem(const std::string& id, const OpenAB::SmartPtr<OpenAB::PIMItem> & item);
163  bool flushInsertions();
164  bool flushModifications();
165 
166  enum eSync doSynchronize();
167  static void* threadSync(void*);
168 
169  struct SyncStats {
170  void clean(){
171  added = 0;
172  modified = 0;
173  removed = 0;
174  };
175  unsigned int added;
176  unsigned int modified;
177  unsigned int removed;
178  pthread_mutex_t mutex;
179 
180  };
181 
182  SyncStats phaseStats;
183  SyncStats globalStats;
184 
185  OpenAB_Sync_params params;
186 
187  OpenAB_Source::Source* source;
188  OpenAB_Storage::Storage* storage;
189 
190  typedef std::vector< OpenAB::SmartPtr<OpenAB_Storage::StorageItem> > vectorElem;
191  typedef std::map< OpenAB::SmartPtr<OpenAB::PIMItemIndex> , vectorElem > dbIndexElem;
192  dbIndexElem indexDB;
193 
194  struct ItemDesc
195  {
196  ItemDesc(const std::string& _id, OpenAB::SmartPtr<OpenAB::PIMItem> vcard) :
197  id (_id),
198  item (vcard){}
199 
200  std::string id;
202  };
203 
204  std::vector<ItemDesc> itemsToBeAdded;
205  std::vector<ItemDesc> itemsToBeModified;
206 
207  bool dbError;
208  bool inputError;
209 
210  pthread_t syncThread;
211  pthread_mutex_t syncMutex;
212  bool threadCreated;
213  bool syncInProgress;
214  eSync lastSyncResult;
215  bool cancelSync;
216 };
217 
218 #endif /* ONE_WAY_SYNC_HPP */
eInit
Definition: Sync.hpp:142
Definition: OneWaySync.hpp:114
Definition: OneWaySync.hpp:112
~OneWaySync()
Definition: OneWaySync.cpp:68
float sync_progress_time
Definition: OneWaySync.hpp:116
enum OpenAB_Sync_params::SyncType sync_type
SyncType
Definition: OneWaySync.hpp:110
Sync Class providing all the Sync controls.
Definition: OneWaySync.hpp:123
OneWaySync(OpenAB_Sync_params &)
Definition: OneWaySync.cpp:40
Documentation for Storage plugin interface. Generic interface is modeled over Sync Plugin specific re...
Definition: Storage.hpp:106
enum OpenAB_Sync::Sync::eResume resume()
Resumes synchronization (if used OpenAB_Source::Source plugin supports it)
Definition: OneWaySync.cpp:208
enum OpenAB_Sync::Sync::eInit init()
Initializes Sync.
Definition: OneWaySync.cpp:93
eCancel
Definition: Sync.hpp:172
unsigned int batch_size
Definition: OneWaySync.hpp:117
void synchronize()
Synchronizes data.
Definition: OneWaySync.cpp:132
OpenAB_Source::Parameters input_params
The parameters required by the Input plugin used.
Definition: OneWaySync.hpp:106
Set of parameters required to perform the synchronization.
Definition: OneWaySync.hpp:103
eResume
Definition: Sync.hpp:202
Documentation for Source plugin interface.
Definition: Source.hpp:76
Virtual class that provide all the callback routines to control the synchronization.
Definition: Sync.hpp:249
OpenAB_Sync::Sync::SyncCallback * cb
The Callback object.
Definition: OneWaySync.hpp:109
OpenAB_Storage::Parameters ab_params
The parameters required by the AB plugin used.
Definition: OneWaySync.hpp:108
void getStats(unsigned int &locallyAdded, unsigned int &locallyModified, unsigned int &locallyRemoved, unsigned int &remotelyAdded, unsigned int &remotelyModified, unsigned int &remotelyRemoved)
Returns statistics of synchronization.
Definition: OneWaySync.cpp:231
std::string ab_plugin
The name of the AB (Address Book) plugin.
Definition: OneWaySync.hpp:107
std::string input_plugin
The name of the Input plugin.
Definition: OneWaySync.hpp:105
enum OpenAB_Sync::Sync::eCancel cancel()
Cancels synchronization.
Definition: OneWaySync.cpp:165
Definition: OneWaySync.hpp:113
Documentation for class Sync plugin interface.
Definition: Sync.hpp:126
eSuspend
Definition: Sync.hpp:187
enum OpenAB_Sync::Sync::eSuspend suspend()
Suspends synchronization (if used OpenAB_Source::Source plugin supports it)
Definition: OneWaySync.cpp:185
Generic storage for plugin parameters. Allows to store map of parameters with different types (OpenAB...
Definition: GenericParameters.hpp:25
eSync
Definition: Sync.hpp:156