Permalink
Browse files

[pvr] added json-rpc pvr operations. needs sync on win32

  • Loading branch information...
1 parent 14e4dac commit d4e810ea42d9eb09e422eb28c40889d7fc74dcf9 Lars Op den Kamp committed Sep 11, 2012
@@ -34,6 +34,7 @@
#include "InputOperations.h"
#include "XBMCOperations.h"
#include "ApplicationOperations.h"
+#include "PVROperations.h"
using namespace std;
using namespace JSONRPC;
@@ -184,7 +185,18 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
// XBMC operations
{ "XBMC.GetInfoLabels", CXBMCOperations::GetInfoLabels },
- { "XBMC.GetInfoBooleans", CXBMCOperations::GetInfoBooleans }
+ { "XBMC.GetInfoBooleans", CXBMCOperations::GetInfoBooleans },
+
+// PVR operations
+ { "PVR.ChannelSwitch", CPVROperations::ChannelSwitch },
+ { "PVR.ChannelUp", CPVROperations::ChannelUp },
+ { "PVR.ChannelDown", CPVROperations::ChannelDown },
+ { "PVR.RecordCurrentChannel", CPVROperations::RecordCurrentChannel },
+ { "PVR.ScheduleRecording", CPVROperations::ScheduleRecording },
+ { "PVR.IsAvailable", CPVROperations::IsAvailable },
+ { "PVR.IsScanningChannels", CPVROperations::IsScanningChannels },
+ { "PVR.IsRecording", CPVROperations::IsRecording },
+ { "PVR.ScanChannels", CPVROperations::ScanChannels }
};
JSONSchemaTypeDefinition::JSONSchemaTypeDefinition()
@@ -11,6 +11,7 @@ SRCS=ApplicationOperations.cpp \
SystemOperations.cpp \
VideoLibrary.cpp \
XBMCOperations.cpp \
+ PVROperations.cpp \
LIB=json-rpc.a
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "PVROperations.h"
+#include "ApplicationMessenger.h"
+#include "utils/log.h"
+
+#include "pvr/PVRManager.h"
+#include "pvr/channels/PVRChannelGroupsContainer.h"
+#include "pvr/channels/PVRChannel.h"
+#include "pvr/timers/PVRTimers.h"
+#include "pvr/timers/PVRTimerInfoTag.h"
+#include "epg/Epg.h"
+#include "epg/EpgContainer.h"
+
+using namespace JSONRPC;
+using namespace PVR;
+using namespace EPG;
+
+JSONRPC_STATUS CPVROperations::ChannelSwitch(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ int iChannelId = (int)parameterObject["channelid"].asInteger();
+ if (iChannelId <= 0)
+ return InvalidParams;
+
+ CLog::Log(LOGDEBUG, "JSONRPC: switch to channel '%d'", iChannelId);
+
+ CFileItemPtr channel = g_PVRChannelGroups->GetByChannelIDFromAll(iChannelId);
+ if (!channel || !channel->HasPVRChannelInfoTag())
+ return InternalError;
+
+ CPVRChannelPtr currentChannel;
+ if (g_PVRManager.GetCurrentChannel(currentChannel) && currentChannel->IsRadio() == channel->GetPVRChannelInfoTag()->IsRadio())
+ CApplicationMessenger::Get().SendAction(CAction(ACTION_CHANNEL_SWITCH, (float)channel->GetPVRChannelInfoTag()->ChannelNumber()));
+ else
+ CApplicationMessenger::Get().MediaPlay(*channel);
+ return ACK;
+}
+
+JSONRPC_STATUS CPVROperations::ChannelUp(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ CLog::Log(LOGDEBUG, "JSONRPC: channel up");
+ CApplicationMessenger::Get().SendAction(CAction(ACTION_NEXT_ITEM));
+ return ACK;
+}
+
+JSONRPC_STATUS CPVROperations::ChannelDown(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ CLog::Log(LOGDEBUG, "JSONRPC: channel down");
+ CApplicationMessenger::Get().SendAction(CAction(ACTION_PREV_ITEM));
+ return ACK;
+}
+
+JSONRPC_STATUS CPVROperations::RecordCurrentChannel(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ CPVRChannelPtr currentChannel;
+ if (g_PVRManager.GetCurrentChannel(currentChannel))
+ {
+ bool bOnOff = !currentChannel->IsRecording();
+ if (g_PVRManager.StartRecordingOnPlayingChannel(bOnOff))
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: set recording on currently playing channel to '%s'", bOnOff ? "on" : "off" );
+ return ACK;
+ }
+ else
+ {
+ CLog::Log(LOGERROR, "JSONRPC: unable to set recording to '%s'", bOnOff ? "on" : "off" );
+ return InternalError;
+ }
+ }
+ else
+ {
+ CLog::Log(LOGERROR, "JSONRPC: failed to start recording - no channel is playing");
+ return FailedToExecute;
+ }
+}
+
+JSONRPC_STATUS CPVROperations::IsAvailable(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ result = g_PVRManager.IsStarted();
+
+ return OK;
+}
+
+JSONRPC_STATUS CPVROperations::IsScanningChannels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ result = g_PVRManager.IsRunningChannelScan();
+
+ return OK;
+}
+
+JSONRPC_STATUS CPVROperations::IsRecording(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ result = g_PVRManager.IsRecording();
+
+ return OK;
+}
+
+JSONRPC_STATUS CPVROperations::ScanChannels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ if (!g_PVRManager.IsRunningChannelScan())
+ g_PVRManager.StartChannelScan();
+
+ return ACK;
+}
+
+JSONRPC_STATUS CPVROperations::ScheduleRecording(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ if (!g_PVRManager.IsStarted())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: PVR not started");
+ return FailedToExecute;
+ }
+
+ int iEpgId = (int)parameterObject["epgid"].asInteger();
+ int iStartTime = (int)parameterObject["starttime"].asInteger();
+
+ if (iEpgId > 0 && iStartTime > 0)
+ {
+ CDateTime startTime(iStartTime);
+ CEpgInfoTagPtr tag = g_EpgContainer.GetById(iEpgId)->GetTag(startTime);
+
+ if (tag && tag->HasPVRChannel())
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: schedule recording - channel: '%s' start: '%s' end: '%s'",
+ tag->PVRChannelName().c_str(),
+ tag->StartAsLocalTime().GetAsLocalizedDateTime(false, false).c_str(),
+ tag->EndAsLocalTime().GetAsLocalizedDateTime(false, false).c_str());
+
+ CPVRTimerInfoTag *newTimer = CPVRTimerInfoTag::CreateFromEpg(*tag);
+ bool bCreated = (newTimer != NULL);
+ bool bAdded = false;
+
+ if (bCreated)
+ {
+ CLog::Log(LOGDEBUG, "JSONRPC: recording scheduled");
+ bAdded = CPVRTimers::AddTimer(*newTimer);
+ delete newTimer;
+ }
+ else
+ {
+ CLog::Log(LOGERROR, "JSONRPC: failed to schedule recording");
+ }
+ return bAdded ? ACK : InternalError;
+ }
+ }
+
+ return InvalidParams;
+}
@@ -0,0 +1,41 @@
+#pragma once
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "utils/StdString.h"
+#include "JSONRPC.h"
+
+namespace JSONRPC
+{
+ class CPVROperations
+ {
+ public:
+ static JSONRPC_STATUS ChannelSwitch(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS ChannelUp(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS ChannelDown(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS RecordCurrentChannel(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS ScheduleRecording(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS IsAvailable(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS IsScanningChannels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS IsRecording(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS ScanChannels(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ };
+}
@@ -1109,6 +1109,7 @@ namespace JSONRPC
"\"RemoveData\": { \"type\": \"boolean\", \"required\": true },"
"\"Navigate\": { \"type\": \"boolean\", \"required\": true },"
"\"WriteFile\": { \"type\": \"boolean\", \"required\": true },"
+ "\"ControlPVR\": { \"type\": \"boolean\", \"required\": true },"
"\"ControlSystem\": { \"type\": \"boolean\", \"required\": true },"
"\"ControlGUI\": { \"type\": \"boolean\", \"required\": true }"
"}"
@@ -2796,6 +2797,84 @@ namespace JSONRPC
"\"type\": \"object\","
"\"description\": \"List of key-value pairs of the retrieved info booleans\""
"}"
+ "}",
+ "\"PVR.ChannelSwitch\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Switch channel to given channelid\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPlayback\","
+ "\"params\": ["
+ "{ \"name\": \"channelid\", \"type\": \"integer\", \"minimum\": 0, \"required\": true }"
+ "],"
+ "\"returns\": \"string\""
+ "}",
+ "\"PVR.ChannelUp\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Switch channel up\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPlayback\","
+ "\"params\": [],"
+ "\"returns\": \"string\""
+ "}",
+ "\"PVR.ChannelDown\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Switch channel down\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPlayback\","
+ "\"params\": [],"
+ "\"returns\": \"string\""
+ "}",
+ "\"PVR.RecordCurrentChannel\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Toggles Recording of currently playing channel\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPVR\","
+ "\"params\": [],"
+ "\"returns\": \"string\""
+ "}",
+ "\"PVR.ScheduleRecording\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Schedule recording\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPVR\","
+ "\"params\": ["
+ "{ \"name\": \"epgid\", \"type\": \"integer\", \"minimum\": 0, \"required\": true },"
+ "{ \"name\": \"uniqueid\", \"type\": \"integer\", \"minimum\": 0, \"required\": true },"
+ "{ \"name\": \"starttime\", \"type\": \"integer\", \"minimum\": 0, \"required\": true }"
+ "],"
+ "\"returns\": \"string\""
+ "}",
+ "\"PVR.IsAvailable\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Checks whether PVR is available or not\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ReadData\","
+ "\"params\": [],"
+ "\"returns\": \"boolean\""
+ "}",
+ "\"PVR.IsScanningChannels\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Checks whether PVR is scanning channels\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ReadData\","
+ "\"params\": [],"
+ "\"returns\": \"boolean\""
+ "}",
+ "\"PVR.IsRecording\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Checks whether PVR is recording\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ReadData\","
+ "\"params\": [],"
+ "\"returns\": \"boolean\""
+ "}",
+ "\"PVR.ScanChannels\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Starts a channel scan\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPVR\","
+ "\"params\": [],"
+ "\"returns\": \"string\""
"}"
};
Oops, something went wrong.

0 comments on commit d4e810e

Please sign in to comment.