summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-08-04 23:58:46 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-08-04 23:58:46 +0100
commit9b243ac94f57cbc35384a4076a73b937e15e356f (patch)
treea8de408d8213a9ecf495e190a49fa7e1abd62588
parentPrefer unique_ptr for local SI tables, pass them around as const refs (diff)
downloadp2pvr-9b243ac94f57cbc35384a4076a73b937e15e356f.tar.bz2
p2pvr-9b243ac94f57cbc35384a4076a73b937e15e356f.tar.xz
p2pvr-9b243ac94f57cbc35384a4076a73b937e15e356f.zip
Move the frontend file descriptor ownership into the parent tuner as an AdHoc FileHandle
-rw-r--r--p2pvr/devices/frontend.cpp8
-rw-r--r--p2pvr/devices/frontend.h5
-rw-r--r--p2pvr/devices/frontends/ofdm.cpp8
-rw-r--r--p2pvr/devices/tuner.cpp17
-rw-r--r--p2pvr/devices/tuner.h3
5 files changed, 16 insertions, 25 deletions
diff --git a/p2pvr/devices/frontend.cpp b/p2pvr/devices/frontend.cpp
index c368fda..c6f258b 100644
--- a/p2pvr/devices/frontend.cpp
+++ b/p2pvr/devices/frontend.cpp
@@ -6,9 +6,8 @@
namespace P2PVR {
namespace DVB {
-Frontend::Frontend(Tuner * t, int fd, const struct dvb_frontend_info & i, IceTray::Logging::LoggerPtr log) :
+Frontend::Frontend(Tuner * t, const struct dvb_frontend_info & i, IceTray::Logging::LoggerPtr log) :
tuner(t),
- frontendFD(fd),
fe_info(i),
logger(log)
{
@@ -16,7 +15,6 @@ Frontend::Frontend(Tuner * t, int fd, const struct dvb_frontend_info & i, IceTra
Frontend::~Frontend()
{
- close(frontendFD);
}
const struct dvb_frontend_info &
@@ -29,7 +27,7 @@ fe_status
Frontend::GetStatus() const
{
fe_status_t status;
- if (ioctl(frontendFD, FE_READ_STATUS, &status) < 0) {
+ if (ioctl(tuner->frontendFD, FE_READ_STATUS, &status) < 0) {
logger->messagebf(LOG::ERR, "Reading frontend %s status failed (%s:%d)", tuner->Device(), strerror(errno), errno);
throw P2PVR::DeviceError(tuner->Device(), strerror(errno), errno);
}
@@ -44,5 +42,5 @@ Frontend::FactoryKey(fe_type t)
}
}
-INSTANTIATEFACTORY(P2PVR::DVB::Frontend, P2PVR::DVB::Tuner *, int, const struct dvb_frontend_info &);
+INSTANTIATEFACTORY(P2PVR::DVB::Frontend, P2PVR::DVB::Tuner *, const struct dvb_frontend_info &);
diff --git a/p2pvr/devices/frontend.h b/p2pvr/devices/frontend.h
index 29180f4..4e47c10 100644
--- a/p2pvr/devices/frontend.h
+++ b/p2pvr/devices/frontend.h
@@ -13,7 +13,7 @@ class Tuner;
class Frontend {
public:
typedef boost::function<bool(long)> OnFrequencyFound;
- Frontend(Tuner *, int fd, const struct dvb_frontend_info &, IceTray::Logging::LoggerPtr);
+ Frontend(Tuner *, const struct dvb_frontend_info &, IceTray::Logging::LoggerPtr);
virtual ~Frontend();
fe_status_t GetStatus() const;
@@ -26,12 +26,11 @@ class Frontend {
protected:
const Tuner * tuner;
- const int frontendFD;
const struct dvb_frontend_info fe_info;
IceTray::Logging::LoggerPtr logger;
};
-typedef AdHoc::Factory<Frontend, Tuner *, int, const struct dvb_frontend_info &> FrontendFactory;
+typedef AdHoc::Factory<Frontend, Tuner *, const struct dvb_frontend_info &> FrontendFactory;
typedef boost::shared_ptr<Frontend> FrontendPtr;
}
}
diff --git a/p2pvr/devices/frontends/ofdm.cpp b/p2pvr/devices/frontends/ofdm.cpp
index 15602eb..991996d 100644
--- a/p2pvr/devices/frontends/ofdm.cpp
+++ b/p2pvr/devices/frontends/ofdm.cpp
@@ -11,8 +11,8 @@ namespace DVB {
namespace Frontends {
class OFDM : public Frontend {
public:
- OFDM(Tuner * t, int fd, const struct dvb_frontend_info & i) :
- Frontend(t, fd, i, LOGMANAGER()->getLogger<OFDM>())
+ OFDM(Tuner * t, const struct dvb_frontend_info & i) :
+ Frontend(t, i, LOGMANAGER()->getLogger<OFDM>())
{
}
@@ -41,7 +41,7 @@ class OFDM : public Frontend {
{
dvb_frontend_parameters feparams;
memset(&feparams, 0, sizeof(dvb_frontend_parameters));
- if (ioctl(frontendFD, FE_GET_FRONTEND, &feparams) < 0) {
+ if (ioctl(tuner->frontendFD, FE_GET_FRONTEND, &feparams) < 0) {
logger->messagebf(LOG::ERR, "Reading frontend parameters failed (%s:%d)", tuner->Device(), strerror(errno), errno);
throw P2PVR::DeviceError(tuner->Device(), strerror(errno), errno);
}
@@ -72,7 +72,7 @@ class OFDM : public Frontend {
void SetParameters(const dvb_frontend_parameters & feparams) const
{
- if (ioctl(frontendFD, FE_SET_FRONTEND, &feparams) < 0) {
+ if (ioctl(tuner->frontendFD, FE_SET_FRONTEND, &feparams) < 0) {
logger->messagebf(LOG::ERR, "Tuning of device %s failed (%s:%d)", tuner->Device(), strerror(errno), errno);
throw P2PVR::DeviceError(tuner->Device(), strerror(errno), errno);
}
diff --git a/p2pvr/devices/tuner.cpp b/p2pvr/devices/tuner.cpp
index f65fc32..b13e5c1 100644
--- a/p2pvr/devices/tuner.cpp
+++ b/p2pvr/devices/tuner.cpp
@@ -19,24 +19,15 @@ IceTray::Logging::LoggerPtr Tuner::logger = LOGMANAGER()->getLogger<Tuner>();
Tuner::Tuner(const boost::filesystem::path & df) :
deviceFrontend(df),
deviceRoot(df.branch_path()),
+ frontendFD(deviceFrontend, O_RDWR),
backgroundThread(NULL),
lastUsedTime(time(NULL))
{
- int fd = open(deviceFrontend.string().c_str(), O_RDWR);
- if (fd < 0) {
+ struct dvb_frontend_info fe_info;
+ if (ioctl(frontendFD, FE_GET_INFO, &fe_info) < 0) {
throw DeviceError(deviceFrontend.string(), strerror(errno), errno);
}
- try {
- struct dvb_frontend_info fe_info;
- if (ioctl(fd, FE_GET_INFO, &fe_info) < 0) {
- throw DeviceError(deviceFrontend.string(), strerror(errno), errno);
- }
- frontend = FrontendPtr(FrontendFactory::createNew(Frontend::FactoryKey(fe_info.type), this, fd, fe_info));
- }
- catch (...) {
- close(fd);
- throw;
- }
+ frontend = FrontendPtr(FrontendFactory::createNew(Frontend::FactoryKey(fe_info.type), this, fe_info));
logger->messagebf(LOG::INFO, "%s: Attached to %s (%s, type %s)", __PRETTY_FUNCTION__,
deviceRoot, frontend->Info().name, frontend->Type());
}
diff --git a/p2pvr/devices/tuner.h b/p2pvr/devices/tuner.h
index e170002..b4d92b3 100644
--- a/p2pvr/devices/tuner.h
+++ b/p2pvr/devices/tuner.h
@@ -3,6 +3,7 @@
#include <dvb.h>
#include <boost/filesystem/path.hpp>
+#include <fileUtils.h>
#include "frontend.h"
#include <map>
#include <thread>
@@ -69,6 +70,7 @@ class Tuner : public PrivateTuner {
const boost::filesystem::path deviceFrontend;
const boost::filesystem::path deviceRoot;
+ AdHoc::FileUtils::FileHandle frontendFD;
BackgroundClients backgroundClients;
std::thread * backgroundThread;
std::mutex lock;
@@ -92,6 +94,7 @@ class Tuner : public PrivateTuner {
};
private:
+ friend class Frontend;
friend class Frontends::OFDM;
IceTray::OptionsResolver<Options> options;
};