L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cmd_control
1// -*- Mode: C++ -*-
2// vim:ft=cpp
3/*
4 * Copyright (C) 2016, 2024 Kernkonzept GmbH.
5 * Author(s): Sarah Hoffmann <sarah.hoffmann@kernkonzept.com>
6 *
7 * License: see LICENSE.spdx (in this directory or the directories above)
8 */
9#pragma once
10
11#include <l4/sys/cxx/ipc_epiface>
12#include <l4/sys/cxx/ipc_string>
13
14namespace L4Re { namespace Ned {
15
16/**
17 * Direct control interface for Ned.
18 */
19class Cmd_control : public L4::Kobject_0t<Cmd_control>
20{
21 L4_INLINE_RPC_NF(long, execute, (L4::Ipc::String<> cmd,
22 L4::Ipc::Array<char> &result));
23
24public:
25 /**
26 * Execute the given Lua code.
27 *
28 * \param[in] cmd String with Lua code to execute.
29 *
30 * \retval L4_EOK Code was successfully executed.
31 * \retval -L4_EINVAL Code could not be parsed.
32 * \retval -L4_EIO Error during code execution.
33 *
34 * The code is executed using the global Lua state of ned
35 * which is retained between successive calls to execute.
36 * Thus you may define data in one call to execute and use
37 * it in a subsequent call.
38 *
39 * This function does not return any results from the execution
40 * of the Lua code itself.
41 */
42 long execute(L4::Ipc::String<> cmd) noexcept
43 {
44 L4::Ipc::Array<char> res(0, NULL);
45 return execute_t::call(c(), cmd, res);
46 }
47
48 /**
49 * Execute the given Lua code.
50 *
51 * \param[in] cmd String with Lua code to execute.
52 * \param[out] result The first return value of the Lua code block
53 * as string.
54 *
55 * \retval L4_EOK Code was successfully executed.
56 * \retval -L4_EINVAL Code could not be parsed.
57 * \retval -L4_EIO Error during code execution.
58 *
59 * The code is executed using the global Lua state of ned
60 * which is retained between successive calls to execute.
61 * Thus you may define data in one call to execute and use
62 * it in a subsequent call.
63 */
64 long execute(L4::Ipc::String<> cmd,
65 L4::Ipc::String<char> *result) noexcept
66 {
67 L4::Ipc::Array<char> res(result->length, result->data);
68 long r = execute_t::call(c(), cmd, res);
69 if (r >= 0)
70 result->length = res.length;
71 return r;
72 }
73
74 typedef L4::Typeid::Rpcs<execute_t> Rpcs;
75};
76
77} } // namespace