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"
13 #include "groupscreen.h"
15 Tournament active_tournament;
16 std::vector<SkeletonGroup> active_groups;
17 std::vector<GenericScreen *> screens;
18 unsigned char framebuf[800 * 600 * 4], screenbuf[800 * 600 * 4];
20 void init(pqxx::connection &conn)
22 for (std::vector<GenericScreen *>::const_iterator i = screens.begin(); i != screens.end(); ++i) {
25 screens.erase(screens.begin(), screens.end());
27 conn.perform(FetchCurrentTournament(&active_tournament));
28 conn.perform(FetchListOfActiveGroups(&active_groups));
30 if (active_tournament.id == -1) {
31 std::fprintf(stderr, "No active tournament\n");
33 std::fprintf(stderr, "Current tournament is %d\n", active_tournament.id);
35 for (std::vector<SkeletonGroup>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
36 std::fprintf(stderr, "tourn: %u round: %u parallel: %u\n",
37 i->tournament, i->round, i->parallel);
39 screens.push_back(new GroupScreen(conn, i->tournament, i->round, i->parallel));
44 void main_loop(pqxx::connection &conn)
46 if (active_tournament.id == -1) {
47 // No active tournament, sleep a second or so and exit
48 conn.await_notification(1, 0);
52 memset(framebuf, 0, 800*600*4);
54 if (screens[0]->check_invalidated()) {
55 screens[0]->draw(screenbuf);
58 memcpy(framebuf, screenbuf, 800*600*4);
61 conn.await_notification(0, 50000);
64 int main(int argc, char **argv)
66 ptc_open("CCBS bigscreen", 800, 600);
70 pqxx::connection conn("dbname=ccbs host=altersex.samfundet.no user=ccbs password=GeT|>>B_");
71 FlagTrigger tournament_changed(conn, "active_tournament");
72 FlagTrigger rounds_changed(conn, "active_groups");
74 // when active_tournament or active_rounds is changed, we destroy everything and start from scratch
75 // (at least currently)
77 tournament_changed.reset_flag();
78 rounds_changed.reset_flag();
83 } while (!tournament_changed.get_flag() && !rounds_changed.get_flag());
84 std::fprintf(stderr, "active_tournament or active_groups changed, resetting...\n");
86 } catch (const std::exception &e) {
87 std::fprintf(stderr, "Exception: %s\n", e.what());