From: Steinar H. Gunderson Date: Sun, 20 Feb 2005 02:06:44 +0000 (+0000) Subject: GroupScreen now checks the "last updated" information. X-Git-Url: https://git.sesse.net/?p=ccbs;a=commitdiff_plain;h=32d2a098bec8a1ace0f86f28110da45d060f8447 GroupScreen now checks the "last updated" information. --- diff --git a/bigscreen/Makefile b/bigscreen/Makefile index 42b031f..8cdf717 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 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 index 0000000..bbb801e --- /dev/null +++ b/bigscreen/fetch_needs_update.cpp @@ -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 index 0000000..6f101d8 --- /dev/null +++ b/bigscreen/fetch_needs_update.h @@ -0,0 +1,20 @@ +#ifndef _FETCH_NEEDS_UPDATE_H +#define _FETCH_NEEDS_UPDATE_H 1 + +#include +#include +#include + +/* 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) */ diff --git a/bigscreen/groupscreen.cpp b/bigscreen/groupscreen.cpp index d8450f8..441117d 100644 --- a/bigscreen/groupscreen.cpp +++ b/bigscreen/groupscreen.cpp @@ -1,9 +1,11 @@ +#include #include #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); diff --git a/bigscreen/groupscreen.h b/bigscreen/groupscreen.h index 2d0e81b..7297975 100644 --- a/bigscreen/groupscreen.h +++ b/bigscreen/groupscreen.h @@ -2,6 +2,8 @@ #define _GROUPSCREEN_H 1 #include +#include +#include #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);