summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--p2pvr/carddaemon/Jamfile.jam1
-rw-r--r--p2pvr/carddaemon/carddaemon.cpp48
-rw-r--r--p2pvr/daemon/Jamfile.jam1
-rw-r--r--p2pvr/daemon/daemon.cpp46
-rw-r--r--p2pvr/lib/Jamfile.jam1
-rw-r--r--p2pvr/lib/daemonBase.cpp62
-rw-r--r--p2pvr/lib/daemonBase.h31
-rw-r--r--p2pvr/lib/muxer.cpp6
-rw-r--r--p2pvr/lib/muxer.h2
-rw-r--r--p2pvr/lib/p2LoggerWrapper.cpp38
-rw-r--r--p2pvr/lib/p2LoggerWrapper.h23
-rw-r--r--p2pvr/lib/siParsers/table.h3
-rw-r--r--p2pvr/lib/tuner.cpp7
13 files changed, 179 insertions, 90 deletions
diff --git a/p2pvr/carddaemon/Jamfile.jam b/p2pvr/carddaemon/Jamfile.jam
index 9b4aa83..5efeb01 100644
--- a/p2pvr/carddaemon/Jamfile.jam
+++ b/p2pvr/carddaemon/Jamfile.jam
@@ -4,7 +4,6 @@ lib boost_system ;
lib p2pvrcarddaemon :
[ glob *.cpp ]
:
- <library>..//p2daemonlib
<library>../ice//p2pvrice
<library>../lib//p2pvrlib
;
diff --git a/p2pvr/carddaemon/carddaemon.cpp b/p2pvr/carddaemon/carddaemon.cpp
index 1ea7e43..a9b9beb 100644
--- a/p2pvr/carddaemon/carddaemon.cpp
+++ b/p2pvr/carddaemon/carddaemon.cpp
@@ -1,55 +1,19 @@
-#include <daemon.h>
-#include <options.h>
-#include <logger.h>
-#include <Ice/Ice.h>
+#include <daemonBase.h>
#include "localDevices.h"
+#include <Ice/ObjectAdapter.h>
-class P2PvrCardDaemon : public Daemon {
+class P2PvrCardDaemon : public DaemonBase {
public:
P2PvrCardDaemon(int argc, char ** argv) :
- ic(Ice::initialize(argc, argv))
+ DaemonBase(argc, argv)
{
}
- ~P2PvrCardDaemon()
+ void addServants(const Ice::ObjectAdapterPtr & adapter, const IceUtil::TimerPtr & timer) const
{
- ic->destroy();
+ adapter->add(new LocalDevices(adapter, timer), ic->stringToIdentity("Devices"));
}
-
- void run() const
- {
- IceUtil::TimerPtr timer = new IceUtil::Timer();
- Logger()->messagebf(LOG_INFO, "Creating adapter (%s, %s)", Adapter, Endpoint);
- auto adapter = ic->createObjectAdapterWithEndpoints(Adapter, Endpoint);
- P2PVR::LocalDevicesPrx::checkedCast(adapter->add(new LocalDevices(adapter, timer), ic->stringToIdentity(Identity)));
- adapter->activate();
- ic->waitForShutdown();
- timer->destroy();
- }
-
- void shutdown() const
- {
- ic->shutdown();
- }
- INITOPTIONS;
-
- private:
- Ice::CommunicatorPtr ic;
-
- static std::string Adapter;
- static std::string Endpoint;
- static std::string Identity;
};
-std::string P2PvrCardDaemon::Adapter;
-std::string P2PvrCardDaemon::Endpoint;
-std::string P2PvrCardDaemon::Identity;
-
DECLARE_GENERIC_LOADER("p2pvrcarddaemon", DaemonLoader, P2PvrCardDaemon);
-DECLARE_OPTIONS(P2PvrCardDaemon, "P2PVR Card Daemon")
-("p2pvr.carddaemon.iceadapter", Options::value(&Adapter, "DefaultAdapter"), "ICE Adapter name")
-("p2pvr.carddaemon.iceendpoint", Options::value(&Endpoint, "default -p 10001"), "ICE Endpoint address")
-("p2pvr.carddaemon.iceidentity", Options::value(&Identity, "Devices"), "ICE Interface identity")
-END_OPTIONS(P2PvrCardDaemon);
-
diff --git a/p2pvr/daemon/Jamfile.jam b/p2pvr/daemon/Jamfile.jam
index 7379c7a..8a6ee8c 100644
--- a/p2pvr/daemon/Jamfile.jam
+++ b/p2pvr/daemon/Jamfile.jam
@@ -4,7 +4,6 @@ lib IceUtil ;
lib p2pvrdaemon :
[ glob *.cpp ]
:
- <library>..//p2daemonlib
<library>../ice//p2pvrice
<library>../lib//p2pvrlib
;
diff --git a/p2pvr/daemon/daemon.cpp b/p2pvr/daemon/daemon.cpp
index 6f0d326..d4b59a0 100644
--- a/p2pvr/daemon/daemon.cpp
+++ b/p2pvr/daemon/daemon.cpp
@@ -1,63 +1,27 @@
-#include <daemon.h>
-#include <options.h>
-#include <Ice/Ice.h>
+#include <daemonBase.h>
#include "localDevices.h"
#include "globalDevices.h"
#include "maintenance.h"
#include "si.h"
#include "schedules.h"
-#include <logger.h>
+#include <Ice/ObjectAdapter.h>
-#include <linux/dvb/frontend.h>
-
-class P2PvrDaemon : public Daemon {
+class P2PvrDaemon : public DaemonBase {
public:
P2PvrDaemon(int argc, char ** argv) :
- ic(Ice::initialize(argc, argv))
- {
- }
-
- ~P2PvrDaemon()
+ DaemonBase(argc, argv)
{
- ic->destroy();
}
- void run() const
+ void addServants(const Ice::ObjectAdapterPtr & adapter, const IceUtil::TimerPtr & timer) const
{
- IceUtil::TimerPtr timer = new IceUtil::Timer();
- Logger()->messagebf(LOG_INFO, "Creating adapter (%s, %s)", Adapter, Endpoint);
- auto adapter = ic->createObjectAdapterWithEndpoints(Adapter, Endpoint);
adapter->add(new LocalDevices(adapter, timer), ic->stringToIdentity("Devices"));
adapter->add(new GlobalDevices(), ic->stringToIdentity("GlobalDevices"));
adapter->add(new Maintenance(adapter, timer), ic->stringToIdentity("Maintenance"));
adapter->add(new SI(), ic->stringToIdentity("SI"));
adapter->add(new Schedules(), ic->stringToIdentity("Schedules"));
- adapter->activate();
-
- ic->waitForShutdown();
- timer->destroy();
- }
-
- void shutdown() const
- {
- ic->shutdown();
}
- INITOPTIONS;
-
- private:
- Ice::CommunicatorPtr ic;
-
- static std::string Adapter;
- static std::string Endpoint;
};
-std::string P2PvrDaemon::Adapter;
-std::string P2PvrDaemon::Endpoint;
-
DECLARE_GENERIC_LOADER("p2pvrdaemon", DaemonLoader, P2PvrDaemon);
-DECLARE_OPTIONS(P2PvrDaemon, "P2PVR Daemon")
-("p2pvr.daemon.iceadapter", Options::value(&Adapter, "DefaultAdapter"), "ICE Adapter name")
-("p2pvr.daemon.iceendpoint", Options::value(&Endpoint, "default -p 10000"), "ICE Endpoint address")
-END_OPTIONS(P2PvrDaemon);
-
diff --git a/p2pvr/lib/Jamfile.jam b/p2pvr/lib/Jamfile.jam
index 1b250e7..1868a6a 100644
--- a/p2pvr/lib/Jamfile.jam
+++ b/p2pvr/lib/Jamfile.jam
@@ -7,6 +7,7 @@ cpp-pch pch : pch.hpp :
<library>..//p2common
<library>..//p2sql
<library>..//p2lib
+ <library>..//p2daemonlib
<implicit-dependency>../ice//p2pvrice
;
diff --git a/p2pvr/lib/daemonBase.cpp b/p2pvr/lib/daemonBase.cpp
new file mode 100644
index 0000000..ac429ea
--- /dev/null
+++ b/p2pvr/lib/daemonBase.cpp
@@ -0,0 +1,62 @@
+#include "daemonBase.h"
+#include "p2LoggerWrapper.h"
+#include <logger.h>
+#include <Ice/ObjectAdapter.h>
+
+std::string DaemonBase::Adapter;
+std::string DaemonBase::Endpoint;
+
+DECLARE_OPTIONS(DaemonBase, "P2PVR Daemon")
+("p2pvr.daemon.iceadapter", Options::value(&Adapter, "DefaultAdapter"), "ICE Adapter name")
+("p2pvr.daemon.iceendpoint", Options::value(&Endpoint, "default -p 10000"), "ICE Endpoint address")
+END_OPTIONS(DaemonBase);
+
+DaemonBase::DaemonBase(int argc, char ** argv) :
+ ic(Ice::initialize(args(argc, argv), initData()))
+{
+}
+
+DaemonBase::~DaemonBase()
+{
+ ic->destroy();
+}
+
+void
+DaemonBase::run() const
+{
+ IceUtil::TimerPtr timer = new IceUtil::Timer();
+ Logger()->messagebf(LOG_INFO, "Creating adapter (%s, %s)", Adapter, Endpoint);
+ auto adapter = ic->createObjectAdapterWithEndpoints(Adapter, Endpoint);
+ addServants(adapter, timer);
+ adapter->activate();
+
+ ic->waitForShutdown();
+ timer->destroy();
+}
+
+void
+DaemonBase::shutdown() const
+{
+ ic->shutdown();
+}
+
+Ice::InitializationData
+DaemonBase::initData()
+{
+ Ice::InitializationData data;
+ data.logger = new P2LoggerWrapper();
+ return data;
+}
+
+Ice::StringSeq &
+DaemonBase::args(int, char **)
+{
+ _args.clear();
+ _args.push_back("--Ice.ThreadPool.Client.Size=5");
+ _args.push_back("--Ice.ThreadPool.Server.Size=5");
+ _args.push_back("--Ice.ThreadPool.Client.SizeMax=10");
+ _args.push_back("--Ice.ThreadPool.Server.SizeMax=20");
+ _args.push_back("--Ice.ThreadPool.Client.SizeWarn=8");
+ _args.push_back("--Ice.ThreadPool.Server.SizeWarn=16");
+ return _args;
+}
diff --git a/p2pvr/lib/daemonBase.h b/p2pvr/lib/daemonBase.h
new file mode 100644
index 0000000..3cf9b19
--- /dev/null
+++ b/p2pvr/lib/daemonBase.h
@@ -0,0 +1,31 @@
+#ifndef DAEMONBASE_H
+#define DAEMONBASE_H
+
+#include <Ice/Communicator.h>
+#include <Ice/Initialize.h>
+#include <daemon.h>
+#include <options.h>
+
+class DaemonBase : public Daemon {
+ public:
+ DaemonBase(int argc, char ** argv);
+ ~DaemonBase();
+
+ void run() const;
+ void shutdown() const;
+ INITOPTIONS;
+
+ protected:
+ virtual void addServants(const Ice::ObjectAdapterPtr &, const IceUtil::TimerPtr &) const = 0;
+ static Ice::InitializationData initData();
+ Ice::StringSeq & args(int, char **);
+
+ Ice::StringSeq _args;
+ Ice::CommunicatorPtr ic;
+
+ static std::string Adapter;
+ static std::string Endpoint;
+};
+
+#endif
+
diff --git a/p2pvr/lib/muxer.cpp b/p2pvr/lib/muxer.cpp
index f7014ed..ae2ee28 100644
--- a/p2pvr/lib/muxer.cpp
+++ b/p2pvr/lib/muxer.cpp
@@ -32,6 +32,7 @@ Muxer::~Muxer()
bool
Muxer::NewData(const P2PVR::Data & data, const Ice::Current &)
{
+ std::lock_guard<std::mutex> g(lock);
ReadMuxerAndSend();
if (write(fds[0], &data.front(), data.size()) < 1) {
return true;
@@ -42,10 +43,9 @@ Muxer::NewData(const P2PVR::Data & data, const Ice::Current &)
bool
Muxer::ReadMuxerAndSend() const
{
+ pollfd fd = { fds[1], POLLIN, 0 };
while (true) {
- pollfd fd = { fds[1], POLLIN, 0 };
- const timespec timeout = {0, 0};
- auto p = ppoll(&fd, 1, &timeout, NULL);
+ auto p = poll(&fd, 1, 0);
if (p < 0) {
// error
return true;
diff --git a/p2pvr/lib/muxer.h b/p2pvr/lib/muxer.h
index 1058b01..4b1187d 100644
--- a/p2pvr/lib/muxer.h
+++ b/p2pvr/lib/muxer.h
@@ -2,6 +2,7 @@
#define MUXER_H
#include <dvb.h>
+#include <mutex>
class Muxer : public P2PVR::RawDataClient {
public:
@@ -14,6 +15,7 @@ class Muxer : public P2PVR::RawDataClient {
bool ReadMuxerAndSend() const;
const P2PVR::RawDataClientPrx & target;
int fds[2];
+ std::mutex lock;
};
#endif
diff --git a/p2pvr/lib/p2LoggerWrapper.cpp b/p2pvr/lib/p2LoggerWrapper.cpp
new file mode 100644
index 0000000..42d4757
--- /dev/null
+++ b/p2pvr/lib/p2LoggerWrapper.cpp
@@ -0,0 +1,38 @@
+#include "p2LoggerWrapper.h"
+#include "logger.h"
+
+P2LoggerWrapper::P2LoggerWrapper(const std::string & p) :
+ prefix(p)
+{
+}
+
+void
+P2LoggerWrapper::print(const std::string & message)
+{
+ ::Logger()->messagebf(LOG_INFO, "%s: %s", prefix, message);
+}
+
+void
+P2LoggerWrapper::trace(const std::string & cat, const std::string & message)
+{
+ ::Logger()->messagebf(LOG_DEBUG, "%s: [%s] %s", prefix, cat, message);
+}
+
+void
+P2LoggerWrapper::warning(const std::string & message)
+{
+ ::Logger()->messagebf(LOG_WARNING, "%s: %s", prefix, message);
+}
+
+void
+P2LoggerWrapper::error(const std::string & message)
+{
+ ::Logger()->messagebf(LOG_ERR, "%s: %s", prefix, message);
+}
+
+Ice::LoggerPtr
+P2LoggerWrapper::cloneWithPrefix(const std::string & p)
+{
+ return new P2LoggerWrapper(prefix + "-" + p);
+}
+
diff --git a/p2pvr/lib/p2LoggerWrapper.h b/p2pvr/lib/p2LoggerWrapper.h
new file mode 100644
index 0000000..8febda5
--- /dev/null
+++ b/p2pvr/lib/p2LoggerWrapper.h
@@ -0,0 +1,23 @@
+#ifndef P2LOGGERWRAPPER
+#define P2LOGGERWRAPPER
+
+#include <Ice/Logger.h>
+
+class P2LoggerWrapper : public Ice::Logger {
+ public:
+ P2LoggerWrapper(const std::string & prefix = std::string());
+
+ void print(const std::string & message);
+ void trace(const std::string & cat, const std::string & message);
+ void warning(const std::string & message);
+ void error(const std::string & message);
+
+ Ice::LoggerPtr cloneWithPrefix(const std::string & prefix);
+
+ private:
+ const std::string prefix;
+};
+
+
+#endif
+
diff --git a/p2pvr/lib/siParsers/table.h b/p2pvr/lib/siParsers/table.h
index 4ed2e8b..9de08d6 100644
--- a/p2pvr/lib/siParsers/table.h
+++ b/p2pvr/lib/siParsers/table.h
@@ -9,6 +9,7 @@
#include <arpa/inet.h>
#include <dvb.h>
#include <logger.h>
+#include <mutex>
typedef unsigned char u_char;
@@ -36,6 +37,7 @@ class SiTableParserBase : public P2PVR::RawDataClient {
virtual bool ParseInfoTable(const u_char * data, size_t len) = 0;
time_t startTime;
unsigned int incomplete;
+ std::mutex lock;
};
struct SiTableHeaderBase {
@@ -93,6 +95,7 @@ class SiTableParser : public SiTableParserBase {
auto siTable = reinterpret_cast<const TableType *>(data);
if (siTable->header.current_next_indicator == 1 // current only, please.
&& CheckTableId(siTable->header.tableid)) { // only tables we're interested in, please.
+ std::lock_guard<std::mutex> g(lock);
uint16_t contentId = ntohs(siTable->header.content_id);
ContentType & content = contents[contentId];
uint8_t sectionNumber = siTable->header.section_number >> SectionNumberShift();
diff --git a/p2pvr/lib/tuner.cpp b/p2pvr/lib/tuner.cpp
index 1095667..f4263ee 100644
--- a/p2pvr/lib/tuner.cpp
+++ b/p2pvr/lib/tuner.cpp
@@ -271,7 +271,7 @@ Tuner::StartSendingSection(int pid, const P2PVR::RawDataClientPrx & client, cons
}
int
-Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientPrx & client, const Ice::Current &)
+Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientPrx & client, const Ice::Current & ice)
{
time(&lastUsedTime);
Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
@@ -279,8 +279,11 @@ Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientP
throw P2PVR::DeviceError("demux", "Packet Id list cannot be empty", 0);
}
+ if (ice.con) {
+ ice.con->createProxy(client->ice_getIdentity());
+ }
std::lock_guard<std::mutex> g(lock);
- int demux = backgroundClients.insert(BackgroundClients::value_type(OpenDemux(), client)).first->first;
+ int demux = backgroundClients.insert(BackgroundClients::value_type(OpenDemux(), client->ice_collocationOptimized(false))).first->first;
struct dmx_pes_filter_params pesFilterParams;
memset(&pesFilterParams, 0, sizeof(struct dmx_pes_filter_params));