Try to listen on a NOTIFY trigger.
authorSteinar H. Gunderson <sesse@samfundet.no>
Fri, 18 Feb 2005 17:55:57 +0000 (17:55 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Fri, 18 Feb 2005 17:55:57 +0000 (17:55 +0000)
bigscreen/ccbs_bigscreen.cpp

index 6afc0a0..bd8b37b 100644 (file)
@@ -3,11 +3,32 @@
 #include <pqxx/pqxx>
 #include "glwindow.h"
 
+/*
+ * A trigger that exits whenever it's trigged (used when we change big things
+ * such as starting a new tournament, and it's not really worth doing a clean
+ * change).
+ */
+class ExitTrigger : pqxx::trigger {
+public:
+       ExitTrigger(pqxx::connection_base &conn, const PGSTD::string &name)
+               : pqxx::trigger(conn, name) {}
+       
+       virtual void operator() (int pid)
+       {
+               std::fprintf(stderr, "Received an exit trigger from pid %u\n", pid);
+               exit(0);
+       }
+};
+
 int main(int argc, char **argv)
 {
        GLWindow glw("CCBS bigscreen", 800, 600, 32, false, 16, -1);
        try {
                pqxx::connection conn("dbname=ccbs host=sql.samfundet.no user=ccbs password=GeT|>>B_");
+               ExitTrigger et(conn, "bs_tournament_changed");
+               
+               sleep(1);
+
                pqxx::work t(conn, "trx");
 
                // fetch all songs
@@ -16,6 +37,8 @@ int main(int argc, char **argv)
                        std::fprintf(stderr, "%s\n", i["title"].c_str());
                }
                t.commit();
+
+               sleep(1);
        } catch (const std::exception &e) {
                std::fprintf(stderr, "Exception: %s\n", e.what());
                exit(1);