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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines