diff options
author | Lars Hanisch <dvb@flensrocker.de> | 2011-06-15 23:01:54 +0200 |
---|---|---|
committer | Lars Hanisch <dvb@flensrocker.de> | 2011-06-15 23:01:54 +0200 |
commit | 41adafa231a3130288c7140449c02a3608c6599c (patch) | |
tree | ad81bc6bbbbf89adee82340b8ea972f2dd2f1fa8 | |
parent | 52eac73927cc0110ea9f93a40186d01564f6d69a (diff) | |
download | vdr-plugin-dynamite-41adafa231a3130288c7140449c02a3608c6599c.tar.gz vdr-plugin-dynamite-41adafa231a3130288c7140449c02a3608c6599c.tar.bz2 |
add udev property dynamite_cardindex to attach a device at a preferred slot (if free)
-rw-r--r-- | HISTORY | 4 | ||||
-rw-r--r-- | README | 4 | ||||
-rw-r--r-- | dynamicdevice.c | 42 | ||||
-rw-r--r-- | dynamicdevice.h | 3 | ||||
-rw-r--r-- | dynamite.c | 12 |
5 files changed, 51 insertions, 14 deletions
@@ -144,3 +144,7 @@ VDR Plugin 'dynamite' Revision History - add new parameter "--free-device-slots" and leave an additional slot free if streamdev-client is loaded + +2011-06-15: Version 0.0.6d + +- add udev property "dynamite_cardindex" to attach a device at a preferred slot (if free) @@ -230,6 +230,7 @@ example for udev rule: ACTION=="add", SUBSYSTEM=="dvb", ENV{DVB_DEVICE_TYPE}=="frontend" \ , ENV{dynamite_attach}="yes" \ , ENV{dynamite_instanceid}="0" \ + , ENV{dynamite_cardindex}="5" \ , ENV{dynamite_timeout}="10" \ , ENV{dynamite_timeout_handler_arg}="%k" @@ -248,6 +249,9 @@ dynamite_attach dynamite_instanceid n: attach only at vdr with matching instance id +dynamite_cardindex + n: if possible attach at slot with given cardindex + dynamite_timeout n: set GetTS timeout in seconds on this device diff --git a/dynamicdevice.c b/dynamicdevice.c index 2f9bbee..0c290cd 100644 --- a/dynamicdevice.c +++ b/dynamicdevice.c @@ -12,14 +12,16 @@ int cDynamicDevice::numDynamicDevices = 0; cMutex cDynamicDevice::arrayMutex; cDynamicDevice *cDynamicDevice::dynamicdevice[MAXDEVICES] = { NULL }; -int cDynamicDevice::IndexOf(const char *DevPath, int &NextFreeIndex) +int cDynamicDevice::IndexOf(const char *DevPath, int &NextFreeIndex, int WishIndex) { cMutexLock lock(&arrayMutex); NextFreeIndex = -1; int index = -1; - for (int i = 0; ((index < 0) || (NextFreeIndex < 0)) && (i < numDynamicDevices); i++) { + for (int i = 0; (i < numDynamicDevices) && ((index < 0) || (NextFreeIndex < 0) || ((WishIndex >= 0) && (dynamicdevice[i]->CardIndex() != WishIndex))); i++) { if (dynamicdevice[i]->devpath == NULL) { - if (NextFreeIndex < 0) + if (WishIndex >= 0) + isyslog("dynamite: device at slot %d has cardindex %d", i + 1, dynamicdevice[i]->CardIndex()); + if ((NextFreeIndex < 0) || ((WishIndex >= 0) && (dynamicdevice[i]->CardIndex() == WishIndex))) NextFreeIndex = i; } else if (index < 0) { @@ -72,6 +74,23 @@ bool cDynamicDevice::ProcessQueuedCommands(void) return true; } +int cDynamicDevice::GetProposedCardIndex(const char *DevPath) +{ + int cardindex = -1; + if (DevPath == NULL) + return cardindex; + cUdevDevice *dev = cUdev::GetDeviceFromDevName(DevPath); + if (dev != NULL) { + const char *val = dev->GetPropertyValue("dynamite_cardindex"); + isyslog("dynamite: udev cardindex is %s", val); + int intVal = -1; + if (val && (sscanf(val, "%d", &intVal) == 1) && (intVal >= 0) && (intVal <= MAXDEVICES)) + cardindex = intVal; + delete dev; + } + return cardindex; +} + void cDynamicDevice::DetachAllDevices(bool Force) { cMutexLock lock(&arrayMutex); @@ -127,8 +146,11 @@ eDynamicDeviceReturnCode cDynamicDevice::AttachDevice(const char *DevPath) return ddrcNotSupported; cMutexLock lock(&arrayMutex); + int wishIndex = GetProposedCardIndex(DevPath); + if (wishIndex >= 0) + isyslog("dynamite: %s wants card index %d", DevPath, wishIndex); int freeIndex = -1; - int index = IndexOf(DevPath, freeIndex); + int index = IndexOf(DevPath, freeIndex, wishIndex); int adapter = -1; int frontend = -1; @@ -211,7 +233,7 @@ eDynamicDeviceReturnCode cDynamicDevice::DetachDevice(const char *DevPath, bool if (isnumber(DevPath)) index = strtol(DevPath, NULL, 10) - 1; else - index = IndexOf(DevPath, freeIndex); + index = IndexOf(DevPath, freeIndex, -1); if ((index < 0) || (index >= numDynamicDevices)) { esyslog("dynamite: device %s not found", DevPath); @@ -255,7 +277,7 @@ eDynamicDeviceReturnCode cDynamicDevice::SetLockDevice(const char *DevPath, bool if (isnumber(DevPath)) index = strtol(DevPath, NULL, 10) - 1; else - index = IndexOf(DevPath, freeIndex); + index = IndexOf(DevPath, freeIndex, -1); if ((index < 0) || (index >= numDynamicDevices)) return ddrcNotFound; @@ -275,7 +297,7 @@ eDynamicDeviceReturnCode cDynamicDevice::SetIdle(const char *DevPath, bool Idle) if (isnumber(DevPath)) index = strtol(DevPath, NULL, 10) - 1; else - index = IndexOf(DevPath, freeIndex); + index = IndexOf(DevPath, freeIndex, -1); if ((index < 0) || (index >= numDynamicDevices)) return ddrcNotFound; @@ -296,7 +318,7 @@ eDynamicDeviceReturnCode cDynamicDevice::SetGetTSTimeout(const char *DevPath, in if (isnumber(DevPath)) index = strtol(DevPath, NULL, 10) - 1; else - index = IndexOf(DevPath, freeIndex); + index = IndexOf(DevPath, freeIndex, -1); if ((index < 0) || (index >= numDynamicDevices)) return ddrcNotFound; @@ -327,7 +349,7 @@ eDynamicDeviceReturnCode cDynamicDevice::SetGetTSTimeoutHandlerArg(const char *D if (isnumber(DevPath)) index = strtol(DevPath, NULL, 10) - 1; else - index = IndexOf(DevPath, freeIndex); + index = IndexOf(DevPath, freeIndex, -1); if ((index < 0) || (index >= numDynamicDevices)) return ddrcNotFound; @@ -340,7 +362,7 @@ bool cDynamicDevice::IsAttached(const char *DevPath) { cMutexLock lock(&arrayMutex); int freeIndex = -1; - int index = IndexOf(DevPath, freeIndex); + int index = IndexOf(DevPath, freeIndex, -1); return ((index >= 0) && (index >= numDynamicDevices)); } diff --git a/dynamicdevice.h b/dynamicdevice.h index b953b97..3c4ef37 100644 --- a/dynamicdevice.h +++ b/dynamicdevice.h @@ -26,11 +26,12 @@ private: public: static cDvbDeviceProbe *dvbprobe; static bool enableOsdMessages; - static int IndexOf(const char *DevPath, int &NextFreeIndex); + static int IndexOf(const char *DevPath, int &NextFreeIndex, int WishIndex); static int NumDynamicDevices(void) { return numDynamicDevices; } ///< Returns the total number of dynamic devices. static cDynamicDevice *GetDynamicDevice(int Index); static bool ProcessQueuedCommands(void); + static int GetProposedCardIndex(const char *DevPath); static void DetachAllDevices(bool Force); static cString ListAllDevices(int &ReplyCode); // for SVDRP command LSTD static cString AttachDevicePattern(const char *Pattern); @@ -10,7 +10,7 @@ #include "menu.h" #include "monitor.h" -static const char *VERSION = "0.0.6c"; +static const char *VERSION = "0.0.6d"; static const char *DESCRIPTION = tr("attach/detach devices on the fly"); static const char *MAINMENUENTRY = NULL; @@ -20,9 +20,15 @@ private: public: virtual bool Probe(int Adapter, int Frontend) { + if (firstProbe) { + firstProbe = false; + isyslog("dynamite: preparing %d dynamic device slots for dvb devices", MAXDVBDEVICES); + while (cDevice::NumDevices() < MAXDVBDEVICES) + new cDynamicDevice; + } cString devpath = cString::sprintf("/dev/dvb/adapter%d/frontend%d", Adapter, Frontend); int freeIndex = -1; - if (cDynamicDevice::IndexOf(*devpath, freeIndex) >= 0) // already attached - should not happen + if (cDynamicDevice::IndexOf(*devpath, freeIndex, -1) >= 0) // already attached - should not happen return true; if (freeIndex < 0) { if ((cDevice::NumDevices() >= MAXDEVICES) || (cDynamicDevice::NumDynamicDevices() >= MAXDEVICES)) { @@ -209,7 +215,7 @@ bool cPluginDynamite::Initialize(void) int dummy = 0; for (cUdevDevice *d = devices->First(); d; d = devices->Next(d)) { const char *devpath = d->GetDevnode(); - if ((devpath != NULL) && (cDynamicDevice::IndexOf(devpath, dummy) < 0)) { + if ((devpath != NULL) && (cDynamicDevice::IndexOf(devpath, dummy, -1) < 0)) { isyslog("dynamite: probing %s", devpath); cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcAttach, devpath); } |