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"
16 Tournament active_tournament;
17 std::vector<SkeletonGroup> active_groups;
18 std::vector<GenericScreen *> screens;
19 SplitScreen *mainscreen = NULL;
20 unsigned char framebuf[800 * 600 * 4], screenbuf[800 * 600 * 4];
22 void init(pqxx::connection &conn)
24 for (std::vector<GenericScreen *>::const_iterator i = screens.begin(); i != screens.end(); ++i) {
27 screens.erase(screens.begin(), screens.end());
31 conn.perform(FetchCurrentTournament(&active_tournament));
32 conn.perform(FetchListOfActiveGroups(&active_groups));
34 if (active_tournament.id == -1) {
35 std::fprintf(stderr, "No active tournament\n");
37 std::fprintf(stderr, "Current tournament is %d\n", active_tournament.id);
39 for (std::vector<SkeletonGroup>::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) {
40 std::fprintf(stderr, "tourn: %u round: %u parallel: %u\n",
41 i->tournament, i->round, i->parallel);
43 screens.push_back(new GroupScreen(conn, i->tournament, i->round, i->parallel));
48 screens.push_back(NULL);
49 screens.push_back(NULL);
50 screens.push_back(NULL);
51 screens.push_back(NULL);
53 mainscreen = new SplitScreen(screens[0], screens[1], screens[2], screens[3]);
56 void main_loop(pqxx::connection &conn)
58 if (active_tournament.id == -1) {
59 // No active tournament, sleep a second or so and exit
60 conn.await_notification(1, 0);
64 if (mainscreen->check_invalidated()) {
65 mainscreen->draw(framebuf);
69 conn.await_notification(0, 50000);
72 int main(int argc, char **argv)
74 ptc_open("CCBS bigscreen", 800, 600);
78 pqxx::connection conn("dbname=ccbs host=altersex.samfundet.no user=ccbs password=GeT|>>B_");
79 FlagTrigger tournament_changed(conn, "active_tournament");
80 FlagTrigger rounds_changed(conn, "active_groups");
82 // when active_tournament or active_rounds is changed, we destroy everything and start from scratch
83 // (at least currently)
85 tournament_changed.reset_flag();
86 rounds_changed.reset_flag();
91 } while (!tournament_changed.get_flag() && !rounds_changed.get_flag());
92 std::fprintf(stderr, "active_tournament or active_groups changed, resetting...\n");
94 } catch (const std::exception &e) {
95 std::fprintf(stderr, "Exception: %s\n", e.what());