From: Steinar H. Gunderson Date: Sat, 19 Feb 2005 15:16:20 +0000 (+0000) Subject: Fetch the list of current active rounds and display it. X-Git-Url: https://git.sesse.net/?p=ccbs;a=commitdiff_plain;h=44f3ad694f8fe5dd76602d30c9bc1f3de9650f97 Fetch the list of current active rounds and display it. --- diff --git a/bigscreen/Makefile b/bigscreen/Makefile index 55ba613..76d280d 100644 --- a/bigscreen/Makefile +++ b/bigscreen/Makefile @@ -4,7 +4,7 @@ CPPFLAGS=-I/usr/include/postgresql $(shell freetype-config --cflags) -Itinyptc/ CXXFLAGS=-g -Wall LDFLAGS=-L/usr/X11R6/lib LIBS=$(shell freetype-config --libs) $(shell libpq3-config) -lpqxx tinyptc/libtinyptc.a -lX11 -CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o fetch_current_tournament.o fonts.o +CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o fetch_current_tournament.o fetch_list_of_active_groups.o fonts.o all: ccbs-bigscreen diff --git a/bigscreen/ccbs_bigscreen.cpp b/bigscreen/ccbs_bigscreen.cpp index c233f47..9db87c8 100644 --- a/bigscreen/ccbs_bigscreen.cpp +++ b/bigscreen/ccbs_bigscreen.cpp @@ -7,20 +7,27 @@ #include "flagtrigger.h" #include "widestring.h" #include "fetch_current_tournament.h" +#include "fetch_list_of_active_groups.h" #include "fonts.h" Tournament active_tournament; +std::vector active_groups; unsigned char framebuf[800 * 600 * 4]; void init(pqxx::connection &conn) { conn.perform(FetchCurrentTournament(&active_tournament)); + conn.perform(FetchListOfActiveGroups(&active_groups)); if (active_tournament.id == -1) { std::fprintf(stderr, "No active tournament\n"); } else { - std::fprintf(stderr, "Current tournament is %d (name: '%s')\n", - active_tournament.id, active_tournament.name.c_str()); + std::fprintf(stderr, "Current tournament is %d\n", active_tournament.id); + + for (std::vector::const_iterator i = active_groups.begin(); i != active_groups.end(); ++i) { + std::fprintf(stderr, "tourn: %u round: %u parallel: %u\n", + i->tournament, i->round, i->parallel); + } } } diff --git a/bigscreen/fetch_list_of_active_groups.cpp b/bigscreen/fetch_list_of_active_groups.cpp new file mode 100644 index 0000000..1df6758 --- /dev/null +++ b/bigscreen/fetch_list_of_active_groups.cpp @@ -0,0 +1,19 @@ +#include "fetch_list_of_active_groups.h" + +FetchListOfActiveGroups::FetchListOfActiveGroups(std::vector *active) : active(active) {} +void FetchListOfActiveGroups::operator() (pqxx::transaction<> &t) +{ + // make sure we start with an empty list + active->erase(active->begin(), active->end()); + + pqxx::result res( t.exec("SELECT * FROM bigscreen.active_groups") ); + for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) { + Group g; + + g.tournament = i["tournament"].as(g.tournament); + g.round = i["round"].as(g.round); + g.parallel = i["parallel"].as(g.parallel); + + active->push_back(g); + } +} diff --git a/bigscreen/fetch_list_of_active_groups.h b/bigscreen/fetch_list_of_active_groups.h new file mode 100644 index 0000000..113160d --- /dev/null +++ b/bigscreen/fetch_list_of_active_groups.h @@ -0,0 +1,21 @@ +#ifndef _FETCH_LIST_OF_ACTIVE_GROUPS_H +#define _FETCH_LIST_OF_ACTIVE_GROUPS_H 1 + +#include +#include + +struct Group { + unsigned tournament, round, parallel; +}; + +/* A transactor that fetches the current list of active groups. */ +class FetchListOfActiveGroups : public pqxx::transactor<> { +private: + std::vector *active; + +public: + FetchListOfActiveGroups(std::vector *active); + void operator() (pqxx::transaction<> &t); +}; + +#endif /* !defined(_FETCH_LIST_OF_ACTIVE_GROUPS_H) */