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 fetch_list_of_active_groups.o fetch_max_score_for_song.o fetch_max_score_for_player.o fetch_group.o fonts.o groupscreen.o splitscreen.o rotatescreen.o screen.o
+CCBS_BIGSCREEN_OBJS=ccbs_bigscreen.o flagtrigger.o widestring.o fetch_current_tournament.o fetch_list_of_active_groups.o fetch_max_score_for_song.o fetch_max_score_for_player.o fetch_group.o fetch_needs_update.o fonts.o groupscreen.o splitscreen.o rotatescreen.o screen.o
all: ccbs-bigscreen
--- /dev/null
+#include "fetch_needs_update.h"
+
+FetchNeedsUpdate::FetchNeedsUpdate(struct timeval last_updated, unsigned tournament, unsigned round, unsigned parallel, bool *result)
+ : last_updated(last_updated), tournament(tournament), round(round), parallel(parallel), result(result)
+{
+}
+
+void FetchNeedsUpdate::operator() (pqxx::transaction<> &t)
+{
+ // as we don't seem to have proper handling for timestamps in libpqxx,
+ // let's ask the database do to the work for us
+ char buf[256];
+ time_t lu = last_updated.tv_sec;
+ strftime(buf, 256, "%F %T", localtime(&lu));
+
+ pqxx::result res( t.exec(std::string("SELECT (last_updated > '") + buf + "') AS needs_update FROM bigscreen.active_groups WHERE "
+ "tournament=" + pqxx::to_string(tournament) + " AND "
+ "round=" + pqxx::to_string(round) + " AND "
+ "parallel=" + pqxx::to_string(parallel)) );
+
+ try {
+ *result = res.at(0)["needs_update"].as(*result);
+ } catch (PGSTD::out_of_range &e) {
+ *result = false;
+ }
+}
--- /dev/null
+#ifndef _FETCH_NEEDS_UPDATE_H
+#define _FETCH_NEEDS_UPDATE_H 1
+
+#include <pqxx/transactor>
+#include <time.h>
+#include <sys/time.h>
+
+/* A transactor that fetches when a given round was last updated. */
+class FetchNeedsUpdate : public pqxx::transactor<> {
+private:
+ struct timeval last_updated;
+ unsigned tournament, round, parallel;
+ bool *result;
+
+public:
+ FetchNeedsUpdate(struct timeval last_updated, unsigned tournament, unsigned round, unsigned parallel, bool *result);
+ void operator() (pqxx::transaction<> &t);
+};
+
+#endif /* !defined(_FETCH_NEEDS_UPDATE_H) */
+#include <cstdio>
#include <algorithm>
#include "groupscreen.h"
#include "fetch_group.h"
#include "fetch_max_score_for_song.h"
#include "fetch_max_score_for_player.h"
+#include "fetch_needs_update.h"
#include "fonts.h"
GroupScreen::GroupScreen(pqxx::connection &conn, unsigned tournament, unsigned round, unsigned parallel)
bool GroupScreen::check_invalidated()
{
- // we might want to do this slightly more sophisticated later, but for now this will do
- return !valid || scores_changed.get_flag();
+ if (!valid)
+ return true;
+ if (!scores_changed.get_flag())
+ return false;
+
+ bool needs_update;
+ conn.perform(FetchNeedsUpdate(last_updated, tournament, round, parallel, &needs_update));
+
+ if (!needs_update)
+ scores_changed.reset_flag();
+
+ return needs_update;
}
void GroupScreen::draw(unsigned char *buf)
Group group;
conn.perform(FetchGroup(tournament, round, parallel, &group));
+ gettimeofday(&last_updated, NULL);
memset(buf, 0, 800 * 600 * 4);
#define _GROUPSCREEN_H 1
#include <pqxx/connection>
+#include <time.h>
+#include <sys/time.h>
#include "screen.h"
#include "flagtrigger.h"
FlagTrigger scores_changed;
pqxx::connection &conn;
bool valid;
+ struct timeval last_updated;
public:
GroupScreen(pqxx::connection &conn, unsigned tournament, unsigned round, unsigned parallel);