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
#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<Group> 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<Group>::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);
+ }
}
}
--- /dev/null
+#include "fetch_list_of_active_groups.h"
+
+FetchListOfActiveGroups::FetchListOfActiveGroups(std::vector<Group> *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);
+ }
+}
--- /dev/null
+#ifndef _FETCH_LIST_OF_ACTIVE_GROUPS_H
+#define _FETCH_LIST_OF_ACTIVE_GROUPS_H 1
+
+#include <pqxx/transactor>
+#include <vector>
+
+struct Group {
+ unsigned tournament, round, parallel;
+};
+
+/* A transactor that fetches the current list of active groups. */
+class FetchListOfActiveGroups : public pqxx::transactor<> {
+private:
+ std::vector<Group> *active;
+
+public:
+ FetchListOfActiveGroups(std::vector<Group> *active);
+ void operator() (pqxx::transaction<> &t);
+};
+
+#endif /* !defined(_FETCH_LIST_OF_ACTIVE_GROUPS_H) */