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

Comparing trunk/Publisher.cpp (file contents):
Revision 15 by douglas, 2004-07-13T20:14:49-07:00 vs.
Revision 34 by douglas, 2004-07-20T16:49:06-07:00

# Line 5 | Line 5
5   // $Id$
6  
7   #include "Publisher.hpp"
8 + #include "Rss.hpp"
9  
10 < Publisher::Publisher(const std::set<Buddy>& buddies, bool start) : start(start)
10 > Publisher::Publisher(const std::set<Buddy>& buddies, const Database& database, bool start) : buddies(buddies),
11 >        database(database), start(start)
12   {
13 <        if (start)
13 >        if (start) publisher.Spawn(etl::Bind<0>(&Publisher::publish, this));
14 > }
15 >
16 > int Publisher::publish()
17 > {
18 >        cerr << bright << green << "Publisher::publish()\n" << reset;
19 >
20 >        // publish
21 >
22 >        while (true)
23          {
24 <                publisher.Spawn(etl::BindAll(&Publisher::publish, this, buddies));
24 >                double next(api::GetWallTimerSeconds() + Hour(1)), now;
25 >
26 >                update();
27 >
28 >                do
29 >                {
30 >                        sleep(Minute(1));
31 >
32 >                        now = api::GetWallTimerSeconds();
33 >                }
34 >                while (now < next);
35          }
36   }
37  
38 < int Publisher::publish(const std::set<Buddy>& buddies)
38 > void Publisher::update()
39   {
40 <        cerr << "Publisher::publish()\n";
40 >        cerr << bright << yellow << "Publisher::update()\n" << reset;
41  
42 <        // publish
42 >        Stamp stamp;
43 >        ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host, database.user, database.password,
44 >                database.db));
45 >
46 >        db->Execute("DELETE FROM messages WHERE stamp<'" + ext::String(stamp - Day(30)) + "'");
47 >
48 >        for (std::set<Buddy>::const_iterator buddy(buddies.begin()); buddy != buddies.end(); ++buddy)
49 >        {
50 >                ext::Handle<dbi::ResultSet> messages(db->Execute("SELECT stamp, message FROM messages WHERE id='"
51 >                        + lexical_cast<ext::String>(buddy->getId()) + "'"));
52 >                std::vector<AwayMessage> messages_;
53 >
54 >                while (messages->MoveNext()) messages_.push_back(AwayMessage(messages->GetString("message"),
55 >                        messages->GetString("stamp")));
56 >
57 >                Rss rss(*buddy, messages_, stamp);
58 >        }
59   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines