Fetch the list of current active rounds and display it.
authorSteinar H. Gunderson <sesse@samfundet.no>
Sat, 19 Feb 2005 15:16:20 +0000 (15:16 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sat, 19 Feb 2005 15:16:20 +0000 (15:16 +0000)
bigscreen/Makefile
bigscreen/ccbs_bigscreen.cpp
bigscreen/fetch_list_of_active_groups.cpp [new file with mode: 0644]
bigscreen/fetch_list_of_active_groups.h [new file with mode: 0644]

index 55ba613..76d280d 100644 (file)
@@ -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
 
index c233f47..9db87c8 100644 (file)
@@ -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<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);
+               }
        }
 }
 
diff --git a/bigscreen/fetch_list_of_active_groups.cpp b/bigscreen/fetch_list_of_active_groups.cpp
new file mode 100644 (file)
index 0000000..1df6758
--- /dev/null
@@ -0,0 +1,19 @@
+#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);
+       }
+}
diff --git a/bigscreen/fetch_list_of_active_groups.h b/bigscreen/fetch_list_of_active_groups.h
new file mode 100644 (file)
index 0000000..113160d
--- /dev/null
@@ -0,0 +1,21 @@
+#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) */