00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef INCL_SYNC_MANAGER
00037 #define INCL_SYNC_MANAGER
00038
00042 #include "base/globalsdef.h"
00043 #include "base/util/ArrayList.h"
00044 #include "http/TransportAgent.h"
00045 #include "spds/constants.h"
00046 #include "spds/AbstractSyncConfig.h"
00047 #include "spds/SyncSource.h"
00048 #include "spds/SyncMLBuilder.h"
00049 #include "spds/SyncMLProcessor.h"
00050 #include "spds/CredentialHandler.h"
00051 #include "spds/CredentialHandler.h"
00052 #include "spds/SyncReport.h"
00053 #include "spds/MappingsManager.h"
00054
00055
00056 #define DATA_SIZE_TOLERANCE 1.06
00057
00058 BEGIN_NAMESPACE
00059
00060 typedef enum {
00061 STATE_START = 0,
00062 STATE_PKG1_SENDING = 1,
00063 STATE_PKG1_SENT = 2,
00064 STATE_PKG3_SENDING = 3,
00065 STATE_PKG3_SENT = 4,
00066 STATE_PKG5_SENDING = 5,
00067 STATE_PKG5_SENT = 6
00068 } SyncManagerState ;
00069
00070
00078 class SyncManager {
00079
00080 public:
00088 SyncManager(AbstractSyncConfig& config, SyncReport& report);
00089 ~SyncManager();
00090
00095 int prepareSync(SyncSource** sources);
00096
00105 int sync();
00106
00110 int endSync();
00111
00122 DevInf *createDeviceInfo();
00123
00132 bool askServerDevInf();
00133
00139 void clearServerDevInf();
00140
00141
00147 void setTransportAgent(TransportAgent* t);
00148
00160 const StringBuffer lookupMappings(Enumeration& mappings, const StringBuffer& guid);
00161
00162
00163 private:
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 static const char encodedKeyPrefix[];
00176
00177 void encodeItemKey(SyncItem *syncItem);
00178 void decodeItemKey(SyncItem *syncItem);
00179
00180
00181 struct CommandInfo {
00182 const char* commandName;
00183 const char* cmdRef;
00184 const char* format;
00185 const char* dataType;
00186 long size;
00187 };
00188
00189 DevInf* devInf;
00190 AbstractSyncConfig& config;
00191 SyncReport& syncReport;
00192
00193 CredentialHandler credentialHandler;
00194 SyncMLBuilder syncMLBuilder;
00195 SyncMLProcessor syncMLProcessor;
00196
00199 TransportAgent* transportAgent;
00200
00201 SyncManagerState currentState;
00202 SyncSource** sources;
00203 ArrayList commands;
00204
00205 MappingsManager** mmanager;
00206
00207
00208
00209 int sourcesNumber;
00210 int count;
00211
00212
00213
00214
00215
00216 char** sortedSourcesFromServer;
00217
00218 StringBuffer syncURL;
00219 StringBuffer deviceId;
00220 int responseTimeout;
00221 int maxMsgSize;
00222 int maxObjSize;
00223 bool loSupport;
00224 unsigned int readBufferSize;
00225 char credentialInfo[1024];
00226
00227
00228
00229
00230
00231 class IncomingSyncItem : public SyncItem {
00232 public:
00233 IncomingSyncItem(const WCHAR* key,
00234 const CommandInfo &cmdInfo,
00235 int currentSource) :
00236 SyncItem(key),
00237 offset(0),
00238 cmdName(cmdInfo.commandName),
00239 cmdRef(cmdInfo.cmdRef),
00240 sourceIndex(currentSource) {
00241 }
00242
00243 long offset;
00244 const StringBuffer cmdName;
00245 const StringBuffer cmdRef;
00246 const int sourceIndex;
00247 } *incomingItem;
00248
00249 void initialize();
00250 bool readSyncSourceDefinition(SyncSource& source);
00251 bool commitChanges(SyncSource& source);
00252 int assignSources(SyncSource** sources);
00253
00254 Status *processSyncItem(Item* item, const CommandInfo &cmdInfo, SyncMLBuilder &syncMLBuilder);
00255 bool checkForServerChanges(SyncML* syncml, ArrayList &statusList);
00256
00267 const char* getUserAgent(AbstractSyncConfig& config);
00268 bool isToExit();
00269 void setSourceStateAndError(unsigned int index, SourceState state,
00270 unsigned int code, const char* msg);
00271
00272
00273
00274 long getToleranceDataSize(long size);
00275 bool testIfDataSizeMismatch(long allocatedSize, long receivedSize);
00276
00285 SyncItem* getItem(SyncSource& source, SyncItem* (SyncSource::* getItem)());
00286
00291 void addMapCommand(int sourceIndex);
00292
00293 };
00294
00295
00296 END_NAMESPACE
00297
00300 #endif
00301