2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "SystemOperations.h"
22 #include "ApplicationMessenger.h"
23 #include "interfaces/Builtins.h"
24 #include "utils/Variant.h"
25 #include "powermanagement/PowerManager.h"
27 using namespace JSONRPC;
29 JSONRPC_STATUS CSystemOperations::GetProperties(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
31 CVariant properties = CVariant(CVariant::VariantTypeObject);
32 for (unsigned int index = 0; index < parameterObject["properties"].size(); index++)
34 CStdString propertyName = parameterObject["properties"][index].asString();
37 if ((ret = GetPropertyValue(client->GetPermissionFlags(), propertyName, property)) != OK)
40 properties[propertyName] = property;
48 JSONRPC_STATUS CSystemOperations::EjectOpticalDrive(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
50 return CBuiltins::Execute("EjectTray") == 0 ? ACK : FailedToExecute;
53 JSONRPC_STATUS CSystemOperations::Shutdown(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
55 if (g_powerManager.CanPowerdown())
57 CApplicationMessenger::Get().Powerdown();
61 return FailedToExecute;
64 JSONRPC_STATUS CSystemOperations::Suspend(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
66 if (g_powerManager.CanSuspend())
68 CApplicationMessenger::Get().Suspend();
72 return FailedToExecute;
75 JSONRPC_STATUS CSystemOperations::Hibernate(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
77 if (g_powerManager.CanHibernate())
79 CApplicationMessenger::Get().Hibernate();
83 return FailedToExecute;
86 JSONRPC_STATUS CSystemOperations::Reboot(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
88 if (g_powerManager.CanReboot())
90 CApplicationMessenger::Get().Restart();
94 return FailedToExecute;
97 JSONRPC_STATUS CSystemOperations::GetPropertyValue(int permissions, const CStdString &property, CVariant &result)
99 if (property.Equals("canshutdown"))
100 result = g_powerManager.CanPowerdown() && (permissions & ControlPower);
101 else if (property.Equals("cansuspend"))
102 result = g_powerManager.CanSuspend() && (permissions & ControlPower);
103 else if (property.Equals("canhibernate"))
104 result = g_powerManager.CanHibernate() && (permissions & ControlPower);
105 else if (property.Equals("canreboot"))
106 result = g_powerManager.CanReboot() && (permissions & ControlPower);
108 return InvalidParams;