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.size() > 0) {
55 if (screens[0]->check_invalidated()) {
56 screens[0]->draw(screenbuf);
59 memcpy(framebuf, screenbuf, 800*600*4);
63 conn.await_notification(0, 50000);
66 int main(int argc, char **argv)
68 ptc_open("CCBS bigscreen", 800, 600);
72 pqxx::connection conn("dbname=ccbs host=altersex.samfundet.no user=ccbs password=GeT|>>B_");
73 FlagTrigger tournament_changed(conn, "active_tournament");
74 FlagTrigger rounds_changed(conn, "active_groups");
76 // when active_tournament or active_rounds is changed, we destroy everything and start from scratch
77 // (at least currently)
79 tournament_changed.reset_flag();
80 rounds_changed.reset_flag();
85 } while (!tournament_changed.get_flag() && !rounds_changed.get_flag());
86 std::fprintf(stderr, "active_tournament or active_groups changed, resetting...\n");
88 } catch (const std::exception &e) {
89 std::fprintf(stderr, "Exception: %s\n", e.what());