Skip to content

Commit

Permalink
Bump coolness factor
Browse files Browse the repository at this point in the history
Log ascii logo with some metadata.
Metadata added to header <fairmq/Version.h>.
  • Loading branch information
dennisklein committed Sep 13, 2018
1 parent 2c6b2e7 commit c2bea85
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 36 deletions.
54 changes: 30 additions & 24 deletions fairmq/DeviceRunner.cxx
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/

#include "DeviceRunner.h"
#include <fairmq/Tools.h>

#include <exception>
#include <fairmq/Tools.h>
#include <fairmq/Version.h>

using namespace fair::mq;

DeviceRunner::DeviceRunner(int argc, char* const argv[])
DeviceRunner::DeviceRunner(int argc, char* const argv[], bool printLogo)
: fRawCmdLineArgs(tools::ToStrVector(argc, argv, false))
, fConfig()
, fDevice(nullptr)
, fPluginManager(fRawCmdLineArgs)
, fPrintLogo(printLogo)
, fEvents()
{}

Expand All @@ -33,26 +36,34 @@ auto DeviceRunner::Run() -> int
fEvents.Emit<hooks::SetCustomCmdLineOptions>(*this);
////////////////////////

fPluginManager.ForEachPluginProgOptions([&](boost::program_options::options_description options){
fConfig.AddToCmdLineOptions(options);
});
fPluginManager.ForEachPluginProgOptions(
[&](boost::program_options::options_description options) {
fConfig.AddToCmdLineOptions(options);
});
fConfig.AddToCmdLineOptions(fPluginManager.ProgramOptions());

////// CALL HOOK ///////
fEvents.Emit<hooks::ModifyRawCmdLineArgs>(*this);
////////////////////////

if (fConfig.ParseAll(fRawCmdLineArgs, true))
{
if (fConfig.ParseAll(fRawCmdLineArgs, true)) {
return 0;
}

if (fPrintLogo) {
LOG(info) << std::endl
<< " ______ _ _______ _________ " << std::endl
<< " / ____/___ _(_)_______ |/ /_ __ \\ version " << FAIRMQ_GIT_VERSION << std::endl
<< " / /_ / __ `/ / ___/__ /|_/ /_ / / / build " << FAIRMQ_BUILD_TYPE << std::endl
<< " / __/ / /_/ / / / _ / / / / /_/ / " << FAIRMQ_REPO_URL << std::endl
<< " /_/ \\__,_/_/_/ /_/ /_/ \\___\\_\\ " << FAIRMQ_LICENSE << " © " << FAIRMQ_COPYRIGHT << std::endl;
}

////// CALL HOOK ///////
fEvents.Emit<hooks::InstantiateDevice>(*this);
////////////////////////

if (!fDevice)
{
if (!fDevice) {
LOG(error) << "getDevice(): no valid device provided. Exiting.";
return 1;
}
Expand All @@ -61,16 +72,14 @@ auto DeviceRunner::Run() -> int

// Handle --print-channels
fDevice->RegisterChannelEndpoints();
if (fConfig.Count("print-channels"))
{
if (fConfig.Count("print-channels")) {
fDevice->PrintRegisteredChannels();
fDevice->ChangeState(FairMQDevice::END);
return 0;
}

// Handle --version
if (fConfig.Count("version"))
{
if (fConfig.Count("version")) {
std::cout << "User device version: " << fDevice->GetVersion() << std::endl;
std::cout << "FAIRMQ_INTERFACE_VERSION: " << FAIRMQ_INTERFACE_VERSION << std::endl;
fDevice->ChangeState(FairMQDevice::END);
Expand Down Expand Up @@ -99,18 +108,15 @@ auto DeviceRunner::Run() -> int

auto DeviceRunner::RunWithExceptionHandlers() -> int
{
try
{
try {
return Run();
}
catch (std::exception& e)
{
LOG(error) << "Unhandled exception reached the top of main: " << e.what() << ", application will now exit";
} catch (std::exception& e) {
LOG(error) << "Unhandled exception reached the top of main: " << e.what()
<< ", application will now exit";
return 1;
}
catch (...)
{
LOG(error) << "Non-exception instance being thrown. Please make sure you use std::runtime_exception() instead. Application will now exit.";
} catch (...) {
LOG(error) << "Non-exception instance being thrown. Please make sure you use "
"std::runtime_exception() instead. Application will now exit.";
return 1;
}
}
30 changes: 18 additions & 12 deletions fairmq/DeviceRunner.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
Expand All @@ -20,18 +20,17 @@
#include <string>
#include <vector>

namespace fair
{
namespace mq
{
namespace fair {
namespace mq {

/**
* @class DeviceRunner DeviceRunner.h <fairmq/DeviceRunner.h>
* @brief Utility class to facilitate a convenient top-level device launch/shutdown.
*
* Runs a single FairMQ device with config and plugin support.
*
* For customization user hooks are executed at various steps during device launch/shutdown in the following sequence:
* For customization user hooks are executed at various steps during device launch/shutdown in the
* following sequence:
*
* LoadPlugins
* |
Expand All @@ -44,34 +43,41 @@ namespace mq
* v
* InstatiateDevice
*
* Each hook has access to all members of the DeviceRunner and really only differs by the point in time it is called.
* Each hook has access to all members of the DeviceRunner and really only differs by the point in
* time it is called.
*
* For an example usage of this class see the fairmq/runFairMQDevice.h header.
*/
class DeviceRunner
{
public:
DeviceRunner(int argc, char* const argv[]);
DeviceRunner(int argc, char* const argv[], bool printLogo = true);

auto Run() -> int;
auto RunWithExceptionHandlers() -> int;

template<typename H>
auto AddHook(std::function<void(DeviceRunner&)> hook) -> void { fEvents.Subscribe<H>("runner", hook); }
auto AddHook(std::function<void(DeviceRunner&)> hook) -> void
{
fEvents.Subscribe<H>("runner", hook);
}
template<typename H>
auto RemoveHook() -> void { fEvents.Unsubscribe<H>("runner"); }
auto RemoveHook() -> void
{
fEvents.Unsubscribe<H>("runner");
}

std::vector<std::string> fRawCmdLineArgs;
FairMQProgOptions fConfig;
std::unique_ptr<FairMQDevice> fDevice;
PluginManager fPluginManager;
const bool fPrintLogo;

private:
EventManager fEvents;
};

namespace hooks
{
namespace hooks {
struct LoadPlugins : Event<DeviceRunner&> {};
struct SetCustomCmdLineOptions : Event<DeviceRunner&> {};
struct ModifyRawCmdLineArgs : Event<DeviceRunner&> {};
Expand Down
4 changes: 4 additions & 0 deletions fairmq/Version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
#define FAIRMQ_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define FAIRMQ_GIT_VERSION "@PROJECT_GIT_VERSION@"
#define FAIRMQ_GIT_DATE "@PROJECT_GIT_DATE@"
#define FAIRMQ_REPO_URL "https://github.com/FairRootGroup/FairMQ"
#define FAIRMQ_LICENSE "LGPL-3.0"
#define FAIRMQ_COPYRIGHT "2012-2018 GSI"
#define FAIRMQ_BUILD_TYPE "@CMAKE_BUILD_TYPE@"

#endif // FAIR_MQ_VERSION_H

0 comments on commit c2bea85

Please sign in to comment.