]> git.sesse.net Git - ccbs/blobdiff - bigscreen/ccbs_bigscreen.cpp
Fix so we actually get the NOTIFY.
[ccbs] / bigscreen / ccbs_bigscreen.cpp
index 778720f9e90aa97037dcb67db3ce1dc4acbad52a..71bd966cc1aad8e61c331feaa313605db5713634 100644 (file)
@@ -1,10 +1,49 @@
-#include <stdio.h>
+#include <cstdio>
 #include <unistd.h>
 #include <unistd.h>
+#include <pqxx/pqxx>
 #include "glwindow.h"
 
 #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 ~ExitTrigger() throw () {}
+       
+       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);
 int main(int argc, char **argv)
 {
        GLWindow glw("CCBS bigscreen", 800, 600, 32, false, 16, -1);
-       sleep(5);
+       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
+               pqxx::result res( t.exec("SELECT * FROM songs") );
+               for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
+                       std::fprintf(stderr, "%s\n", i["title"].c_str());
+               }
+               t.commit();
+               conn.get_notifs();
+               sleep(1);
+       } catch (const std::exception &e) {
+               std::fprintf(stderr, "Exception: %s\n", e.what());
+               exit(1);
+       }
+       
        return 0;
 }
        return 0;
 }