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_list_of_finished_groups.h"
12 #include "fetch_group.h"
13 #include "fetch_auxilliary_screens.h"
15 #include "groupscreen.h"
16 #include "top10scorescreen.h"
17 #include "top5chosenscreen.h"
18 #include "splitscreen.h"
19 #include "rotatescreen.h"
21 Tournament active_tournament;
22 std::vector<SkeletonGroup> active_groups;
23 std::vector<GenericScreen *> screens;
24 GenericScreen *mainscreen = NULL;
25 unsigned char framebuf[800 * 600 * 4], screenbuf[800 * 600 * 4];
27 void init(pqxx::connection &conn)
29 std::vector<widestring> aux_screens;
31 if (screens.size() == 0 || mainscreen != screens[0])
34 for (std::vector<GenericScreen *>::const_iterator i = screens.begin(); i != screens.end(); ++i) {
37 screens.erase(screens.begin(), screens.end());
39 conn.perform(FetchCurrentTournament(&active_tournament));
40 conn.perform(FetchListOfActiveGroups(&active_groups));
42 if (active_tournament.id == -1) {
43 std::fprintf(stderr, "No active tournament\n");
45 std::fprintf(stderr, "Current tournament is %d\n", active_tournament.id);
47 for (std::vector<SkeletonGroup>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
48 std::fprintf(stderr, "tourn: %u round: %u parallel: %u num_machines: %u\n",
49 i->tournament, i->round, i->parallel, i->num_machines);
52 for (unsigned j = 0; j < i->num_machines; ++j) {
53 RotateScreen *rs = new RotateScreen();
54 screens.push_back(rs);
55 rs->add_screen(new GroupScreen(conn, i->tournament, i->round, i->parallel, j, i->num_machines));
60 RotateScreen *aux_screen = new RotateScreen();
61 screens.push_back(aux_screen);
63 conn.perform(FetchAuxilliaryScreens(&aux_screens));
64 for (std::vector<widestring>::const_iterator i = aux_screens.begin(); i != aux_screens.end(); ++i) {
65 if (*i == widestring("top10scores")) {
66 aux_screen->add_screen(new Top10ScoreScreen(conn, active_tournament.id));
69 if (*i == widestring("top5chosen")) {
70 aux_screen->add_screen(new Top5ChosenScreen(conn, active_tournament.id));
73 std::fprintf(stderr, "Foobarbaz?\n");
76 // add all finished screens to the auxilliary screens
77 std::vector<SkeletonGroup> finished_groups;
78 conn.perform(FetchListOfFinishedGroups(active_tournament.id, &finished_groups));
80 for (std::vector<SkeletonGroup>::const_iterator i = finished_groups.begin(); i != finished_groups.end(); ++i) {
81 aux_screen->add_screen(new GroupScreen(conn, i->tournament, i->round, i->parallel, 0, 1));
85 screens.push_back(NULL);
86 screens.push_back(NULL);
87 screens.push_back(NULL);
88 screens.push_back(NULL);
90 if (screens[1] == NULL) {
91 mainscreen = screens[0];
93 mainscreen = new SplitScreen(screens[0], screens[1], screens[2], screens[3]);
97 void main_loop(pqxx::connection &conn)
99 if (active_tournament.id == -1) {
100 // No active tournament, sleep a second or so and exit
101 conn.await_notification(1, 0);
105 if (mainscreen && mainscreen->check_invalidated()) {
106 mainscreen->draw(framebuf);
107 ptc_update(framebuf);
108 conn.await_notification(0, 10000);
110 ptc_update(framebuf);
111 conn.await_notification(0, 200000);
115 int main(int argc, char **argv)
117 ptc_open("CCBS bigscreen", 800, 600);
121 pqxx::connection conn("dbname=ccbs host=altersex.samfundet.no user=ccbs password=GeT|>>B_");
122 FlagTrigger tournament_changed(conn, "active_tournament");
123 FlagTrigger rounds_changed(conn, "active_groups");
125 // when active_tournament or active_rounds is changed, we destroy everything and start from scratch
126 // (at least currently)
128 tournament_changed.reset_flag();
129 rounds_changed.reset_flag();
134 } while (!tournament_changed.get_flag() && !rounds_changed.get_flag());
135 std::fprintf(stderr, "active_tournament or active_groups changed, resetting...\n");
137 } catch (const std::exception &e) {
138 std::fprintf(stderr, "Exception: %s\n", e.what());