Skip to content

Commit

Permalink
add device interface
Browse files Browse the repository at this point in the history
  • Loading branch information
flensrocker committed Feb 13, 2016
1 parent ae58483 commit a6960f0
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion dbus2vdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
122 changes: 122 additions & 0 deletions device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#include "device.h"
#include "common.h"
#include "helper.h"

#include <vdr/device.h>


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 =
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
" \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
"<node>\n"
" <interface name=\""DBUS_VDR_DEVICE_INTERFACE"\">\n"
" <method name=\"GetPrimary\">\n"
" <arg name=\"index\" type=\"i\" direction=\"out\"/>\n"
" <arg name=\"number\" type=\"i\" direction=\"out\"/>\n"
" <arg name=\"hasDecoder\" type=\"b\" direction=\"out\"/>\n"
" <arg name=\"isPrimary\" type=\"b\" direction=\"out\"/>\n"
" <arg name=\"name\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"RequestPrimary\">\n"
" <arg name=\"index\" type=\"i\" direction=\"in\"/>\n"
" </method>\n"
" <method name=\"List\">\n"
" <arg name=\"device\" type=\"a(iibbs)\" direction=\"out\"/>\n"
" </method>\n"
" </interface>\n"
"</node>\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)
{
}
21 changes: 21 additions & 0 deletions device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef __DBUS2VDR_DEVICE_H
#define __DBUS2VDR_DEVICE_H

#include "object.h"
#include <vdr/thread.h>

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

0 comments on commit a6960f0

Please sign in to comment.