diff --git a/CMake/FindUUID.cmake b/CMake/FindUUID.cmake new file mode 100644 index 0000000000000000000000000000000000000000..7fdac87a2aae3c3e6ce19e92ae5e3b67db80426f --- /dev/null +++ b/CMake/FindUUID.cmake @@ -0,0 +1,49 @@ +# - Try to find libuuid: A library to generate UUIDs +# Variables used by this module: +# UUID_ROOT_DIR - QPID root directory +# Variables defined by this module: +# UUID_FOUND - system has UUID +# UUID_INCLUDE_DIR - the UUID include directory (cached) +# UUID_INCLUDE_DIRS - the UUID include directories +# (identical to UUID_INCLUDE_DIR) +# UUID_LIBRARY - the UUID library (cached) +# UUID_LIBRARIES - the UUID libraries +# (identical to UUID_LIBRARY) + +# 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$ + +if(NOT UUID_FOUND) + + find_path(UUID_INCLUDE_DIR uuid/uuid.h + HINTS ${UUID_ROOT_DIR} PATH_SUFFIXES include) + find_library(UUID_LIBRARY uuid + HINTS ${UUID_ROOT_DIR} PATH_SUFFIXES lib) + + mark_as_advanced(UUID_INCLUDE_DIR UUID_LIBRARY) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(UUID DEFAULT_MSG + UUID_LIBRARY UUID_INCLUDE_DIR) + + set(UUID_INCLUDE_DIRS ${UUID_INCLUDE_DIR}) + set(UUID_LIBRARIES ${UUID_LIBRARY}) + +endif(NOT UUID_FOUND) diff --git a/LCS/MessageBus/src/Message.cc b/LCS/MessageBus/src/Message.cc index 23e620ae0e260d197cbf8cf99de3a4fae2cd87ce..7f8f56e667690714d757612b666cbd687f177873 100644 --- a/LCS/MessageBus/src/Message.cc +++ b/LCS/MessageBus/src/Message.cc @@ -29,6 +29,11 @@ #include <Common/StringUtil.h> #include <MessageBus/Message.h> +#include <qpid/types/Uuid.h> + +#include <time.h> + + namespace LOFAR { using namespace StringUtil; @@ -58,6 +63,27 @@ const string LOFAR_MSG_TEMPLATE = "\ </payload>\n\ </message>"; +static string _timestamp() { + // Get now (in seconds since epoch) + time_t now = time(NULL); + + // Dissect into components (year, month, etc) + struct tm now_tm; + gmtime_r(&now, &now_tm); + + // Convert to string + char buffer[64]; + if (strftime(buffer, sizeof buffer, "%FT%T", &now_tm) == 0) + buffer[0] = 0; + + return buffer; +} + +static string _uuid() { + qpid::types::Uuid uuid(true); + return uuid.str(); +} + Message::Message(const std::string &from, const std::string &forUser, const std::string &summary, @@ -67,7 +93,7 @@ Message::Message(const std::string &from, const std::string &sasid) { itsQpidMsg.setContent(formatString(LOFAR_MSG_TEMPLATE.c_str(), protocol.c_str(), protocolVersion.c_str(), - from.c_str(), forUser.c_str(), "", "", summary.c_str(), + from.c_str(), forUser.c_str(), _uuid().c_str(), _timestamp().c_str(), summary.c_str(), momid.c_str(), sasid.c_str(), "%s")); } @@ -117,6 +143,9 @@ std::ostream& Message::print (std::ostream& os) const os << "momid : " << momid() << endl; os << "sasid : " << sasid() << endl; os << "payload : " << payload() << endl; + os << "BEGIN FULL PACKET" << endl; + os << itsQpidMsg.getContent() << endl; + os << "END FULL PACKET" << endl; return (os); } diff --git a/LCS/MessageBus/src/message.py b/LCS/MessageBus/src/message.py index ddf68582db662474a098c06757353971338f17c7..7d0aa47cd4e8f3d51f1db9e8a38a856f9349e06b 100644 --- a/LCS/MessageBus/src/message.py +++ b/LCS/MessageBus/src/message.py @@ -18,6 +18,7 @@ import qpid.messaging import xml.dom.minidom as xml +import datetime LOFAR_MSG_TEMPLATE = """ <message> @@ -44,6 +45,19 @@ LOFAR_MSG_TEMPLATE = """ </payload> </message>""" +def _timestamp(): + """ + Return the current time as YYYY-MM-DDTHH:MM:SS + """ + now = datetime.datetime.now() + return now.strftime("%FT%T") + +def _uuid(): + """ + Return an UUID + """ + return str(qpid.messaging.uuid4()) + class Message(object): def __init__(self, from_, forUser, summary, protocol, protocolVersion, momid, sasid): self.document = xml.parseString(LOFAR_MSG_TEMPLATE) @@ -59,8 +73,8 @@ class Message(object): self.from_ = from_ self.forUser = forUser self.summary = summary - self.uuid = "" - self.timestamp = "" + self.uuid = _uuid() + self.timestamp = _timestamp() self.momid = momid self.sasid = sasid diff --git a/lofar_config.h.cmake b/lofar_config.h.cmake index a08d70c1d91db1a30f6b4d22da3048ddd0706c5b..82188e2d50dec046ed5e56b5a86a20c2863b8c3d 100644 --- a/lofar_config.h.cmake +++ b/lofar_config.h.cmake @@ -165,6 +165,9 @@ /* Defined if shared memory is used */ #cmakedefine HAVE_SHMEM 1 +/* Defined if uuid is installed */ +#cmakedefine HAVE_UUID 1 + /* Define if WCSLIB is installed */ #cmakedefine HAVE_WCSLIB 1