📄 syncclient.h
字号:
/*
* Copyright (C) 2003-2007 Funambol, Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
#ifndef INCL_SYNCCLIENT
#define INCL_SYNCCLIENT
/** @cond API */
/** @addtogroup Client */
/** @{ */
#include "base/fscapi.h"
#include "base/Log.h"
#include "spds/SyncManagerConfig.h"
#include "spds/SyncSource.h"
#include "spds/constants.h"
#include "spds/SyncReport.h"
/**
* This class wraps the common operations executed by a typical
* client. It contains default implementations for calls invoked
* by the library core to parameterize or control the
* synchronization. A client can override these calls by
* subclassing SyncClient and using an instance of its own class
* instead.
*
* Warning: the library contains global data in several different
* places. Therefore it is not possible to execute multiple
* sessions in parallel.
*/
class SyncClient {
public:
SyncClient();
virtual ~SyncClient();
/*
* Execute a synchronization on the specified sources.
* The sources will be configured automatically using the
* client configuration set in the constructor.
*
* @param config - the configuration to be used for this sync
* @param sources - NULL terminated array of sources to sync.
*
* @return - 0 on success, an error otherwise
*/
virtual int sync(SyncManagerConfig& config, SyncSource** sources);
/**
* Execute a synchronization with sources that are chosen based
* on the sourceNames param or, if sourceNames is NULL, based
* on the configuration: in this case all available sources will be used.
*
* - calls prepareSync() to give a derived class the chance to
* setup syncing and get ready for creating sources
* - iterates over sources to sync, asks for the corresponding
* client source with createSource()
* - calls beginSync() to give the derived class a class to do
* after all sources have been configured successfully
* - executes the synchronization: call sync(sources**)
*
* This version of the call is easier to use for clients whose
* sync sources are determined by the configuration or by an array
* of desired sources to sync
*
* @param config: the configuration to be used for this sync
* @param sourceNames: optional, a NULL terminated array of source names that
* we want to sync. If NULL, sources to sync are chosen
* from the configuration.
* @return 0 on success, an error otherwise
*/
virtual int sync(SyncManagerConfig& config, char** sourceNames = NULL);
/*
* Returns a pointer to the internal syncReport.
* Used to get detailed results on the executed synchronization.
* Must be called after sync() method.
*/
SyncReport* getSyncReport();
protected:
/**
* A callback into a derived class which is called after
* reading the SyncML configuration and before creating sources.
* Not used by the sync(SyncSource**) call.
*
* @param config a reference to SyncManager configuration
* can be used to read client specific properties
* @return 0 for success, an error code otherwise - an error code
* aborts the whole synchronization
*/
virtual int prepareSync(SyncManagerConfig& config) {
return ERR_NONE;
}
/**
* A factory method that is used by the sync() call to create
* the sync sources that are to be synchronized. Not used by the
* sync(SyncSource**) call.
*
* @param name name of the sync source
* @param pos position of the SyncSource in the SSConfig array
* (index: 0 - numSources-1)
* @param config a pointer to the source's configuration: this
* includes all properties that the client library
* knows and uses itself (only valid during this call)
* This pointer is owned by SyncManagerConfig, sources uses it
* to initialize the internal config by reference.
* @retval source the sync source created by the client or NULL if
* there is no sync source currently associated with
* the config or it is inactive; instance is a new SyncSource*
* and it's freed by the caller (see finally)
* @return 0 for success, an error code otherwise - an error code
* aborts the whole synchronization and the value of *source is
* ignored
*/
virtual int createSyncSource(const char *name, const int pos,
SyncSourceConfig* config,
SyncSource **source) {
*source = NULL;
return ERR_UNSPECIFIED;
}
/**
* Callback invoked after creating all sources.
* @return 0 for success, an error code otherwise - an error code stops
* immediately
*/
virtual int beginSync(SyncSource **source) {
return ERR_NONE;
}
/**
* Callback invoked after the sync process.
* @return: 0 for success, an error code otherwise
*/
virtual int endSync(SyncSource **source) {
return ERR_NONE;
}
/**
* Callback invoked after the prepareSync function.
* @return 0 for success, an error code otherwise - an error code stops
* immediately
*/
virtual int continueAfterPrepareSync() {
return ERR_NONE;
}
/**
* Callback invoked after the sync function.
* @return: 0 for success, an error code otherwise
*/
virtual int continueAfterSync() {
return ERR_NONE;
}
// The report of the synchronization process.
// Sources reports are initializated during sync(sources**) call.
SyncReport syncReport;
};
/** @} */
/** @endcond */
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -