From c3cc3a490df4937dc70cc2442c6724c4b6d956ec Mon Sep 17 00:00:00 2001 From: Lars Hanisch Date: Thu, 17 Feb 2011 01:44:32 +0100 Subject: dynamite can call an external program if the GetTSTimeout of a device triggers In setup.conf set dynamite.GetTSTimeoutHandler to a program you want to execute. If the udev-property dynamite_timeout_handler_arg is set it will be passed as the argument to it otherwise the devpath with wich the device was attached to dynamite. --- dynamicdevice.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'dynamicdevice.c') diff --git a/dynamicdevice.c b/dynamicdevice.c index c7841f0..328e146 100644 --- a/dynamicdevice.c +++ b/dynamicdevice.c @@ -251,6 +251,29 @@ void cDynamicDevice::SetDefaultGetTSTimeout(int Seconds) } } +eDynamicDeviceReturnCode cDynamicDevice::SetGetTSTimeoutHandlerArg(const char *DevPath, const char *Arg) +{ + if (!DevPath || !Arg) + return ddrcNotSupported; + + cMutexLock lock(&arrayMutex); + int freeIndex = -1; + int index = -1; + if (isnumber(DevPath)) + index = strtol(DevPath, NULL, 10) - 1; + else + index = IndexOf(DevPath, freeIndex); + + 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); + return ddrcSuccess; +} + bool cDynamicDevice::IsAttached(const char *DevPath) { cMutexLock lock(&arrayMutex); @@ -262,6 +285,7 @@ bool cDynamicDevice::IsAttached(const char *DevPath) cDynamicDevice::cDynamicDevice() :index(-1) ,devpath(NULL) +,getTSTimeoutHandlerArg(NULL) ,isDetachable(true) ,getTSTimeout(defaultGetTSTimeout) { @@ -277,6 +301,9 @@ cDynamicDevice::cDynamicDevice() cDynamicDevice::~cDynamicDevice() { DeleteSubDevice(); + if (getTSTimeoutHandlerArg) + delete getTSTimeoutHandlerArg; + getTSTimeoutHandlerArg = NULL; } void cDynamicDevice::DeleteSubDevice() @@ -700,6 +727,10 @@ bool cDynamicDevice::GetTSPacket(uchar *&Data) d = **devpath; esyslog("dynamite: device %s hasn't delivered any data for %d seconds, it will be detached", d, getTSTimeout); cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcDetach, *devpath); + const char *timeoutHandlerArg = *devpath; + if (getTSTimeoutHandlerArg) + timeoutHandlerArg = **getTSTimeoutHandlerArg; + cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcService, *cString::sprintf("dynamite-CallGetTSTimeoutHandler-v0.1 %s", timeoutHandlerArg)); return false; } } -- cgit v1.2.3