src/include/common/spds/SyncMLBuilder.h

00001 /*
00002  * Funambol is a mobile platform developed by Funambol, Inc. 
00003  * Copyright (C) 2003 - 2007 Funambol, Inc.
00004  * 
00005  * This program is free software; you can redistribute it and/or modify it under
00006  * the terms of the GNU Affero General Public License version 3 as published by
00007  * the Free Software Foundation with the addition of the following permission 
00008  * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
00009  * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
00010  * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  * 
00017  * You should have received a copy of the GNU Affero General Public License 
00018  * along with this program; if not, see http://www.gnu.org/licenses or write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00020  * MA 02110-1301 USA.
00021  * 
00022  * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
00023  * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
00024  * 
00025  * The interactive user interfaces in modified source and object code versions
00026  * of this program must display Appropriate Legal Notices, as required under
00027  * Section 5 of the GNU Affero General Public License version 3.
00028  * 
00029  * In accordance with Section 7(b) of the GNU Affero General Public License
00030  * version 3, these Appropriate Legal Notices must retain the display of the
00031  * "Powered by Funambol" logo. If the display of the logo is not reasonably 
00032  * feasible for technical reasons, the Appropriate Legal Notices must display
00033  * the words "Powered by Funambol".
00034  */
00035 
00036 #ifndef INCL_SYNCML_BUILDER
00037 #define INCL_SYNCML_BUILDER
00038 
00040 #include "spds/DataTransformer.h"
00041 #include "spds/SyncSource.h"
00042 #include "spds/SyncMap.h"
00043 #include "syncml/core/TagNames.h"
00044 #include "syncml/core/ObjectDel.h"
00045 #include "syncml/formatter/Formatter.h"
00046 #include "base/globalsdef.h"
00047 
00048 BEGIN_NAMESPACE
00049 
00050 class SyncMLBuilder {
00051 
00052     public:
00053         SyncMLBuilder();
00054         ~SyncMLBuilder();
00055         SyncMLBuilder(char*  t, char*  d);
00056 
00057         /*
00058          * Convert the SyncML object into an xml message
00059          */
00060         char*  prepareMsg(SyncML* syncml);
00061 
00062         /*
00063          * Convert the SyncML object into an xml message
00064          */
00065         SyncML*  prepareSyncML(ArrayList* commands, bool final);
00066 
00067         /*
00068         * Set init parameters.
00069         *
00070         */
00071         void     set(const char* t, const char* d);
00072 
00073         /*
00074         * Prepare the init SyncML* message with credential and db alert to sync
00075         *
00076         * @param maxMsgSize       used as MaxMsgSize value in Meta part of the message unless 0
00077         * @param maxObjSize       used as MaxObjSize value in Meta part of the message unless 0
00078         */
00079         SyncML*  prepareInitObject(Cred* cred, ArrayList* alerts, ArrayList* commands,
00080                                    unsigned long maxMsgSize = 0, unsigned long maxObjSize = 0);
00081 
00082         /*
00083         * Prepare the SyncHdr message with credential if not null
00084         *
00085         * @param maxMsgSize       used as MaxMsgSize value in Meta part of the message unless 0
00086         * @param maxObjSize       used as MaxObjSize value in Meta part of the message unless 0
00087         */
00088         SyncHdr* prepareSyncHdr(Cred* cred, unsigned long maxMsgSize = 0, unsigned long maxObjSize = 0);
00089 
00090         /*
00091         * Prepare the init alert
00092         */
00093         Alert*   prepareInitAlert(SyncSource& source, unsigned long maxObjSize = 0);
00094 
00095         /*
00096         * Prepare the special init alert for Address Change Notification
00097         */
00098         Alert*   prepareAddrChangeAlert(SyncSource& source);
00099 
00100         /*
00101         * Prepare alert with a specific code, defaults to 222 which requests
00102         * the server changes.
00103         */
00104         Alert*   prepareAlert(SyncSource& source, int code=222);
00105 
00106         /*
00107         * Prepare the status for Sync Header
00108         */
00109         Status*  prepareSyncHdrStatus(Chal* chal, int data);
00110 
00111         /*
00112         * Prepare the status for Alert command
00113         */
00114         Status*  prepareAlertStatus(SyncSource& s,  ArrayList* alert, int authStatusCode);
00115 
00116         /*
00117         * Prepare the status for Item command. COMMAND could be ADD, REPLACE, DEL
00118         */
00119         Status*  prepareItemStatus(const char*  COMMAND, const char*  key, const char*  cmdRef, int code);
00120 
00121         /*
00122         * Add the status to the corrent list of commands. It is responsible to collapse the status if needed
00123         */
00124         void     addItemStatus(ArrayList* previousStatus, Status* status);
00125 
00126         /*
00127         * Prepare the status for Sync command
00128         */
00129         Status*  prepareSyncStatus(SyncSource& source, Sync* sync);
00130 
00134         Status* prepareCmdStatus(AbstractCommand &cmd, int status);
00135 
00140         AbstractCommand *prepareDevInf(AbstractCommand *cmd, DevInf &devInf);
00141 
00142         /*
00143         * Prepare the Sync object. It doesn't contain any items. It is to prepare the insert of items
00144         */
00145         Sync*    prepareSyncCommand(SyncSource& source);
00146 
00147         /*
00148         * Prepare the Map object. It doesn't containt anything. It is to prepare the insert of map items
00149         */
00150         Map*     prepareMapCommand(SyncSource& source);
00151 
00152         /*
00153         * Prepare the MapItem. It could contain only one MapItem
00154         */
00155         MapItem* prepareMapItem(SyncMap* syncMap);
00156 
00157         /*
00158          * @param[in, out] syncItemOffset           number of bytes of item data already sent, continue there and update it
00159          * @param maxBytes                          maximum amount of item data to send; always send at least one byte to ensure progress
00160          * @param[out] sentBytes                    number of bytes actually included in message
00161          */
00162         ArrayList* prepareItem(SyncItem* syncItem,
00163                                long &syncItemOffset, long maxBytes, long &sentBytes,
00164                                const char*  type, char*  COMMAND);
00165 
00166         /*
00167         * Add the MapItem to the Map command.
00168         */
00169         void     addMapItem(Map* map, MapItem* mapItem);
00170 
00171         /*
00172         * Add a SyncItem into the modificationCommand. It is responsible to collapse if needed.
00173         * If the modificationCommand is NULL, then this is the first item and modificationCommand
00174         * is initialized.
00175         *
00176         * @param[in, out] modificationCommand      new items are added here, created if necessary
00177         * @param[in, out] syncItemOffset           number of bytes of item data already sent, continue there and update it
00178         * @param maxBytes                          maximum amount of item data to send; always send at least one byte to ensure progress
00179         * @param COMMAND                           REPLACE_COMMAND_NAME, ADD_COMMAND_NAME, DELETE_COMMAND_NAME
00180         * @param syncItem                          item to be added, NULL causes the call to return without doing anything
00181         * @param defaultType                       fallback if the syncItem does not define a type
00182         * @return number of bytes of item data included
00183         */
00184         long addItem(ModificationCommand* &modificationCommand,
00185                      long &syncItemOffset, long maxBytes,
00186                      char*  COMMAND, SyncItem* syncItem,
00187                      const char*  defaultType);
00188 
00189         /*
00190         * Reset the cmdID counter
00191         */
00192         void resetCommandID();
00193 
00194         /*
00195         * increase the msgID counter
00196         */
00197         void increaseMsgRef();
00198 
00199         /*
00200         * reset MsgId counter
00201         */
00202 
00203         void resetMessageID();
00204 
00205         /*
00206         * reset MsgRef counter
00207         */
00208         void resetMsgRef();
00209 
00210     private:
00211 
00212         void initialize();
00213 
00214         char*  target;
00215         char*  device;
00216 
00217         unsigned long sessionID;
00218         unsigned int  msgID    ;
00219         unsigned int  cmdID    ;
00220         unsigned int  msgRef   ;
00221 
00222         ComplexData* getComplexData(SyncItem* syncItem, long &syncItemOffset, long maxBytes, long &sentBytes);
00223 
00224 };
00225 
00226 
00227 END_NAMESPACE
00228 
00230 #endif

Generated on Tue Jun 10 17:20:21 2008 for Funambol C++ Client Library by  doxygen 1.5.2