From bd5f62dadc0e136414cb9b6ed08f1654ed8bf2ef Mon Sep 17 00:00:00 2001 From: Antonio Lopez Date: Wed, 8 Oct 2025 18:50:28 +0200 Subject: [PATCH 1/2] #745 Fix Recording Service issues --- .../c++11/FileStorageWriter.cxx | 26 ++++++++------ .../pluggable_storage/c++11/README.md | 10 +++--- .../service_admin/c++11/Requester.cxx | 35 +++++++++++++------ .../service_admin/c++11/Requester.hpp | 4 ++- 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/examples/recording_service/pluggable_storage/c++11/FileStorageWriter.cxx b/examples/recording_service/pluggable_storage/c++11/FileStorageWriter.cxx index 7d847d605..a59a5df40 100644 --- a/examples/recording_service/pluggable_storage/c++11/FileStorageWriter.cxx +++ b/examples/recording_service/pluggable_storage/c++11/FileStorageWriter.cxx @@ -70,16 +70,22 @@ FileStorageWriter::FileStorageWriter( FileStorageWriter::~FileStorageWriter() { - if (info_file_.good()) { - /* Obtain current time */ - int64_t current_time = (int64_t) time(NULL); - if (current_time == -1) { - // can't throw in a destructor - std::cerr << "Failed to obtain the current time"; - } - /* Time was returned in seconds. Transform to nanoseconds */ - current_time *= NANOSECS_PER_SEC; - info_file_ << "End timestamp: " << current_time << std::endl; + if (info_file_.fail()) { + std::cerr << "Failed to use file to store metadata"; + } + + /* Obtain current time */ + int64_t current_time = (int64_t) time(NULL); + if (current_time == -1) { + // can't throw in a destructor + std::cerr << "Failed to obtain the current time"; + } + /* Time was returned in seconds. Transform to nanoseconds */ + current_time *= NANOSECS_PER_SEC; + info_file_ << "End timestamp: " << current_time << std::endl; + + if (info_file_.fail()) { + std::cerr << "Failed to write end timestamp"; } } diff --git a/examples/recording_service/pluggable_storage/c++11/README.md b/examples/recording_service/pluggable_storage/c++11/README.md index 10e9a020b..86c365d47 100644 --- a/examples/recording_service/pluggable_storage/c++11/README.md +++ b/examples/recording_service/pluggable_storage/c++11/README.md @@ -147,10 +147,12 @@ RTI Recording Service (Recorder) 7.0.0 starting... RTI Recording Service started ``` -*Recorder* will create two files, `Cpp_PluggableStorage.dat` and -`Cpp_PluggableStorage.dat.info`. The `HelloMsg` recorded samples are in the *.dat* -file. The *.dat.info* file contains information about when the service started -and finished. +*Recorder* will create three files: +* `Cpp_PluggableStorage.dat`: contains the `HelloMsg` recorded samples. +* `Cpp_PluggableStorage.dat.info`: contains information about when the service +started and finished. +* `Cpp_PluggableStorage.dat.pub`: contains discovery information required to +replay the recorded database. ## Running the C++ example (Replay storage reader) diff --git a/examples/recording_service/service_admin/c++11/Requester.cxx b/examples/recording_service/service_admin/c++11/Requester.cxx index c6cd8f327..9ea2d0a04 100644 --- a/examples/recording_service/service_admin/c++11/Requester.cxx +++ b/examples/recording_service/service_admin/c++11/Requester.cxx @@ -44,13 +44,26 @@ CommandActionKind ArgumentsParser::parse_command_kind(char *arg) return command_kind; } -uint64_t ArgumentsParser::parse_number(char *arg) +uint32_t ArgumentsParser::parse_domain_id(char *arg) +{ + std::stringstream stream(arg); + uint32_t value; + if (!(stream >> value)) { + std::stringstream error_stream; + error_stream << "Error: could not parse domain id value provided, '" << arg + << "'"; + throw std::runtime_error(error_stream.str()); + } + return value; +} + +uint64_t ArgumentsParser::parse_timestamp(char *arg) { std::stringstream stream(arg); uint64_t value; if (!(stream >> value)) { std::stringstream error_stream; - error_stream << "Error: could not parse uint64 value provided, '" << arg + error_stream << "Error: could not parse timestamp value provided, '" << arg << "'"; throw std::runtime_error(error_stream.str()); } @@ -237,7 +250,7 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[]) << DOMAIN_ID_ARG_NAME << " parameter"; throw std::runtime_error(error_stream.str()); } - admin_domain_id_ = parse_number(argv[current_arg + 1]); + admin_domain_id_ = parse_domain_id(argv[current_arg + 1]); current_arg += 2; } else if (TIME_TAG_ARG_NAME.compare(argv[current_arg]) == 0) { // This parameter may use one or two arguments @@ -264,7 +277,7 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[]) octet_kind_ = OctetKind::BREAKPOINT; // This parameter may use one or two arguments br_params_.value().timestamp_nanos( - parse_number(argv[current_arg + 1])); + parse_timestamp(argv[current_arg + 1])); // Check if a label has been provided if (current_arg + 2 < argc) { br_params_.label(std::string(argv[current_arg + 2])); @@ -285,14 +298,14 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[]) // This parameter may use one or two arguments if (is_number(argv[current_arg + 1])) { br_params_.value().timestamp_nanos( - parse_number(argv[current_arg + 1])); + parse_timestamp(argv[current_arg + 1])); } else { br_params_.label(std::string(argv[current_arg + 1])); } current_arg += 2; } else if (current_arg + 2 < argc) { br_params_.value().timestamp_nanos( - parse_number(argv[current_arg + 1])); + parse_timestamp(argv[current_arg + 1])); br_params_.label(std::string(argv[current_arg + 2])); current_arg += 3; } else { @@ -308,14 +321,14 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[]) // This parameter may use one or two arguments if (is_number(argv[current_arg + 1])) { br_params_.value().timestamp_nanos( - parse_number(argv[current_arg + 1])); + parse_timestamp(argv[current_arg + 1])); } else { br_params_.label(std::string(argv[current_arg + 1])); } current_arg += 2; } else if (current_arg + 2 < argc) { br_params_.value().timestamp_nanos( - parse_number(argv[current_arg + 1])); + parse_timestamp(argv[current_arg + 1])); br_params_.label(std::string(argv[current_arg + 2])); current_arg += 3; } else { @@ -330,7 +343,7 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[]) if (current_arg + 1 < argc) { octet_kind_ = OctetKind::CONTINUE; continue_params_.value().offset( - parse_number(argv[current_arg + 1])); + parse_timestamp(argv[current_arg + 1])); current_arg += 2; } else { // No number of seconds for the continue param @@ -344,7 +357,7 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[]) if (current_arg + 1 < argc) { octet_kind_ = OctetKind::CONTINUE; continue_params_.value().slices( - parse_number(argv[current_arg + 1])); + parse_timestamp(argv[current_arg + 1])); current_arg += 2; } else { // No number of slices for the continue param @@ -357,7 +370,7 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[]) if (current_arg + 1 < argc) { octet_kind_ = OctetKind::TIMESTAMPHOLDER; timestamp_holder_.timestamp_nanos( - parse_number(argv[current_arg + 1])); + parse_timestamp(argv[current_arg + 1])); current_arg += 2; } else { // No timestamp for the jump in time diff --git a/examples/recording_service/service_admin/c++11/Requester.hpp b/examples/recording_service/service_admin/c++11/Requester.hpp index e8d1005d4..0ff8378ba 100644 --- a/examples/recording_service/service_admin/c++11/Requester.hpp +++ b/examples/recording_service/service_admin/c++11/Requester.hpp @@ -82,7 +82,9 @@ class ArgumentsParser { static RTI::Service::Admin::CommandActionKind parse_command_kind(char *arg); - static uint64_t parse_number(char *arg); + static uint32_t parse_domain_id(char *arg); + + static uint64_t parse_timestamp(char *arg); static bool is_number(char *arg); }; From 444d1ca875a16b7447e83673eeb383028e0109e9 Mon Sep 17 00:00:00 2001 From: Antonio Lopez Date: Mon, 20 Oct 2025 10:18:53 +0200 Subject: [PATCH 2/2] #745 Apply feedback --- .../pluggable_storage/c++11/FileStorageWriter.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/recording_service/pluggable_storage/c++11/FileStorageWriter.cxx b/examples/recording_service/pluggable_storage/c++11/FileStorageWriter.cxx index a59a5df40..e85b6fa2f 100644 --- a/examples/recording_service/pluggable_storage/c++11/FileStorageWriter.cxx +++ b/examples/recording_service/pluggable_storage/c++11/FileStorageWriter.cxx @@ -72,6 +72,7 @@ FileStorageWriter::~FileStorageWriter() { if (info_file_.fail()) { std::cerr << "Failed to use file to store metadata"; + return; } /* Obtain current time */ @@ -79,6 +80,7 @@ FileStorageWriter::~FileStorageWriter() if (current_time == -1) { // can't throw in a destructor std::cerr << "Failed to obtain the current time"; + return; } /* Time was returned in seconds. Transform to nanoseconds */ current_time *= NANOSECS_PER_SEC;