Skip to content
Snippets Groups Projects
Commit 47ac86db authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #7432: Added FindUUID, and generate timestamp + uuid for qpid messages...

Task #7432: Added FindUUID, and generate timestamp + uuid for qpid messages (actually using Qpids own UUID functions)
parent 4a7afcd1
No related branches found
No related tags found
No related merge requests found
# - 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)
......@@ -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);
}
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment