summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Hanisch <dvb@flensrocker.de>2011-03-25 21:20:07 +0100
committerLars Hanisch <dvb@flensrocker.de>2011-03-25 21:20:07 +0100
commit59cb96c4c68c1031d713ee36342643378641ca4e (patch)
treec6177a5b57eac5f220ca7e9ffcaee4f7505be38e
parent2e1250d57513f385d3dbd6527f94d98366c84fc9 (diff)
downloadvdr-plugin-dynamite-59cb96c4c68c1031d713ee36342643378641ca4e.tar.gz
vdr-plugin-dynamite-59cb96c4c68c1031d713ee36342643378641ca4e.tar.bz2
add some OSD functionalityv0.0.6a
-rw-r--r--HISTORY4
-rw-r--r--Makefile2
-rw-r--r--README9
-rw-r--r--dynamicdevice.c17
-rw-r--r--dynamicdevice.h5
-rw-r--r--dynamite.c9
-rw-r--r--menu.c131
-rw-r--r--menu.h20
8 files changed, 192 insertions, 5 deletions
diff --git a/HISTORY b/HISTORY
index 1debf83..3665ca9 100644
--- a/HISTORY
+++ b/HISTORY
@@ -135,3 +135,7 @@ VDR Plugin 'dynamite' Revision History
- scan with udev for dvb devices on startup to bridge gaps in the adapter numbers
- add udev property "dynamite_attach" to keep devices from being attached
- add udev property "dynamite_instanceid" to associate the devices to different vdr instances
+
+2011-03-25: Version 0.0.6a
+
+- add some OSD functionality
diff --git a/Makefile b/Makefile
index f3f7775..5021dd6 100644
--- a/Makefile
+++ b/Makefile
@@ -55,7 +55,7 @@ endif
### The object files (add further files here):
-OBJS = $(PLUGIN).o dynamicdevice.o monitor.o udev.o
+OBJS = $(PLUGIN).o dynamicdevice.o menu.o monitor.o udev.o
### The main target:
diff --git a/README b/README
index 8d1e490..5692f4b 100644
--- a/README
+++ b/README
@@ -170,6 +170,15 @@ CallGetTSTimeoutHandler arg
Don't forget to prefix them with "plug dynamite"...
+Controlling dynamite with the OSD
+---------------------------------
+The main menu item "dynamite" offers the following possibilities:
+- list attached devices
+- scan for new DVB devices
+- detach device
+- lock/unlock device
+- switch device to idle
+
Signals emitted via cPluginManager::CallAllServices
---------------------------------------------------
On some actions dynamite calls the Service interface of every plugin
diff --git a/dynamicdevice.c b/dynamicdevice.c
index 9aeccb9..3426994 100644
--- a/dynamicdevice.c
+++ b/dynamicdevice.c
@@ -1,11 +1,13 @@
#include "dynamicdevice.h"
#include "udev.h"
#include <glob.h>
+#include <vdr/skins.h>
#include <vdr/transfer.h>
cPlugin *cDynamicDevice::dynamite = NULL;
int cDynamicDevice::defaultGetTSTimeout = 0;
cDvbDeviceProbe *cDynamicDevice::dvbprobe = NULL;
+bool cDynamicDevice::enableOsdMessages = false;
int cDynamicDevice::numDynamicDevices = 0;
cMutex cDynamicDevice::arrayMutex;
cDynamicDevice *cDynamicDevice::dynamicdevice[MAXDEVICES] = { NULL };
@@ -28,6 +30,13 @@ int cDynamicDevice::IndexOf(const char *DevPath, int &NextFreeIndex)
return index;
}
+cDynamicDevice *cDynamicDevice::GetDynamicDevice(int Index)
+{
+ if ((Index < 0) || (Index >= numDynamicDevices))
+ return NULL;
+ return dynamicdevice[Index];
+}
+
bool cDynamicDevice::ProcessQueuedCommands(void)
{
for (cDynamicDeviceProbe::cDynamicDeviceProbeItem *dev = cDynamicDeviceProbe::commandQueue.First(); dev; dev = cDynamicDeviceProbe::commandQueue.Next(dev)) {
@@ -184,6 +193,10 @@ attach:
isyslog("dynamite: attached device %s to dynamic device slot %d", DevPath, freeIndex + 1);
dynamicdevice[freeIndex]->ReadUdevProperties();
cPluginManager::CallAllServices("dynamite-event-DeviceAttached-v0.1", (void*)DevPath);
+ if (enableOsdMessages) {
+ cString osdMsg = cString::sprintf("attached %s", DevPath);
+ Skins.QueueMessage(mtInfo, *osdMsg);
+ }
return ddrcSuccess;
}
@@ -224,6 +237,10 @@ eDynamicDeviceReturnCode cDynamicDevice::DetachDevice(const char *DevPath, bool
dynamicdevice[index]->DeleteSubDevice();
isyslog("dynamite: detached device %s%s", DevPath, (Force ? " (forced)" : ""));
+ if (enableOsdMessages) {
+ cString osdMsg = cString::sprintf("detached %s", DevPath);
+ Skins.QueueMessage(mtInfo, *osdMsg);
+ }
return ddrcSuccess;
}
diff --git a/dynamicdevice.h b/dynamicdevice.h
index e76a842..b953b97 100644
--- a/dynamicdevice.h
+++ b/dynamicdevice.h
@@ -25,9 +25,11 @@ private:
static cDynamicDevice *dynamicdevice[MAXDEVICES];
public:
static cDvbDeviceProbe *dvbprobe;
+ static bool enableOsdMessages;
static int IndexOf(const char *DevPath, int &NextFreeIndex);
static int NumDynamicDevices(void) { return numDynamicDevices; }
///< Returns the total number of dynamic devices.
+ static cDynamicDevice *GetDynamicDevice(int Index);
static bool ProcessQueuedCommands(void);
static void DetachAllDevices(bool Force);
static cString ListAllDevices(int &ReplyCode); // for SVDRP command LSTD
@@ -48,14 +50,15 @@ 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();
+ const char *GetDevPath(void) const;
void DeleteSubDevice(void);
+ bool IsDetachable(void) const { return isDetachable; }
virtual bool SetIdleDevice(bool Idle, bool TestOnly);
virtual bool CanScanForEPG(void) const;
protected:
diff --git a/dynamite.c b/dynamite.c
index cc27ede..52866cb 100644
--- a/dynamite.c
+++ b/dynamite.c
@@ -7,11 +7,12 @@
#include <getopt.h>
#include <vdr/plugin.h>
#include "dynamicdevice.h"
+#include "menu.h"
#include "monitor.h"
-static const char *VERSION = "0.0.6";
+static const char *VERSION = "0.0.6a";
static const char *DESCRIPTION = "attach/detach devices on the fly";
-static const char *MAINMENUENTRY = NULL;
+static const char *MAINMENUENTRY = "dynamite";
class cDynamiteDvbDeviceProbe : public cDvbDeviceProbe {
private:
@@ -220,6 +221,8 @@ void cPluginDynamite::MainThreadHook(void)
// WARNING: Use with great care - see PLUGINS.html!
if (!cDynamicDevice::ProcessQueuedCommands())
esyslog("dynamite: can't process all queued commands");
+ if (!cDynamicDevice::enableOsdMessages)
+ cDynamicDevice::enableOsdMessages = true;
}
cString cPluginDynamite::Active(void)
@@ -237,7 +240,7 @@ time_t cPluginDynamite::WakeupTime(void)
cOsdObject *cPluginDynamite::MainMenuAction(void)
{
// Perform the action when selected from the main VDR menu.
- return NULL;
+ return new cDynamiteMainMenu;
}
cMenuSetupPage *cPluginDynamite::SetupMenu(void)
diff --git a/menu.c b/menu.c
new file mode 100644
index 0000000..30a90f3
--- /dev/null
+++ b/menu.c
@@ -0,0 +1,131 @@
+#include "menu.h"
+#include "dynamicdevice.h"
+
+
+class cDynamiteMenuDevicelist : public cOsdMenu
+{
+public:
+ cVector<int> deviceIds;
+ cStringList devicePaths;
+
+ cDynamiteMenuDevicelist(const char *Title)
+ :cOsdMenu(Title)
+ {
+ cDynamicDevice *d;
+ const char *cp;
+ char *p;
+ for (int i = 0; i < cDynamicDevice::NumDynamicDevices(); i++) {
+ d = cDynamicDevice::GetDynamicDevice(i);
+ if (d == NULL)
+ continue;
+ cp = d->GetDevPath();
+ if ((cp == NULL) || (strlen(cp) == 0))
+ continue;
+ p = strdup(cp);
+ if (p == NULL)
+ continue;
+ deviceIds.Append(i);
+ devicePaths.Append(p);
+ cString text = cString::sprintf("%d%s %s", i + 1, (d->IsDetachable() ? " " : "*"), p);
+ Add(new cOsdItem(*text));
+ }
+ }
+};
+
+enum eMenuAction { maList,
+ maScan,
+ maDetach,
+ maLock,
+ maUnlock,
+ maSetIdle
+ };
+
+class cDynamiteMenuItem : public cOsdItem
+{
+public:
+ eMenuAction action;
+ bool showList;
+
+ cDynamiteMenuItem(eMenuAction Action, const char *Text, bool ShowList = true)
+ :cOsdItem(Text)
+ ,action(Action)
+ ,showList(ShowList)
+ {
+ }
+
+ virtual eOSState Action(int DevId, const char *DevPath)
+ {
+ switch (action) {
+ case maScan:
+ isyslog("dynamite: menu action: scan for dvb devices");
+ cDynamicDevice::AttachDevicePattern("/dev/dvb/adapter*/frontend*");
+ return osEnd;
+ case maDetach:
+ isyslog("dynamite: menu action: detach device %s", DevPath);
+ cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcDetach, DevPath);
+ return osEnd;
+ case maLock:
+ case maUnlock:
+ isyslog("dynamite: menu action: %slock device %s", (action == maUnlock ? "un" : ""), DevPath);
+ cDynamicDevice::SetLockDevice(DevPath, action == maLock);
+ break;
+ case maSetIdle:
+ isyslog("dynamite: menu action: set idle mode on device %s", DevPath);
+ cDynamicDevice::SetIdle(DevPath, true);
+ break;
+ default:
+ return osUnknown;
+ }
+ return osUnknown;
+ }
+};
+
+cDynamiteMainMenu::cDynamiteMainMenu(void)
+:cOsdMenu("dynamite")
+{
+ Add(new cDynamiteMenuItem(maList, "list attached devices"));
+ Add(new cDynamiteMenuItem(maScan, "scan for new DVB devices", false));
+ Add(new cDynamiteMenuItem(maDetach, "detach device"));
+ Add(new cDynamiteMenuItem(maLock, "lock device"));
+ Add(new cDynamiteMenuItem(maUnlock, "unlock device"));
+ Add(new cDynamiteMenuItem(maSetIdle, "switch device to idle"));
+}
+
+cDynamiteMainMenu::~cDynamiteMainMenu(void)
+{
+}
+
+eOSState cDynamiteMainMenu::ProcessKey(eKeys Key)
+{
+ cDynamiteMenuItem *item = dynamic_cast<cDynamiteMenuItem*>(Get(Current()));
+ if (item == NULL)
+ return cOsdMenu::ProcessKey(Key);
+ eOSState state = osUnknown;
+ switch (Key) {
+ case kOk:
+ {
+ if (HasSubMenu()) {
+ cDynamiteMenuDevicelist *dl = dynamic_cast<cDynamiteMenuDevicelist*>(SubMenu());
+ if (dl != NULL) {
+ int i = dl->Current();
+ if ((i >= 0) && (i < dl->deviceIds.Size()))
+ state = item->Action(dl->deviceIds[i], dl->devicePaths[i]);
+ }
+ CloseSubMenu();
+ }
+ else {
+ if (item->showList)
+ state = AddSubMenu(new cDynamiteMenuDevicelist(item->Text()));
+ else
+ state = item->Action(-1, NULL);
+ }
+ break;
+ }
+ default:
+ {
+ state = cOsdMenu::ProcessKey(Key);
+ break;
+ }
+ }
+ return state;
+}
diff --git a/menu.h b/menu.h
new file mode 100644
index 0000000..609a545
--- /dev/null
+++ b/menu.h
@@ -0,0 +1,20 @@
+#ifndef __DYNAMITEMENU_H
+#define __DYNAMITEMENU_H
+
+#include <vdr/osdbase.h>
+
+
+class cDynamiteMainMenu : public cOsdMenu
+{
+private:
+
+protected:
+
+public:
+ cDynamiteMainMenu(void);
+ virtual ~cDynamiteMainMenu(void);
+ virtual eOSState ProcessKey(eKeys Key);
+};
+
+#endif
+