Legrand / Raritan / Server Technology Xerus™ JSON-RPC API
Loading...
Searching...
No Matches
LuaService.idl
1/* SPDX-License-Identifier: BSD-3-Clause */
2/*
3 * Copyright 2015 Raritan Inc. All rights reserved.
4 */
5
6/**
7 * Lua-Service
8 *
9 * Lua-Service is a service that you can use to upload and execute a Lua script.
10 *
11 * When the service is starting, a cleanup is done first. That means
12 * still running scripts will be killed and it will be tested for which script
13 * an option is given. If something does not match, the script or option
14 * will be deleted.
15 *
16 * After the service is launched, ScriptOptions::autoStart will be evaluated for
17 * each script. If the flag is \c true, the script is going to be executed with a
18 * delay of Environment::autoStartDelay milliseconds.
19 *
20 * You can download and upload a script with Manager::getScript() and Manager::setScript().
21 * On upload, if the script name is already taken, the old script will be overwritten.
22 * Otherwise, a new script will be created.
23 *
24 * Use Manager::startScript() to execute a Lua script and Manager::terminateScript() to stop a script.
25 * If ScriptOptions::autoRestart is set to \c true, the script restarts automatically
26 * after it has exited.
27 *
28 * To get the output for a script use Manager::getScriptOutput(). The output
29 * is limited to Environment::outputBufferSize bytes and mapped to a virtual
30 * address. On the first query, call the method with starting address zero. After
31 * that use the returned address \c nAddr for the next request.
32 *
33 * A script can be called with arguments, see ScriptOptions and Manager::startScriptWithArgs().
34 */
35module luaservice {
36
37 /**
38 * A structure that describes the state of a script.
39 *
40 * When a script is uploaded the new #execState is #STAT_NEW, #exitType and
41 * #exitStatus are not valid.
42 *
43 * When the #execState is changed to #STAT_TERMINATED, #exitType and #exitStatus
44 * will be set.
45 */
46 structure ScriptState {
47
48 /** Execution state of a script */
49 enumeration ExecState {
50 STAT_NEW, ///< the script never ran (after uploading or system (re)start)
51 STAT_RUNNING, ///< script is running
52 STAT_TERMINATED, ///< script is terminated
53 STAT_RESTARTING ///< script is terminated and restarts after the Environment::restartInterval
54 };
55
56 /** Describes the type of #exitStatus */
57 enumeration ExitType {
58 EXIT_CODE, ///< #exitStatus is an exit code
59 SIGNAL ///< #exitStatus is a signal
60 };
61
62 ExecState execState; ///< execution state of the script
63 ExitType exitType; ///< type of exit status
64 int exitStatus; ///< exit code or signal
65 };
66
67 /** Script options */
68 structure ScriptOptions {
69 map <string, string> defaultArgs; ///< default arguments passed to the Lua script
70 boolean autoStart; ///< starts a script after system booting
71 boolean autoRestart; ///< restarts a script after termination or crash
72 };
73
74 /**
75 * Environment represents two kinds of information:
76 * - limit (l)
77 * - current status (cs)
78 *
79 * A limit of zero means no limit. The unit of size
80 * is byte. The unit of time is millisecond.
81 */
82 structure Environment {
83 int maxScriptMemoryGrowth;///< maximum virtual memory growth per script (l)
84 int maxAmountOfScripts; ///< number of scripts that can be stored (l)
85 int amountOfScripts; ///< number of scripts that are stored (cs)
86 int maxScriptSize; ///< maximum size of a script file (l)
87 int maxAllScriptSize; ///< maximum size of all script files (l)
88 int allScriptSize; ///< size of all script files (cs)
89 int outputBufferSize; ///< output buffer size per script (l)
90 int restartInterval; ///< minimum delay to next (re)start (cs)
91 int autoStartDelay; ///< minimum delay to auto-start a script
92 };
93
94 /**
95 * There is a single manager instance.
96 */
97 interface Manager {
98
99 /** Error codes */
100 constant int NO_ERROR = 0; ///< no error
101 constant int ERR_INVALID_NAME = 1; ///< script name is invalid
102 constant int ERR_NO_SUCH_SCRIPT = 2; ///< script name not found
103 constant int ERR_MAX_SCRIPT_NUMBERS_EXCEEDED = 3; ///< maximum amount of stored script files is reached
104 constant int ERR_MAX_SCRIPT_SIZE_EXCEEDED = 4; ///< maximum size of a script file is reached
105 constant int ERR_MAX_ALL_SCRIPT_SIZE_EXCEEDED = 5; ///< maximum size of all script files is reached
106 constant int ERR_NOT_TERMINATED = 6; ///< script is not terminated
107 constant int ERR_NOT_RUNNING = 7; ///< script is not running
108 constant int ERR_INVALID_ADDR = 8; ///< address parameter is wrong
109 constant int ERR_TOO_MANY_ARGUMENTS = 10; ///< too many arguments
110 constant int ERR_ARGUMENT_NOT_VALID = 11; ///< the argument has one or more invalid characters
111
112 /**
113 * Upload a script to instance
114 *
115 * If there is a script with the same name the new script will replace
116 * the existing script (script must be in \c STAT_NEW or \c STAT_TERMINATED).
117 *
118 * @param name The name of the script file
119 * @param script The script file packed in a string
120 * @param options The options for the script
121 *
122 * @return #NO_ERROR if OK
123 * @return #ERR_INVALID_NAME if script name is invalid
124 * @return #ERR_MAX_SCRIPT_SIZE_EXCEEDED if the size of the new script is greater than the maximum file size
125 * @return #ERR_MAX_ALL_SCRIPT_SIZE_EXCEEDED if maximum size of all script files is reached
126 * @return #ERR_MAX_SCRIPT_NUMBERS_EXCEEDED if maximum amount of script files is reached
127 * @return #ERR_NOT_TERMINATED if trying to replace a running script
128 */
129 int setScript(in string name, in string script, in ScriptOptions options);
130
131 /**
132 * To download a script file.
133 *
134 * @param name The name of an existing script
135 *
136 * @return #NO_ERROR if OK
137 * @return #ERR_INVALID_NAME if script name is invalid
138 * @return #ERR_NO_SUCH_SCRIPT if there is no script with the name
139 */
140 int getScript(in string name, out string script);
141
142 /**
143 * Returns all script names in a string vector.
144 *
145 * If there are no scripts the vector is empty.
146 *
147 * @return A vector with all script names.
148 */
149 vector<string> getScriptNames();
150
151 /**
152 * Deletes a script.
153 *
154 * @param name The name of the script
155 *
156 * @return #NO_ERROR if OK
157 * @return #ERR_INVALID_NAME if script name is invalid
158 * @return #ERR_NO_SUCH_SCRIPT if there is no script with the name
159 * @return #ERR_NOT_TERMINATED if trying to delete a running script
160 */
161 int deleteScript(in string name);
162
163 /**
164 * Sets new options for a script.
165 *
166 * @param name The name of the script
167 * @param options The new options
168 *
169 * @return #NO_ERROR if OK
170 * @return #ERR_INVALID_NAME if script name is invalid
171 * @return #ERR_NO_SUCH_SCRIPT if there is no script with the name
172 * @return #ERR_TOO_MANY_ARGUMENTS if the size of the map is to big
173 * @return #ERR_ARGUMENT_NOT_VALID if a string in the arguments is not valid
174 */
175 int setScriptOptions(in string name, in ScriptOptions options);
176
177 /**
178 * Returns the options for a script.
179 *
180 * @param name The name of the script
181 * @param options The options of the script
182 *
183 * @return #NO_ERROR if OK
184 * @return #ERR_INVALID_NAME if script name is invalid
185 * @return #ERR_NO_SUCH_SCRIPT if there is no script with the name
186 */
187 int getScriptOptions(in string name, out ScriptOptions options);
188
189 /**
190 * To query the environment information.
191 *
192 * @return the environment information
193 */
195
196 /**
197 * To get output from a script as a string
198 *
199 * The output is stored in a string buffer with a defined size. The buffer is addressable with an
200 * (virtual) address. The address will be increased every time the buffer gets filled.
201 *
202 * To get the output for the first time just call with address zero.
203 * Use the returned \c nAddr in following calls.
204 *
205 * If \c iAddr is negative the last n bytes will be returned, e.g. -9 returns the last 9 characters.
206 * If \c iAddr is zero the whole available buffer will be returned.
207 * If \c iAddr is positive the returned buffer starts at this address.
208 * If \c iAddr is equal to \c nAddr there is no data available.
209 * If \c iAddr and \c oAddr are not equal there was data lost (exception: first call with zero).
210 *
211 * @param name The name of the script
212 * @param iAddr The virtual start address where the returned output should begin
213 * @param oAddr The virtual address from where the string starts
214 * @param nAddr The virtual address for the next query
215 * @param more A boolean which indicates if there is more data available
216 *
217 * @return #NO_ERROR if OK
218 * @return #ERR_INVALID_NAME if file name is invalid
219 * @return #ERR_NO_SUCH_SCRIPT if there is no script with the name
220 * @return #ERR_INVALID_ADDR if \c iAddr is negative and its absolute value is greater than the limit
221 */
222 int getScriptOutput(in string name, in long iAddr, out long oAddr, out long nAddr, out string oString, out boolean more);
223
224 /**
225 * Clear the output buffer of a script.
226 *
227 * @param name The name of the script
228 *
229 * @return #NO_ERROR if OK
230 * @return #ERR_INVALID_NAME if file name is invalid
231 * @return #ERR_NO_SUCH_SCRIPT if there is no script with the name
232 */
233 int clearScriptOutput(in string name);
234
235 /**
236 * Start a script
237 *
238 * @return #NO_ERROR if OK
239 * @return #ERR_INVALID_NAME if file name is invalid
240 * @return #ERR_NO_SUCH_SCRIPT if there is no script with the name
241 * @return #ERR_NOT_TERMINATED if the script is running or restarting
242 */
243 int startScript(in string name);
244
245 /**
246 * Start a script with arguments
247 *
248 * The method starts a Lua script. You can add arguments depending on the Lua script.
249 * The arguments will override the default arguments. All arguments are stored in a global table
250 * called \c ARGS in Lua.
251 *
252 * @return #NO_ERROR if OK
253 * @return #ERR_INVALID_NAME if file name is invalid
254 * @return #ERR_NO_SUCH_SCRIPT if there is no script with the name
255 * @return #ERR_NOT_TERMINATED if the script is running or restarting
256 * @return #ERR_TOO_MANY_ARGUMENTS if the size of the map is to big
257 * @return #ERR_ARGUMENT_NOT_VALID if a string in the arguments is not valid
258 */
259 int startScriptWithArgs(in string name, in map<string, string> arguments);
260
261 /**
262 * Stop a script
263 *
264 * This method stops a running or restarting script. After terminating, ScriptOptions::autoRestart will
265 * \e not be evaluated.
266 *
267 * @return #NO_ERROR if OK
268 * @return #ERR_INVALID_NAME if file name is invalid
269 * @return #ERR_NO_SUCH_SCRIPT if there is no script with the name
270 * @return #ERR_NOT_RUNNING if the script is not running or restarting
271 */
272 int terminateScript(in string name);
273
274 /**
275 * Returns the state for a single script.
276 *
277 * @param name The script name
278 * @param state The state of the script
279 *
280 * @return #NO_ERROR if OK
281 * @return #ERR_INVALID_NAME if file name is invalid
282 * @return #ERR_NO_SUCH_SCRIPT if there is no script with the name
283 */
284 int getScriptState(in string name, out ScriptState state);
285
286
287 /**
288 * Returns the state for all scripts. If the map is empty then there are no scripts on the machine.
289 *
290 * @return A map with names as keys and states as values for all available scripts.
291 */
292 map<string, ScriptState> getScriptStates();
293 };
294
295}
There is a single manager instance.
constant int ERR_NO_SUCH_SCRIPT
script name not found
constant int ERR_NOT_TERMINATED
script is not terminated
constant int ERR_MAX_SCRIPT_NUMBERS_EXCEEDED
maximum amount of stored script files is reached
map< string, ScriptState > getScriptStates()
Returns the state for all scripts.
constant int NO_ERROR
Error codes.
int setScriptOptions(in string name, in ScriptOptions options)
Sets new options for a script.
vector< string > getScriptNames()
Returns all script names in a string vector.
constant int ERR_NOT_RUNNING
script is not running
constant int ERR_INVALID_ADDR
address parameter is wrong
constant int ERR_INVALID_NAME
script name is invalid
int getScript(in string name, out string script)
To download a script file.
constant int ERR_MAX_SCRIPT_SIZE_EXCEEDED
maximum size of a script file is reached
int setScript(in string name, in string script, in ScriptOptions options)
Upload a script to instance.
int getScriptOutput(in string name, in long iAddr, out long oAddr, out long nAddr, out string oString, out boolean more)
To get output from a script as a string.
int terminateScript(in string name)
Stop a script.
constant int ERR_TOO_MANY_ARGUMENTS
too many arguments
int getScriptState(in string name, out ScriptState state)
Returns the state for a single script.
int startScript(in string name)
Start a script.
int deleteScript(in string name)
Deletes a script.
int getScriptOptions(in string name, out ScriptOptions options)
Returns the options for a script.
int startScriptWithArgs(in string name, in map< string, string > arguments)
Start a script with arguments.
Environment getEnvironment()
To query the environment information.
constant int ERR_MAX_ALL_SCRIPT_SIZE_EXCEEDED
maximum size of all script files is reached
constant int ERR_ARGUMENT_NOT_VALID
the argument has one or more invalid characters
int clearScriptOutput(in string name)
Clear the output buffer of a script.
Lua-Service.
Environment represents two kinds of information:
int maxAmountOfScripts
number of scripts that can be stored (l)
int restartInterval
minimum delay to next (re)start (cs)
int allScriptSize
size of all script files (cs)
int amountOfScripts
number of scripts that are stored (cs)
int maxAllScriptSize
maximum size of all script files (l)
int autoStartDelay
minimum delay to auto-start a script
int outputBufferSize
output buffer size per script (l)
int maxScriptSize
maximum size of a script file (l)
int maxScriptMemoryGrowth
maximum virtual memory growth per script (l)
boolean autoRestart
restarts a script after termination or crash
boolean autoStart
starts a script after system booting
map< string, string > defaultArgs
default arguments passed to the Lua script
A structure that describes the state of a script.
ExitType
Describes the type of exitStatus.
@ SIGNAL
exitStatus is a signal
@ EXIT_CODE
exitStatus is an exit code
ExecState execState
execution state of the script
ExitType exitType
type of exit status
int exitStatus
exit code or signal
ExecState
Execution state of a script.
@ STAT_RESTARTING
script is terminated and restarts after the Environment::restartInterval
@ STAT_TERMINATED
script is terminated
@ STAT_NEW
the script never ran (after uploading or system (re)start)
@ STAT_RUNNING
script is running