gstreamer
Loading...
Searching...
No Matches
gstreamerCSVConnection.cc
Go to the documentation of this file.
1// gstreamer
4
5// Non-Doxygen implementation file: behavior is documented in the header.
6
7bool GstreamerCsvFactory::openConnection() {
8 // Both streams must be open for the CSV plugin to operate.
9 if (ofile_true_info.is_open() && ofile_true_info.is_open()) {
10 // Already open for this thread; nothing to do.
11 return true;
12 }
13
14 if (!ofile_true_info.is_open()) {
15 ofile_true_info.clear(); // clear fail/eof bits from last use
16 // std::ios::out — open for writing.
17 // std::ios::trunc — if the file already exists, truncate it to size 0 on open (wipe its contents). If it doesn’t exist, it will be created.
18 // another variant: std::ios::app: append
19 ofile_true_info.open(filename_true_info(), std::ios::out | std::ios::trunc);
20
21 if (!ofile_true_info.is_open() || !ofile_true_info) {
22 log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, " could not open file ", filename_true_info());
23 }
24
25 log->info(0, "GstreamerCsvFactory: opened file " + filename_true_info());
26 }
27
28 if (!ofile_digitized.is_open()) {
29 ofile_digitized.clear(); // clear fail/eof bits from last use
30 // std::ios::out — open for writing.
31 // std::ios::trunc — if the file already exists, truncate it to size 0 on open (wipe its contents). If it doesn’t exist, it will be created.
32 // another variant: std::ios::app: append
33 ofile_digitized.open(filename_digitized(), std::ios::out | std::ios::trunc);
34
35 if (!ofile_digitized.is_open() || !ofile_true_info) {
36 log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, " could not open file ", filename_digitized());
37 }
38
39 log->info(0, "GstreamerCsvFactory: opened file " + filename_digitized());
40 }
41
42
43 return true;
44}
45
46bool GstreamerCsvFactory::closeConnectionImpl() {
47 // Ensure any buffered events are written before closing the files.
49
50 if (ofile_true_info.is_open()) ofile_true_info.close();
51 if (ofile_digitized.is_open()) ofile_digitized.close();
52
53 if (ofile_true_info.is_open()) {
54 log->error(ERR_CANTCLOSEOUTPUT, SFUNCTION_NAME, " could not close file " + filename_true_info());
55 }
56 if (ofile_digitized.is_open()) {
57 log->error(ERR_CANTCLOSEOUTPUT, SFUNCTION_NAME, " could not close file " + filename_digitized());
58 }
59
60 return true;
61}
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
void flushEventBuffer()
Flush the internal event buffer, writing all buffered events to the output medium.
Definition gstreamer.cc:34
Shared constants and error codes for the gstreamer module.
#define ERR_CANTCLOSEOUTPUT
Output medium could not be closed cleanly.
#define ERR_CANTOPENOUTPUT
Output medium could not be opened (file/device not accessible).