Use <> includes, not ""
[elliptics.git] / include / elliptics / cppdef.h
blob92bc0eb727cb33a6792c6f87efbb02933613d2d0
1 /*
2 * 2008+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #ifndef __EDEF_H
17 #define __EDEF_H
19 #include <errno.h>
20 #include <stdint.h>
22 #include <elliptics/packet.h>
23 #include <elliptics/interface.h>
25 #include <iostream>
26 #include <fstream>
27 #include <exception>
28 #include <stdexcept>
29 #include <string>
30 #include <vector>
32 namespace zbr {
34 class elliptics_log {
35 public:
36 elliptics_log(const uint32_t mask = DNET_LOG_ERROR | DNET_LOG_INFO) {
37 ll.log_mask = mask;
38 ll.log = elliptics_log::logger;
39 ll.log_private = this;
41 virtual ~elliptics_log() {};
43 virtual void log(const uint32_t mask, const char *msg) = 0;
46 * Clone is used instead of 'virtual' copy constructor, since we have to
47 * hold a reference to object outside of our scope, namely python created
48 * logger. This is also a reason we return 'unsigned long' instead of
49 * 'elliptics_log *' - python does not have pointer.
51 virtual unsigned long clone(void) = 0;
53 static void logger(void *priv, const uint32_t mask, const char *msg);
54 uint32_t get_log_mask(void) { return ll.log_mask; };
55 struct dnet_log *get_dnet_log(void) { return &ll; };
56 protected:
57 struct dnet_log ll;
60 class elliptics_log_file : public elliptics_log {
61 public:
62 elliptics_log_file(const char *file, const uint32_t mask = DNET_LOG_ERROR | DNET_LOG_INFO);
63 virtual ~elliptics_log_file();
65 virtual unsigned long clone(void);
66 virtual void log(const uint32_t mask, const char *msg);
68 std::string *file;
69 private:
71 * Oh shi, I put pointer here to avoid boost::python compiler issues,
72 * when it tries to copy stream, which is not allowed
74 std::ofstream *stream;
77 class elliptics_callback {
78 public:
79 elliptics_callback();
80 virtual ~elliptics_callback();
82 virtual int callback(struct dnet_net_state *state, struct dnet_cmd *cmd, struct dnet_attr *attr);
84 static int elliptics_complete_callback(struct dnet_net_state *st, struct dnet_cmd *cmd, struct dnet_attr *a, void *priv) {
85 elliptics_callback *c = reinterpret_cast<elliptics_callback *>(priv);
87 return c->callback(st, cmd, a);
90 std::string wait(int completed = 1);
92 protected:
93 std::string data;
94 pthread_cond_t wait_cond;
95 pthread_mutex_t lock;
96 int complete;
99 class elliptics_node {
100 public:
101 /* we shold use elliptics_log and proper copy constructor here, but not this time */
102 elliptics_node(elliptics_log &l);
103 elliptics_node(elliptics_log &l, struct dnet_config &cfg);
104 virtual ~elliptics_node();
106 void transform(const std::string &data, struct dnet_id &id);
108 void add_groups(std::vector<int> &groups);
109 std::vector<int> get_groups() {return groups;};
111 void add_remote(const char *addr, const int port, const int family = AF_INET);
113 void read_file(struct dnet_id &id, const std::string &file, uint64_t offset, uint64_t size);
114 void read_file(const std::string &remote, const std::string &file, uint64_t offset, uint64_t size, int type);
116 void write_file(struct dnet_id &id, const std::string &file, uint64_t local_offset,
117 uint64_t offset, uint64_t size, unsigned int aflags, unsigned int ioflags);
118 void write_file(const std::string &remote, const std::string &file,
119 uint64_t local_offset, uint64_t offset, uint64_t size,
120 unsigned int aflags, unsigned int ioflags, int type);
122 std::string read_data_wait(struct dnet_id &id, uint64_t offset, uint64_t size,
123 uint32_t aflags, uint32_t ioflags);
124 std::string read_data_wait(const std::string &remote, uint64_t offset, uint64_t size,
125 uint32_t aflags, uint32_t ioflags, int type);
127 void prepare_latest(struct dnet_id &id, uint32_t aflags, std::vector<int> &groups);
129 std::string read_latest(struct dnet_id &id, uint64_t offset, uint64_t size,
130 uint32_t aflags, uint32_t ioflags);
131 std::string read_latest(const std::string &remote, uint64_t offset, uint64_t size,
132 uint32_t aflags, uint32_t ioflags, int type);
134 std::string write_data_wait(struct dnet_id &id, const std::string &str,
135 uint64_t remote_offset, unsigned int aflags, unsigned int ioflags);
136 std::string write_data_wait(const std::string &remote, const std::string &str,
137 uint64_t remote_offset, unsigned int aflags, unsigned int ioflags, int type);
139 std::string write_prepare(const std::string &remote, const std::string &str, uint64_t remote_offset,
140 uint64_t psize, unsigned int aflags, unsigned int ioflags, int type);
141 std::string write_commit(const std::string &remote, const std::string &str, uint64_t remote_offset,
142 uint64_t csize, unsigned int aflags, unsigned int ioflags, int type);
143 std::string write_plain(const std::string &remote, const std::string &str, uint64_t remote_offset,
144 unsigned int aflags, unsigned int ioflags, int type);
146 std::string lookup_addr(const std::string &remote, const int group_id);
147 std::string lookup_addr(const struct dnet_id &id);
149 std::string create_metadata(const struct dnet_id &id, const std::string &obj,
150 const std::vector<int> &groups, const struct timespec &ts);
151 int write_metadata(const struct dnet_id &id, const std::string &obj,
152 const std::vector<int> &groups, const struct timespec &ts, int aflags);
154 void lookup(const std::string &data, const elliptics_callback &c);
155 void lookup(const struct dnet_id &id, const elliptics_callback &c);
156 std::string lookup(const std::string &data);
158 void remove_raw(struct dnet_id &id, int aflags);
159 void remove_raw(const std::string &data, int type, int aflags);
160 void remove(struct dnet_id &id);
161 void remove(const std::string &data, int type = EBLOB_TYPE_DATA);
163 std::string stat_log();
165 int state_num();
167 int request_cmd(struct dnet_trans_control &ctl);
169 std::string read_metadata(struct dnet_id &id);
171 void update_status(const char *addr, const int port, const int family,
172 struct dnet_node_status *status, int update);
173 void update_status(struct dnet_id &id, struct dnet_node_status *status, int update);
175 std::vector<std::string> read_data_range(struct dnet_io_attr &io, int group_id, uint32_t aflags = 0);
177 std::vector<struct dnet_io_attr> remove_data_range(struct dnet_io_attr &io, int group_id, uint32_t aflags = 0);
179 std::vector<std::pair<struct dnet_id, struct dnet_addr> > get_routes();
181 std::string exec(struct dnet_id *id, const std::string &script, const std::string &binary, int type);
182 std::string exec_name(struct dnet_id *id, const std::string &name, const std::string &script,
183 const std::string &binary, int type);
185 std::vector<std::string> bulk_read(std::vector<struct dnet_io_attr> &ios, int group_id, uint32_t aflags = 0);
186 std::vector<std::string> bulk_read(std::vector<std::string> &keys, int group_id, uint32_t aflags= 0);
188 std::string bulk_write(std::vector<struct dnet_io_attr> &ios, std::vector<std::string> &data, uint32_t aflags);
190 protected:
191 int write_data_ll(struct dnet_id *id, void *remote, unsigned int remote_len,
192 void *data, unsigned int size, elliptics_callback &c,
193 unsigned int aflags, unsigned int ioflags, int type);
194 struct dnet_node *node;
195 elliptics_log *log;
197 std::vector<int> groups;
200 }; /* namespace zbr */
201 #endif /* __EDEF_H */