Index: /trunk/FACT++/src/gcn.cc
===================================================================
--- /trunk/FACT++/src/gcn.cc	(revision 19563)
+++ /trunk/FACT++/src/gcn.cc	(revision 19564)
@@ -1,4 +1,6 @@
 #include <functional>
 #include <boost/algorithm/string/join.hpp>
+
+#include "Database.h"
 
 #include "Dim.h"
@@ -41,4 +43,6 @@
     bool fDebugRx;
 
+    string fUri;
+
     uint32_t     fRxSize;
     vector<char> fRxData;
@@ -79,5 +83,5 @@
     {
         if (root.isNull())
-            return -1;
+            return -255;
 
         const string role = root.attribute("role", "").toStdString();
@@ -93,5 +97,5 @@
                 const QDomElement time = root.firstChildElement("TimeStamp");
                 if (orig.isNull() || time.isNull())
-                    return -1;
+                    return -254;
 
                 fLastKeepAlive = Time(time.text().toStdString());
@@ -126,5 +130,5 @@
             //const QDomElement ref  = root.firstChildElement("Reference");
             if (who.isNull() || what.isNull() || when.isNull())
-                return -1;
+                return -253;
 
             const auto ptype = GetType(what);
@@ -149,4 +153,10 @@
 
             const auto &id = ptype->first;
+
+            if (id==0)
+            {
+                Warn("Packet ID = 0");
+                return -252;
+            }
 
             // Gravitational wave event
@@ -187,5 +197,5 @@
             {
                 Warn("Missing elements: "+boost::algorithm::join(missing, ", "));
-                return -1;
+                return -id;
             }
 
@@ -468,5 +478,5 @@
             Out() << fRxData.data() << '\n';
             Out() << "------------------------------------------------------" << endl;
-            PostClose(false);
+            PostClose(true);
             return;
         }
@@ -482,5 +492,28 @@
             Out() << fRxData.data() << '\n';
             Out() << "------------------------------------------------------" << endl;
-            PostClose(false);
+            //PostClose(false);
+
+            try
+            {
+                auto db = Database(fUri);
+
+                // Make an entry in the alter databse to issue a call
+                const string query =
+                    "INSERT FlareTriggers SET\n"
+                    " fTriggerInserted=Now(),\n"
+                    " fNight="+to_string(Time().NightAsInt())+",\n"
+                    " fRunID="+to_string(-rc)+",\n"
+                    " fTriggerType=8";
+
+                auto q = db.query(query);
+                q.execute();
+                if (!q.info().empty())
+                    Info(q.info());
+            }
+            catch (const mysqlpp::ConnectionFailed &e)
+            {
+                Error(e.what());
+            }
+
             return;
         }
@@ -525,4 +558,9 @@
         fDebugRx = b;
         Connection::SetVerbose(b);
+    }
+
+    void SetURI(const string &uri)
+    {
+        fUri = uri;
     }
 
@@ -680,4 +718,6 @@
         fGCN.SetEndPoints(conf.Vec<string>("addr"));
 
+        fGCN.SetURI(conf.Get<string>("schedule-database"));
+
         return -1;
     }
@@ -701,4 +741,5 @@
         ("addr,a",        vars<string>(),  "Network addresses of GCN server")
         ("quiet,q",       po_bool(true),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
+        ("schedule-database", var<string>(), "Database link as in\n\tuser:password@server[:port]/database[?compress=0|1].")
         ;
 
