1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "SystemBuiltins.h"
#include "ServiceBroker.h"
#include "messaging/ApplicationMessenger.h"
#include "utils/StringUtils.h"
/*! \brief Execute a system executable.
* \param params The parameters.
* \details params[0] = The path to the executable.
*
* Set the template parameter Wait to true to wait for execution exit.
*/
template<int Wait=0>
static int Exec(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_MINIMIZE);
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_EXECUTE_OS, Wait, -1, nullptr, params[0]);
return 0;
}
/*! \brief Hibernate system.
* \param params (ignored)
*/
static int Hibernate(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_HIBERNATE);
return 0;
}
/*! \brief Inhibit idle shutdown timer.
* \param params The parameters.
* \details params[0] = "true" to inhibit shutdown timer (optional).
*/
static int InhibitIdle(const std::vector<std::string>& params)
{
bool inhibit = (params.size() == 1 && StringUtils::EqualsNoCase(params[0], "true"));
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_INHIBITIDLESHUTDOWN, inhibit);
return 0;
}
/*! \brief Minimize application.
* \param params (ignored)
*/
static int Minimize(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_MINIMIZE);
return 0;
}
/*! \brief Powerdown system.
* \param params (ignored)
*/
static int Powerdown(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_POWERDOWN);
return 0;
}
/*! \brief Quit application.
* \param params (ignored)
*/
static int Quit(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_QUIT);
return 0;
}
/*! \brief Reboot system.
* \param params (ignored)
*/
static int Reboot(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_RESTART);
return 0;
}
/*! \brief Restart application.
* \param params (ignored)
*/
static int RestartApp(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_RESTARTAPP);
return 0;
}
/*! \brief Activate screensaver.
* \param params (ignored)
*/
static int ActivateScreensaver(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_ACTIVATESCREENSAVER);
return 0;
}
/*! \brief Reset screensaver.
* \param params (ignored)
*/
static int ResetScreensaver(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_RESETSCREENSAVER);
return 0;
}
/*! \brief Inhibit screensaver.
* \param params The parameters.
* \details params[0] = "true" to inhibit screensaver (optional).
*/
static int InhibitScreenSaver(const std::vector<std::string>& params)
{
bool inhibit = (params.size() == 1 && StringUtils::EqualsNoCase(params[0], "true"));
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_INHIBITSCREENSAVER, inhibit);
return 0;
}
/*! \brief Shutdown system.
* \param params (ignored)
*/
static int Shutdown(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_SHUTDOWN);
return 0;
}
/*! \brief Suspend system.
* \param params (ignored)
*/
static int Suspend(const std::vector<std::string>& params)
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_SUSPEND);
return 0;
}
// Note: For new Texts with comma add a "\" before!!! Is used for table text.
//
/// \page page_List_of_built_in_functions
/// \section built_in_functions_15 System built-in's
///
/// -----------------------------------------------------------------------------
///
/// \table_start
/// \table_h2_l{
/// Function,
/// Description }
/// \table_row2_l{
/// <b>`ActivateScreensaver`</b>
/// ,
/// Starts the screensaver
/// }
/// \table_row2_l{
/// <b>`InhibitScreensaver(yesNo)`</b>
/// ,
/// Inhibit the screensaver
/// @param[in] yesNo value with "true" or "false" to inhibit or allow screensaver (leaving empty defaults to false)
/// }
/// \table_row2_l{
/// <b>`Hibernate`</b>
/// ,
/// Hibernate (S4) the System
/// }
/// \table_row2_l{
/// <b>`InhibitIdleShutdown(true/false)`</b>
/// ,
/// Prevent the system to shutdown on idle.
/// @param[in] value "true" to inhibit shutdown timer (optional).
/// }
/// \table_row2_l{
/// <b>`Minimize`</b>
/// ,
/// Minimizes Kodi
/// }
/// \table_row2_l{
/// <b>`Powerdown`</b>
/// ,
/// Powerdown system
/// }
/// \table_row2_l{
/// <b>`Quit`</b>
/// ,
/// Quits Kodi
/// }
/// \table_row2_l{
/// <b>`Reboot`</b>
/// ,
/// Cold reboots the system (power cycle)
/// }
/// \table_row2_l{
/// <b>`Reset`</b>
/// ,
/// Reset the system (same as reboot)
/// }
/// \table_row2_l{
/// <b>`Restart`</b>
/// ,
/// Restart the system (same as reboot)
/// }
/// \table_row2_l{
/// <b>`RestartApp`</b>
/// ,
/// Restarts Kodi (only implemented under Windows and Linux)
/// }
/// \table_row2_l{
/// <b>`ShutDown`</b>
/// ,
/// Trigger default Shutdown action defined in System Settings
/// }
/// \table_row2_l{
/// <b>`Suspend`</b>
/// ,
/// Suspends (S3 / S1 depending on bios setting) the System
/// }
/// \table_row2_l{
/// <b>`System.Exec(exec)`</b>
/// ,
/// Execute shell commands
/// @param[in] exec The path to the executable
/// }
/// \table_row2_l{
/// <b>`System.ExecWait(exec)`</b>
/// ,
/// Execute shell commands and freezes Kodi until shell is closed
/// @param[in] exec The path to the executable
/// }
/// \table_end
///
CBuiltins::CommandMap CSystemBuiltins::GetOperations() const
{
return {{"activatescreensaver", {"Activate Screensaver", 0, ActivateScreensaver}},
{"resetscreensaver", {"Reset Screensaver", 0, ResetScreensaver}},
{"hibernate", {"Hibernates the system", 0, Hibernate}},
{"inhibitidleshutdown", {"Inhibit idle shutdown", 0, InhibitIdle}},
{"inhibitscreensaver", {"Inhibit Screensaver", 0, InhibitScreenSaver}},
{"minimize", {"Minimize Kodi", 0, Minimize}},
{"powerdown", {"Powerdown system", 0, Powerdown}},
{"quit", {"Quit Kodi", 0, Quit}},
{"reboot", {"Reboot the system", 0, Reboot}},
{"reset", {"Reset the system (same as reboot)", 0, Reboot}},
{"restart", {"Restart the system (same as reboot)", 0, Reboot}},
{"restartapp", {"Restart Kodi", 0, RestartApp}},
{"shutdown", {"Shutdown the system", 0, Shutdown}},
{"suspend", {"Suspends the system", 0, Suspend}},
{"system.exec", {"Execute shell commands", 1, Exec<0>}},
{"system.execwait",
{"Execute shell commands and freezes Kodi until shell is closed", 1, Exec<1>}}};
}
|