22 #include "plugin-rest-api.h" 24 #include "model/Plugin.h" 26 #include <webview/rest_api_manager.h> 50 WebRequest::METHOD_GET,
"/?", std::bind(&PluginRestApi::cb_list_plugins,
this));
52 WebRequest::METHOD_PUT,
55 &PluginRestApi::cb_set_plugin_state,
this, std::placeholders::_1, std::placeholders::_2));
72 PluginRestApi::cb_list_plugins()
77 for (
const auto &i : available_plugins) {
78 const std::string &
name = i.first;
79 const std::string &description = i.second;
86 p.set_description(description);
87 p.set_is_meta(is_meta);
90 std::vector<std::string> v{std::make_move_iterator(std::begin(plugin_list)),
91 std::make_move_iterator(std::end(plugin_list))};
92 p.set_meta_children(std::move(v));
94 p.set_is_loaded(is_loaded);
104 std::string plugin = params.
path_arg(
"name");
107 response.
set_kind(
"PluginOpResponse");
114 response.
set_message(
"Request is missing required field 'desired_state'");
120 if (*des_state ==
"LOADED") {
133 }
else if (*des_state ==
"AVAILABLE" || *des_state ==
"UNLOADED") {
void set_message(const std::string &message)
Set message value.
PluginManager * plugin_manager
This is the member used to access the PluginManager.
virtual void finalize()
Finalize the thread.
Webview REST API component.
virtual void init()
Initialize the thread.
static std::string api_version()
Get version of implemented API.
void set_state(const std::string &state)
Set state value.
PluginOpResponse representation for JSON transfer.
REST processing exception.
std::list< std::pair< std::string, std::string > > get_available_plugins()
Generate list of all available plugins.
Fawkes library namespace.
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
std::list< std::string > get_meta_plugin_children(const std::string &plugin_name)
Get meta plugin children.
void set_name(const std::string &name)
Set name value.
Thread class encapsulation of pthreads.
std::optional< std::string > desired_state() const
Get desired_state value.
void unregister_api(WebviewRestApi *api)
Remove a request processor.
Logger * logger
This is the Logger member used to access the logger.
void register_api(WebviewRestApi *api)
Add a REST API.
static std::string api_version()
Get version of implemented API.
void set_name(const char *name)
Set plugin name.
~PluginRestApi()
Destructor.
void add_handler(WebRequest::Method method, std::string path, Handler handler)
Add handler function.
virtual void loop()
Code to execute in the thread.
Base class for exceptions in Fawkes.
REST parameters to pass to handlers.
PluginRestApi()
Constructor.
void push_back(M &m)
Add item at the back of the container.
void unload(const std::string &plugin_name)
Unload plugin.
bool has_query_arg(const std::string &what)
Check if query argument is set.
const char * name() const
Get name of thread.
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
PluginOpRequest representation for JSON transfer.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
void set_kind(const std::string &kind)
Set kind value.
void load(const std::string &plugin_list)
Load plugin.
Container to return array via REST.
bool is_loaded(const std::string &plugin_name)
Check if plugin is loaded.
WebviewRestApiManager * webview_rest_api_manager
Webview REST API manager.
bool is_meta_plugin(const std::string &plugin_name)
Check if plugin is a meta plugin.
std::string path_arg(const std::string &what)
Get a path argument.