ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Zoe.cpp
(Generate patch)

Comparing trunk/Zoe.cpp (file contents):
Revision 52 by douglas, 2004-08-30T17:12:49-07:00 vs.
Revision 67 by douglas, 2004-10-01T10:27:27-07:00

# Line 8 | Line 8
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>
# Line 19 | Line 23 | extern "C"
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);
# Line 100 | Line 99 | ext::String Zoe::generator(Generator gen
99  
100                          uname(&system);
101  
102 <                        generator_.InsertAllLast(_S(" (") + system.sysname);
102 >                        generator_.InsertAllLast(_R(" (") + system.sysname);
103                  }
104  
105                  if (generator == agent)
# Line 125 | Line 124 | ext::String Zoe::generator(Generator gen
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");
# Line 152 | Line 151 | void Zoe::configure()
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  
# Line 172 | Line 171 | void Zoe::configure()
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_;
# Line 219 | Line 221 | void Zoe::initialize()
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 ('"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines