diff --git a/LCS/MessageBus/include/MessageBus/Message.h b/LCS/MessageBus/include/MessageBus/Message.h index 1117ac5545c76d88e1bcbc1d10339ac3ab214120..02989063493115ee59fa4d8d0d0f6503d3b08351 100644 --- a/LCS/MessageBus/include/MessageBus/Message.h +++ b/LCS/MessageBus/include/MessageBus/Message.h @@ -26,6 +26,9 @@ #ifdef HAVE_QPID #include <qpid/messaging/Message.h> #include <qpid/types/Variant.h> +#else +#include <MessageBus/QpidMock.h> +#endif #include <string> #include <ostream> @@ -126,5 +129,3 @@ inline std::ostream &operator<<(std::ostream &os, const Message &msg) #endif -#endif - diff --git a/LCS/MessageBus/include/MessageBus/MsgBus.h b/LCS/MessageBus/include/MessageBus/MsgBus.h index 849c43bad7fe060c9db19ebf47ae8dd56835cca3..29ff84ba6e7b7cefae6b21af8fb9165bb1d04081 100644 --- a/LCS/MessageBus/include/MessageBus/MsgBus.h +++ b/LCS/MessageBus/include/MessageBus/MsgBus.h @@ -30,6 +30,9 @@ #include <qpid/messaging/Sender.h> #include <qpid/messaging/Session.h> #include <qpid/messaging/Address.h> +#else +#include <MessageBus/QpidMock.h> +#endif #include <Common/Exception.h> #include <MessageBus/Message.h> @@ -86,5 +89,3 @@ private: #endif -#endif - diff --git a/LCS/MessageBus/include/MessageBus/QpidMock.h b/LCS/MessageBus/include/MessageBus/QpidMock.h new file mode 100644 index 0000000000000000000000000000000000000000..5b7c428d49895b37892e988c6a043b0bbb839ae3 --- /dev/null +++ b/LCS/MessageBus/include/MessageBus/QpidMock.h @@ -0,0 +1,151 @@ +//# QpidMock.h: A fake implementation of the QPID API +//# +//# Copyright (C) 2015 +//# ASTRON (Netherlands Institute for Radio Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands +//# +//# This file is part of the LOFAR software suite. +//# The LOFAR software suite 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 3 of the License, or +//# (at your option) any later version. +//# +//# The LOFAR software suite 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 the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. +//# +//# $Id$ + +#ifndef LOFAR_MESSAGEBUS_QPIDMUCK_H +#define LOFAR_MESSAGEBUS_QPIDMUCK_H + +#ifndef HAVE_QPID +#include <Common/LofarLogger.h> +#include <string> +#include <map> +#include <list> +#include <ostream> +#include <climits> + +/* + * Provide all the classes and types in the qpid namespace + * that are used by LOFAR. Where possible, return codes will + * indicate that messages are not sent or received. + * + * No exceptions are thrown. Messages only keep track of their content. + * + * Also, using this mock will result in WARNINGS in the log + * that messaging will not take place. + */ + +namespace qpid { + namespace types { + typedef std::exception Exception; + + class Variant { + public: + typedef std::map<std::string, std::string> Map; + typedef std::list<std::string> List; + }; + + class Uuid { + public: + Uuid(bool) {} + + std::string str() const { return "uuid"; } + }; + } + + namespace messaging { + class Duration { + public: + Duration(unsigned long) {} + + static const unsigned long FOREVER = ULONG_MAX; + }; + + typedef std::string Address; + + class Message { + public: + Message() {} + Message(const std::string &content): content(content) {} + + void setContent(const std::string &newContent) { content = newContent; } + std::string getContent() const { return content; } + + void setContentType(const std::string &) {} + void setDurable(bool) {} + + std::string getMessageId() const { return ""; } + std::string getUserId() const { return ""; } + std::string getCorrelationId() const { return ""; } + std::string getSubject() const { return ""; } + std::string getReplyTo() const { return ""; } + std::string getContentType() const { return ""; } + unsigned getPriority() const { return 0; } + bool getDurable() const { return false; } + bool getRedelivered() const { return false; } + types::Variant::Map getProperties() const { return types::Variant::Map(); } + unsigned getContentSize() const { return content.size(); } + unsigned getTtl() const { return 0; } + protected: + std::string content; + }; + + class Receiver { + public: + void setCapacity(unsigned) {} + + std::string getName() const { return ""; } + + bool get(Message &, Duration = Duration::FOREVER) { return false; } + }; + + class Sender { + public: + std::string getName() const { return ""; } + + void send(const Message &, bool) {} + }; + + class Session { + public: + void acknowledge(Message&) {} + void reject(Message&) {} + void release(Message&) {} + + Sender createSender(const std::string &) { return Sender(); } + Receiver createReceiver(const std::string &) { return Receiver(); } + + bool nextReceiver(Receiver&, Duration) { return false; } + }; + + class Connection { + public: + Connection(const std::string &, const std::string &) { + LOG_WARN_STR("QPID support NOT enabled! Will NOT connect to any broker, and messages will be lost!"); + } + + std::string getUrl() const { return ""; } + + void open() {} + void close() {} + + Session createSession() { return Session(); } + }; + } +} + +std::ostream& operator<<(std::ostream& out, const qpid::types::Variant& value); +std::ostream& operator<<(std::ostream& out, const qpid::types::Variant::Map& map); +std::ostream& operator<<(std::ostream& out, const qpid::types::Variant::List& list); + +#endif + +#endif + diff --git a/LCS/MessageBus/src/CMakeLists.txt b/LCS/MessageBus/src/CMakeLists.txt index e8062864899dc5048adb5fcc42620b8d8d9ea9fc..73a0d969dc36e8e738f1736f807c392b099936b1 100644 --- a/LCS/MessageBus/src/CMakeLists.txt +++ b/LCS/MessageBus/src/CMakeLists.txt @@ -7,7 +7,8 @@ set(messagebus_LIB_SRCS Package__Version.cc LogSink.cc MsgBus.cc - Message.cc) + Message.cc + QpidMock.cc) set(messagebus_PROGRAMS ) diff --git a/LCS/MessageBus/src/LogSink.cc b/LCS/MessageBus/src/LogSink.cc index 9e698119ebd12d8dd313617a98ef5067d92c2c80..a40f54c9f6d7a6bd8f6bfa416ab6d5ccd025847b 100644 --- a/LCS/MessageBus/src/LogSink.cc +++ b/LCS/MessageBus/src/LogSink.cc @@ -8,13 +8,13 @@ #include <string> #include <sstream> +namespace LOFAR { + #ifdef HAVE_QPID #include <qpid/messaging/Logger.h> using namespace qpid::messaging; -namespace LOFAR { - class QpidLogSink: public LoggerOutput { public: QpidLogSink() { @@ -85,6 +85,11 @@ namespace LOFAR { Logger::setOutput(qpidLogSink); } +#else + void qpidlogsink_init() { + LOG_WARN("QPID support NOT enabled! Messaging will NOT be functional!"); + } +#endif + } // namespace LOFAR -#endif diff --git a/LCS/MessageBus/src/LogSink.h b/LCS/MessageBus/src/LogSink.h index ddddee4c8dcb620abdcf2ef4506b87888ed9e50f..907d81adf8cf38b4dacd6dc1fcc0f119bfb92c5d 100644 --- a/LCS/MessageBus/src/LogSink.h +++ b/LCS/MessageBus/src/LogSink.h @@ -25,12 +25,8 @@ namespace LOFAR { -#ifdef HAVE_QPID - void qpidlogsink_init(); -#endif - } // namespace LOFAR #endif diff --git a/LCS/MessageBus/src/Message.cc b/LCS/MessageBus/src/Message.cc index 2993229754a543729f77c8335b4bc87873a755bb..18f80492de38154c68e1bd730870420d87cf30e4 100644 --- a/LCS/MessageBus/src/Message.cc +++ b/LCS/MessageBus/src/Message.cc @@ -29,7 +29,9 @@ #include <Common/StringUtil.h> #include <MessageBus/Message.h> +#ifdef HAVE_QPID #include <qpid/types/Uuid.h> +#endif #include <time.h> diff --git a/LCS/MessageBus/src/MsgBus.cc b/LCS/MessageBus/src/MsgBus.cc index e40584cb3cee3a477a324811060f3411d77b1463..01b6e8e50ff0eeac89e6ce726258bab12a911b94 100644 --- a/LCS/MessageBus/src/MsgBus.cc +++ b/LCS/MessageBus/src/MsgBus.cc @@ -7,6 +7,8 @@ #ifdef HAVE_QPID #include <qpid/types/Exception.h> #include <qpid/messaging/exceptions.h> +#endif + #include <stdlib.h> using namespace qpid::messaging; @@ -174,4 +176,3 @@ namespace LOFAR { } // namespace LOFAR -#endif diff --git a/LCS/MessageBus/src/QpidMock.cc b/LCS/MessageBus/src/QpidMock.cc new file mode 100644 index 0000000000000000000000000000000000000000..45e3d5e48e66d1b72dea9239f60e104dcacf9d68 --- /dev/null +++ b/LCS/MessageBus/src/QpidMock.cc @@ -0,0 +1,44 @@ +//# QpidMock.cc: A fake implementation of the QPID API +//# +//# Copyright (C) 2015 +//# ASTRON (Netherlands Institute for Radio Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands +//# +//# This file is part of the LOFAR software suite. +//# The LOFAR software suite 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 3 of the License, or +//# (at your option) any later version. +//# +//# The LOFAR software suite 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 the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. +//# +//# $Id$ + +#include <lofar_config.h> + +#ifndef HAVE_QPID +#include <MessageBus/QpidMock.h> + +std::ostream& operator<<(std::ostream& out, const qpid::types::Variant& value) { + (void)value; + return out; +} + +std::ostream& operator<<(std::ostream& out, const qpid::types::Variant::Map& map) { + (void)map; + return out; +} + +std::ostream& operator<<(std::ostream& out, const qpid::types::Variant::List& list) { + (void)list; + return out; +} + +#endif +