2014-03-07 19:18:48 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Yandex/Common.h>
|
|
|
|
#include <boost/function.hpp>
|
|
|
|
#include <future>
|
2014-06-04 13:48:36 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <boost/ptr_container/ptr_vector.hpp>
|
|
|
|
#include <zookeeper/zookeeper.h>
|
2014-06-30 11:33:06 +00:00
|
|
|
#include <Poco/SharedPtr.h>
|
|
|
|
#include <Poco/Event.h>
|
2014-03-07 19:18:48 +00:00
|
|
|
|
|
|
|
namespace zkutil
|
|
|
|
{
|
2014-11-30 07:01:00 +00:00
|
|
|
typedef const ACL_vector * ACLPtr;
|
2014-06-04 13:48:36 +00:00
|
|
|
typedef Stat Stat;
|
|
|
|
|
|
|
|
struct Op
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Op() : data(new zoo_op_t) {}
|
|
|
|
virtual ~Op() {}
|
|
|
|
|
|
|
|
std::unique_ptr<zoo_op_t> data;
|
|
|
|
|
2015-01-21 03:56:28 +00:00
|
|
|
struct Remove;
|
|
|
|
struct Create;
|
|
|
|
struct SetData;
|
|
|
|
struct Check;
|
2014-06-04 13:48:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Op::Remove : public Op
|
|
|
|
{
|
|
|
|
Remove(const std::string & path_, int32_t version) :
|
|
|
|
path(path_)
|
|
|
|
{
|
|
|
|
zoo_delete_op_init(data.get(), path.c_str(), version);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string path;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Op::Create : public Op
|
|
|
|
{
|
2014-11-30 07:01:00 +00:00
|
|
|
Create(const std::string & path_, const std::string & value_, ACLPtr acl, int32_t flags);
|
2014-06-04 13:48:36 +00:00
|
|
|
|
|
|
|
std::string getPathCreated()
|
|
|
|
{
|
|
|
|
return created_path.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string path;
|
|
|
|
std::string value;
|
|
|
|
std::vector<char> created_path;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Op::SetData : public Op
|
|
|
|
{
|
|
|
|
SetData(const std::string & path_, const std::string & value_, int32_t version) :
|
|
|
|
path(path_), value(value_)
|
|
|
|
{
|
|
|
|
zoo_set_op_init(data.get(), path.c_str(), value.c_str(), value.size(), version, &stat);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
std::string path;
|
|
|
|
std::string value;
|
|
|
|
Stat stat;
|
|
|
|
};
|
2014-03-07 19:18:48 +00:00
|
|
|
|
2014-06-04 13:48:36 +00:00
|
|
|
struct Op::Check : public Op
|
|
|
|
{
|
|
|
|
Check(const std::string & path_, int32_t version) :
|
|
|
|
path(path_)
|
|
|
|
{
|
|
|
|
zoo_check_op_init(data.get(), path.c_str(), version);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
std::string path;
|
|
|
|
};
|
2014-03-07 19:18:48 +00:00
|
|
|
|
2015-01-21 03:56:28 +00:00
|
|
|
struct OpResult : public zoo_op_result_t
|
2014-06-04 13:48:36 +00:00
|
|
|
{
|
2014-07-03 17:24:17 +00:00
|
|
|
/// Указатели в этой структуре указывают на поля в классе Op.
|
|
|
|
/// Поэтому деструктор не нужен
|
2014-06-04 13:48:36 +00:00
|
|
|
};
|
2014-03-07 19:18:48 +00:00
|
|
|
|
|
|
|
typedef boost::ptr_vector<Op> Ops;
|
2014-06-04 13:48:36 +00:00
|
|
|
typedef std::vector<OpResult> OpResults;
|
|
|
|
typedef std::shared_ptr<OpResults> OpResultsPtr;
|
2014-03-07 19:18:48 +00:00
|
|
|
typedef std::vector<std::string> Strings;
|
|
|
|
|
2014-06-04 13:48:36 +00:00
|
|
|
namespace CreateMode
|
|
|
|
{
|
|
|
|
extern const int Persistent;
|
|
|
|
extern const int Ephemeral;
|
|
|
|
extern const int EphemeralSequential;
|
|
|
|
extern const int PersistentSequential;
|
|
|
|
}
|
2014-03-07 19:18:48 +00:00
|
|
|
|
2014-06-30 11:33:06 +00:00
|
|
|
typedef Poco::SharedPtr<Poco::Event> EventPtr;
|
2014-03-07 19:18:48 +00:00
|
|
|
|
|
|
|
}
|