Skip to content

Commit a6960f0

Browse files
committed
add device interface
1 parent ae58483 commit a6960f0

File tree

7 files changed

+172
-2
lines changed

7 files changed

+172
-2
lines changed

HISTORY

+4
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,7 @@ VDR Plugin 'dbus2vdr' Revision History
236236

237237
2015-09-30: Version 26
238238
- make compatible with vdr 2.3.1
239+
240+
2016-02-13: Version 28
241+
- add device interface
242+

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ DEFINES += -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
5656

5757
### The object files (add further files here):
5858

59-
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
59+
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
6060
SWOBJS = libvdr-exitpipe.o libvdr-i18n.o libvdr-thread.o libvdr-tools.o shutdown-wrapper.o
6161

6262
### The main target:

README

+14
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ Interface "channel"
9494

9595
The returned array contains the channel number and the string from the channels.conf.
9696

97+
Interface "device"
98+
-------------------
99+
- get current primary device
100+
vdr-dbus-send.sh /Devices device.GetPrimary
101+
102+
- request switch to primary device
103+
vdr-dbus-send.sh /Devices device.RequestPrimary int32:index
104+
105+
- list devices
106+
vdr-dbus-send.sh /Devices device.List
107+
108+
The returned array contains the device index, number, a boolean value "hasDecoder",
109+
a boolean value "isPrimary" and the name of the device.
110+
97111
Interface "epg"
98112
---------------
99113
- disable EIT scanner with timeout (default: 3600)

common.h

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#define DBUS_VDR_BUSNAME "de.tvdr.vdr"
77
#define DBUS_VDR_CHANNEL_INTERFACE DBUS_VDR_BUSNAME".channel"
8+
#define DBUS_VDR_DEVICE_INTERFACE DBUS_VDR_BUSNAME".device"
89
#define DBUS_VDR_EPG_INTERFACE DBUS_VDR_BUSNAME".epg"
910
#define DBUS_VDR_OSD_INTERFACE DBUS_VDR_BUSNAME".osd"
1011
#define DBUS_VDR_PLUGIN_INTERFACE DBUS_VDR_BUSNAME".plugin"

dbus2vdr.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "common.h"
1616
#include "connection.h"
1717
#include "channel.h"
18+
#include "device.h"
1819
#include "epg.h"
1920
#include "helper.h"
2021
#include "mainloop.h"
@@ -37,7 +38,7 @@
3738
#include "avahi-helper.h"
3839

3940

40-
static const char *VERSION = "27";
41+
static const char *VERSION = "28";
4142
static const char *DESCRIPTION = trNOOP("control vdr via D-Bus");
4243
static const char *MAINMENUENTRY = NULL;
4344

@@ -117,6 +118,7 @@ static cString SetSessionEnv(const char *Name, cString &Store, const char *Optio
117118
static void AddAllObjects(cDBusConnection *Connection, bool EnableOSD)
118119
{
119120
Connection->AddObject(new cDBusChannels);
121+
Connection->AddObject(new cDBusDevices);
120122
Connection->AddObject(new cDBusEpg);
121123
if (EnableOSD)
122124
Connection->AddObject(new cDBusOsdObject);
@@ -467,6 +469,12 @@ void cPluginDbus2vdr::MainThreadHook(void)
467469
raise(SIGSTOP);
468470
}
469471
}
472+
473+
int requestPrimaryDevice = cDBusDevices::RequestedPrimaryDevice(true);
474+
if (requestPrimaryDevice >= 0) {
475+
cControl::Shutdown();
476+
cDevice::SetPrimaryDevice(requestPrimaryDevice + 1);
477+
}
470478
}
471479

472480
cString cPluginDbus2vdr::Active(void)

device.c

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include "device.h"
2+
#include "common.h"
3+
#include "helper.h"
4+
5+
#include <vdr/device.h>
6+
7+
8+
int cDBusDevices::_requestedPrimaryDevice = -1;
9+
cMutex cDBusDevices::_requestedPrimaryDeviceMutex;
10+
11+
void cDBusDevices::SetPrimaryDeviceRequest(int index)
12+
{
13+
cMutexLock MutexLock(&_requestedPrimaryDeviceMutex);
14+
_requestedPrimaryDevice = index;
15+
}
16+
17+
int cDBusDevices::RequestedPrimaryDevice(bool clear)
18+
{
19+
cMutexLock MutexLock(&_requestedPrimaryDeviceMutex);
20+
int ret = _requestedPrimaryDevice;
21+
if (clear)
22+
_requestedPrimaryDevice = -1;
23+
return ret;
24+
}
25+
26+
namespace cDBusDevicesHelper
27+
{
28+
static const char *_xmlNodeInfo =
29+
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
30+
" \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
31+
"<node>\n"
32+
" <interface name=\""DBUS_VDR_DEVICE_INTERFACE"\">\n"
33+
" <method name=\"GetPrimary\">\n"
34+
" <arg name=\"index\" type=\"i\" direction=\"out\"/>\n"
35+
" <arg name=\"number\" type=\"i\" direction=\"out\"/>\n"
36+
" <arg name=\"hasDecoder\" type=\"b\" direction=\"out\"/>\n"
37+
" <arg name=\"isPrimary\" type=\"b\" direction=\"out\"/>\n"
38+
" <arg name=\"name\" type=\"s\" direction=\"out\"/>\n"
39+
" </method>\n"
40+
" <method name=\"RequestPrimary\">\n"
41+
" <arg name=\"index\" type=\"i\" direction=\"in\"/>\n"
42+
" </method>\n"
43+
" <method name=\"List\">\n"
44+
" <arg name=\"device\" type=\"a(iibbs)\" direction=\"out\"/>\n"
45+
" </method>\n"
46+
" </interface>\n"
47+
"</node>\n";
48+
49+
static void AddDevice(GVariantBuilder *Variant, const cDevice *Device, bool AsStruct)
50+
{
51+
gint32 index = -1;
52+
gint32 number = -1;
53+
gboolean hasDecoder = FALSE;
54+
gboolean isPrimary = FALSE;
55+
cString name = "";
56+
if (Device != NULL) {
57+
index = Device->CardIndex();
58+
number = Device->DeviceNumber();
59+
hasDecoder = Device->HasDecoder();
60+
isPrimary = Device->IsPrimaryDevice();
61+
name = Device->DeviceName();
62+
cDBusHelper::ToUtf8(name);
63+
}
64+
65+
if (AsStruct)
66+
g_variant_builder_add(Variant, "(iibbs)", index, number, hasDecoder, isPrimary, *name);
67+
else {
68+
g_variant_builder_add(Variant, "i", index);
69+
g_variant_builder_add(Variant, "i", number);
70+
g_variant_builder_add(Variant, "b", hasDecoder);
71+
g_variant_builder_add(Variant, "b", isPrimary);
72+
g_variant_builder_add(Variant, "s", *name);
73+
}
74+
}
75+
76+
static void GetPrimary(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
77+
{
78+
GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("(iibbs)"));
79+
const cDevice *dev = cDevice::PrimaryDevice();
80+
AddDevice(builder, dev, false);
81+
g_dbus_method_invocation_return_value(Invocation, g_variant_builder_end(builder));
82+
g_variant_builder_unref(builder);
83+
}
84+
85+
static void RequestPrimary(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
86+
{
87+
gint32 index = -1;
88+
g_variant_get(Parameters, "(i)", &index);
89+
cDBusDevices::SetPrimaryDeviceRequest(index);
90+
g_dbus_method_invocation_return_value(Invocation, NULL);
91+
}
92+
93+
static void List(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
94+
{
95+
GVariantBuilder *array = g_variant_builder_new(G_VARIANT_TYPE("a(iibbs)"));
96+
97+
for (int i = 0; i < cDevice::NumDevices(); i++) {
98+
const cDevice *dev = cDevice::GetDevice(i);
99+
if (dev != NULL)
100+
AddDevice(array, dev, true);
101+
}
102+
103+
GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("(a(iibbs))"));
104+
g_variant_builder_add_value(builder, g_variant_builder_end(array));
105+
g_dbus_method_invocation_return_value(Invocation, g_variant_builder_end(builder));
106+
g_variant_builder_unref(array);
107+
g_variant_builder_unref(builder);
108+
}
109+
}
110+
111+
112+
cDBusDevices::cDBusDevices(void)
113+
:cDBusObject("/Devices", cDBusDevicesHelper::_xmlNodeInfo)
114+
{
115+
AddMethod("GetPrimary", cDBusDevicesHelper::GetPrimary);
116+
AddMethod("RequestPrimary", cDBusDevicesHelper::RequestPrimary);
117+
AddMethod("List", cDBusDevicesHelper::List);
118+
}
119+
120+
cDBusDevices::~cDBusDevices(void)
121+
{
122+
}

device.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __DBUS2VDR_DEVICE_H
2+
#define __DBUS2VDR_DEVICE_H
3+
4+
#include "object.h"
5+
#include <vdr/thread.h>
6+
7+
class cDBusDevices : public cDBusObject
8+
{
9+
private:
10+
static cMutex _requestedPrimaryDeviceMutex;
11+
static int _requestedPrimaryDevice;
12+
13+
public:
14+
static void SetPrimaryDeviceRequest(int index);
15+
static int RequestedPrimaryDevice(bool clear);
16+
17+
cDBusDevices(void);
18+
virtual ~cDBusDevices(void);
19+
};
20+
21+
#endif

0 commit comments

Comments
 (0)