2009-03-08 14:41:20 +01:00
|
|
|
/*
|
2009-03-25 15:21:04 +01:00
|
|
|
* Copyright (C) 2005-2008 Patrick Ohly <patrick.ohly@gmx.de>
|
|
|
|
* Copyright (C) 2009 Intel Corporation
|
2009-03-08 14:41:20 +01:00
|
|
|
*
|
2009-04-30 18:35:56 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) version 3.
|
2009-03-08 14:41:20 +01:00
|
|
|
*
|
2009-04-30 18:35:56 +02:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2009-03-08 14:41:20 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2009-04-30 18:35:56 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2009-03-08 14:41:20 +01:00
|
|
|
*
|
2009-04-30 18:35:56 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
2009-03-08 14:41:20 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCL_SYNTHESISENGINE
|
|
|
|
#define INCL_SYNTHESISENGINE
|
|
|
|
|
2009-09-02 05:13:10 +02:00
|
|
|
#include <syncevo/Logging.h>
|
2009-07-03 12:27:07 +02:00
|
|
|
|
2009-03-08 14:41:20 +01:00
|
|
|
#include <synthesis/generic_types.h>
|
|
|
|
#include <synthesis/sync_declarations.h>
|
|
|
|
#include <synthesis/engine_defs.h>
|
2009-03-23 16:13:45 +01:00
|
|
|
#include <synthesis/syerror.h>
|
2009-03-08 14:41:20 +01:00
|
|
|
|
|
|
|
// TODO: remove dependency on header file.
|
|
|
|
// Currently required because shared_ptr
|
|
|
|
// checks that type is completely defined.
|
|
|
|
#include <synthesis/enginemodulebase.h>
|
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include <boost/shared_array.hpp>
|
2009-08-13 17:22:45 +02:00
|
|
|
#include <boost/scoped_array.hpp>
|
2009-03-08 14:41:20 +01:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2009-10-05 14:49:32 +02:00
|
|
|
#include <syncevo/declarations.h>
|
2010-03-17 08:54:38 +01:00
|
|
|
#include <syncevo/util.h>
|
2009-10-02 17:23:53 +02:00
|
|
|
SE_BEGIN_CXX
|
|
|
|
|
2009-03-08 14:41:20 +01:00
|
|
|
typedef boost::shared_ptr<sysync::SessionType> SharedSession;
|
|
|
|
typedef boost::shared_ptr<sysync::KeyType> SharedKey;
|
|
|
|
class SharedBuffer : public boost::shared_array<char>
|
|
|
|
{
|
|
|
|
size_t m_size;
|
|
|
|
public:
|
|
|
|
SharedBuffer() :
|
|
|
|
m_size(0)
|
|
|
|
{}
|
|
|
|
|
2009-09-17 20:47:35 +02:00
|
|
|
/** transfers ownership */
|
2009-03-08 14:41:20 +01:00
|
|
|
explicit SharedBuffer(char *p, size_t size):
|
|
|
|
boost::shared_array<char>(p),
|
|
|
|
m_size(size)
|
|
|
|
{}
|
|
|
|
|
2009-09-17 20:47:35 +02:00
|
|
|
/** transfers ownership with custom destructor */
|
2009-03-08 14:41:20 +01:00
|
|
|
template <class D> SharedBuffer(char *p, size_t size, const D &d) :
|
|
|
|
boost::shared_array<char>(p, d),
|
|
|
|
m_size(size)
|
|
|
|
{}
|
|
|
|
|
2009-09-17 20:47:35 +02:00
|
|
|
/** copies memory */
|
|
|
|
explicit SharedBuffer(const char *p, size_t size):
|
|
|
|
boost::shared_array<char>(new char [size]),
|
|
|
|
m_size(size)
|
|
|
|
{ memcpy(get(), p, size); }
|
|
|
|
|
2009-03-08 14:41:20 +01:00
|
|
|
size_t size() { return m_size; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper around a class which is derived from
|
|
|
|
* TEngineModuleBase. Provides a C++
|
|
|
|
* interface which uses Boost smart pointers and
|
|
|
|
* exceptions derived from std::runtime_error to track
|
|
|
|
* resources/report errors.
|
|
|
|
*/
|
|
|
|
class SharedEngine {
|
|
|
|
boost::shared_ptr<sysync::TEngineModuleBase> m_engine;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SharedEngine(sysync::TEngineModuleBase *engine = NULL): m_engine(engine) {}
|
|
|
|
|
|
|
|
sysync::TEngineModuleBase *get() { return m_engine.get(); }
|
|
|
|
|
|
|
|
void Connect(const string &aEngineName,
|
|
|
|
sysync::CVersion aPrgVersion = 0,
|
|
|
|
sysync::uInt16 aDebugFlags = 0);
|
|
|
|
void Disconnect();
|
|
|
|
|
|
|
|
void InitEngineXML(const string &aConfigXML);
|
2009-09-27 22:48:04 +02:00
|
|
|
SharedSession OpenSession(const string &aSessionID);
|
2009-03-08 14:41:20 +01:00
|
|
|
SharedKey OpenSessionKey(SharedSession &aSessionH);
|
|
|
|
|
|
|
|
void SessionStep(const SharedSession &aSessionH,
|
|
|
|
sysync::uInt16 &aStepCmd,
|
|
|
|
sysync::TEngineProgressInfo *aInfoP = NULL);
|
|
|
|
SharedBuffer GetSyncMLBuffer(const SharedSession &aSessionH, bool aForSend);
|
|
|
|
void WriteSyncMLBuffer(const SharedSession &aSessionH, const char *data, size_t len);
|
|
|
|
SharedKey OpenKeyByPath(const SharedKey &aParentKeyH,
|
2010-01-04 17:50:27 +01:00
|
|
|
const string &aPath,
|
|
|
|
bool noThrow = false);
|
2009-03-08 14:41:20 +01:00
|
|
|
SharedKey OpenSubkey(const SharedKey &aParentKeyH,
|
2010-01-04 17:50:27 +01:00
|
|
|
sysync::sInt32 aID,
|
|
|
|
bool noThrow = false);
|
2009-03-08 14:41:20 +01:00
|
|
|
|
|
|
|
string GetStrValue(const SharedKey &aKeyH, const string &aValName);
|
|
|
|
void SetStrValue(const SharedKey &aKeyH, const string &aValName, const string &aValue);
|
|
|
|
|
|
|
|
sysync::sInt32 GetInt32Value(const SharedKey &aKeyH, const string &aValName);
|
|
|
|
void SetInt32Value(const SharedKey &aKeyH, const string &aValName, sysync::sInt32 aValue);
|
2009-07-03 12:27:07 +02:00
|
|
|
|
2009-10-02 17:23:53 +02:00
|
|
|
void doDebug(Logger::Level level,
|
2009-07-03 12:27:07 +02:00
|
|
|
const char *prefix,
|
|
|
|
const char *file,
|
|
|
|
int line,
|
|
|
|
const char *function,
|
|
|
|
const char *format,
|
|
|
|
va_list args);
|
2009-03-08 14:41:20 +01:00
|
|
|
};
|
|
|
|
|
2009-03-23 16:13:45 +01:00
|
|
|
/**
|
|
|
|
* thrown when a function returns a non-okay error code
|
|
|
|
*/
|
2010-03-17 08:54:38 +01:00
|
|
|
class BadSynthesisResult : public StatusException
|
2009-03-23 16:13:45 +01:00
|
|
|
{
|
|
|
|
public:
|
2010-03-17 08:54:38 +01:00
|
|
|
BadSynthesisResult(const std::string &file,
|
|
|
|
int line,
|
|
|
|
const string &what,
|
|
|
|
sysync::TSyErrorEnum result)
|
|
|
|
: StatusException(file, line, what, SyncMLStatus(result))
|
|
|
|
{}
|
|
|
|
|
|
|
|
sysync::TSyErrorEnum result() const { return sysync::TSyErrorEnum(syncMLStatus()); }
|
2009-03-23 16:13:45 +01:00
|
|
|
};
|
|
|
|
|
2009-03-08 14:41:20 +01:00
|
|
|
/**
|
|
|
|
* thrown when a key cannot be opened because it doesn't exist
|
|
|
|
*/
|
2009-03-23 16:13:45 +01:00
|
|
|
class NoSuchKey : public BadSynthesisResult
|
2009-03-08 14:41:20 +01:00
|
|
|
{
|
|
|
|
public:
|
2010-03-17 08:54:38 +01:00
|
|
|
NoSuchKey(const std::string &file, int line, const string &what) :
|
|
|
|
BadSynthesisResult(file, line, what, sysync::DB_NoContent)
|
2009-03-08 14:41:20 +01:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2009-08-13 17:22:45 +02:00
|
|
|
/**
|
|
|
|
* A class which wraps the underlying sysync::SDK_InterfaceType
|
|
|
|
* methods. Any sysync::SDK_InterfaceType pointer can be casted
|
|
|
|
* into this class because this class doesn't add any virtual
|
|
|
|
* functions or data.
|
|
|
|
*/
|
|
|
|
struct SDKInterface : public sysync::SDK_InterfaceType
|
|
|
|
{
|
|
|
|
sysync::TSyError setValue(sysync::KeyH aItemKey,
|
|
|
|
const std::string &field,
|
|
|
|
const char *data,
|
|
|
|
size_t datalen);
|
|
|
|
sysync::TSyError getValue(sysync::KeyH aItemKey,
|
|
|
|
const std::string &field,
|
|
|
|
SharedBuffer &data);
|
|
|
|
};
|
|
|
|
|
2009-10-02 17:23:53 +02:00
|
|
|
|
|
|
|
SE_END_CXX
|
2009-03-08 14:41:20 +01:00
|
|
|
#endif // INCL_SYNTHESISENGINE
|