Updated python scripts to use new eblob class
[elliptics.git] / example / eblob_gen / eblob_gen.h
blobbd87b275ba53889d2447b5d6c6a20012cbe4dbd7
1 /*
2 * 2011+ 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 __EBLOB_GEN_H
17 #define __EBLOB_GEN_H
19 #include "config.h"
21 #include <time.h>
22 #include <libtar.h>
24 #include <fstream>
25 #include <iostream>
26 #include <map>
27 #include <string>
28 #include <sstream>
30 #include <boost/shared_ptr.hpp>
32 #include <eblob/eblob.hpp>
33 #include <elliptics/cppdef.h>
35 using namespace zbr;
37 class eblob_gen {
38 public:
39 eblob_gen(elliptics_log &l);
40 virtual ~eblob_gen();
42 void add_remote(const char *addr, const int port, const int family = AF_INET);
43 void write(const std::string &name, const std::string &data, const struct timespec &ts);
44 private:
45 elliptics_node node;
48 #include <time.h>
50 class eblob_data_source {
51 public:
52 eblob_data_source() {};
53 virtual ~eblob_data_source() {};
55 void prepend_data(std::string &data, const size_t size, struct timespec *ts = NULL);
57 virtual bool next(const bool prepend, const struct timespec *ts,
58 std::string &name, std::string &data) = 0;
61 #define BOOST_FILESYSTEM_VERSION 2
63 #include <boost/filesystem/operations.hpp>
64 namespace fs = boost::filesystem;
66 class eblob_dir_source : public eblob_data_source {
67 public:
68 eblob_dir_source(const std::string &path);
69 virtual ~eblob_dir_source();
71 virtual bool next(const bool prepend, const struct timespec *ts,
72 std::string &name, std::string &data);
73 private:
74 fs::directory_iterator end_itr, itr;
77 class eblob_tar_source : public eblob_data_source {
78 public:
79 eblob_tar_source(const std::string &path);
80 virtual ~eblob_tar_source();
82 virtual bool next(const bool prepend, const struct timespec *ts,
83 std::string &name, std::string &data);
84 private:
85 TAR *tar;
88 class eblob_processor {
89 public:
90 eblob_processor(const std::string &log_file, const bool prepend_data,
91 std::vector<int> &groups, const std::string &eblob_base,
92 const struct eblob_config &cfg);
94 void process(elliptics_node &node, const std::string &path);
96 private:
97 bool prepend_data_;
98 std::vector<int> groups_;
99 struct eblob_config eblob_cfg_;
100 std::string eblob_base_, log_file_;
102 std::map<std::string, boost::shared_ptr<eblob> > blobs;
105 #endif /* __EBLOB_GEN_H */