summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Hanisch <dvb@flensrocker.de>2011-02-23 20:43:42 +0100
committerLars Hanisch <dvb@flensrocker.de>2011-02-23 20:54:05 +0100
commit5ac5fdf0bef95b12d90dfca7de23332211beb706 (patch)
tree59925890d82e0c5810f0c5e4416f88e4326e3914
parente919a8339c29cd190fc4cd5a832317eb9f4451c6 (diff)
downloadvdr-plugin-dynamite-5ac5fdf0bef95b12d90dfca7de23332211beb706.tar.gz
vdr-plugin-dynamite-5ac5fdf0bef95b12d90dfca7de23332211beb706.tar.bz2
move reading of udev properties from the monitor to the attacher
Now they are recognized on devices present at startup.
-rw-r--r--HISTORY5
-rw-r--r--dynamicdevice.c67
-rw-r--r--dynamicdevice.h5
-rw-r--r--dynamite.c2
-rw-r--r--monitor.c6
-rw-r--r--udev.c20
-rw-r--r--udev.h1
7 files changed, 86 insertions, 20 deletions
diff --git a/HISTORY b/HISTORY
index 7f7a47b..c415997 100644
--- a/HISTORY
+++ b/HISTORY
@@ -98,3 +98,8 @@ VDR Plugin 'dynamite' Revision History
- add idle option to cDevice, "idle"-devices must close all their handles.
They are ignored by the epg-scan.
+
+2011-02-23: Version 0.0.5j
+
+- move reading of udev properties from the monitor to the attacher,
+ so that they are recognized on devices present at startup.
diff --git a/dynamicdevice.c b/dynamicdevice.c
index efbe142..e7f5b1e 100644
--- a/dynamicdevice.c
+++ b/dynamicdevice.c
@@ -1,4 +1,5 @@
#include "dynamicdevice.h"
+#include "udev.h"
#include <glob.h>
#include <vdr/transfer.h>
@@ -154,6 +155,7 @@ attach:
cCondWait::SleepMs(2);
dynamicdevice[freeIndex]->devpath = new cString(DevPath);
isyslog("dynamite: attached device %s to dynamic device slot %d", DevPath, freeIndex + 1);
+ dynamicdevice[freeIndex]->ReadUdevProperties();
return ddrcSuccess;
}
@@ -211,8 +213,7 @@ eDynamicDeviceReturnCode cDynamicDevice::SetLockDevice(const char *DevPath, bool
if ((index < 0) || (index >= numDynamicDevices))
return ddrcNotFound;
- dynamicdevice[index]->isDetachable = !Lock;
- isyslog("dynamite: %slocked device %s", Lock ? "" : "un", DevPath);
+ dynamicdevice[index]->InternSetLock(Lock);
return ddrcSuccess;
}
@@ -253,11 +254,7 @@ eDynamicDeviceReturnCode cDynamicDevice::SetGetTSTimeout(const char *DevPath, in
if ((index < 0) || (index >= numDynamicDevices))
return ddrcNotFound;
- dynamicdevice[index]->getTSTimeout = Seconds;
- if (Seconds == 0)
- isyslog("dynamite: disable GetTSTimeout on device %s", DevPath);
- else
- isyslog("dynamite: set GetTSTimeout on device %s to %d seconds", DevPath, Seconds);
+ dynamicdevice[index]->InternSetGetTSTimeout(Seconds);
return ddrcSuccess;
}
@@ -265,10 +262,10 @@ void cDynamicDevice::SetDefaultGetTSTimeout(int Seconds)
{
if (Seconds >= 0) {
defaultGetTSTimeout = Seconds;
+ isyslog("dynamite: set default GetTSTimeout to %d seconds", Seconds);
cMutexLock lock(&arrayMutex);
for (int i = 0; i < numDynamicDevices; i++)
- dynamicdevice[i]->getTSTimeout = Seconds;
- isyslog("dynamite: set default GetTSTimeout on all devices to %d seconds", Seconds);
+ dynamicdevice[i]->InternSetGetTSTimeout(Seconds);
}
}
@@ -288,10 +285,7 @@ eDynamicDeviceReturnCode cDynamicDevice::SetGetTSTimeoutHandlerArg(const char *D
if ((index < 0) || (index >= numDynamicDevices))
return ddrcNotFound;
- if (dynamicdevice[index]->getTSTimeoutHandlerArg)
- delete dynamicdevice[index]->getTSTimeoutHandlerArg;
- dynamicdevice[index]->getTSTimeoutHandlerArg = new cString(Arg);
- isyslog("dynamite: set GetTSTimeoutHandlerArg on device %s to %s", DevPath, Arg);
+ dynamicdevice[index]->InternSetGetTSTimeoutHandlerArg(Arg);
return ddrcSuccess;
}
@@ -328,6 +322,53 @@ cDynamicDevice::~cDynamicDevice()
getTSTimeoutHandlerArg = NULL;
}
+const char *cDynamicDevice::GetDevPath(void) const
+{
+ return (devpath ? **devpath : "");
+}
+
+void cDynamicDevice::ReadUdevProperties(void)
+{
+ if (devpath == NULL)
+ return;
+ cUdevDevice *dev = cUdev::GetDeviceFromDevName(**devpath);
+ if (dev != NULL) {
+ const char *timeout = dev->GetPropertyValue("dynamite_timeout");
+ int seconds = -1;
+ if (timeout && (sscanf(timeout, "%d", &seconds) == 1) && (seconds >= 0))
+ InternSetGetTSTimeout(seconds);
+
+ const char *timeoutHandlerArg = dev->GetPropertyValue("dynamite_timeout_handler_arg");
+ if (timeoutHandlerArg)
+ InternSetGetTSTimeoutHandlerArg(timeoutHandlerArg);
+
+ delete dev;
+ }
+}
+
+void cDynamicDevice::InternSetGetTSTimeout(int Seconds)
+{
+ getTSTimeout = Seconds;
+ if (Seconds == 0)
+ isyslog("dynamite: disable GetTSTimeout on device %s", GetDevPath());
+ else
+ isyslog("dynamite: set GetTSTimeout on device %s to %d seconds", GetDevPath(), Seconds);
+}
+
+void cDynamicDevice::InternSetGetTSTimeoutHandlerArg(const char *Arg)
+{
+ if (getTSTimeoutHandlerArg)
+ delete getTSTimeoutHandlerArg;
+ getTSTimeoutHandlerArg = new cString(Arg);
+ isyslog("dynamite: set GetTSTimeoutHandlerArg on device %s to %s", GetDevPath(), Arg);
+}
+
+void cDynamicDevice::InternSetLock(bool Lock)
+{
+ isDetachable = !Lock;
+ isyslog("dynamite: %slocked device %s", Lock ? "" : "un", GetDevPath());
+}
+
void cDynamicDevice::DeleteSubDevice()
{
if (subDevice) {
diff --git a/dynamicdevice.h b/dynamicdevice.h
index 43df2c8..2f90a73 100644
--- a/dynamicdevice.h
+++ b/dynamicdevice.h
@@ -48,6 +48,11 @@ private:
time_t getTSWatchdog;
int getTSTimeout;
bool restartSectionHandler;
+ const char *GetDevPath(void) const;
+ void ReadUdevProperties(void);
+ void InternSetGetTSTimeout(int Seconds);
+ void InternSetGetTSTimeoutHandlerArg(const char *Arg);
+ void InternSetLock(bool Lock);
public:
cDynamicDevice();
void DeleteSubDevice(void);
diff --git a/dynamite.c b/dynamite.c
index 504987f..01d79f3 100644
--- a/dynamite.c
+++ b/dynamite.c
@@ -8,7 +8,7 @@
#include "dynamicdevice.h"
#include "monitor.h"
-static const char *VERSION = "0.0.5i";
+static const char *VERSION = "0.0.5j";
static const char *DESCRIPTION = "attach/detach devices on the fly";
static const char *MAINMENUENTRY = NULL;
diff --git a/monitor.c b/monitor.c
index f911698..e603c30 100644
--- a/monitor.c
+++ b/monitor.c
@@ -216,12 +216,6 @@ void cUdevDvbFilter::Process(cUdevDevice &Device)
if (!devname || cDynamicDevice::IsAttached(devname))
return;
cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcAttach, devname);
- const char *timeout = Device.GetPropertyValue("dynamite_timeout");
- if (timeout)
- cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcService, *cString::sprintf("dynamite-SetGetTSTimeout-v0.1 %s %s", devname, timeout));
- const char *timeoutHandlerArg = Device.GetPropertyValue("dynamite_timeout_handler_arg");
- if (timeoutHandlerArg)
- cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcService, *cString::sprintf("dynamite-SetGetTSTimeoutHandlerArg-v0.1 %s %s", devname, timeoutHandlerArg));
}
}
diff --git a/udev.c b/udev.c
index f37fc77..79207cf 100644
--- a/udev.c
+++ b/udev.c
@@ -115,3 +115,23 @@ void cUdev::Free(void)
udev_unref(udev);
udev = NULL;
}
+
+cUdevDevice *cUdev::GetDeviceFromDevName(const char *DevName)
+{
+ if (DevName == NULL)
+ return NULL;
+ struct stat statbuf;
+ if (stat(DevName, &statbuf) < 0)
+ return NULL;
+ char type;
+ if (S_ISBLK(statbuf.st_mode))
+ type = 'b';
+ else if (S_ISCHR(statbuf.st_mode))
+ type = 'c';
+ else
+ return NULL;
+ udev_device *dev = udev_device_new_from_devnum(udev, type, statbuf.st_rdev);
+ if (dev == NULL)
+ return NULL;
+ return new cUdevDevice(dev);
+}
diff --git a/udev.h b/udev.h
index af079ab..e3c82ea 100644
--- a/udev.h
+++ b/udev.h
@@ -37,6 +37,7 @@ private:
public:
static struct udev *Init(void);
static void Free(void);
+ static cUdevDevice *GetDeviceFromDevName(const char *DevName);
};
#endif // __DYNAMITEUDEV_H