From 4edbb92086c6e63cc1d4234cdf992f71a0ea2806 Mon Sep 17 00:00:00 2001 From: David Lutton Date: Sun, 11 Sep 2016 23:09:38 +0100 Subject: Creates FIFO but breaks stdout --- src/dabOutput/dabOutput.h | 2 +- src/dabOutput/dabOutputFifo.cpp | 58 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) (limited to 'src/dabOutput') diff --git a/src/dabOutput/dabOutput.h b/src/dabOutput/dabOutput.h index d68cd9c..9032297 100644 --- a/src/dabOutput/dabOutput.h +++ b/src/dabOutput/dabOutput.h @@ -154,6 +154,7 @@ class DabOutputFifo : public DabOutputFile DabOutputFifo() : DabOutputFile() {} ~DabOutputFifo() {} + int Open(const char* filename); int Write(void* buffer, int size); std::string get_info() const { @@ -405,4 +406,3 @@ class DabOutputZMQ : public DabOutput #endif #endif - diff --git a/src/dabOutput/dabOutputFifo.cpp b/src/dabOutput/dabOutputFifo.cpp index 6b1c016..1bc4d92 100644 --- a/src/dabOutput/dabOutputFifo.cpp +++ b/src/dabOutput/dabOutputFifo.cpp @@ -27,8 +27,65 @@ #include #include #include +#include // mkfifo +#include // mkfifo #include "dabOutput.h" +int DabOutputFifo::Open(const char* filename) +{ + char* token = strchr((char*)filename, '?'); + if (token != NULL) { + *(token++) = 0; + char* nextPair; + char* key; + char* value; + // Go through all the &stuff=foo pairs + // Only the key "type" is supported + do { + nextPair = strchr(token, '&'); + if (nextPair != NULL) { + *nextPair = 0; + } + key = token; + value = strchr(token, '='); + if (value != NULL) { + *(value++) = 0; + if (strcmp(key, "type") == 0) { + if (strcmp(value, "raw") == 0) { + this->type_ = ETI_FILE_TYPE_RAW; + break; + } else if (strcmp(value, "framed") == 0) { + this->type_ = ETI_FILE_TYPE_FRAMED; + break; + } else if (strcmp(value, "streamed") == 0) { + this->type_ = ETI_FILE_TYPE_STREAMED; + break; + } else { + etiLog.log(error, + "File type '%s' is not supported.\n", value); + return -1; + } + } + else { + etiLog.log(warn, "Parameter '%s' unknown\n", key); + } + } + } while (nextPair != NULL); + } + + this->file_ = mkfifo(filename, 0666); + if (this->file_ == -1) { + perror(filename); + return -2; + } + this->file_ = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); + if (this->file_ == -1) { + perror(filename); + return -1; + } + return 0; +} + int DabOutputFifo::Write(void* buffer, int size) { @@ -71,4 +128,3 @@ FIFO_WRITE_ERROR: perror("Error while writting to file"); return -1; } - -- cgit v1.2.3 From e0a3d294c48d234a21a1a2403cbe200ae287e82e Mon Sep 17 00:00:00 2001 From: David Lutton Date: Sun, 11 Sep 2016 23:33:21 +0100 Subject: Attempt to create FIFO before open, no checks --- src/dabOutput/dabOutputFifo.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/dabOutput') diff --git a/src/dabOutput/dabOutputFifo.cpp b/src/dabOutput/dabOutputFifo.cpp index 1bc4d92..decd443 100644 --- a/src/dabOutput/dabOutputFifo.cpp +++ b/src/dabOutput/dabOutputFifo.cpp @@ -74,10 +74,6 @@ int DabOutputFifo::Open(const char* filename) } this->file_ = mkfifo(filename, 0666); - if (this->file_ == -1) { - perror(filename); - return -2; - } this->file_ = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); if (this->file_ == -1) { perror(filename); -- cgit v1.2.3