ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Publisher.cpp
Revision: 32
Committed: 2004-07-20T00:40:43-07:00 (20 years, 11 months ago) by douglas
File size: 1416 byte(s)
Log Message:
w00t!

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

Properties

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