Skip to content

Commit 85c5016

Browse files
authored
#745 Fix Recording Service issues on several modern C++ examples #RECORD-1555 #RECORD-1553 (#746)
* #745 Fix Recording Service issues * #745 Apply feedback
1 parent 1b2d857 commit 85c5016

File tree

4 files changed

+51
-26
lines changed

4 files changed

+51
-26
lines changed

examples/recording_service/pluggable_storage/c++11/FileStorageWriter.cxx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,24 @@ FileStorageWriter::FileStorageWriter(
7070

7171
FileStorageWriter::~FileStorageWriter()
7272
{
73-
if (info_file_.good()) {
74-
/* Obtain current time */
75-
int64_t current_time = (int64_t) time(NULL);
76-
if (current_time == -1) {
77-
// can't throw in a destructor
78-
std::cerr << "Failed to obtain the current time";
79-
}
80-
/* Time was returned in seconds. Transform to nanoseconds */
81-
current_time *= NANOSECS_PER_SEC;
82-
info_file_ << "End timestamp: " << current_time << std::endl;
73+
if (info_file_.fail()) {
74+
std::cerr << "Failed to use file to store metadata";
75+
return;
76+
}
77+
78+
/* Obtain current time */
79+
int64_t current_time = (int64_t) time(NULL);
80+
if (current_time == -1) {
81+
// can't throw in a destructor
82+
std::cerr << "Failed to obtain the current time";
83+
return;
84+
}
85+
/* Time was returned in seconds. Transform to nanoseconds */
86+
current_time *= NANOSECS_PER_SEC;
87+
info_file_ << "End timestamp: " << current_time << std::endl;
88+
89+
if (info_file_.fail()) {
90+
std::cerr << "Failed to write end timestamp";
8391
}
8492
}
8593

examples/recording_service/pluggable_storage/c++11/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ RTI Recording Service (Recorder) 7.0.0 starting...
147147
RTI Recording Service started
148148
```
149149

150-
*Recorder* will create two files, `Cpp_PluggableStorage.dat` and
151-
`Cpp_PluggableStorage.dat.info`. The `HelloMsg` recorded samples are in the *.dat*
152-
file. The *.dat.info* file contains information about when the service started
153-
and finished.
150+
*Recorder* will create three files:
151+
* `Cpp_PluggableStorage.dat`: contains the `HelloMsg` recorded samples.
152+
* `Cpp_PluggableStorage.dat.info`: contains information about when the service
153+
started and finished.
154+
* `Cpp_PluggableStorage.dat.pub`: contains discovery information required to
155+
replay the recorded database.
154156

155157
## Running the C++ example (Replay storage reader)
156158

examples/recording_service/service_admin/c++11/Requester.cxx

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,26 @@ CommandActionKind ArgumentsParser::parse_command_kind(char *arg)
4444
return command_kind;
4545
}
4646

47-
uint64_t ArgumentsParser::parse_number(char *arg)
47+
uint32_t ArgumentsParser::parse_domain_id(char *arg)
48+
{
49+
std::stringstream stream(arg);
50+
uint32_t value;
51+
if (!(stream >> value)) {
52+
std::stringstream error_stream;
53+
error_stream << "Error: could not parse domain id value provided, '" << arg
54+
<< "'";
55+
throw std::runtime_error(error_stream.str());
56+
}
57+
return value;
58+
}
59+
60+
uint64_t ArgumentsParser::parse_timestamp(char *arg)
4861
{
4962
std::stringstream stream(arg);
5063
uint64_t value;
5164
if (!(stream >> value)) {
5265
std::stringstream error_stream;
53-
error_stream << "Error: could not parse uint64 value provided, '" << arg
66+
error_stream << "Error: could not parse timestamp value provided, '" << arg
5467
<< "'";
5568
throw std::runtime_error(error_stream.str());
5669
}
@@ -237,7 +250,7 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[])
237250
<< DOMAIN_ID_ARG_NAME << " parameter";
238251
throw std::runtime_error(error_stream.str());
239252
}
240-
admin_domain_id_ = parse_number(argv[current_arg + 1]);
253+
admin_domain_id_ = parse_domain_id(argv[current_arg + 1]);
241254
current_arg += 2;
242255
} else if (TIME_TAG_ARG_NAME.compare(argv[current_arg]) == 0) {
243256
// This parameter may use one or two arguments
@@ -264,7 +277,7 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[])
264277
octet_kind_ = OctetKind::BREAKPOINT;
265278
// This parameter may use one or two arguments
266279
br_params_.value().timestamp_nanos(
267-
parse_number(argv[current_arg + 1]));
280+
parse_timestamp(argv[current_arg + 1]));
268281
// Check if a label has been provided
269282
if (current_arg + 2 < argc) {
270283
br_params_.label(std::string(argv[current_arg + 2]));
@@ -285,14 +298,14 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[])
285298
// This parameter may use one or two arguments
286299
if (is_number(argv[current_arg + 1])) {
287300
br_params_.value().timestamp_nanos(
288-
parse_number(argv[current_arg + 1]));
301+
parse_timestamp(argv[current_arg + 1]));
289302
} else {
290303
br_params_.label(std::string(argv[current_arg + 1]));
291304
}
292305
current_arg += 2;
293306
} else if (current_arg + 2 < argc) {
294307
br_params_.value().timestamp_nanos(
295-
parse_number(argv[current_arg + 1]));
308+
parse_timestamp(argv[current_arg + 1]));
296309
br_params_.label(std::string(argv[current_arg + 2]));
297310
current_arg += 3;
298311
} else {
@@ -308,14 +321,14 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[])
308321
// This parameter may use one or two arguments
309322
if (is_number(argv[current_arg + 1])) {
310323
br_params_.value().timestamp_nanos(
311-
parse_number(argv[current_arg + 1]));
324+
parse_timestamp(argv[current_arg + 1]));
312325
} else {
313326
br_params_.label(std::string(argv[current_arg + 1]));
314327
}
315328
current_arg += 2;
316329
} else if (current_arg + 2 < argc) {
317330
br_params_.value().timestamp_nanos(
318-
parse_number(argv[current_arg + 1]));
331+
parse_timestamp(argv[current_arg + 1]));
319332
br_params_.label(std::string(argv[current_arg + 2]));
320333
current_arg += 3;
321334
} else {
@@ -330,7 +343,7 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[])
330343
if (current_arg + 1 < argc) {
331344
octet_kind_ = OctetKind::CONTINUE;
332345
continue_params_.value().offset(
333-
parse_number(argv[current_arg + 1]));
346+
parse_timestamp(argv[current_arg + 1]));
334347
current_arg += 2;
335348
} else {
336349
// No number of seconds for the continue param
@@ -344,7 +357,7 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[])
344357
if (current_arg + 1 < argc) {
345358
octet_kind_ = OctetKind::CONTINUE;
346359
continue_params_.value().slices(
347-
parse_number(argv[current_arg + 1]));
360+
parse_timestamp(argv[current_arg + 1]));
348361
current_arg += 2;
349362
} else {
350363
// No number of slices for the continue param
@@ -357,7 +370,7 @@ ArgumentsParser::ArgumentsParser(int argc, char *argv[])
357370
if (current_arg + 1 < argc) {
358371
octet_kind_ = OctetKind::TIMESTAMPHOLDER;
359372
timestamp_holder_.timestamp_nanos(
360-
parse_number(argv[current_arg + 1]));
373+
parse_timestamp(argv[current_arg + 1]));
361374
current_arg += 2;
362375
} else {
363376
// No timestamp for the jump in time

examples/recording_service/service_admin/c++11/Requester.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ class ArgumentsParser {
8282

8383
static RTI::Service::Admin::CommandActionKind parse_command_kind(char *arg);
8484

85-
static uint64_t parse_number(char *arg);
85+
static uint32_t parse_domain_id(char *arg);
86+
87+
static uint64_t parse_timestamp(char *arg);
8688

8789
static bool is_number(char *arg);
8890
};

0 commit comments

Comments
 (0)