gstreamer
Loading...
Searching...
No Matches
gstreamerASCIIConnection.cc
Go to the documentation of this file.
1// gstreamer
4
5// Implementation note (non-Doxygen):
6// Header documentation in gstreamerASCIIFactory.h is authoritative.
7
8bool GstreamerTextFactory::openConnection() {
9 if (ofile.is_open()) {
10 // Already open for this thread; nothing to do.
11 return true;
12 }
13
14 ofile.clear(); // clear fail/eof bits from last use
15 // std::ios::out — open for writing.
16 // 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.
17 // another variant: std::ios::app: append
18 ofile.open(filename(), std::ios::out | std::ios::trunc);
19
20 if (!ofile.is_open() || !ofile) {
21 log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, " could not open file ", filename());
22 }
23
24 log->info(0, "GstreamerTextFactory: opened file " + filename());
25 return true;
26}
27
28bool GstreamerTextFactory::closeConnectionImpl() {
29 // Ensure any buffered events are written before closing the file.
31
32 if (ofile.is_open()) ofile.close();
33
34 if (ofile.is_open()) { log->error(ERR_CANTCLOSEOUTPUT, SFUNCTION_NAME, " could not close file " + filename()); }
35
36 return true;
37}
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).