Skip to content

Commit 53b1188

Browse files
authored
Add an option to specify the output directly of a file in the FLUTE receiver example (#45)
1 parent e9c6577 commit 53b1188

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ cd rt-libflute/build/examples
7070
The application will listen at the multicast address 238.1.1.95 by default. Check the help page for additional options (
7171
``./flute-receiver --help``).
7272

73+
By default, the FLUTE receiver will store the received files under the same path they were transmitted from (essentially
74+
overwriting the files if you are running the transmitter and the receiver on the same machine). To change the output
75+
directly you can use the `-o` option:
76+
77+
````
78+
./flute-receiver -o /path/to/output/directory
79+
````
80+
7381
### Step 2: Setting up a Flute transmitter
7482

7583
To start the Flute transmitter type in

examples/flute-receiver.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static struct argp_option options[] = { // NOLINT
5353
"critical, 6 = none. Default: 2.",
5454
0},
5555
{"tsi", 'T', "ID", 0, "The TSI to use for the FLUTE session (default: 16)", 0},
56+
{"output-path", 'o', "PATH", 0, "Directory to save received files", 0},
5657
{nullptr, 0, nullptr, 0, nullptr, 0}};
5758

5859
/**
@@ -67,6 +68,7 @@ struct ft_arguments {
6768
unsigned log_level = 2; /**< log level */
6869
char **files;
6970
uint64_t tsi = 16;
71+
const char *output_path = nullptr;
7072
};
7173

7274
/**
@@ -94,6 +96,9 @@ static auto parse_opt(int key, char *arg, struct argp_state *state) -> error_t {
9496
case 'T':
9597
arguments->tsi = static_cast<uint64_t>(strtoul(arg, nullptr, 10));
9698
break;
99+
case 'o':
100+
arguments->output_path = arg;
101+
break;
97102
default:
98103
return ARGP_ERR_UNKNOWN;
99104
}
@@ -160,13 +165,18 @@ auto main(int argc, char **argv) -> int {
160165
}
161166

162167
receiver.register_completion_callback(
163-
[](std::shared_ptr<LibFlute::File> file) { //NOLINT
164-
spdlog::info("{} (TOI {}{}{}) has been received",
165-
file->meta().content_location, file->meta().toi, file->meta().etag.empty()?"":", ETag = ", file->meta().etag);
166-
FILE* fd = fopen(file->meta().content_location.c_str(), "wb");
168+
[output_path = arguments.output_path](std::shared_ptr<LibFlute::File> file) { //NOLINT
169+
std::string out_file = file->meta().content_location;
170+
if (output_path && std::strlen(output_path) > 0) {
171+
out_file = (std::filesystem::path(output_path) / std::filesystem::path(out_file).filename()).string();
172+
}
173+
174+
spdlog::info("{} (TOI {}) has been received",
175+
out_file, file->meta().toi);
176+
FILE *fd = fopen(out_file.c_str(), "wb");
167177
fwrite(file->buffer(), 1, file->length(), fd);
168178
fclose(fd);
169-
});
179+
});
170180

171181
// Start the IO service
172182
io.run();

0 commit comments

Comments
 (0)