7 #include "flagtrigger.h"
8 #include "widestring.h"
9 #include "fetch_current_tournament.h"
10 #include "fetch_list_of_active_groups.h"
11 #include "fetch_group.h"
14 Tournament active_tournament;
15 std::vector<SkeletonGroup> active_groups;
16 unsigned char framebuf[800 * 600 * 4];
18 void init(pqxx::connection &conn)
20 conn.perform(FetchCurrentTournament(&active_tournament));
21 conn.perform(FetchListOfActiveGroups(&active_groups));
23 if (active_tournament.id == -1) {
24 std::fprintf(stderr, "No active tournament\n");
26 std::fprintf(stderr, "Current tournament is %d\n", active_tournament.id);
28 for (std::vector<SkeletonGroup>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
29 std::fprintf(stderr, "tourn: %u round: %u parallel: %u\n",
30 i->tournament, i->round, i->parallel);
33 conn.perform(FetchGroup(i->tournament, i->round, i->parallel, &gr));
34 std::fprintf(stderr, "%u players in group\n", gr.players.size());
39 void main_loop(pqxx::connection &conn)
41 if (active_tournament.id == -1) {
42 // No active tournament, sleep a second or so and exit
47 memset(framebuf, 0, 800*600*4);
49 pqxx::work t(conn, "trx");
52 pqxx::result res( t.exec("SELECT * FROM songs WHERE title LIKE 'M%'") );
54 for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
55 my_draw_text(i["title"].as(widestring()), framebuf, 0, y, 1, 255, 255, 255);
57 // std::fprintf(stderr, "%s\n", i["title"].c_str());
65 int main(int argc, char **argv)
67 ptc_open("CCBS bigscreen", 800, 600);
71 pqxx::connection conn("dbname=ccbs host=altersex.samfundet.no user=ccbs password=GeT|>>B_");
72 FlagTrigger tournament_changed(conn, "active_tournament");
73 FlagTrigger rounds_changed(conn, "active_groups");
75 // when active_tournament or active_rounds is changed, we destroy everything and start from scratch
76 // (at least currently)
78 tournament_changed.reset_flag();
79 rounds_changed.reset_flag();
84 } while (!tournament_changed.get_flag() && !rounds_changed.get_flag());
85 std::fprintf(stderr, "active_tournament or active_groups changed, resetting...\n");
87 } catch (const std::exception &e) {
88 std::fprintf(stderr, "Exception: %s\n", e.what());