From a58cb9f959cea8f99b225b70476599e8da52ac08 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 2 Aug 2017 19:50:39 +0100 Subject: Tidy and shuffle some bits --- p2pvr/daemon/muxedFileSink.cpp | 128 --------------------------- p2pvr/daemon/muxedFileSink.h | 32 ------- p2pvr/daemon/sql/schedules/pendingRecord.sql | 13 --- p2pvr/dvb/bindDataHandler.cpp | 16 ---- p2pvr/dvb/bindDataHandler.h | 24 ----- p2pvr/dvb/bindSiParserHandler.h | 29 ------ p2pvr/dvb/unittests/Jamfile.jam | 1 + p2pvr/dvb/unittests/bindDataHandler.cpp | 16 ++++ p2pvr/dvb/unittests/bindDataHandler.h | 24 +++++ p2pvr/lib/bindSiParserHandler.h | 29 ++++++ p2pvr/lib/fileSink.cpp | 28 ------ p2pvr/lib/fileSink.h | 24 ----- p2pvr/lib/serviceStreamer.h | 1 + p2pvr/lib/serviceStreamerCore.h | 2 +- 14 files changed, 72 insertions(+), 295 deletions(-) delete mode 100644 p2pvr/daemon/muxedFileSink.cpp delete mode 100644 p2pvr/daemon/muxedFileSink.h delete mode 100644 p2pvr/daemon/sql/schedules/pendingRecord.sql delete mode 100644 p2pvr/dvb/bindDataHandler.cpp delete mode 100644 p2pvr/dvb/bindDataHandler.h delete mode 100644 p2pvr/dvb/bindSiParserHandler.h create mode 100644 p2pvr/dvb/unittests/bindDataHandler.cpp create mode 100644 p2pvr/dvb/unittests/bindDataHandler.h create mode 100644 p2pvr/lib/bindSiParserHandler.h delete mode 100644 p2pvr/lib/fileSink.cpp delete mode 100644 p2pvr/lib/fileSink.h diff --git a/p2pvr/daemon/muxedFileSink.cpp b/p2pvr/daemon/muxedFileSink.cpp deleted file mode 100644 index ff431bc..0000000 --- a/p2pvr/daemon/muxedFileSink.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "muxedFileSink.h" -#include -#include -#include -#include -#include -#include - -namespace P2PVR { -class MuxerFailure : public P2PVR::DataHandlingException { }; - -MuxedFileSink::MuxedFileSink(const boost::filesystem::path & t, const std::string & cmd) : - logger(LOGMANAGER()->getLogger()) -{ - std::vector params; - boost::algorithm::split(params, cmd, isspace, boost::algorithm::token_compress_on); - for (auto & c : params) { - if (c == "${TARGET}") { - c = t.string(); - } - } - fds = ProcessPipesPtr(new AdHoc::System::ProcessPipes(params, true, true, true)); - fcntl(fds->fdIn(), F_SETFL, O_NONBLOCK); - logger->messagebf(LOG::INFO, "Muxer::%p started with command '%s' for %s", this, cmd, t); -} - -MuxedFileSink::~MuxedFileSink() -{ - close(fds->fdIn()); - int status; - while (waitpid(fds->pid(), &status, WNOHANG) == 0) { - ReadMuxer(5); - } - logger->messagebf(LOG::INFO, "Muxer::%p finished with status %d", this, status); -} - -bool -MuxedFileSink::NewData(const P2PVR::Data & data, const Ice::Current &) -{ - std::lock_guard g(lock); - for (size_t off = 0; off < data.size(); ) { - // Read output until input wouldn't block - if (ReadWaiting()) - return true; - // Send some input - auto w = write(fds->fdIn(), &data[off], data.size() - off); - if (w == -1 && errno != EAGAIN && errno != EWOULDBLOCK) { - logger->messagebf(LOG::ERR, "Muxer::%p write failed (%d:%s)", this, errno, strerror(errno)); - throw MuxerFailure(); - } - off += w; - } - // Read anything that's come out - return ReadAvailable(); -} - -bool -MuxedFileSink::ReadWaiting() const -{ - pollfd fd = { fds->fdIn(), POLLOUT, 0 }; - while (true) { - auto p = poll(&fd, 1, 0); - if (p < 0) { - // error - throw MuxerFailure(); - } - else if (p == 0) { - // write would block - if (ReadMuxer(1)) return true; - } - else { - // write would not block - if (ReadMuxer(0)) return true; - break; - } - } - return false; -} - -bool -MuxedFileSink::ReadAvailable() const -{ - return ReadMuxer(0); -} - -bool -MuxedFileSink::ReadMuxer(int waitTime) const -{ - pollfd fd[2] = { { fds->fdOut(), POLLIN | POLLHUP, 0 }, { fds->fdError(), POLLIN | POLLHUP, 0 } }; - while (true) { - auto p = poll(fd, 2, waitTime); - if (p < 0) { - // error - throw MuxerFailure(); - } - else if (p == 0) { - // all ok - return false; - } - else { - bool closed = false; - for (int i = 0; i < 2; ++i) { - if (fd[i].revents & (POLLIN | POLLHUP)) { - P2PVR::Data buf(BUFSIZ); - auto len = read(fd[i].fd, &buf.front(), buf.size()); - if (len == 0) { - // ok, proc exit - closed = true; - } - if (len < 0) { - // error - throw MuxerFailure(); - } - buf.resize(len); - std::vector lines; - boost::algorithm::split(lines, buf, boost::algorithm::is_any_of("\r\n\f"), boost::algorithm::token_compress_on); - for (const auto & line : lines) { - if (line.empty()) continue; - logger->messagebf(LOG::INFO, "Muxer::%p > %s", this, line); - } - } - } - if (closed) return true; - } - } -} -} - diff --git a/p2pvr/daemon/muxedFileSink.h b/p2pvr/daemon/muxedFileSink.h deleted file mode 100644 index d91e106..0000000 --- a/p2pvr/daemon/muxedFileSink.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef MUXEDFILESINK_H -#define MUXEDFILESINK_H - -#include -#include -#include -#include -#include -#include - -namespace P2PVR { -class MuxedFileSink : public P2PVR::RawDataClient { - public: - MuxedFileSink(const boost::filesystem::path & target, const std::string & cmd); - ~MuxedFileSink(); - - bool NewData(const P2PVR::Data &, const Ice::Current &); - - private: - bool ReadWaiting() const; - bool ReadAvailable() const; - bool ReadMuxer(int wait) const; - typedef boost::shared_ptr ProcessPipesPtr; - ProcessPipesPtr fds; - mutable std::mutex lock; - - IceTray::Logging::LoggerPtr logger; -}; -} - -#endif - diff --git a/p2pvr/daemon/sql/schedules/pendingRecord.sql b/p2pvr/daemon/sql/schedules/pendingRecord.sql deleted file mode 100644 index ba4d7d8..0000000 --- a/p2pvr/daemon/sql/schedules/pendingRecord.sql +++ /dev/null @@ -1,13 +0,0 @@ -select * -from record r, events e, schedules s -where r.serviceid = e.serviceid -and r.eventid = e.eventid -and /*r.scheduleid*/ 161 = s.scheduleid -and r.recordstatus = 1 -and r.recordingstatus = 0 -and e.starttime - s.early - interval '3minutes' < now() -order by e.starttime - s.early - -; -select * -from schedules \ No newline at end of file diff --git a/p2pvr/dvb/bindDataHandler.cpp b/p2pvr/dvb/bindDataHandler.cpp deleted file mode 100644 index 7b25b91..0000000 --- a/p2pvr/dvb/bindDataHandler.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "bindDataHandler.h" - -namespace P2PVR { -namespace DVBSI { -BindDataHandler::BindDataHandler(const Callback & cb) : - callBack(cb) -{ -} - -bool BindDataHandler::NewData(const Data & data, const Ice::Current &) -{ - return callBack(data); -} -} -} - diff --git a/p2pvr/dvb/bindDataHandler.h b/p2pvr/dvb/bindDataHandler.h deleted file mode 100644 index acbe6df..0000000 --- a/p2pvr/dvb/bindDataHandler.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef BINDDATAHANDLER_H -#define BINDDATAHANDLER_H - -#include -#include -#include - -namespace P2PVR { -namespace DVBSI { -class DLL_PUBLIC BindDataHandler : public RawDataClient { - public: - typedef boost::function Callback; - BindDataHandler(const Callback & cb); - - bool NewData(const Data & data, const Ice::Current &) override; - - private: - const Callback callBack; -}; -} -} - -#endif - diff --git a/p2pvr/dvb/bindSiParserHandler.h b/p2pvr/dvb/bindSiParserHandler.h deleted file mode 100644 index d5fadf7..0000000 --- a/p2pvr/dvb/bindSiParserHandler.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef BINDSIPARSERHANDLER_H -#define BINDSIPARSERHANDLER_H - -#include - -namespace P2PVR { -namespace DVBSI { -template -class BindSiParserHandler : public Base { - public: - typedef boost::function Callback; - BindSiParserHandler(const Callback & cb) : - callBack(cb) - { - } - - bool HandleTable(SIObject siObject) - { - return callBack(siObject); - } - - private: - const Callback callBack; -}; -} -} - -#endif - diff --git a/p2pvr/dvb/unittests/Jamfile.jam b/p2pvr/dvb/unittests/Jamfile.jam index 616be7b..c3a75ed 100644 --- a/p2pvr/dvb/unittests/Jamfile.jam +++ b/p2pvr/dvb/unittests/Jamfile.jam @@ -25,6 +25,7 @@ exe createSamples : exe createBroadcast : createBroadcast.cpp + bindDataHandler.cpp : BOOST_TEST_DYN_LINK ..//p2pvrdvb diff --git a/p2pvr/dvb/unittests/bindDataHandler.cpp b/p2pvr/dvb/unittests/bindDataHandler.cpp new file mode 100644 index 0000000..7b25b91 --- /dev/null +++ b/p2pvr/dvb/unittests/bindDataHandler.cpp @@ -0,0 +1,16 @@ +#include "bindDataHandler.h" + +namespace P2PVR { +namespace DVBSI { +BindDataHandler::BindDataHandler(const Callback & cb) : + callBack(cb) +{ +} + +bool BindDataHandler::NewData(const Data & data, const Ice::Current &) +{ + return callBack(data); +} +} +} + diff --git a/p2pvr/dvb/unittests/bindDataHandler.h b/p2pvr/dvb/unittests/bindDataHandler.h new file mode 100644 index 0000000..acbe6df --- /dev/null +++ b/p2pvr/dvb/unittests/bindDataHandler.h @@ -0,0 +1,24 @@ +#ifndef BINDDATAHANDLER_H +#define BINDDATAHANDLER_H + +#include +#include +#include + +namespace P2PVR { +namespace DVBSI { +class DLL_PUBLIC BindDataHandler : public RawDataClient { + public: + typedef boost::function Callback; + BindDataHandler(const Callback & cb); + + bool NewData(const Data & data, const Ice::Current &) override; + + private: + const Callback callBack; +}; +} +} + +#endif + diff --git a/p2pvr/lib/bindSiParserHandler.h b/p2pvr/lib/bindSiParserHandler.h new file mode 100644 index 0000000..d5fadf7 --- /dev/null +++ b/p2pvr/lib/bindSiParserHandler.h @@ -0,0 +1,29 @@ +#ifndef BINDSIPARSERHANDLER_H +#define BINDSIPARSERHANDLER_H + +#include + +namespace P2PVR { +namespace DVBSI { +template +class BindSiParserHandler : public Base { + public: + typedef boost::function Callback; + BindSiParserHandler(const Callback & cb) : + callBack(cb) + { + } + + bool HandleTable(SIObject siObject) + { + return callBack(siObject); + } + + private: + const Callback callBack; +}; +} +} + +#endif + diff --git a/p2pvr/lib/fileSink.cpp b/p2pvr/lib/fileSink.cpp deleted file mode 100644 index 295d550..0000000 --- a/p2pvr/lib/fileSink.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "fileSink.h" - -namespace P2PVR { -FileSink::FileSink(const boost::filesystem::path & path) : - file(fopen(path.string().c_str(), "w")) -{ -} - -FileSink::FileSink(int fd) : - file(fdopen(fd, "w")) -{ -} - -FileSink::~FileSink() -{ - if (file) { - fclose(file); - } -} - -bool -FileSink::NewData(const Data & data, const Ice::Current &) -{ - fwrite(&data.front(), data.size(), 1, file); - return false; -} -} - diff --git a/p2pvr/lib/fileSink.h b/p2pvr/lib/fileSink.h deleted file mode 100644 index 840f995..0000000 --- a/p2pvr/lib/fileSink.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef FILESINK_H -#define FILESINK_H - -#include -#include -#include -#include - -namespace P2PVR { -class DLL_PUBLIC FileSink : public RawDataClient { - public: - FileSink(const boost::filesystem::path & path); - FileSink(int fd); - ~FileSink(); - - bool NewData(const Data & data, const Ice::Current &); - - private: - FILE * const file; -}; -} - -#endif - diff --git a/p2pvr/lib/serviceStreamer.h b/p2pvr/lib/serviceStreamer.h index bfed89a..17c7850 100644 --- a/p2pvr/lib/serviceStreamer.h +++ b/p2pvr/lib/serviceStreamer.h @@ -3,6 +3,7 @@ #include "serviceStreamerCore.h" #include +#include namespace P2PVR { class DLL_PUBLIC ServiceStreamer : public ServiceStreamerCore { diff --git a/p2pvr/lib/serviceStreamerCore.h b/p2pvr/lib/serviceStreamerCore.h index b53a656..233b8f5 100644 --- a/p2pvr/lib/serviceStreamerCore.h +++ b/p2pvr/lib/serviceStreamerCore.h @@ -6,7 +6,7 @@ #include "siParsers/programAssociation.h" #include "siParsers/programMap.h" #include "temporaryIceAdapterObject.h" -#include +#include #include #include #include -- cgit v1.2.3