Skip to content

Commit

Permalink
add method channel.Current to get the current channel
Browse files Browse the repository at this point in the history
  • Loading branch information
flensrocker committed Jan 24, 2016
1 parent 314f95e commit ae58483
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ Interface "channel"
- get count of channels
vdr-dbus-send.sh /Channels channel.Count

- get current channel
vdr-dbus-send.sh /Channels channel.Current

- get channels between from_index and to_index
vdr-dbus-send.sh /Channels channel.GetFromTo int32:from_index int32:to_index

Expand Down
34 changes: 34 additions & 0 deletions channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "helper.h"

#include <vdr/channels.h>
#include <vdr/device.h>


namespace cDBusChannelsHelper
Expand All @@ -15,6 +16,10 @@ namespace cDBusChannelsHelper
" <method name=\"Count\">\n"
" <arg name=\"count\" type=\"i\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"Current\">\n"
" <arg name=\"number\" type=\"i\" direction=\"out\"/>\n"
" <arg name=\"text\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"GetFromTo\">\n"
" <arg name=\"from_index\" type=\"i\" direction=\"in\"/>\n"
" <arg name=\"to_index\" type=\"i\" direction=\"in\"/>\n"
Expand Down Expand Up @@ -56,6 +61,34 @@ namespace cDBusChannelsHelper
g_dbus_method_invocation_return_value(Invocation, g_variant_new("(i)", channels->Count()));
}

static void Current(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
{
int number = cDevice::CurrentChannel();
cString text = "";
const cChannel* currentChannel = NULL;
#if VDRVERSNUM > 20300
LOCK_CHANNELS_READ;
const cChannels *channels = Channels;
currentChannel = channels->GetByNumber(number);
#else
currentChannel = Channels.GetByNumber(number);
#endif
if (currentChannel != NULL) {
text = currentChannel->ToText();
int len = strlen(*text);
if ((len > 0) && ((*text)[len - 1] == '\n'))
text.Truncate(-1);
cDBusHelper::ToUtf8(text);
}

GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("(is)"));
g_variant_builder_add(builder, "i", number);
g_variant_builder_add(builder, "s", *text);

g_dbus_method_invocation_return_value(Invocation, g_variant_builder_end(builder));
g_variant_builder_unref(builder);
}

static void GetFromTo(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
{
gint32 from_index = -1;
Expand Down Expand Up @@ -163,6 +196,7 @@ cDBusChannels::cDBusChannels(void)
:cDBusObject("/Channels", cDBusChannelsHelper::_xmlNodeInfo)
{
AddMethod("Count", cDBusChannelsHelper::Count);
AddMethod("Current", cDBusChannelsHelper::Current);
AddMethod("GetFromTo", cDBusChannelsHelper::GetFromTo);
AddMethod("List", cDBusChannelsHelper::List);
}
Expand Down
2 changes: 1 addition & 1 deletion dbus2vdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "avahi-helper.h"


static const char *VERSION = "26";
static const char *VERSION = "27";
static const char *DESCRIPTION = trNOOP("control vdr via D-Bus");
static const char *MAINMENUENTRY = NULL;

Expand Down

0 comments on commit ae58483

Please sign in to comment.