From a32cbe9b25d5ea8f33daa8bb6e1cb27f784fd5fb Mon Sep 17 00:00:00 2001 From: Marcel Loose <loose@astron.nl> Date: Tue, 3 Apr 2007 14:37:13 +0000 Subject: [PATCH] BugID: 991 Added CommandQueueTrigger class for handling database notifications. --- .../include/BBSControl/CommandQueueTrigger.h | 80 +++++++++++++++++++ .../BBSControl/include/BBSControl/Makefile.am | 1 + CEP/BB/BBSControl/src/CommandQueueTrigger.cc | 59 ++++++++++++++ CEP/BB/BBSControl/src/Makefile.am | 2 + 4 files changed, 142 insertions(+) create mode 100644 CEP/BB/BBSControl/include/BBSControl/CommandQueueTrigger.h create mode 100644 CEP/BB/BBSControl/src/CommandQueueTrigger.cc diff --git a/CEP/BB/BBSControl/include/BBSControl/CommandQueueTrigger.h b/CEP/BB/BBSControl/include/BBSControl/CommandQueueTrigger.h new file mode 100644 index 00000000000..bcde88f7025 --- /dev/null +++ b/CEP/BB/BBSControl/include/BBSControl/CommandQueueTrigger.h @@ -0,0 +1,80 @@ +//# CommandQueueTriggers.h: Handle trigger for the BBS command queue +//# +//# Copyright (C) 2002-2007 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +#ifndef LOFAR_BBSCONTROL_COMMANDQUEUETRIGGER_H +#define LOFAR_BBSCONTROL_COMMANDQUEUETRIGGER_H + +//# Never #include <config.h> or #include <lofar_config.h> in a header file! + +// \file +// Handle trigger for the BBS command queue + +//# Includes +#if defined(HAVE_PQXX) +# include <pqxx/trigger> +#else +# error libpqxx, the C++ API to PostgreSQL, is required +#endif + +#include <Common/lofar_string.h> + +namespace LOFAR +{ + namespace BBS + { + //# Forward Declarations + class CommandQueue; + + // \addtogroup BBSControl + // @{ + + // Functor class for handling in incoming trigger. + class CommandQueueTrigger : public pqxx::trigger + { + public: + // Constructor. The trigger handler will handle notifications received + // from the CommandQueue \a queue. + explicit CommandQueueTrigger(const CommandQueue& queue, + const string& name = ""); + + // Destructor. Reimplemented only because of no-throw specification. + virtual ~CommandQueueTrigger() throw() {} + + // Handle the notification. + virtual void operator()(int be_pid); + + private: + // Here we store a \e reference to the CommandQueue that will trigger + // notifications. + const CommandQueue& itsQueue; + + // Name associated with this trigger handler. + const string itsName; + }; + + // @} + + } // namespace BBS + +} // namespace LOFAR + +#endif diff --git a/CEP/BB/BBSControl/include/BBSControl/Makefile.am b/CEP/BB/BBSControl/include/BBSControl/Makefile.am index 4b346f9c1a7..542d45a01ba 100644 --- a/CEP/BB/BBSControl/include/BBSControl/Makefile.am +++ b/CEP/BB/BBSControl/include/BBSControl/Makefile.am @@ -15,6 +15,7 @@ pkginclude_HEADERS = \ Command.h \ CommandHandler.h \ CommandQueue.h \ + CommandQueueTrigger.h \ CommandQueueTransactors.h \ DomainRegistrationRequest.h \ Exceptions.h \ diff --git a/CEP/BB/BBSControl/src/CommandQueueTrigger.cc b/CEP/BB/BBSControl/src/CommandQueueTrigger.cc new file mode 100644 index 00000000000..248a942aba0 --- /dev/null +++ b/CEP/BB/BBSControl/src/CommandQueueTrigger.cc @@ -0,0 +1,59 @@ +//# CommandQueueTrigger.cc: Handle trigger for the BBS command queue +//# +//# Copyright (C) 2002-2007 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# This program is free software; you can redistribute it and/or modify +//# it under the terms of the GNU General Public License as published by +//# the Free Software Foundation; either version 2 of the License, or +//# (at your option) any later version. +//# +//# This program is distributed in the hope that it will be useful, +//# but WITHOUT ANY WARRANTY; without even the implied warranty of +//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//# GNU General Public License for more details. +//# +//# You should have received a copy of the GNU General Public License +//# along with this program; if not, write to the Free Software +//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//# +//# $Id$ + +//# Always #include <lofar_config.h> first! +#include <lofar_config.h> + +//# Includes +#include <BBSControl/CommandQueueTrigger.h> +#include <BBSControl/CommandQueue.h> +#include <BBSControl/Exceptions.h> +#include <Common/LofarLogger.h> +#include <Common/StreamUtil.h> +#include <Common/lofar_typeinfo.h> + +namespace LOFAR +{ + namespace BBS + { + + CommandQueueTrigger:: CommandQueueTrigger(const CommandQueue& queue, + const string& name) : + pqxx::trigger(*queue.itsConnection, name), + itsQueue(queue), + itsName(name) + { + LOG_DEBUG_STR("Created trigger handler for " << name); + } + + + void CommandQueueTrigger::operator()(int be_pid) + { + LOG_DEBUG_STR("Received notification: " << name() << + "; pid = " << be_pid); + + // itsQueue.blabla(); + } + + } // namespace BBS + +} // namespace LOFAR diff --git a/CEP/BB/BBSControl/src/Makefile.am b/CEP/BB/BBSControl/src/Makefile.am index 0c53de66af6..92c0932b2dc 100644 --- a/CEP/BB/BBSControl/src/Makefile.am +++ b/CEP/BB/BBSControl/src/Makefile.am @@ -15,7 +15,9 @@ libbbscontrol_la_SOURCES = \ BlobStreamableConnection.cc \ DomainRegistrationRequest.cc \ CommandQueue.cc \ + CommandQueueTrigger.cc \ CommandQueueTransactors.cc \ + CommandQueueTrigger.cc \ GlobalProcessControl.cc \ IterationRequest.cc \ IterationResult.cc \ -- GitLab