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_SYNCSOURCEREPORT 00037 #define INCL_SYNCSOURCEREPORT 00038 /** @cond API */ 00039 /** @addtogroup Client */ 00040 /** @{ */ 00041 00042 #include "base/fscapi.h" 00043 #include "base/Log.h" 00044 #include "base/util/utils.h" 00045 #include "spds/constants.h" 00046 #include "event/constants.h" 00047 #include "spds/ItemReport.h" 00048 #include "base/globalsdef.h" 00049 00050 BEGIN_NAMESPACE 00051 00052 00053 /** Possible states of syncsource (state member) */ 00054 typedef enum SourceState{ 00055 SOURCE_ACTIVE = 0, /**< source is part of the current sync and in a sane state */ 00056 SOURCE_INACTIVE = 1, /**< source was excluded from the current sync before starting it */ 00057 SOURCE_ERROR = 2, /**< source encountered and error sometime during the sync */ 00058 } SourceState; 00059 00060 00061 /** 00062 * SyncSourceReport class rapresents the report of each 00063 * SyncSource synchronized. It is used to store the sync results 00064 * for a specific syncsource, its state (active/inactive/error) and 00065 * the status of each item synchronized (both on client and server side). 00066 */ 00067 class SyncSourceReport { 00068 00069 private: 00070 00071 // The error code of the last error occurred for this source. 00072 int lastErrorCode; 00073 00074 // The error message of the last error occurred for this source. 00075 char* lastErrorMsg; 00076 00077 // The source name. 00078 char* sourceName; 00079 00080 // The source state, possible values: 00081 // 0 = SOURCE_ACTIVE -> used in synchronization 00082 // 1 = SOURCE_INACTIVE -> ignored in synchronization 00083 // 2 = SOURCE_ERROR -> error occurred, will be skipped in sync 00084 SourceState state; 00085 00086 // List of ItemReports for client modifications 00087 ArrayList* clientAddItems; 00088 ArrayList* clientModItems; 00089 ArrayList* clientDelItems; 00090 00091 // List of ItemReports for server modifications 00092 ArrayList* serverAddItems; 00093 ArrayList* serverModItems; 00094 ArrayList* serverDelItems; 00095 00096 00097 // Return true if status is [200 <-> 299] (successful) 00098 bool isSuccessful(const int status); 00099 00100 // Function to initialize members. 00101 void initialize(); 00102 00103 /* 00104 * Assign this object with the given SyncReport 00105 * @param sr the syncReport object 00106 */ 00107 void assign(const SyncSourceReport& ssr); 00108 00109 00110 public: 00111 00112 SyncSourceReport(const char* name = NULL); 00113 SyncSourceReport(SyncSourceReport& ssr); 00114 virtual ~SyncSourceReport(); 00115 00116 /** source specific error code, see also SyncReport::getLastErrorCode() */ 00117 const int getLastErrorCode() const; 00118 00119 /** the current state of the source, see SourceState */ 00120 const SourceState getState() const; 00121 00122 /** source specific error message, see also SyncReport::getLastErrorMsg() */ 00123 const char* getLastErrorMsg() const; 00124 00125 /** the unique name of the source that this report is about */ 00126 const char* getSourceName() const; 00127 00128 void setLastErrorCode(const int code); 00129 void setState (const SourceState s); 00130 void setLastErrorMsg (const char* msg); 00131 void setSourceName (const char* name); 00132 00133 /** 00134 * Check the state of this source. 00135 * Returns true if source is active (state = SOURCE_ACTIVE). 00136 */ 00137 bool checkState(); 00138 00139 00140 /** 00141 * Get internal pointer to a specific ItemReport. 00142 * 00143 * @param target to select if client/server side (values = CLIENT - SERVER) 00144 * @param command to select the desired list of ItemReport (values = Add - Replace - Delete) 00145 * @param index the index of desired item inside the list 00146 * 00147 */ 00148 ItemReport* getItemReport(const char* target, const char* command, int index); 00149 00150 00151 /** 00152 * Return the total number of ItemReport for a specific list. 00153 * 00154 * @param target to select if client/server side (values = CLIENT - SERVER) 00155 * @param command to select the desired list of ItemReport (values = Add - Replace - Delete) 00156 * 00157 */ 00158 int getItemReportCount (const char* target, const char* command); 00159 // Only for successful reports. 00160 int getItemReportSuccessfulCount (const char* target, const char* command); 00161 // Only for failed reports. 00162 int getItemReportFailedCount (const char* target, const char* command); 00163 // Only for code = 418 (ALREADY_EXIST) 00164 int getItemReportAlreadyExistCount(const char* target, const char* command); 00165 00166 00167 /** 00168 * Used to add an ItemReport to a specific list. 00169 * This function is called inside API to store the status of each item 00170 * added/modified/deleted on client and on server. 00171 * 00172 * @param target to select if client/server side (values = CLIENT - SERVER) 00173 * @param command to select the desired list of ItemReport (values = Add - Replace - Delete) 00174 * @param ID the LUID of item (used to create the ItemReport element) 00175 * @param status the status code of the operation (used to create the ItemReport element) 00176 * @param statusMessage the status message associated to the operation (used to create the ItemReport element) 00177 * 00178 */ 00179 void addItem(const char* target, const char* command, const WCHAR* ID, const int status, const WCHAR* statusMessage); 00180 00181 00182 00183 /** 00184 * Utility to switch on the right list, based on target and command. 00185 * 00186 * @param target to select if client/server side (values = CLIENT - SERVER) 00187 * @param command to select the desired list of ItemReport (values = Add - Replace - Delete) 00188 * @return a pointer to the desired ArrayList 00189 * 00190 */ 00191 ArrayList* getList(const char* target, const char* command) const; 00192 00193 /** 00194 * all valid strings for "target", NULL terminated 00195 */ 00196 static const char* const targets[]; 00197 00198 /** 00199 * all valid strings for "command", NULL terminated 00200 */ 00201 static const char* const commands[]; 00202 00203 /** 00204 * Assign operator 00205 */ 00206 SyncSourceReport& operator = (const SyncSourceReport& ssr) { 00207 assign(ssr); 00208 return *this; 00209 } 00210 }; 00211 00212 00213 END_NAMESPACE 00214 00215 /** @} */ 00216 /** @endcond */ 00217 #endif 00218