8 |
|
#include "Collector.hpp" |
9 |
|
#include "Publisher.hpp" |
10 |
|
|
11 |
+ |
#include <menes-api/exename.hpp> |
12 |
+ |
#include <menes-app/application.hpp> |
13 |
+ |
#include <menes-ios/stdadapters.hpp> |
14 |
+ |
|
15 |
|
#include <algorithm> |
16 |
|
#include <cstring> |
17 |
|
#include <iterator> |
23 |
|
#include <unistd.h> |
24 |
|
} |
25 |
|
|
26 |
< |
int zoe(const std::vector<const char*> args) |
26 |
> |
struct ZoeCommand : public app::Application |
27 |
|
{ |
28 |
< |
Zoe::program = args[0]; |
25 |
< |
|
26 |
< |
for (int index(1); index < args.size(); ++index) |
28 |
> |
virtual int Run(const app::ArgumentList& args) |
29 |
|
{ |
30 |
< |
ext::String arg(args[index]); |
29 |
< |
Matcher matcher; |
30 |
> |
Zoe::program = api::GetExecutablePath().GetName(); |
31 |
|
|
32 |
< |
if (arg == matcher("^-config=(.*)$")) |
32 |
< |
{ |
33 |
< |
Zoe::config = matcher[1]; |
34 |
< |
} |
35 |
< |
else if (arg == "-collector") |
36 |
< |
{ |
37 |
< |
if (!Zoe::collector) Zoe::collector = true; |
38 |
< |
} |
39 |
< |
else if (arg == "-publisher") |
40 |
< |
{ |
41 |
< |
if (!Zoe::publisher) Zoe::publisher = true; |
42 |
< |
} |
43 |
< |
else if (arg == "-color") |
44 |
< |
{ |
45 |
< |
if (!Zoe::color) Zoe::color = true; |
46 |
< |
} |
47 |
< |
else if (arg == "-D") |
32 |
> |
for (size_t index(0); index < args.GetSize(); ++index) |
33 |
|
{ |
34 |
< |
if (!Zoe::debug) Zoe::debug = true; |
34 |
> |
ext::String arg(args[index]); |
35 |
> |
Matcher matcher; |
36 |
> |
|
37 |
> |
if (arg == matcher("^-config=(.*)$")) |
38 |
> |
{ |
39 |
> |
Zoe::config = matcher[1]; |
40 |
> |
} |
41 |
> |
else if (arg == "-collector") |
42 |
> |
{ |
43 |
> |
if (!Zoe::collector) Zoe::collector = true; |
44 |
> |
} |
45 |
> |
else if (arg == "-publisher") |
46 |
> |
{ |
47 |
> |
if (!Zoe::publisher) Zoe::publisher = true; |
48 |
> |
} |
49 |
> |
else if (arg == "-color") |
50 |
> |
{ |
51 |
> |
if (!Zoe::color) Zoe::color = true; |
52 |
> |
} |
53 |
> |
else if (arg == "-D") |
54 |
> |
{ |
55 |
> |
if (!Zoe::debug) Zoe::debug = true; |
56 |
> |
} |
57 |
> |
else Zoe::usage(); |
58 |
|
} |
51 |
– |
else Zoe::usage(); |
52 |
– |
} |
53 |
– |
|
54 |
– |
Zoe zoe; |
59 |
|
|
60 |
< |
return 0; |
57 |
< |
} |
58 |
< |
|
59 |
< |
int main(int argc, char* argv[]) |
60 |
< |
{ |
61 |
< |
std::vector<const char*> args(argv, argv + argc); |
60 |
> |
Zoe zoe; |
61 |
|
|
62 |
< |
return app::be::ThreadMain_(etl::BindAll(&zoe, args)); |
63 |
< |
} |
62 |
> |
return 0; |
63 |
> |
} |
64 |
> |
} zoe; |
65 |
|
|
66 |
|
Zoe::Zoe() |
67 |
|
{ |
68 |
|
if (!(collector || publisher)) usage(); |
69 |
|
|
70 |
|
configure(); |
71 |
– |
initialize(); |
71 |
|
|
72 |
|
Collector collector(login, password, buddies, database, Zoe::collector); |
73 |
|
Publisher publisher(buddies, database, Zoe::publisher); |
74 |
|
} |
75 |
|
|
76 |
|
bool Zoe::debug(false), Zoe::collector(false), Zoe::publisher(false), |
77 |
< |
Zoe::color(false); |
77 |
> |
Zoe::color(false); |
78 |
|
ext::String Zoe::program, Zoe::config("zoe.xml"); |
79 |
|
|
80 |
|
void Zoe::usage() |
81 |
|
{ |
82 |
< |
cerr << "Usage: " << Zoe::program << " [-config=config] [-collector] " |
82 |
> |
api::Cerr << "Usage: " << Zoe::program << " [-config=config] [-collector] " |
83 |
|
"[-publisher] [-color] [-D]\n"; |
84 |
|
|
85 |
|
exit(1); |
99 |
|
|
100 |
|
uname(&system); |
101 |
|
|
102 |
< |
generator_.InsertAllLast(_S(" (") + system.sysname); |
102 |
> |
generator_.InsertAllLast(_R(" (") + system.sysname); |
103 |
|
} |
104 |
|
|
105 |
|
if (generator == agent) |
124 |
|
|
125 |
|
void Zoe::configure() |
126 |
|
{ |
127 |
< |
if (debug) cerr << "config = " << config << '\n'; |
127 |
> |
if (debug) api::Cerr << "config = " << config << "\n"; |
128 |
|
|
129 |
|
ext::Handle<xml::Document> document(xml::Parse(config)); |
130 |
|
ext::Handle<xml::Node> zoe(*document/"zoe"); |
151 |
|
|
152 |
|
database.db = *zoe/"database"/"db"; |
153 |
|
|
154 |
< |
if (debug) cerr << "login = " << login << "\npassword = " |
154 |
> |
if (debug) api::Cerr << "login = " << login << "\npassword = " |
155 |
|
<< std::string(password.GetSize(), '*') << "\ndatabase = {\n" |
156 |
< |
<< " driver = " << database.driver << "\n host=" << database.host |
157 |
< |
<< "\n user = " << database.user << '\n' |
156 |
> |
<< " driver = " << database.driver << "\n host = " << database.host |
157 |
> |
<< "\n user = " << database.user << "\n" |
158 |
|
<< " password = " << std::string(database.password.GetSize(), '*') |
159 |
|
<< "\n db = " << database.db << "\n}\n"; |
160 |
|
|
171 |
|
this->buddies.insert(buddy_); |
172 |
|
} |
173 |
|
|
174 |
+ |
initialize(); |
175 |
+ |
|
176 |
|
if (debug) |
177 |
|
{ |
178 |
< |
cerr << "buddies = {\n"; |
178 |
> |
api::Cerr << "buddies = {\n"; |
179 |
|
|
180 |
|
for (std::set<Buddy>::const_iterator buddy(this->buddies.begin()); |
181 |
|
buddy != this->buddies.end(); ++buddy) |
182 |
|
{ |
183 |
< |
cerr << " " << *buddy << " = {\n rss = " << buddy->getRss() |
184 |
< |
<< "\n atom = " << buddy->getAtom() << "\n link = " |
185 |
< |
<< buddy->getLink() << "\n }\n"; |
183 |
> |
api::Cerr << " " << *buddy << " = {\n rss = " |
184 |
> |
<< buddy->getRss() << "\n atom = " << buddy->getAtom() |
185 |
> |
<< "\n link = " << buddy->getLink() << "\n id = " |
186 |
> |
<< buddy->getId() << "\n }\n"; |
187 |
|
} |
188 |
|
|
189 |
< |
cerr << "}\n"; |
189 |
> |
api::Cerr << "}\n"; |
190 |
|
} |
191 |
|
|
192 |
< |
if (debug) cerr << "collector = " << lexical_cast<ext::String>(collector) |
193 |
< |
<< "\npublisher = " << lexical_cast<ext::String>(publisher) |
192 |
< |
<< "\ncolor = " << lexical_cast<ext::String>(color) << '\n'; |
192 |
> |
if (debug) api::Cerr << "collector = " << collector << "\npublisher = " |
193 |
> |
<< publisher << "\ncolor = " << color << "\n"; |
194 |
|
} |
195 |
|
|
196 |
|
void Zoe::initialize() |
197 |
|
{ |
198 |
< |
ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host, |
198 |
> |
ext::Handle<dbi::Driver> driver(dbi::GetDriver(database.driver)); |
199 |
> |
ext::Handle<dbi::Connection> db(driver->Connect(database.host, |
200 |
|
database.user, database.password, database.db)); |
201 |
|
ext::Handle<dbi::ResultSet> buddies(db->Execute("SELECT * FROM buddies")); |
202 |
|
std::set<Buddy> buddies_; |
221 |
|
for (std::vector<Buddy>::iterator buddy(difference.begin()); |
222 |
|
buddy != difference.end(); ++buddy) |
223 |
|
{ |
224 |
< |
ext::Uuid id; |
224 |
> |
ext::Uuid id(api::Uuid::CreateSequential()); |
225 |
|
|
226 |
< |
api::Uuid::CreateSequential(id); |
226 |
> |
// api::Uuid::CreateSequential(id); |
227 |
|
|
228 |
|
buddy->setId(id); |
229 |
|
db->Execute("INSERT INTO buddies (id, buddy) VALUES ('" |