Skip to content

Commit

Permalink
BLD: changes required by the new AGPL SeisComP
Browse files Browse the repository at this point in the history
Also removed c++11 flag as it is required for all SeisComP code anyway
  • Loading branch information
luca-s committed Nov 13, 2020
1 parent 71607cb commit bbebc0c
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 42 deletions.
9 changes: 2 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ SC_BEGIN_PACKAGE(RTDD)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/libs)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/libs)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../system/libs)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../system/libs)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../trunk/libs)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../trunk/libs)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../base/common/libs)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../../base/common/libs)

SET(RTDDMSG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/core)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

SUBDIRS(libs apps plugins)
2 changes: 1 addition & 1 deletion apps/scrtdd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ INCLUDE_DIRECTORIES(${RTDDMSG_DIR})

SC_ADD_EXECUTABLE(RTDD ${RTDD_TARGET})
SC_LINK_LIBRARIES_INTERNAL(${RTDD_TARGET} client rtddmsg)
SC_INSTALL_INIT(${RTDD_TARGET} ../../../trunk/apps/templates/initd.py)
SC_INSTALL_INIT(${RTDD_TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/../../../../base/common/apps/templates/initd.py)

FILE(GLOB descs "${CMAKE_CURRENT_SOURCE_DIR}/descriptions/*.xml")
INSTALL(FILES ${descs} DESTINATION ${SC3_PACKAGE_APP_DESC_DIR})
12 changes: 6 additions & 6 deletions apps/scrtdd/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void readConfig(const Seiscomp::Client::Application *,
{}

template <typename T>
void readCLI(const Seiscomp::Client::CommandLine *,
void readCLI(const Seiscomp::System::CommandLine *,
T *storage,
const char *name)
{}
Expand All @@ -47,7 +47,7 @@ void readCLI(const Seiscomp::Client::CommandLine *,
}

template <>
void readCLI<bool>(const Seiscomp::Client::CommandLine *cli,
void readCLI<bool>(const Seiscomp::System::CommandLine *cli,
bool *storage,
const char *name)
{
Expand All @@ -68,7 +68,7 @@ template <typename T> struct OptionImpl : Application::Option
storage(var)
{}

void bind(Seiscomp::Client::CommandLine *cli)
void bind(Seiscomp::System::CommandLine *cli)
{
if (cliParam == nullptr) return;
if (cliGroup != nullptr) cli->addGroup(cliGroup);
Expand All @@ -79,7 +79,7 @@ template <typename T> struct OptionImpl : Application::Option
storage, cliDefault);
}

bool get(Seiscomp::Client::CommandLine *cli)
bool get(Seiscomp::System::CommandLine *cli)
{
if (cliParam == nullptr) return true;
if (cliSwitch) readCLI(cli, storage, cliParam);
Expand Down Expand Up @@ -111,7 +111,7 @@ template <typename T> struct OptionVecImpl : Application::Option
storage(var)
{}

void bind(Seiscomp::Client::CommandLine *cli)
void bind(Seiscomp::System::CommandLine *cli)
{
if (cliParam == nullptr) return;

Expand All @@ -120,7 +120,7 @@ template <typename T> struct OptionVecImpl : Application::Option
cli->addOption(cliGroup ? cliGroup : "Generic", cliParam, cliDesc, storage);
}

bool get(Seiscomp::Client::CommandLine *cli)
bool get(Seiscomp::System::CommandLine *cli)
{
if (cliParam == nullptr) return true;
if (cliSwitch) readCLI(cli, storage, cliParam);
Expand Down
4 changes: 2 additions & 2 deletions apps/scrtdd/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class Application : public Seiscomp::Client::StreamApplication
cliDesc(clidesc), cliDefault(clidefault), cliSwitch(cliswitch)
{}

virtual void bind(Seiscomp::Client::CommandLine *cli) = 0;
virtual bool get(Seiscomp::Client::CommandLine *cli) = 0;
virtual void bind(Seiscomp::System::CommandLine *cli) = 0;
virtual bool get(Seiscomp::System::CommandLine *cli) = 0;
virtual bool get(const Seiscomp::Client::Application *app) = 0;
virtual void printStorage(std::ostream &os) = 0;

Expand Down
2 changes: 1 addition & 1 deletion apps/scrtdd/hdd/waveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void writeTrace(GenericRecordCPtr trace, const std::string &file)
{
std::ofstream ofs(file);
IO::MSeedRecord msRec(*trace);
int reclen = msRec.data()->size() * msRec.data()->bytes() + 64;
int reclen = msRec.data()->size() * msRec.data()->elementSize() + 64;
reclen = nextPowerOf2<int>(reclen, 128,
1048576); // MINRECLEN 128, MAXRECLEN 1048576
if (reclen > 0)
Expand Down
4 changes: 2 additions & 2 deletions apps/scrtdd/rtdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ void RTDD::handleMessage(Core::Message *msg)
// Inform scolv we are going to relocate this origin or not
reloc_resp.setRequestAccepted(!reloc_resp.hasError());

if (!connection()->send("SERVICE_REQUEST", &reloc_resp))
if (!connection()->send("SERVICE_PROVIDE", &reloc_resp))
SEISCOMP_ERROR("Failed sending relocation response");

if (!reloc_resp.hasError())
Expand All @@ -1403,7 +1403,7 @@ void RTDD::handleMessage(Core::Message *msg)
: "no relocation errors")
.c_str());

if (!connection()->send("SERVICE_REQUEST", &reloc_resp))
if (!connection()->send("SERVICE_PROVIDE", &reloc_resp))
SEISCOMP_ERROR("Failed sending relocation response");
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/core/rtddmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#ifndef __RTDD_CORE_RTDDMSG_H__
#define __RTDD_CORE_RTDDMSG_H__

#include <seiscomp3/communication/systemmessages.h>
#include <seiscomp/client.h>
#include <seiscomp3/core/genericmessage.h>
#include <seiscomp3/datamodel/origin.h>
#include <seiscomp3/io/archive/xmlarchive.h>
Expand Down
48 changes: 28 additions & 20 deletions plugins/locator/rtddloc/rtddloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool RTDDLocator::init(const Config::Config &config)
_allowedParameters.push_back("RELOC_TIMEOUT");
}
// Set defaults value
_parameters["RTDD_HOST"] = "localhost";
_parameters["RTDD_HOST"] = "localhost/production";
_parameters["RELOC_TIMEOUT"] = "300"; // seconds

//
Expand Down Expand Up @@ -102,22 +102,29 @@ bool RTDDLocator::setParameter(const string &name, const string &value)
return true;
}

Communication::ConnectionPtr RTDDLocator::createConnection()
Client::ConnectionPtr RTDDLocator::createConnection()
{
Communication::ConnectionPtr connection;
Client::ConnectionPtr connection(new Client::Connection());

connection = Communication::Connection::Create(_parameters["RTDD_HOST"], "",
"SERVICE_REQUEST");
if (!connection)
if (!_parameters["RTDD_HOST"].empty())
{
if (!connection->setSource(_parameters["RTDD_HOST"]))
{
throw GeneralException(stringify("Failed to create connection to '%s'",
_parameters["RTDD_HOST"].c_str()));
}
}

if (connection->connect("", "SERVICE_REQUEST", 5) != Client::OK)
{
throw GeneralException(stringify("Failed to create connection to '%s'",
_parameters["RTDD_HOST"].c_str()));
}

if (connection->subscribe("SERVICE_REQUEST") != Status::SEISCOMP_SUCCESS)
if (connection->subscribe("SERVICE_PROVIDE") != Client::OK)
{
connection.reset();
throw GeneralException("Failed to subscribe to SERVICE_REQUEST");
connection->disconnect();
throw GeneralException("Failed to subscribe to SERVICE_PROVIDE");
}

return connection;
Expand All @@ -133,8 +140,10 @@ Origin *RTDDLocator::relocate(const Origin *origin)
//
// prepare the connection to the messaging
//
double msgWaitTimeout = std::stod(_parameters["RELOC_TIMEOUT"]);
Communication::ConnectionPtr connection = createConnection();
double msgWaitTimeout = std::stod(_parameters["RELOC_TIMEOUT"]);
Client::ConnectionPtr connection = createConnection();
// set receiving messages timeout to 100 milli sec
connection->setTimeout(100);

//
// send relocation request
Expand All @@ -145,7 +154,12 @@ Origin *RTDDLocator::relocate(const Origin *origin)
nonConstOrg->add(DataModel::Arrival::Cast(origin->arrival(i)->clone()));
msg.setOrigin(nonConstOrg);
msg.setProfile(_currentProfile);
connection->send(&msg);
if (!connection->send(&msg))
{
throw LocatorException(
string("Error while seinding relocatio request message to scrtdd: ") +
connection->lastError().toString());
}

//
// wait 1 second for a request accepted response
Expand All @@ -155,9 +169,7 @@ Origin *RTDDLocator::relocate(const Origin *origin)
Core::Time started = Core::Time::GMT();
while ((Core::Time::GMT() - started).length() < 1)
{
int error;
Message *msg = connection->readMessage(
false, Communication::Connection::READ_ALL, NULL, &error);
Message *msg = connection->recv();
RTDDRelocateResponseMessage *relocMsg =
RTDDRelocateResponseMessage::Cast(msg);
if (relocMsg)
Expand All @@ -174,7 +186,6 @@ Origin *RTDDLocator::relocate(const Origin *origin)
break;
}
}
Core::msleep(0.1);
}

//
Expand All @@ -195,9 +206,7 @@ Origin *RTDDLocator::relocate(const Origin *origin)
started = Core::Time::GMT();
while ((Core::Time::GMT() - started).length() < msgWaitTimeout)
{
int error;
Message *msg = connection->readMessage(
false, Communication::Connection::READ_ALL, NULL, &error);
Message *msg = connection->recv();
RTDDRelocateResponseMessage *relocMsg =
RTDDRelocateResponseMessage::Cast(msg);
if (relocMsg)
Expand All @@ -206,7 +215,6 @@ Origin *RTDDLocator::relocate(const Origin *origin)
if (relocMsg->hasError()) throw LocatorException(relocMsg->getError());
return relocMsg->getOrigin().get();
}
Core::msleep(0.1);
}

throw LocatorException(
Expand Down
4 changes: 2 additions & 2 deletions plugins/locator/rtddloc/rtddloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#ifndef __RTDD_PLUGIN_RTDDLOC_H__
#define __RTDD_PLUGIN_RTDDLOC_H__

#include <seiscomp3/communication/connection.h>
#include <seiscomp3/core/plugin.h>
#include <seiscomp3/messaging/connection.h>
#include <seiscomp3/seismology/locatorinterface.h>
#include <string>

Expand Down Expand Up @@ -86,7 +86,7 @@ class RTDDLocator : public Seiscomp::Seismology::LocatorInterface
// Private members
// ----------------------------------------------------------------------
private:
Communication::ConnectionPtr createConnection();
Client::ConnectionPtr createConnection();

ParameterMap _parameters;
IDList _profileNames;
Expand Down

0 comments on commit bbebc0c

Please sign in to comment.