diff --git a/HISTORY b/HISTORY index a2c0b69..1247a4e 100644 --- a/HISTORY +++ b/HISTORY @@ -236,3 +236,7 @@ VDR Plugin 'dbus2vdr' Revision History 2015-09-30: Version 26 - make compatible with vdr 2.3.1 + +2016-02-13: Version 28 +- add device interface + diff --git a/Makefile b/Makefile index 23206e5..0c0a48e 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ DEFINES += -DPLUGIN_NAME_I18N='"$(PLUGIN)"' ### The object files (add further files here): -OBJS = $(PLUGIN).o channel.o connection.o epg.o helper.o mainloop.o network.o object.o osd.o plugin.o recording.o remote.o sd-daemon.o setup.o shutdown.o skin.o status.o timer.o vdr.o +OBJS = $(PLUGIN).o channel.o connection.o device.o epg.o helper.o mainloop.o network.o object.o osd.o plugin.o recording.o remote.o sd-daemon.o setup.o shutdown.o skin.o status.o timer.o vdr.o SWOBJS = libvdr-exitpipe.o libvdr-i18n.o libvdr-thread.o libvdr-tools.o shutdown-wrapper.o ### The main target: diff --git a/README b/README index 95b6943..5aa5034 100644 --- a/README +++ b/README @@ -94,6 +94,20 @@ Interface "channel" The returned array contains the channel number and the string from the channels.conf. +Interface "device" +------------------- +- get current primary device + vdr-dbus-send.sh /Devices device.GetPrimary + +- request switch to primary device + vdr-dbus-send.sh /Devices device.RequestPrimary int32:index + +- list devices + vdr-dbus-send.sh /Devices device.List + + The returned array contains the device index, number, a boolean value "hasDecoder", + a boolean value "isPrimary" and the name of the device. + Interface "epg" --------------- - disable EIT scanner with timeout (default: 3600) diff --git a/common.h b/common.h index bf13115..b3a4a9a 100644 --- a/common.h +++ b/common.h @@ -5,6 +5,7 @@ #define DBUS_VDR_BUSNAME "de.tvdr.vdr" #define DBUS_VDR_CHANNEL_INTERFACE DBUS_VDR_BUSNAME".channel" +#define DBUS_VDR_DEVICE_INTERFACE DBUS_VDR_BUSNAME".device" #define DBUS_VDR_EPG_INTERFACE DBUS_VDR_BUSNAME".epg" #define DBUS_VDR_OSD_INTERFACE DBUS_VDR_BUSNAME".osd" #define DBUS_VDR_PLUGIN_INTERFACE DBUS_VDR_BUSNAME".plugin" diff --git a/dbus2vdr.c b/dbus2vdr.c index 2f21a97..0ac1a05 100644 --- a/dbus2vdr.c +++ b/dbus2vdr.c @@ -15,6 +15,7 @@ #include "common.h" #include "connection.h" #include "channel.h" +#include "device.h" #include "epg.h" #include "helper.h" #include "mainloop.h" @@ -37,7 +38,7 @@ #include "avahi-helper.h" -static const char *VERSION = "27"; +static const char *VERSION = "28"; static const char *DESCRIPTION = trNOOP("control vdr via D-Bus"); static const char *MAINMENUENTRY = NULL; @@ -117,6 +118,7 @@ static cString SetSessionEnv(const char *Name, cString &Store, const char *Optio static void AddAllObjects(cDBusConnection *Connection, bool EnableOSD) { Connection->AddObject(new cDBusChannels); + Connection->AddObject(new cDBusDevices); Connection->AddObject(new cDBusEpg); if (EnableOSD) Connection->AddObject(new cDBusOsdObject); @@ -467,6 +469,12 @@ void cPluginDbus2vdr::MainThreadHook(void) raise(SIGSTOP); } } + + int requestPrimaryDevice = cDBusDevices::RequestedPrimaryDevice(true); + if (requestPrimaryDevice >= 0) { + cControl::Shutdown(); + cDevice::SetPrimaryDevice(requestPrimaryDevice + 1); + } } cString cPluginDbus2vdr::Active(void) diff --git a/device.c b/device.c new file mode 100644 index 0000000..b2bfe16 --- /dev/null +++ b/device.c @@ -0,0 +1,122 @@ +#include "device.h" +#include "common.h" +#include "helper.h" + +#include + + +int cDBusDevices::_requestedPrimaryDevice = -1; +cMutex cDBusDevices::_requestedPrimaryDeviceMutex; + +void cDBusDevices::SetPrimaryDeviceRequest(int index) +{ + cMutexLock MutexLock(&_requestedPrimaryDeviceMutex); + _requestedPrimaryDevice = index; +} + +int cDBusDevices::RequestedPrimaryDevice(bool clear) +{ + cMutexLock MutexLock(&_requestedPrimaryDeviceMutex); + int ret = _requestedPrimaryDevice; + if (clear) + _requestedPrimaryDevice = -1; + return ret; +} + +namespace cDBusDevicesHelper +{ + static const char *_xmlNodeInfo = + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; + + static void AddDevice(GVariantBuilder *Variant, const cDevice *Device, bool AsStruct) + { + gint32 index = -1; + gint32 number = -1; + gboolean hasDecoder = FALSE; + gboolean isPrimary = FALSE; + cString name = ""; + if (Device != NULL) { + index = Device->CardIndex(); + number = Device->DeviceNumber(); + hasDecoder = Device->HasDecoder(); + isPrimary = Device->IsPrimaryDevice(); + name = Device->DeviceName(); + cDBusHelper::ToUtf8(name); + } + + if (AsStruct) + g_variant_builder_add(Variant, "(iibbs)", index, number, hasDecoder, isPrimary, *name); + else { + g_variant_builder_add(Variant, "i", index); + g_variant_builder_add(Variant, "i", number); + g_variant_builder_add(Variant, "b", hasDecoder); + g_variant_builder_add(Variant, "b", isPrimary); + g_variant_builder_add(Variant, "s", *name); + } + } + + static void GetPrimary(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation) + { + GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("(iibbs)")); + const cDevice *dev = cDevice::PrimaryDevice(); + AddDevice(builder, dev, false); + g_dbus_method_invocation_return_value(Invocation, g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + } + + static void RequestPrimary(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation) + { + gint32 index = -1; + g_variant_get(Parameters, "(i)", &index); + cDBusDevices::SetPrimaryDeviceRequest(index); + g_dbus_method_invocation_return_value(Invocation, NULL); + } + + static void List(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation) + { + GVariantBuilder *array = g_variant_builder_new(G_VARIANT_TYPE("a(iibbs)")); + + for (int i = 0; i < cDevice::NumDevices(); i++) { + const cDevice *dev = cDevice::GetDevice(i); + if (dev != NULL) + AddDevice(array, dev, true); + } + + GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("(a(iibbs))")); + g_variant_builder_add_value(builder, g_variant_builder_end(array)); + g_dbus_method_invocation_return_value(Invocation, g_variant_builder_end(builder)); + g_variant_builder_unref(array); + g_variant_builder_unref(builder); + } +} + + +cDBusDevices::cDBusDevices(void) +:cDBusObject("/Devices", cDBusDevicesHelper::_xmlNodeInfo) +{ + AddMethod("GetPrimary", cDBusDevicesHelper::GetPrimary); + AddMethod("RequestPrimary", cDBusDevicesHelper::RequestPrimary); + AddMethod("List", cDBusDevicesHelper::List); +} + +cDBusDevices::~cDBusDevices(void) +{ +} diff --git a/device.h b/device.h new file mode 100644 index 0000000..c3ebff5 --- /dev/null +++ b/device.h @@ -0,0 +1,21 @@ +#ifndef __DBUS2VDR_DEVICE_H +#define __DBUS2VDR_DEVICE_H + +#include "object.h" +#include + +class cDBusDevices : public cDBusObject +{ +private: + static cMutex _requestedPrimaryDeviceMutex; + static int _requestedPrimaryDevice; + +public: + static void SetPrimaryDeviceRequest(int index); + static int RequestedPrimaryDevice(bool clear); + + cDBusDevices(void); + virtual ~cDBusDevices(void); +}; + +#endif