diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-03 00:29:40 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-03 00:29:40 +0100 |
commit | 2a551c907b3fd0c282bce46970066cfd402a594c (patch) | |
tree | c901e9b084900cf7e169848aeb54991a3a6da0a4 /p2pvr/daemon | |
parent | Use libadhocutil (diff) | |
download | p2pvr-2a551c907b3fd0c282bce46970066cfd402a594c.tar.bz2 p2pvr-2a551c907b3fd0c282bce46970066cfd402a594c.tar.xz p2pvr-2a551c907b3fd0c282bce46970066cfd402a594c.zip |
Use libadhocutil
Diffstat (limited to 'p2pvr/daemon')
-rw-r--r-- | p2pvr/daemon/Jamfile.jam | 1 | ||||
-rw-r--r-- | p2pvr/daemon/dbClient.h | 4 | ||||
-rw-r--r-- | p2pvr/daemon/maintenance.cpp | 2 | ||||
-rw-r--r-- | p2pvr/daemon/muxedFileSink.cpp | 19 | ||||
-rw-r--r-- | p2pvr/daemon/muxedFileSink.h | 6 | ||||
-rw-r--r-- | p2pvr/daemon/recorder.cpp | 6 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/Jamfile.jam | 16 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/mockDefs.cpp | 12 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testErrorHandling.cpp | 3 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testMaint.cpp | 3 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testRecording.cpp | 3 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testRecordings.cpp | 3 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testSched.cpp | 2 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testSi.cpp | 2 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp | 2 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testp2ice.cpp | 6 |
16 files changed, 43 insertions, 47 deletions
diff --git a/p2pvr/daemon/Jamfile.jam b/p2pvr/daemon/Jamfile.jam index a2a20c0..c565234 100644 --- a/p2pvr/daemon/Jamfile.jam +++ b/p2pvr/daemon/Jamfile.jam @@ -21,6 +21,7 @@ lib p2pvrdaemon : <library>..//p2sql <library>../devices//p2pvrdevices <library>../daemonbase//p2pvrdaemonbase + <library>..//adhocutil <implicit-dependency>../../libtmdb//tmdb <library>slicer <slicer>yes diff --git a/p2pvr/daemon/dbClient.h b/p2pvr/daemon/dbClient.h index 84cf5e7..cd846e5 100644 --- a/p2pvr/daemon/dbClient.h +++ b/p2pvr/daemon/dbClient.h @@ -6,7 +6,7 @@ #include <list> #include <selectcommand.h> #include <modifycommand.h> -#include <scopeObject.h> +#include <scopeExit.h> #include <rdbmsDataSource.h> #include <sqlVariableBinder.h> #include <sqlHandleAsVariableType.h> @@ -28,7 +28,7 @@ class DatabaseClient : public virtual CommonObjects { private: const DatabaseClient * client; - ScopeObject so; + AdHoc::ScopeExit so; }; template <typename... Args> diff --git a/p2pvr/daemon/maintenance.cpp b/p2pvr/daemon/maintenance.cpp index e3747b3..f6878ec 100644 --- a/p2pvr/daemon/maintenance.cpp +++ b/p2pvr/daemon/maintenance.cpp @@ -64,7 +64,7 @@ Maintenance::ScheduledUpdate() if (!updateRunning) { std::thread update([this] { try { - ScopeObject notRunning([this]{ updateRunning = false; }); + AdHoc::ScopeExit notRunning([this]{ updateRunning = false; }); updateRunning = true; auto si = P2PVR::MaintenancePrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Maintenance"))); time_t now = time(NULL); diff --git a/p2pvr/daemon/muxedFileSink.cpp b/p2pvr/daemon/muxedFileSink.cpp index 3008aa7..16a3588 100644 --- a/p2pvr/daemon/muxedFileSink.cpp +++ b/p2pvr/daemon/muxedFileSink.cpp @@ -1,7 +1,6 @@ #include <pch.hpp> #include "muxedFileSink.h" #include <logger.h> -#include <misc.h> #include <poll.h> #include <sys/wait.h> #include <fcntl.h> @@ -19,21 +18,19 @@ MuxedFileSink::MuxedFileSink(const boost::filesystem::path & t, const std::strin c = t.string(); } } - muxerPid = popenrwe(params, fds); - fcntl(fds[0], F_SETFL, O_NONBLOCK); + 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[0]); + close(fds->fdIn()); int status; - while (waitpid(muxerPid, &status, WNOHANG) == 0) { + while (waitpid(fds->pid(), &status, WNOHANG) == 0) { ReadMuxer(5); } Logger()->messagebf(LOG_INFO, "Muxer::%p finished with status %d", this, status); - close(fds[1]); - close(fds[2]); } bool @@ -45,7 +42,7 @@ MuxedFileSink::NewData(const P2PVR::Data & data, const Ice::Current &) if (ReadWaiting()) return true; // Send some input - auto w = write(fds[0], &data[off], data.size() - off); + 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(); @@ -59,7 +56,7 @@ MuxedFileSink::NewData(const P2PVR::Data & data, const Ice::Current &) bool MuxedFileSink::ReadWaiting() const { - pollfd fd = { fds[0], POLLOUT, 0 }; + pollfd fd = { fds->fdIn(), POLLOUT, 0 }; while (true) { auto p = poll(&fd, 1, 0); if (p < 0) { @@ -88,7 +85,7 @@ MuxedFileSink::ReadAvailable() const bool MuxedFileSink::ReadMuxer(int waitTime) const { - pollfd fd[2] = { { fds[1], POLLIN | POLLHUP, 0 }, { fds[2], POLLIN | POLLHUP, 0 } }; + pollfd fd[2] = { { fds->fdOut(), POLLIN | POLLHUP, 0 }, { fds->fdError(), POLLIN | POLLHUP, 0 } }; while (true) { auto p = poll(fd, 2, waitTime); if (p < 0) { @@ -104,7 +101,7 @@ MuxedFileSink::ReadMuxer(int waitTime) const for (int i = 0; i < 2; ++i) { if (fd[i].revents & (POLLIN | POLLHUP)) { P2PVR::Data buf(BUFSIZ); - auto len = read(fds[i + 1], &buf.front(), buf.size()); + auto len = read(fd[i].fd, &buf.front(), buf.size()); if (len == 0) { // ok, proc exit closed = true; diff --git a/p2pvr/daemon/muxedFileSink.h b/p2pvr/daemon/muxedFileSink.h index 9cca6fa..ec22a62 100644 --- a/p2pvr/daemon/muxedFileSink.h +++ b/p2pvr/daemon/muxedFileSink.h @@ -4,6 +4,8 @@ #include <dvb.h> #include <mutex> #include <boost/filesystem/path.hpp> +#include <boost/shared_ptr.hpp> +#include <processPipes.h> class MuxedFileSink : public P2PVR::RawDataClient { public: @@ -16,8 +18,8 @@ class MuxedFileSink : public P2PVR::RawDataClient { bool ReadWaiting() const; bool ReadAvailable() const; bool ReadMuxer(int wait) const; - int fds[3]; - pid_t muxerPid; + typedef boost::shared_ptr<AdHoc::System::ProcessPipes> ProcessPipesPtr; + ProcessPipesPtr fds; mutable std::mutex lock; }; diff --git a/p2pvr/daemon/recorder.cpp b/p2pvr/daemon/recorder.cpp index 3c97fc6..e965253 100644 --- a/p2pvr/daemon/recorder.cpp +++ b/p2pvr/daemon/recorder.cpp @@ -4,7 +4,7 @@ #include <boost/bind.hpp> #include <logger.h> #include <commonHelpers.h> -#include <scopeObject.h> +#include <scopeExit.h> #include "serviceStreamer.h" #include "storage.h" #include "muxer.h" @@ -66,14 +66,14 @@ Recorder::StartRecording(P2PVR::SchedulePtr schedule, DVBSI::ServicePtr service, auto id = boost::lexical_cast<std::string>(boost::uuids::random_generator()()); auto store = storage->OpenForWrite(id); - ScopeObject _store(NULL, NULL, [this,&store,&storage,&id]() { storage->Close(store); storage->Delete(id); }); + AdHoc::ScopeExit _store(NULL, NULL, [this,&store,&storage,&id]() { storage->Close(store); storage->Delete(id); }); auto target = store; P2PVR::RawDataClientPrx muxer; if (!muxerCommand.empty()) { muxer = P2PVR::RawDataClientPrx::checkedCast(adapter->addWithUUID(new Muxer(store, muxerCommand))); target = muxer; } - ScopeObject _muxer(NULL, NULL, [this,&muxer]() { if (muxer) adapter->remove(muxer->ice_getIdentity()); }); + AdHoc::ScopeExit _muxer(NULL, NULL, [this,&muxer]() { if (muxer) adapter->remove(muxer->ice_getIdentity()); }); auto ss = ServiceStreamerPtr(new ServiceStreamer(service->ServiceId, target, adapter->getCommunicator(), adapter)); ss->Start(); diff --git a/p2pvr/daemon/unittests/Jamfile.jam b/p2pvr/daemon/unittests/Jamfile.jam index 0acbd9e..2097b7a 100644 --- a/p2pvr/daemon/unittests/Jamfile.jam +++ b/p2pvr/daemon/unittests/Jamfile.jam @@ -29,7 +29,7 @@ lib testCommon : <library>p2sqlmodPQ <library>../..//p2sql <library>../..//p2common - <library>../..//p2lib + <library>../..//adhocutil <library>../..//p2ut <define>ROOT=\"$(me)\" <library>boost_system @@ -70,7 +70,7 @@ run <define>BOOST_TEST_DYN_LINK <library>../..//p2common <library>../..//p2basics - <library>../..//p2lib + <library>../..//adhocutil <library>../..//p2xml <library>../..//p2ut <library>..//p2pvrdaemon @@ -93,7 +93,7 @@ run <define>BOOST_TEST_DYN_LINK <library>../..//p2common <library>../..//p2basics - <library>../..//p2lib + <library>../..//adhocutil <library>../..//p2xml <library>../..//p2ut <library>..//p2pvrdaemon @@ -116,7 +116,7 @@ run <define>BOOST_TEST_DYN_LINK <library>../..//p2common <library>../..//p2basics - <library>../..//p2lib + <library>../..//adhocutil <library>../..//p2xml <library>../..//p2ut <library>..//p2pvrdaemon @@ -140,7 +140,7 @@ run <define>BOOST_TEST_DYN_LINK <library>../..//p2common <library>../..//p2basics - <library>../..//p2lib + <library>../..//adhocutil <library>../..//p2xml <library>../..//p2ut <library>..//p2pvrdaemon @@ -162,7 +162,7 @@ run <define>BOOST_TEST_DYN_LINK <library>../..//p2common <library>../..//p2basics - <library>../..//p2lib + <library>../..//adhocutil <library>../..//p2xml <library>../..//p2ut <library>..//p2pvrdaemon @@ -185,7 +185,7 @@ run <define>BOOST_TEST_DYN_LINK <library>../..//p2common <library>../..//p2basics - <library>../..//p2lib + <library>../..//adhocutil <library>../..//p2xml <library>../..//p2ut <library>..//p2pvrdaemon @@ -208,7 +208,7 @@ run <define>BOOST_TEST_DYN_LINK <library>../..//p2common <library>../..//p2basics - <library>../..//p2lib + <library>../..//adhocutil <library>../..//p2xml <library>../..//p2ut <library>..//p2pvrdaemon diff --git a/p2pvr/daemon/unittests/mockDefs.cpp b/p2pvr/daemon/unittests/mockDefs.cpp index 466bfe2..76abb80 100644 --- a/p2pvr/daemon/unittests/mockDefs.cpp +++ b/p2pvr/daemon/unittests/mockDefs.cpp @@ -3,22 +3,22 @@ SchemaOnlyMockDatabase::SchemaOnlyMockDatabase() : MockPqDatabase("user=postgres dbname=postgres", "postgres", { - RootDir.parent_path().parent_path() / "datasources" / "schema.sql" }) + rootDir.parent_path().parent_path() / "datasources" / "schema.sql" }) { } StandardMockDatabase::StandardMockDatabase() : MockPqDatabase("user=postgres dbname=postgres", "postgres", { - RootDir.parent_path().parent_path() / "datasources/schema.sql", - RootDir / "datasources" / "data.sql" }) + rootDir.parent_path().parent_path() / "datasources/schema.sql", + rootDir / "datasources" / "data.sql" }) { } StandardMockDatabasePlusOffset::StandardMockDatabasePlusOffset() : MockPqDatabase("user=postgres dbname=postgres", "postgres", { - RootDir.parent_path().parent_path() / "datasources" / "schema.sql", - RootDir / "datasources" / "data.sql", - RootDir / "datasources" / "eventOffset.sql" }) + rootDir.parent_path().parent_path() / "datasources" / "schema.sql", + rootDir / "datasources" / "data.sql", + rootDir / "datasources" / "eventOffset.sql" }) { } diff --git a/p2pvr/daemon/unittests/testErrorHandling.cpp b/p2pvr/daemon/unittests/testErrorHandling.cpp index 9c720a2..b522557 100644 --- a/p2pvr/daemon/unittests/testErrorHandling.cpp +++ b/p2pvr/daemon/unittests/testErrorHandling.cpp @@ -4,7 +4,6 @@ #include <testOptionsSource.h> #include <Ice/ObjectAdapter.h> #include <Ice/Service.h> -#include <scopeObject.h> #include <maintenance.h> #include <mockTuner.h> #include "mockDevices.h" @@ -26,7 +25,7 @@ class Core : public TestAppInstance { ic = Ice::initialize(paramCount, NULL); adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12006"); TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (RootDir / "datasources").string() }, + { "common.datasourceRoot", (rootDir / "datasources").string() }, }); adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices")); adapter->add(new SI(), ic->stringToIdentity("SI")); diff --git a/p2pvr/daemon/unittests/testMaint.cpp b/p2pvr/daemon/unittests/testMaint.cpp index 0d7d5a0..38c9478 100644 --- a/p2pvr/daemon/unittests/testMaint.cpp +++ b/p2pvr/daemon/unittests/testMaint.cpp @@ -4,7 +4,6 @@ #include <testOptionsSource.h> #include <Ice/ObjectAdapter.h> #include <Ice/Service.h> -#include <scopeObject.h> #include <maintenance.h> #include <mockTuner.h> #include "mockDevices.h" @@ -27,7 +26,7 @@ class Core : public CommonObjects, public TestAppInstance { ic = Ice::initialize(paramCount, NULL); auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12000"); TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (RootDir / "datasources").string() }, + { "common.datasourceRoot", (rootDir / "datasources").string() }, }); adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices")); adapter->add(new MockScheduler(), ic->stringToIdentity("Schedules")); diff --git a/p2pvr/daemon/unittests/testRecording.cpp b/p2pvr/daemon/unittests/testRecording.cpp index 720b868..d3ecee6 100644 --- a/p2pvr/daemon/unittests/testRecording.cpp +++ b/p2pvr/daemon/unittests/testRecording.cpp @@ -4,7 +4,6 @@ #include <testOptionsSource.h> #include <Ice/ObjectAdapter.h> #include <Ice/Service.h> -#include <scopeObject.h> #include <maintenance.h> #include <mockTuner.h> #include "mockDevices.h" @@ -29,7 +28,7 @@ class Core : public CommonObjects, public TestAppInstance { ic = Ice::initialize(paramCount, NULL); adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12005"); TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (RootDir / "datasources").string() }, + { "common.datasourceRoot", (rootDir / "datasources").string() }, }); adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices")); adapter->add(new MockScheduler(), ic->stringToIdentity("Schedules")); diff --git a/p2pvr/daemon/unittests/testRecordings.cpp b/p2pvr/daemon/unittests/testRecordings.cpp index eb3d5db..ff8f676 100644 --- a/p2pvr/daemon/unittests/testRecordings.cpp +++ b/p2pvr/daemon/unittests/testRecordings.cpp @@ -4,7 +4,6 @@ #include <testOptionsSource.h> #include <Ice/ObjectAdapter.h> #include <Ice/Service.h> -#include <scopeObject.h> #include <maintenance.h> #include <mockTuner.h> #include <si.h> @@ -25,7 +24,7 @@ class Core : public TestAppInstance { ic = Ice::initialize(paramCount, NULL); auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12001"); TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (RootDir / "datasources").string() }, + { "common.datasourceRoot", (rootDir / "datasources").string() }, }); adapter->add(new Recordings(), ic->stringToIdentity("Recordings")); adapter->add(new SI(), ic->stringToIdentity("SI")); diff --git a/p2pvr/daemon/unittests/testSched.cpp b/p2pvr/daemon/unittests/testSched.cpp index 3a513d0..9afdaad 100644 --- a/p2pvr/daemon/unittests/testSched.cpp +++ b/p2pvr/daemon/unittests/testSched.cpp @@ -26,7 +26,7 @@ class Core : public TestAppInstance { ic = Ice::initialize(paramCount, NULL); auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12003"); TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (RootDir / "datasources").string() }, + { "common.datasourceRoot", (rootDir / "datasources").string() }, }); adapter->add(new Schedules(), ic->stringToIdentity("Schedules")); adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices")); diff --git a/p2pvr/daemon/unittests/testSi.cpp b/p2pvr/daemon/unittests/testSi.cpp index 6cc810b..9e42e74 100644 --- a/p2pvr/daemon/unittests/testSi.cpp +++ b/p2pvr/daemon/unittests/testSi.cpp @@ -23,7 +23,7 @@ class Core : public TestAppInstance { ic = Ice::initialize(paramCount, NULL); auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12002"); TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (RootDir / "datasources").string() }, + { "common.datasourceRoot", (rootDir / "datasources").string() }, }); adapter->add(new SI(), ic->stringToIdentity("SI")); adapter->activate(); diff --git a/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp b/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp index 2608fd8..077486c 100644 --- a/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp +++ b/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp @@ -20,7 +20,7 @@ class TestCommonObjects : public CommonObjects, public TestAppInstance { TestCommonObjects() { TestOptionsSource::LoadTestOptions({ - { "common.datasourceRoot", (RootDir / "datasources").string() }, + { "common.datasourceRoot", (rootDir / "datasources").string() }, }); } }; diff --git a/p2pvr/daemon/unittests/testp2ice.cpp b/p2pvr/daemon/unittests/testp2ice.cpp index 4d29cc9..8229bf5 100644 --- a/p2pvr/daemon/unittests/testp2ice.cpp +++ b/p2pvr/daemon/unittests/testp2ice.cpp @@ -6,9 +6,9 @@ #include <sourceObject.h> #include <testAppInstance.h> -const boost::filesystem::path variant = BinDir.leaf(); -const boost::filesystem::path compiler = BinDir.parent_path().leaf(); -const boost::filesystem::path root = RootDir.parent_path().parent_path(); +const boost::filesystem::path variant = binDir.leaf(); +const boost::filesystem::path compiler = binDir.parent_path().leaf(); +const boost::filesystem::path root = rootDir.parent_path().parent_path(); const boost::filesystem::path iceroot = root / "ice"; static |