Skip to content

Commit b7b9464

Browse files
TMP: second attempt
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
1 parent ff7dfe9 commit b7b9464

3 files changed

Lines changed: 60 additions & 36 deletions

File tree

ddsenabler/include/ddsenabler/DDSEnabler.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <ddsenabler_yaml/EnablerConfiguration.hpp>
4343

4444
#include <ddsenabler/CallbackSet.hpp>
45+
#include <ddsenabler/library/library_dll.h>
4546

4647
namespace eprosima {
4748
namespace ddsenabler {
@@ -61,6 +62,7 @@ class DDSEnabler
6162
* @param configuration: Structure encapsulating all enabler configuration options.
6263
* @param callbacks: Set of callbacks to be used by the enabler.
6364
*/
65+
DDSENABLER_DllAPI
6466
DDSEnabler(
6567
const yaml::EnablerConfiguration& configuration,
6668
const CallbackSet& callbacks);
@@ -72,6 +74,7 @@ class DDSEnabler
7274
*
7375
* @return \c true if operation was succesful, \c false otherwise.
7476
*/
77+
DDSENABLER_DllAPI
7578
bool set_file_watcher(
7679
const std::string& file_path);
7780

@@ -84,6 +87,7 @@ class DDSEnabler
8487
* @return \c RETCODE_NO_DATA if new allowed topics list is the same as the previous one
8588
* @return \c RETCODE_ERROR if any other error has occurred.
8689
*/
90+
DDSENABLER_DllAPI
8791
utils::ReturnCode reload_configuration(
8892
yaml::EnablerConfiguration& new_configuration);
8993

@@ -94,6 +98,7 @@ class DDSEnabler
9498
* @param json: The JSON message to publish.
9599
* @return \c true if the message was published successfully, \c false otherwise.
96100
*/
101+
DDSENABLER_DllAPI
97102
bool publish(
98103
const std::string& topic_name,
99104
const std::string& json);

ddsenabler/include/ddsenabler/dds_enabler_runner.hpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,38 @@
1919

2020
#pragma once
2121

22-
#include <memory>
23-
#include <string>
24-
25-
#include <cpp_utils/event/FileWatcherHandler.hpp>
26-
#include <cpp_utils/event/PeriodicEventHandler.hpp>
27-
#include <cpp_utils/exception/ConfigurationException.hpp>
28-
#include <cpp_utils/exception/InitializationException.hpp>
29-
#include <cpp_utils/logging/BaseLogConfiguration.hpp>
30-
#include <cpp_utils/logging/StdLogConsumer.hpp>
31-
#include <cpp_utils/ReturnCode.hpp>
32-
#include <cpp_utils/time/time_utils.hpp>
33-
34-
#include <ddspipe_core/logging/DdsLogConsumer.hpp>
35-
3622
#include <ddsenabler_yaml/EnablerConfiguration.hpp>
3723

3824
#include <ddsenabler/CallbackSet.hpp>
3925
#include <ddsenabler/DDSEnabler.hpp>
4026

27+
#include <ddsenabler/library/library_dll.h>
28+
4129
namespace eprosima {
4230
namespace ddsenabler {
4331

32+
/**
33+
* @brief Create a DDS Enabler instance from a configuration file path.
34+
*
35+
* @param configuration_path Path to the configuration file.
36+
* @param callbacks Set of callbacks to be used by the DDS Enabler.
37+
* @param enabler Output parameter to hold the created DDS Enabler instance.
38+
* @return true if the DDS Enabler was created successfully, false otherwise.
39+
*/
40+
DDSENABLER_DllAPI
4441
bool create_dds_enabler(
45-
const char* ddsEnablerConfigFile,
42+
const char* configuration_path,
4643
const CallbackSet& callbacks,
4744
std::shared_ptr<DDSEnabler>& enabler);
48-
45+
/**
46+
* @brief Create a DDS Enabler instance from a configuration object.
47+
*
48+
* @param configuration DDS Enabler configuration object.
49+
* @param callbacks Set of callbacks to be used by the DDS Enabler.
50+
* @param enabler Output parameter to hold the created DDS Enabler instance.
51+
* @return true if the DDS Enabler was created successfully, false otherwise.
52+
*/
53+
DDSENABLER_DllAPI
4954
bool create_dds_enabler(
5055
yaml::EnablerConfiguration configuration,
5156
const CallbackSet& callbacks,

ddsenabler/src/cpp/dds_enabler_runner.cpp

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
#include <string>
2121

22+
#include <cpp_utils/exception/ConfigurationException.hpp>
23+
#include <cpp_utils/exception/InitializationException.hpp>
2224
#include <cpp_utils/Log.hpp>
2325
#include <cpp_utils/logging/StdLogConsumer.hpp>
2426

27+
#include <ddspipe_core/logging/DdsLogConsumer.hpp>
28+
2529
#include <ddsenabler_participants/DDSEnablerLogConsumer.hpp>
2630

2731
#include <ddsenabler/dds_enabler_runner.hpp>
@@ -32,35 +36,44 @@ namespace eprosima {
3236
namespace ddsenabler {
3337

3438
bool create_dds_enabler(
35-
const char* ddsEnablerConfigFile,
39+
const char* configuration_path,
3640
const CallbackSet& callbacks,
3741
std::shared_ptr<DDSEnabler>& enabler)
3842
{
3943
std::string dds_enabler_config_file = "";
40-
if (ddsEnablerConfigFile != NULL)
44+
if (configuration_path != NULL)
4145
{
42-
dds_enabler_config_file = ddsEnablerConfigFile;
46+
dds_enabler_config_file = configuration_path;
4347
}
4448

45-
// Load configuration from file
46-
eprosima::ddsenabler::yaml::EnablerConfiguration configuration(dds_enabler_config_file);
47-
48-
// Create DDS Enabler instance
49-
if (!create_dds_enabler(
50-
configuration,
51-
callbacks,
52-
enabler))
49+
try
5350
{
54-
EPROSIMA_LOG_ERROR(DDSENABLER_EXECUTION,
55-
"Failed to create DDS Enabler from configuration file: " << dds_enabler_config_file);
56-
return false;
57-
}
51+
// Load configuration from file
52+
eprosima::ddsenabler::yaml::EnablerConfiguration configuration(dds_enabler_config_file);
53+
54+
// Create DDS Enabler instance
55+
if (!create_dds_enabler(
56+
configuration,
57+
callbacks,
58+
enabler))
59+
{
60+
EPROSIMA_LOG_ERROR(DDSENABLER_EXECUTION,
61+
"Failed to create DDS Enabler from configuration file: " << dds_enabler_config_file);
62+
return false;
63+
}
5864

59-
// Set the file watcher to reload the configuration if the file changes
60-
if (!enabler->set_file_watcher(dds_enabler_config_file))
65+
// Set the file watcher to reload the configuration if the file changes
66+
if (!enabler->set_file_watcher(dds_enabler_config_file))
67+
{
68+
EPROSIMA_LOG_ERROR(DDSENABLER_EXECUTION,
69+
"Failed to set file watcher.");
70+
return false;
71+
}
72+
}
73+
catch (const eprosima::utils::ConfigurationException& e)
6174
{
6275
EPROSIMA_LOG_ERROR(DDSENABLER_EXECUTION,
63-
"Failed to set file watcher.");
76+
"Error Loading DDS Enabler Configuration. Error message:\n " << e.what());
6477
return false;
6578
}
6679

@@ -79,8 +92,9 @@ bool create_dds_enabler(
7992
eprosima::utils::Formatter error_msg;
8093
if (!configuration.is_valid(error_msg))
8194
{
82-
throw eprosima::utils::ConfigurationException(
83-
eprosima::utils::Formatter() << "Invalid configuration: " << error_msg);
95+
EPROSIMA_LOG_ERROR(DDSENABLER_EXECUTION,
96+
"Invalid configuration: " << error_msg);
97+
return false;
8498
}
8599

86100
// Logging

0 commit comments

Comments
 (0)