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"
14 #include "splitscreen.h"
15 #include "rotatescreen.h"
17 Tournament active_tournament;
18 std::vector<SkeletonGroup> active_groups;
19 std::vector<GenericScreen *> screens;
20 GenericScreen *mainscreen = NULL;
21 unsigned char framebuf[800 * 600 * 4], screenbuf[800 * 600 * 4];
23 void init(pqxx::connection &conn)
25 if (screens.size() == 0 || mainscreen != screens[0])
28 for (std::vector<GenericScreen *>::const_iterator i = screens.begin(); i != screens.end(); ++i) {
31 screens.erase(screens.begin(), screens.end());
33 conn.perform(FetchCurrentTournament(&active_tournament));
34 conn.perform(FetchListOfActiveGroups(&active_groups));
36 if (active_tournament.id == -1) {
37 std::fprintf(stderr, "No active tournament\n");
39 std::fprintf(stderr, "Current tournament is %d\n", active_tournament.id);
41 for (std::vector<SkeletonGroup>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
42 std::fprintf(stderr, "tourn: %u round: %u parallel: %u\n",
43 i->tournament, i->round, i->parallel);
46 RotateScreen *rs = new RotateScreen();
47 screens.push_back(rs);
48 rs->add_screen(new GroupScreen(conn, i->tournament, i->round, i->parallel));
53 screens.push_back(NULL);
54 screens.push_back(NULL);
55 screens.push_back(NULL);
56 screens.push_back(NULL);
58 if (screens[1] == NULL) {
59 mainscreen = screens[0];
61 mainscreen = new SplitScreen(screens[0], screens[1], screens[2], screens[3]);
65 void main_loop(pqxx::connection &conn)
67 if (active_tournament.id == -1) {
68 // No active tournament, sleep a second or so and exit
69 conn.await_notification(1, 0);
73 if (mainscreen && mainscreen->check_invalidated()) {
74 mainscreen->draw(framebuf);
76 conn.await_notification(0, 10000);
79 conn.await_notification(0, 200000);
83 int main(int argc, char **argv)
85 ptc_open("CCBS bigscreen", 800, 600);
89 pqxx::connection conn("dbname=ccbs host=altersex.samfundet.no user=ccbs password=GeT|>>B_");
90 FlagTrigger tournament_changed(conn, "active_tournament");
91 FlagTrigger rounds_changed(conn, "active_groups");
93 // when active_tournament or active_rounds is changed, we destroy everything and start from scratch
94 // (at least currently)
96 tournament_changed.reset_flag();
97 rounds_changed.reset_flag();
102 } while (!tournament_changed.get_flag() && !rounds_changed.get_flag());
103 std::fprintf(stderr, "active_tournament or active_groups changed, resetting...\n");
105 } catch (const std::exception &e) {
106 std::fprintf(stderr, "Exception: %s\n", e.what());