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/util/ArrayList.h"
00043 #include "http/TransportAgent.h"
00044 #include "spds/constants.h"
00045 #include "spds/SyncManagerConfig.h"
00046 #include "spds/SyncSource.h"
00047 #include "spds/SyncMLBuilder.h"
00048 #include "spds/SyncMLProcessor.h"
00049 #include "spds/CredentialHandler.h"
00050 #include "spds/CredentialHandler.h"
00051 #include "spds/SyncReport.h"
00052
00053
00054 typedef enum {
00055 STATE_START = 0,
00056 STATE_PKG1_SENDING = 1,
00057 STATE_PKG1_SENT = 2,
00058 STATE_PKG3_SENDING = 3,
00059 STATE_PKG3_SENT = 4,
00060 STATE_PKG5_SENDING = 5,
00061 STATE_PKG5_SENT = 6
00062 } SyncManagerState ;
00063
00064
00065
00066 #define DATA_SIZE_TOLERANCE 1.06
00067
00068
00069 static void fillContentTypeInfoList(ArrayList &l, const char* types);
00070
00071
00079 class SyncManager {
00080
00081 public:
00089 SyncManager(SyncManagerConfig& config, SyncReport& report);
00090 ~SyncManager();
00091
00092 int prepareSync(SyncSource** sources);
00093
00094 int sync();
00095
00096 int endSync();
00097
00108 virtual DevInf *createDeviceInfo();
00109
00110 private:
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 static const char encodedKeyPrefix[];
00123
00124 void encodeItemKey(SyncItem *syncItem);
00125 void decodeItemKey(SyncItem *syncItem);
00126
00127
00128 struct CommandInfo {
00129 const char* commandName;
00130 const char* cmdRef;
00131 const char* format;
00132 const char* dataType;
00133 long size;
00134 };
00135
00136 DevInf* devInf;
00137 SyncManagerConfig& config;
00138 SyncReport& syncReport;
00139
00140 CredentialHandler credentialHandler;
00141 SyncMLBuilder syncMLBuilder;
00142 SyncMLProcessor syncMLProcessor;
00143 TransportAgent* transportAgent;
00144
00145 SyncManagerState currentState;
00146 SyncSource** sources;
00147 ArrayList* commands;
00148 ArrayList** mappings;
00149
00150
00151
00152
00153 int sourcesNumber;
00154 int count;
00155
00156
00157
00158
00159
00160 char** sortedSourcesFromServer;
00161
00162 ArrayList** allItemsList;
00163
00164 StringBuffer syncURL;
00165 StringBuffer deviceId;
00166 int responseTimeout;
00167 int maxMsgSize;
00168 int maxObjSize;
00169 BOOL loSupport;
00170 unsigned int readBufferSize;
00171 char credentialInfo[1024];
00172
00173
00174
00175
00176
00177 class IncomingSyncItem : public SyncItem {
00178 public:
00179 IncomingSyncItem(const WCHAR* key,
00180 const CommandInfo &cmdInfo,
00181 int currentSource) :
00182 SyncItem(key),
00183 offset(0),
00184 cmdName(cmdInfo.commandName),
00185 cmdRef(cmdInfo.cmdRef),
00186 sourceIndex(currentSource) {
00187 }
00188
00189 long offset;
00190 const StringBuffer cmdName;
00191 const StringBuffer cmdRef;
00192 const int sourceIndex;
00193 } *incomingItem;
00194
00195 void initialize();
00196 BOOL readSyncSourceDefinition(SyncSource& source);
00197 BOOL commitChanges(SyncSource& source);
00198 int assignSources(SyncSource** sources);
00199
00200 Status *processSyncItem(Item* item, const CommandInfo &cmdInfo, SyncMLBuilder &syncMLBuilder);
00201 BOOL checkForServerChanges(SyncML* syncml, ArrayList &statusList);
00202
00203 const char* getUserAgent(SyncManagerConfig& config);
00204 bool isToExit();
00205 void setSourceStateAndError(unsigned int index, SourceState state,
00206 unsigned int code, const char* msg);
00207
00208
00209
00210 long getToleranceDataSize(long size);
00211 bool testIfDataSizeMismatch(long allocatedSize, long receivedSize);
00212
00221 SyncItem* getItem(SyncSource& source, SyncItem* (SyncSource::* getItem)());
00222
00227 void addMapCommand(int sourceIndex);
00228 };
00229
00232 #endif
00233