src/include/common/spds/SyncMLBuilder.h

00001 /*
00002  * Copyright (C) 2003-2007 Funambol
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00019 #ifndef INCL_SYNCML_BUILDER
00020 #define INCL_SYNCML_BUILDER
00021 
00023 #include "spds/DataTransformer.h"
00024 #include "spds/SyncSource.h"
00025 #include "spds/SyncMap.h"
00026 #include "syncml/core/TagNames.h"
00027 #include "syncml/core/ObjectDel.h"
00028 #include "syncml/formatter/Formatter.h"
00029 
00030 class SyncMLBuilder {
00031 
00032     public:
00033         SyncMLBuilder() EXTRA_SECTION_01;
00034         ~SyncMLBuilder() EXTRA_SECTION_01;
00035         SyncMLBuilder(char*  t, char*  d) EXTRA_SECTION_01;
00036         
00037         /*
00038          * Convert the SyncML object into an xml message
00039          */
00040         char*  prepareMsg(SyncML* syncml) EXTRA_SECTION_01;        
00041         
00042         /*
00043          * Convert the SyncML object into an xml message
00044          */       
00045         SyncML*  prepareSyncML(ArrayList* commands, BOOL final) EXTRA_SECTION_01;
00046          
00047         /*
00048         * Set init parameters.
00049         *
00050         */
00051         void     set(const char* t, const char* d) EXTRA_SECTION_01;
00052         
00053         /*
00054         * Prepare the init SyncML* message with credential and db alert to sync
00055         *
00056         * @param maxMsgSize       used as MaxMsgSize value in Meta part of the message unless 0
00057         * @param maxObjSize       used as MaxObjSize value in Meta part of the message unless 0
00058         */
00059         SyncML*  prepareInitObject(Cred* cred, ArrayList* alerts, ArrayList* commands,
00060                                    unsigned long maxMsgSize = 0, unsigned long maxObjSize = 0) EXTRA_SECTION_01;
00061         
00062         /*
00063         * Prepare the SyncHdr message with credential if not null
00064         *
00065         * @param maxMsgSize       used as MaxMsgSize value in Meta part of the message unless 0
00066         * @param maxObjSize       used as MaxObjSize value in Meta part of the message unless 0
00067         */        
00068         SyncHdr* prepareSyncHdr(Cred* cred, unsigned long maxMsgSize = 0, unsigned long maxObjSize = 0) EXTRA_SECTION_01;
00069 
00070         /*
00071         * Prepare the init alert
00072         */
00073         Alert*   prepareInitAlert(SyncSource& source, unsigned long maxObjSize = 0) EXTRA_SECTION_01;
00074         
00075         /*
00076         * Prepare the special init alert for Address Change Notification
00077         */
00078         Alert*   prepareAddrChangeAlert(SyncSource& source) EXTRA_SECTION_01;
00079         
00080         /*
00081         * Prepare alert with a specific code, defaults to 222 which requests
00082         * the server changes.
00083         */ 
00084         Alert*   prepareAlert(SyncSource& source, int code=222) EXTRA_SECTION_01;
00085 
00086         /*
00087         * Prepare the status for Sync Header
00088         */ 
00089         Status*  prepareSyncHdrStatus(Chal* chal, int data) EXTRA_SECTION_01;
00090         
00091         /*
00092         * Prepare the status for Alert command
00093         */
00094         Status*  prepareAlertStatus(SyncSource& s,  ArrayList* alert, int authStatusCode) EXTRA_SECTION_01;
00095 
00096         /*
00097         * Prepare the status for Item command. COMMAND could be ADD, REPLACE, DEL
00098         */
00099         Status*  prepareItemStatus(const char*  COMMAND, const char*  key, const char*  cmdRef, int code) EXTRA_SECTION_01;
00100         
00101         /*
00102         * Add the status to the corrent list of commands. It is responsible to collapse the status if needed
00103         */ 
00104         void     addItemStatus(ArrayList* previousStatus, Status* status) EXTRA_SECTION_01;
00105 
00106         /*
00107         * Prepare the status for Sync command
00108         */
00109         Status*  prepareSyncStatus(SyncSource& source, Sync* sync) EXTRA_SECTION_01;
00110 
00114         Status* prepareCmdStatus(AbstractCommand &cmd, int status) EXTRA_SECTION_01;
00115 
00120         AbstractCommand *prepareDevInf(AbstractCommand *cmd, DevInf &devInf) EXTRA_SECTION_01;
00121         
00122         /*
00123         * Prepare the Sync object. It doesn't contain any items. It is to prepare the insert of items
00124         */
00125         Sync*    prepareSyncCommand(SyncSource& source) EXTRA_SECTION_01;
00126         
00127         /*
00128         * Prepare the Map object. It doesn't containt anything. It is to prepare the insert of map items
00129         */
00130         Map*     prepareMapCommand(SyncSource& source)EXTRA_SECTION_01;
00131         
00132         /*
00133         * Prepare the MapItem. It could contain only one MapItem
00134         */
00135         MapItem* prepareMapItem(SyncMap* syncMap) EXTRA_SECTION_01;
00136 
00137         /*
00138          * @param[in, out] syncItemOffset           number of bytes of item data already sent, continue there and update it
00139          * @param maxBytes                          maximum amount of item data to send; always send at least one byte to ensure progress
00140          * @param[out] sentBytes                    number of bytes actually included in message
00141          */
00142         ArrayList* prepareItem(SyncItem* syncItem,
00143                                long &syncItemOffset, long maxBytes, long &sentBytes,
00144                                const char*  type, char*  COMMAND);
00145 
00146         /*
00147         * Add the MapItem to the Map command.
00148         */
00149         void     addMapItem(Map* map, MapItem* mapItem) EXTRA_SECTION_01;
00150         
00151         /*
00152         * Add a SyncItem into the modificationCommand. It is responsible to collapse if needed.
00153         * If the modificationCommand is NULL, then this is the first item and modificationCommand
00154         * is initialized.
00155         *
00156         * @param[in, out] modificationCommand      new items are added here, created if necessary
00157         * @param[in, out] syncItemOffset           number of bytes of item data already sent, continue there and update it
00158         * @param maxBytes                          maximum amount of item data to send; always send at least one byte to ensure progress
00159         * @param COMMAND                           REPLACE_COMMAND_NAME, ADD_COMMAND_NAME, DELETE_COMMAND_NAME
00160         * @param syncItem                          item to be added, NULL causes the call to return without doing anything
00161         * @param defaultType                       fallback if the syncItem does not define a type
00162         * @return number of bytes of item data included
00163         */
00164         long addItem(ModificationCommand* &modificationCommand,
00165                      long &syncItemOffset, long maxBytes,
00166                      char*  COMMAND, SyncItem* syncItem,
00167                      const char*  defaultType) EXTRA_SECTION_01;
00168         
00169         /*
00170         * Reset the cmdID counter
00171         */
00172         void resetCommandID() EXTRA_SECTION_01;
00173 
00174         /*
00175         * increase the msgID counter
00176         */
00177         void increaseMsgRef() EXTRA_SECTION_01;
00178         
00179         /*
00180         * reset MsgId counter
00181         */
00182         
00183         void resetMessageID() EXTRA_SECTION_01;
00184         
00185         /*
00186         * reset MsgRef counter
00187         */
00188         void resetMsgRef();
00189 
00190     private:
00191 
00192         void initialize();
00193 
00194         char*  target;
00195         char*  device;
00196 
00197         unsigned long sessionID;
00198         unsigned int  msgID    ;
00199         unsigned int  cmdID    ;
00200         unsigned int  msgRef   ;
00201         
00202         ComplexData* getComplexData(SyncItem* syncItem, long &syncItemOffset, long maxBytes, long &sentBytes);
00203 
00204 };
00205 
00207 #endif

Generated on Fri Apr 27 12:29:18 2007 for Funambol C++ Client Library by  doxygen 1.5.2