2 * Copyright (C) 2005-2006 Patrick Ohly
3 * Copyright (C) 2007 Funambol
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef INCL_EVOLUTIONSYNCCLIENT
21 #define INCL_EVOLUTIONSYNCCLIENT
25 #include "EvolutionSmartPtr.h"
26 #include "SyncEvolutionConfig.h"
27 #include <client/SyncClient.h>
28 #include <spds/SyncManagerConfig.h>
37 * This is the main class inside sync4jevolution which
38 * looks at the configuration, activates all enabled
39 * sources and executes the synchronization.
42 class EvolutionSyncClient : public SyncClient, public EvolutionSyncConfig, public ConfigUserInterface {
43 const string m_server;
44 const set<string> m_sources;
45 const bool m_doLogging;
50 * a pointer to the active SourceList instance if one exists;
51 * used for error handling in throwError() on the iPhone
53 static SourceList *m_sourceListPtr;
57 * @param server identifies the server config to be used
58 * @param syncMode setting this overrides the sync mode from the config
59 * @param doLogging write additional log and datatbase files about the sync
61 EvolutionSyncClient(const string &server,
62 bool doLogging = false,
63 const set<string> &sources = set<string>());
64 ~EvolutionSyncClient();
67 * A helper function which interactively asks the user for
68 * a certain password. May throw errors.
70 * The default implementation uses stdin/stdout to communicate
73 * @param descr A simple string explaining what the password is needed for,
74 * e.g. "SyncML server". Has to be unique and understandable
76 * @return entered password
78 virtual string askPassword(const string &descr);
80 bool getQuiet() { return m_quiet; }
81 void setQuiet(bool quiet) { m_quiet = quiet; }
82 SyncMode getSyncMode() { return m_syncMode; }
83 void setSyncMode(SyncMode syncMode) { m_syncMode = syncMode; }
86 * Executes the sync, throws an exception in case of failure.
87 * Handles automatic backups and report generation.
92 * Determines the log directory of the previous sync (either in
93 * temp or logdir) and shows changes since then.
98 * throws a runtime_error with the given string
99 * or (on the iPhone, where exception handling is not
100 * supported by the toolchain) prints an error directly
103 * @param error a string describing the error
105 static void throwError(const string &error);
108 * An error handler which prints the error message and then
109 * stops the program. Never returns.
111 * The API was chosen so that it can be used as libebook/libecal
112 * "backend-dies" signal handler.
114 static void fatalError(void *object, const char *error);
117 * When using Evolution this function starts a background thread
118 * which drives the default event loop. Without that loop
119 * "backend-died" signals are not delivered. The problem with
120 * the thread is that it seems to interfere with gconf startup
121 * when added to the main() function of syncevolution. Therefore
122 * it is started by EvolutionSyncSource::beginSync() (for unit
123 * testing of sync sources) and EvolutionSyncClient::sync() (for
126 static void startLoopThread();
129 /* AbstractSyncConfig API */
130 virtual AbstractSyncSourceConfig* getAbstractSyncSourceConfig(const char* name) const;
131 virtual AbstractSyncSourceConfig* getAbstractSyncSourceConfig(unsigned int i) const;
132 virtual unsigned int getAbstractSyncSourceConfigsCount() const;
136 * Callback for derived classes: called after setting up the client's
137 * and sources' configuration. Can be used to reconfigure before
138 * actually starting the synchronization.
140 * @param sources a NULL terminated array of all active sources
142 virtual void prepare(SyncSource **sources);
146 * the code common to init() and status():
147 * populate source list with active sources and open
148 * them for reading without changing their state yet
150 void initSources(SourceList &sourceList);
153 #endif // INCL_EVOLUTIONSYNCCLIENT