ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Publisher.cpp
Revision: 34
Committed: 2004-07-20T16:49:06-07:00 (20 years, 11 months ago) by douglas
File size: 1439 byte(s)
Log Message:
Yeah, that's right.

File Contents

# Content
1 // Zoe AIM Away Message RSS Feed Generator
2 //
3 // Seth King and Douglas Thrift
4 //
5 // $Id$
6
7 #include "Publisher.hpp"
8 #include "Rss.hpp"
9
10 Publisher::Publisher(const std::set<Buddy>& buddies, const Database& database, bool start) : buddies(buddies),
11 database(database), start(start)
12 {
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 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 void Publisher::update()
39 {
40 cerr << bright << yellow << "Publisher::update()\n" << reset;
41
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 }

Properties

Name Value
svn:eol-style native
svn:keywords Id