summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Hanisch <dvb@flensrocker.de>2014-01-08 20:49:35 (GMT)
committerLars Hanisch <dvb@flensrocker.de>2014-01-08 20:49:35 (GMT)
commit6d80369a7f30e7f294493bfc53451ffb08a6a472 (patch)
treee0de1c3efedbcec77143f49e433c3bcd79ef4287
parent6122b5ebedb64db39ffc79289795735b6fc1918c (diff)
downloadvdr-plugin-dynamite-6d80369a7f30e7f294493bfc53451ffb08a6a472.tar.gz
vdr-plugin-dynamite-6d80369a7f30e7f294493bfc53451ffb08a6a472.tar.bz2
new version 0.2.1v0.2.1
- put cUdev classes into a namespace, since pvrinput uses the same code - add some vdr 2.1.3 compatibility stuff - remove an undetected NULL pointer dereference at udev monitor
-rw-r--r--.gitignore5
-rw-r--r--dynamicdevice.c9
-rw-r--r--dynamicdevice.h4
-rw-r--r--dynamite.c7
-rw-r--r--monitor.c13
-rw-r--r--monitor.h12
-rw-r--r--udev.c72
-rw-r--r--udev.h83
8 files changed, 124 insertions, 81 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4138a97
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.dependencies
+*.[oa]
+*.so
+po/*.mo
+po/dynamite.pot
diff --git a/dynamicdevice.c b/dynamicdevice.c
index 98efd37..8106e36 100644
--- a/dynamicdevice.c
+++ b/dynamicdevice.c
@@ -1065,12 +1065,21 @@ bool cDynamicDevice::HasIBPTrickSpeed(void)
return cDevice::HasIBPTrickSpeed();
}
+#if APIVERSNUM > 20102
+void cDynamicDevice::TrickSpeed(int Speed, bool Forward)
+{
+ if (subDevice)
+ return subDevice->TrickSpeed(Speed, Forward);
+ cDevice::TrickSpeed(Speed, Forward);
+}
+#else
void cDynamicDevice::TrickSpeed(int Speed)
{
if (subDevice)
return subDevice->TrickSpeed(Speed);
cDevice::TrickSpeed(Speed);
}
+#endif
void cDynamicDevice::Clear(void)
{
diff --git a/dynamicdevice.h b/dynamicdevice.h
index 0b39ec7..a7969bb 100644
--- a/dynamicdevice.h
+++ b/dynamicdevice.h
@@ -156,7 +156,11 @@ public:
virtual cRect CanScaleVideo(const cRect &Rect, int Alignment = taCenter);
virtual void ScaleVideo(const cRect &Rect = cRect::Null);
virtual bool HasIBPTrickSpeed(void);
+#if APIVERSNUM > 20102
+ virtual void TrickSpeed(int Speed, bool Forward);
+#else
virtual void TrickSpeed(int Speed);
+#endif
virtual void Clear(void);
virtual void Play(void);
virtual void Freeze(void);
diff --git a/dynamite.c b/dynamite.c
index b493c13..00fcc65 100644
--- a/dynamite.c
+++ b/dynamite.c
@@ -11,10 +11,14 @@
#include "monitor.h"
#include "status.h"
-static const char *VERSION = "0.2.0";
+static const char *VERSION = "0.2.1";
static const char *DESCRIPTION = tr("attach/detach devices on the fly");
static const char *MAINMENUENTRY = NULL;
+#ifndef MAXDVBDEVICES
+#define MAXDVBDEVICES (MAXDEVICES>>1)
+#endif
+
class cDynamiteDvbDeviceProbe : public cDvbDeviceProbe {
private:
static bool firstProbe;
@@ -113,7 +117,6 @@ cPluginDynamite::~cPluginDynamite()
{
cDynamiteStatus::DeInit();
cUdevMonitor::ShutdownAllMonitors();
- cUdev::Free();
if (cDynamicDevice::idleHook != NULL) {
delete cDynamicDevice::idleHook;
cDynamicDevice::idleHook = NULL;
diff --git a/monitor.c b/monitor.c
index 5bf9adb..f965213 100644
--- a/monitor.c
+++ b/monitor.c
@@ -86,6 +86,7 @@ cUdevMonitor::~cUdevMonitor(void)
if (monitor)
udev_monitor_unref(monitor);
monitor = NULL;
+ cUdev::Free();
}
#define MONITOR_POLL_INTERVAL_MS 500
@@ -148,8 +149,8 @@ bool cUdevMonitor::DelFilter(cUdevFilter *Filter)
if (Filter->monitor != this)
return false;
cMutexLock lock(&filtersMutex);
- filters.Del(Filter);
Filter->monitor = NULL;
+ filters.Del(Filter);
if (filters.Count() == 0)
Cancel(3);
return true;
@@ -168,7 +169,7 @@ cUdevFilter::~cUdevFilter(void)
// --- cUdevLogFilter --------------------------------------------------------
-static void InternLogProcess(int Level, cUdevDevice &Device)
+static void InternLogProcess(int Level, const cUdevDevice &Device)
{
char *indent = new char[Level + 2];
indent[0] = '+';
@@ -198,14 +199,14 @@ static void InternLogProcess(int Level, cUdevDevice &Device)
}
}
-void cUdevLogFilter::Process(cUdevDevice &Device)
+void cUdevLogFilter::Process(const cUdevDevice &Device)
{
InternLogProcess(0, Device);
}
// --- cUdevDvbFilter --------------------------------------------------------
-void cUdevDvbFilter::Process(cUdevDevice &Device)
+void cUdevDvbFilter::Process(const cUdevDevice &Device)
{
const char *action = Device.GetAction();
if (action && (strcmp(action, "add") == 0)) {
@@ -236,7 +237,7 @@ cUdevUsbRemoveFilter::cItem::~cItem(void)
cMutex cUdevUsbRemoveFilter::mutexFilter;
cUdevUsbRemoveFilter *cUdevUsbRemoveFilter::filter = NULL;
-void cUdevUsbRemoveFilter::Process(cUdevDevice &Device)
+void cUdevUsbRemoveFilter::Process(const cUdevDevice &Device)
{
const char *action = Device.GetAction();
const char *syspath = Device.GetSyspath();
@@ -324,7 +325,7 @@ cUdevPatternFilter::~cUdevPatternFilter(void)
filters.Del(this, false);
}
-void cUdevPatternFilter::Process(cUdevDevice &Device)
+void cUdevPatternFilter::Process(const cUdevDevice &Device)
{
const char *action = Device.GetAction();
if (action && (strcmp(action, "add") == 0)) {
diff --git a/monitor.h b/monitor.h
index c370db0..ff73173 100644
--- a/monitor.h
+++ b/monitor.h
@@ -7,6 +7,8 @@
#define MAXUDEVMONITORS 10
+using namespace dynamite;
+
class cUdevFilter;
class cUdevMonitor : public cThread {
@@ -39,7 +41,7 @@ class cUdevFilter : public cListObject {
friend class cUdevMonitor;
protected:
const cUdevMonitor *monitor;
- virtual void Process(cUdevDevice &Device) = 0;
+ virtual void Process(const cUdevDevice &Device) = 0;
public:
cUdevFilter(void);
virtual ~cUdevFilter(void);
@@ -47,12 +49,12 @@ public:
class cUdevLogFilter : public cUdevFilter {
protected:
- virtual void Process(cUdevDevice &Device);
+ virtual void Process(const cUdevDevice &Device);
};
class cUdevDvbFilter : public cUdevFilter {
protected:
- virtual void Process(cUdevDevice &Device);
+ virtual void Process(const cUdevDevice &Device);
};
class cUdevUsbRemoveFilter : public cUdevFilter {
@@ -70,7 +72,7 @@ private:
cMutex mutexItems;
cList<cItem> items;
protected:
- virtual void Process(cUdevDevice &Device);
+ virtual void Process(const cUdevDevice &Device);
public:
static void AddItem(const char *item, const char *devpath);
static void RemoveItem(const char *item, const char *devpath);
@@ -84,7 +86,7 @@ protected:
static cList<cUdevPatternFilter> filters;
virtual ~cUdevPatternFilter(void);
- virtual void Process(cUdevDevice &Device);
+ virtual void Process(const cUdevDevice &Device);
private:
cUdevPatternFilter(const char *Pattern);
cString pattern;
diff --git a/udev.c b/udev.c
index 0ead16b..254ad63 100644
--- a/udev.c
+++ b/udev.c
@@ -3,16 +3,16 @@
// --- cUdevListEntry --------------------------------------------------------
-cUdevListEntry::cUdevListEntry(struct udev_list_entry *ListEntry)
+dynamite::cUdevListEntry::cUdevListEntry(struct udev_list_entry *ListEntry)
:listEntry(ListEntry)
{
}
-cUdevListEntry::~cUdevListEntry(void)
+dynamite::cUdevListEntry::~cUdevListEntry(void)
{
}
-cUdevListEntry *cUdevListEntry::GetNext(void) const
+dynamite::cUdevListEntry *dynamite::cUdevListEntry::GetNext(void) const
{
if (listEntry == NULL)
return NULL;
@@ -22,14 +22,14 @@ cUdevListEntry *cUdevListEntry::GetNext(void) const
return new cUdevListEntry(next);
}
-const char *cUdevListEntry::GetName(void) const
+const char *dynamite::cUdevListEntry::GetName(void) const
{
if (listEntry == NULL)
return NULL;
return udev_list_entry_get_name(listEntry);
}
-const char *cUdevListEntry::GetValue(void) const
+const char *dynamite::cUdevListEntry::GetValue(void) const
{
if (listEntry == NULL)
return NULL;
@@ -38,19 +38,19 @@ const char *cUdevListEntry::GetValue(void) const
// --- cUdevDevice -----------------------------------------------------------
-cUdevDevice::cUdevDevice(udev_device *Device, bool DoUnref)
+dynamite::cUdevDevice::cUdevDevice(udev_device *Device, bool DoUnref)
:device(Device)
,doUnref(DoUnref)
{
}
-cUdevDevice::~cUdevDevice(void)
+dynamite::cUdevDevice::~cUdevDevice(void)
{
if (doUnref && device)
udev_device_unref(device);
}
-int cUdevDevice::Compare(const cListObject &ListObject) const
+int dynamite::cUdevDevice::Compare(const cListObject &ListObject) const
{
const char *n1 = GetDevnode();
const char *n2 = ((cUdevDevice*)&ListObject)->GetDevnode();
@@ -59,14 +59,14 @@ int cUdevDevice::Compare(const cListObject &ListObject) const
return 0;
}
-const char *cUdevDevice::GetAction(void) const
+const char *dynamite::cUdevDevice::GetAction(void) const
{
if (device == NULL)
return NULL;
return udev_device_get_action(device);
}
-cUdevListEntry *cUdevDevice::GetDevlinksList(void) const
+dynamite::cUdevListEntry *dynamite::cUdevDevice::GetDevlinksList(void) const
{
if (device == NULL)
return NULL;
@@ -76,21 +76,21 @@ cUdevListEntry *cUdevDevice::GetDevlinksList(void) const
return new cUdevListEntry(listEntry);
}
-const char *cUdevDevice::GetDevnode(void) const
+const char *dynamite::cUdevDevice::GetDevnode(void) const
{
if (device == NULL)
return false;
return udev_device_get_devnode(device);
}
-const char *cUdevDevice::GetDevpath(void) const
+const char *dynamite::cUdevDevice::GetDevpath(void) const
{
if (device == NULL)
return false;
return udev_device_get_devpath(device);
}
-cUdevDevice *cUdevDevice::GetParent(void) const
+dynamite::cUdevDevice *dynamite::cUdevDevice::GetParent(void) const
{
if (device == NULL)
return NULL;
@@ -100,28 +100,28 @@ cUdevDevice *cUdevDevice::GetParent(void) const
return new cUdevDevice(parent, false);
}
-const char *cUdevDevice::GetPropertyValue(const char *Key) const
+const char *dynamite::cUdevDevice::GetPropertyValue(const char *Key) const
{
if (device == NULL)
return false;
return udev_device_get_property_value(device, Key);
}
-const char *cUdevDevice::GetSubsystem(void) const
+const char *dynamite::cUdevDevice::GetSubsystem(void) const
{
if (device == NULL)
return false;
return udev_device_get_subsystem(device);
}
-const char *cUdevDevice::GetSysname(void) const
+const char *dynamite::cUdevDevice::GetSysname(void) const
{
if (device == NULL)
return false;
return udev_device_get_sysname(device);
}
-const char *cUdevDevice::GetSyspath(void) const
+const char *dynamite::cUdevDevice::GetSyspath(void) const
{
if (device == NULL)
return false;
@@ -130,23 +130,37 @@ const char *cUdevDevice::GetSyspath(void) const
// --- cUdev -----------------------------------------------------------------
-struct udev *cUdev::udev = NULL;
+cMutex dynamite::cUdev::udev_mutex;
+int dynamite::cUdev::udev_refcount = 0;
+struct udev *dynamite::cUdev::udev = NULL;
-struct udev *cUdev::Init(void)
+struct udev *dynamite::cUdev::Init(void)
{
+ udev_mutex.Lock();
if (udev == NULL)
udev = udev_new();
+ else
+ udev_ref(udev);
+ udev_refcount++;
+ udev_mutex.Unlock();
return udev;
}
-void cUdev::Free(void)
+void dynamite::cUdev::Free(void)
{
- if (udev)
+ udev_mutex.Lock();
+ if (udev_refcount <= 0)
+ esyslog("udev: don't call cUdev::Free before cUdev::Init!");
+ else {
+ udev_refcount--;
udev_unref(udev);
- udev = NULL;
+ if (udev_refcount <= 0)
+ udev = NULL;
+ }
+ udev_mutex.Unlock();
}
-cUdevDevice *cUdev::GetDeviceFromDevName(const char *DevName)
+dynamite::cUdevDevice *dynamite::cUdev::GetDeviceFromDevName(const char *DevName)
{
if (DevName == NULL)
return NULL;
@@ -166,7 +180,7 @@ cUdevDevice *cUdev::GetDeviceFromDevName(const char *DevName)
return new cUdevDevice(dev);
}
-cUdevDevice *cUdev::GetDeviceFromSysPath(const char *SysPath)
+dynamite::cUdevDevice *dynamite::cUdev::GetDeviceFromSysPath(const char *SysPath)
{
if (SysPath == NULL)
return NULL;
@@ -176,7 +190,7 @@ cUdevDevice *cUdev::GetDeviceFromSysPath(const char *SysPath)
return new cUdevDevice(dev);
}
-cList<cUdevDevice> *cUdev::EnumDevices(const char *Subsystem, const char *Property, const char *Value)
+cList<dynamite::cUdevDevice> *dynamite::cUdev::EnumDevices(const char *Subsystem, const char *Property, const char *Value)
{
cList<cUdevDevice> *devices = new cList<cUdevDevice>;
struct udev_enumerate *e = udev_enumerate_new(udev);
@@ -187,20 +201,20 @@ cList<cUdevDevice> *cUdev::EnumDevices(const char *Subsystem, const char *Proper
if (e != NULL) {
int rc = 0;
if (Subsystem && ((rc = udev_enumerate_add_match_subsystem(e, Subsystem)) < 0)) {
- esyslog("dynamite: can't add subsystem %s to enum-filter: %d", Subsystem, rc);
+ esyslog("udev: can't add subsystem %s to enum-filter: %d", Subsystem, rc);
goto unref;
}
if (Property && Value && ((rc = udev_enumerate_add_match_property(e, Property, Value)) < 0)) {
- esyslog("dynamite: can't add property %s value %s to enum-filter: %d", Property, Value, rc);
+ esyslog("udev: can't add property %s value %s to enum-filter: %d", Property, Value, rc);
goto unref;
}
if ((rc = udev_enumerate_scan_devices(e)) < 0) {
- esyslog("dynamite: can't scan for devices: %d", rc);
+ esyslog("udev: can't scan for devices: %d", rc);
goto unref;
}
l = udev_enumerate_get_list_entry(e);
if (l == NULL) {
- isyslog("dynamite: no devices found for %s/%s=%s", Subsystem, Property, Value);
+ isyslog("udev: no devices found for %s/%s=%s", Subsystem, Property, Value);
goto unref;
}
listEntry = new cUdevListEntry(l);
diff --git a/udev.h b/udev.h
index c062b98..985e18d 100644
--- a/udev.h
+++ b/udev.h
@@ -4,48 +4,53 @@
#include <libudev.h>
#include <vdr/tools.h>
+#include <vdr/thread.h>
-class cUdevListEntry {
-private:
- struct udev_list_entry *listEntry;
-public:
- cUdevListEntry(struct udev_list_entry *ListEntry);
- virtual ~cUdevListEntry(void);
-
- cUdevListEntry *GetNext(void) const;
- const char *GetName(void) const;
- const char *GetValue(void) const;
- };
+namespace dynamite {
+ class cUdevListEntry {
+ private:
+ struct udev_list_entry *listEntry;
+ public:
+ cUdevListEntry(struct udev_list_entry *ListEntry);
+ virtual ~cUdevListEntry(void);
+
+ cUdevListEntry *GetNext(void) const;
+ const char *GetName(void) const;
+ const char *GetValue(void) const;
+ };
-class cUdevDevice : public cListObject {
-private:
- struct udev_device *device;
- bool doUnref;
-public:
- cUdevDevice(udev_device *Device, bool DoUnref = true);
- virtual ~cUdevDevice(void);
- virtual int Compare(const cListObject &ListObject) const;
+ class cUdevDevice : public cListObject {
+ private:
+ struct udev_device *device;
+ bool doUnref;
+ public:
+ cUdevDevice(udev_device *Device, bool DoUnref = true);
+ virtual ~cUdevDevice(void);
+ virtual int Compare(const cListObject &ListObject) const;
- const char *GetAction(void) const;
- cUdevListEntry *GetDevlinksList(void) const;
- const char *GetDevnode(void) const;
- const char *GetDevpath(void) const;
- cUdevDevice *GetParent(void) const;
- const char *GetPropertyValue(const char *Key) const;
- const char *GetSubsystem(void) const;
- const char *GetSysname(void) const;
- const char *GetSyspath(void) const;
- };
+ const char *GetAction(void) const;
+ cUdevListEntry *GetDevlinksList(void) const;
+ const char *GetDevnode(void) const;
+ const char *GetDevpath(void) const;
+ cUdevDevice *GetParent(void) const;
+ const char *GetPropertyValue(const char *Key) const;
+ const char *GetSubsystem(void) const;
+ const char *GetSysname(void) const;
+ const char *GetSyspath(void) const;
+ };
-class cUdev {
-private:
- static struct udev *udev;
-public:
- static struct udev *Init(void);
- static void Free(void);
- static cUdevDevice *GetDeviceFromDevName(const char *DevName);
- static cUdevDevice *GetDeviceFromSysPath(const char *SysPath);
- static cList<cUdevDevice> *EnumDevices(const char *Subsystem, const char *Property, const char *Value);
- };
+ class cUdev {
+ private:
+ static cMutex udev_mutex;
+ static int udev_refcount; // newer libudev does this on its own
+ static struct udev *udev;
+ public:
+ static struct udev *Init(void);
+ static void Free(void);
+ static cUdevDevice *GetDeviceFromDevName(const char *DevName);
+ static cUdevDevice *GetDeviceFromSysPath(const char *SysPath);
+ static cList<cUdevDevice> *EnumDevices(const char *Subsystem, const char *Property, const char *Value);
+ };
+}
#endif // __DYNAMITEUDEV_H