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
00054
00055 #define DATA_SIZE_TOLERANCE 1.06
00056
00057 BEGIN_NAMESPACE
00058
00059 typedef enum {
00060 STATE_START = 0,
00061 STATE_PKG1_SENDING = 1,
00062 STATE_PKG1_SENT = 2,
00063 STATE_PKG3_SENDING = 3,
00064 STATE_PKG3_SENT = 4,
00065 STATE_PKG5_SENDING = 5,
00066 STATE_PKG5_SENT = 6
00067 } SyncManagerState ;
00068
00069
00077 class SyncManager {
00078
00079 public:
00087 SyncManager(AbstractSyncConfig& config, SyncReport& report);
00088 ~SyncManager();
00089
00094 int prepareSync(SyncSource** sources);
00095
00104 int sync();
00105
00109 int endSync();
00110
00121 DevInf *createDeviceInfo();
00122
00123 private:
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 static const char encodedKeyPrefix[];
00136
00137 void encodeItemKey(SyncItem *syncItem);
00138 void decodeItemKey(SyncItem *syncItem);
00139
00140
00141 struct CommandInfo {
00142 const char* commandName;
00143 const char* cmdRef;
00144 const char* format;
00145 const char* dataType;
00146 long size;
00147 };
00148
00149 DevInf* devInf;
00150 AbstractSyncConfig& config;
00151 SyncReport& syncReport;
00152
00153 CredentialHandler credentialHandler;
00154 SyncMLBuilder syncMLBuilder;
00155 SyncMLProcessor syncMLProcessor;
00156 TransportAgent* transportAgent;
00157
00158 SyncManagerState currentState;
00159 SyncSource** sources;
00160 ArrayList commands;
00161 ArrayList* mappings;
00162
00163
00164
00165
00166 int sourcesNumber;
00167 int count;
00168
00169
00170
00171
00172
00173 char** sortedSourcesFromServer;
00174
00175 ArrayList** allItemsList;
00176
00177 StringBuffer syncURL;
00178 StringBuffer deviceId;
00179 int responseTimeout;
00180 int maxMsgSize;
00181 int maxObjSize;
00182 bool loSupport;
00183 unsigned int readBufferSize;
00184 char credentialInfo[1024];
00185
00186
00187
00188
00189
00190 class IncomingSyncItem : public SyncItem {
00191 public:
00192 IncomingSyncItem(const WCHAR* key,
00193 const CommandInfo &cmdInfo,
00194 int currentSource) :
00195 SyncItem(key),
00196 offset(0),
00197 cmdName(cmdInfo.commandName),
00198 cmdRef(cmdInfo.cmdRef),
00199 sourceIndex(currentSource) {
00200 }
00201
00202 long offset;
00203 const StringBuffer cmdName;
00204 const StringBuffer cmdRef;
00205 const int sourceIndex;
00206 } *incomingItem;
00207
00208 void initialize();
00209 bool readSyncSourceDefinition(SyncSource& source);
00210 bool commitChanges(SyncSource& source);
00211 int assignSources(SyncSource** sources);
00212
00213 Status *processSyncItem(Item* item, const CommandInfo &cmdInfo, SyncMLBuilder &syncMLBuilder);
00214 bool checkForServerChanges(SyncML* syncml, ArrayList &statusList);
00215
00216 const char* getUserAgent(AbstractSyncConfig& config);
00217 bool isToExit();
00218 void setSourceStateAndError(unsigned int index, SourceState state,
00219 unsigned int code, const char* msg);
00220
00221
00222
00223 long getToleranceDataSize(long size);
00224 bool testIfDataSizeMismatch(long allocatedSize, long receivedSize);
00225
00234 SyncItem* getItem(SyncSource& source, SyncItem* (SyncSource::* getItem)());
00235
00240 void addMapCommand(int sourceIndex);
00241
00242 };
00243
00244
00245 END_NAMESPACE
00246
00249 #endif
00250