]> git.sesse.net Git - ccbs/commitdiff
GroupScreen now checks the "last updated" information.
authorSteinar H. Gunderson <sesse@samfundet.no>
Sun, 20 Feb 2005 02:06:44 +0000 (02:06 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sun, 20 Feb 2005 02:06:44 +0000 (02:06 +0000)
bigscreen/Makefile
bigscreen/fetch_needs_update.cpp [new file with mode: 0644]
bigscreen/fetch_needs_update.h [new file with mode: 0644]
bigscreen/groupscreen.cpp
bigscreen/groupscreen.h

index 42b031f4d45c52183a06d63f735241c5c6b8f5da..8cdf7175b719de1cc2791721058e291e4acc244a 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 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
 
diff --git a/bigscreen/fetch_needs_update.cpp b/bigscreen/fetch_needs_update.cpp
new file mode 100644 (file)
index 0000000..bbb801e
--- /dev/null
@@ -0,0 +1,26 @@
+#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;
+       }
+}
diff --git a/bigscreen/fetch_needs_update.h b/bigscreen/fetch_needs_update.h
new file mode 100644 (file)
index 0000000..6f101d8
--- /dev/null
@@ -0,0 +1,20 @@
+#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) */
index d8450f8679d370a8e16b97170433e5e75ae6855b..441117d45e29f95e58056748ab2add1635b5a93e 100644 (file)
@@ -1,9 +1,11 @@
+#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)
@@ -17,8 +19,18 @@ GroupScreen::~GroupScreen()
 
 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)
@@ -27,6 +39,7 @@ 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);
 
index 2d0e81b608c68cc686208a26a912734bdf062fac..72979750cd254550013d288a6125f952b79124a2 100644 (file)
@@ -2,6 +2,8 @@
 #define _GROUPSCREEN_H 1
 
 #include <pqxx/connection>
+#include <time.h>
+#include <sys/time.h>
 
 #include "screen.h"
 #include "flagtrigger.h"
@@ -14,6 +16,7 @@ private:
        FlagTrigger scores_changed;
        pqxx::connection &conn;
        bool valid;
+       struct timeval last_updated;
 
 public:
        GroupScreen(pqxx::connection &conn, unsigned tournament, unsigned round, unsigned parallel);