src/include/common/spds/SyncSourceReport.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_SYNCSOURCEREPORT
00020 #define INCL_SYNCSOURCEREPORT
00021 
00025 #include "base/fscapi.h"
00026 #include "base/Log.h"
00027 #include "base/util/utils.h"
00028 #include "spds/constants.h"
00029 #include "event/constants.h"
00030 #include "spds/ItemReport.h"
00031 
00032 
00034 typedef enum SourceState{
00035     SOURCE_ACTIVE       = 0,        
00036     SOURCE_INACTIVE     = 1,        
00037     SOURCE_ERROR        = 2,        
00038 } SourceState;
00039 
00040 
00047 class SyncSourceReport {
00048 
00049 private:
00050 
00051     // The error code of the last error occurred for this source.
00052     int         lastErrorCode;
00053 
00054     // The error message of the last error occurred for this source.
00055     char*       lastErrorMsg;
00056 
00057     // The source name.
00058     char*       sourceName;
00059 
00060     // The source state, possible values:
00061     // 0 = SOURCE_ACTIVE   -> used in synchronization
00062     // 1 = SOURCE_INACTIVE -> ignored in synchronization
00063     // 2 = SOURCE_ERROR    -> error occurred, will be skipped in sync
00064     SourceState state;
00065 
00066     // List of ItemReports for client modifications
00067     ArrayList*  clientAddItems;
00068     ArrayList*  clientModItems;
00069     ArrayList*  clientDelItems;
00070 
00071     // List of ItemReports for server modifications
00072     ArrayList*  serverAddItems;
00073     ArrayList*  serverModItems;
00074     ArrayList*  serverDelItems;
00075 
00076 
00077     // Return true if status is [200 <-> 299] (successful)
00078     bool isSuccessful(const int status);
00079 
00080     // Function to initialize members.
00081     void initialize();
00082 
00083     /*
00084      * Assign this object with the given SyncReport
00085      * @param sr the syncReport object
00086      */
00087     void assign(const SyncSourceReport& ssr);
00088 
00089 
00090 public:
00091 
00092     SyncSourceReport(const char* name = NULL);
00093     SyncSourceReport(SyncSourceReport& ssr);
00094     virtual ~SyncSourceReport();
00095 
00097     const int   getLastErrorCode() const;
00098 
00100     const SourceState   getState() const;
00101 
00103     const char*  getLastErrorMsg() const;
00104 
00106     const char*    getSourceName() const;
00107 
00108     void setLastErrorCode(const int code);
00109     void setState        (const SourceState s);
00110     void setLastErrorMsg (const char* msg);
00111     void setSourceName   (const char* name);
00112 
00117     bool checkState();
00118 
00119 
00128     ItemReport* getItemReport(const char* target, const char* command, int index);
00129 
00130 
00138     int getItemReportCount            (const char* target, const char* command);
00139     // Only for successful reports.
00140     int getItemReportSuccessfulCount  (const char* target, const char* command);
00141     // Only for failed reports.
00142     int getItemReportFailedCount      (const char* target, const char* command);
00143     // Only for code = 418 (ALREADY_EXIST)
00144     int getItemReportAlreadyExistCount(const char* target, const char* command);
00145 
00146 
00159     void addItem(const char* target, const char* command, const WCHAR* ID, const int status, const WCHAR* statusMessage);
00160 
00161 
00162 
00171     ArrayList* getList(const char* target, const char* command) const;
00172 
00176     static const char* const targets[];
00177     
00181     static const char* const commands[];
00182     
00186     SyncSourceReport& operator = (const SyncSourceReport& ssr) {
00187         assign(ssr);
00188         return *this;
00189     }
00190 };
00191 
00194 #endif
00195 

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