00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef INCL_SYNC_MANAGER
00020 #define INCL_SYNC_MANAGER
00021
00025 #include "base/util/ArrayList.h"
00026 #include "http/TransportAgent.h"
00027 #include "spds/constants.h"
00028 #include "spds/SyncManagerConfig.h"
00029 #include "spds/SyncSource.h"
00030 #include "spds/SyncMLBuilder.h"
00031 #include "spds/SyncMLProcessor.h"
00032 #include "spds/CredentialHandler.h"
00033 #include "spds/CredentialHandler.h"
00034 #include "spds/SyncReport.h"
00035
00036
00037 typedef enum {
00038 STATE_START = 0,
00039 STATE_PKG1_SENDING = 1,
00040 STATE_PKG1_SENT = 2,
00041 STATE_PKG3_SENDING = 3,
00042 STATE_PKG3_SENT = 4,
00043 STATE_PKG5_SENDING = 5,
00044 STATE_PKG5_SENT = 6
00045 } SyncManagerState ;
00046
00047
00048
00049 #define DATA_SIZE_TOLERANCE 1.06
00050
00051
00052 static void fillContentTypeInfoList(ArrayList &l, const char* types);
00053
00054
00062 class SyncManager {
00063
00064 public:
00072 SyncManager(SyncManagerConfig& config, SyncReport& report) EXTRA_SECTION_01;
00073 ~SyncManager() EXTRA_SECTION_01;
00074
00075 int prepareSync(SyncSource** sources) EXTRA_SECTION_01;
00076
00077 int sync() EXTRA_SECTION_01;
00078
00079 int endSync() EXTRA_SECTION_01;
00080
00091 virtual DevInf *createDeviceInfo() EXTRA_SECTION_01;
00092
00093 private:
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 static const char encodedKeyPrefix[];
00106
00107 void encodeItemKey(SyncItem *syncItem);
00108 void decodeItemKey(SyncItem *syncItem);
00109
00110
00111 struct CommandInfo {
00112 const char* commandName;
00113 const char* cmdRef;
00114 const char* format;
00115 const char* dataType;
00116 long size;
00117 };
00118
00119 DevInf* devInf;
00120 SyncManagerConfig& config;
00121 SyncReport& syncReport;
00122
00123 CredentialHandler credentialHandler;
00124 SyncMLBuilder syncMLBuilder;
00125 SyncMLProcessor syncMLProcessor;
00126 TransportAgent* transportAgent;
00127
00128 SyncManagerState currentState;
00129 SyncSource** sources;
00130 ArrayList* commands;
00131 ArrayList** mappings;
00132
00133
00134
00135
00136 int sourcesNumber;
00137 int count;
00138
00139
00140
00141
00142
00143 char** sortedSourcesFromServer;
00144
00145 ArrayList** allItemsList;
00146
00147 StringBuffer syncURL;
00148 StringBuffer deviceId;
00149 int responseTimeout;
00150 int maxMsgSize;
00151 int maxObjSize;
00152 BOOL loSupport;
00153 unsigned int maxModPerMsg;
00154 unsigned int readBufferSize;
00155 char credentialInfo[1024];
00156
00157
00158
00159
00160
00161 class IncomingSyncItem : public SyncItem {
00162 public:
00163 IncomingSyncItem(const WCHAR* key,
00164 const CommandInfo &cmdInfo,
00165 int currentSource) :
00166 SyncItem(key),
00167 offset(0),
00168 cmdName(cmdInfo.commandName),
00169 cmdRef(cmdInfo.cmdRef),
00170 sourceIndex(currentSource) {
00171 }
00172
00173 long offset;
00174 const StringBuffer cmdName;
00175 const StringBuffer cmdRef;
00176 const int sourceIndex;
00177 } *incomingItem;
00178
00179 void initialize() EXTRA_SECTION_01;
00180 BOOL readSyncSourceDefinition(SyncSource& source) EXTRA_SECTION_01;
00181 BOOL commitChanges(SyncSource& source) EXTRA_SECTION_01;
00182 int assignSources(SyncSource** sources) EXTRA_SECTION_01;
00183
00184 Status *processSyncItem(Item* item, const CommandInfo &cmdInfo, SyncMLBuilder &syncMLBuilder) EXTRA_SECTION_01;
00185 BOOL checkForServerChanges(SyncML* syncml, ArrayList &statusList) EXTRA_SECTION_01;
00186
00187 const char* getUserAgent(SyncManagerConfig& config) EXTRA_SECTION_01;
00188 bool isToExit();
00189 void setSourceStateAndError(unsigned int index, SourceState state,
00190 unsigned int code, const char* msg);
00191
00192
00193
00194 long getToleranceDataSize(long size);
00195 bool testIfDataSizeMismatch(long allocatedSize, long receivedSize);
00196
00205 SyncItem* getItem(SyncSource& source, SyncItem* (SyncSource::* getItem)());
00206 };
00207
00210 #endif
00211