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));
72PluginRestApi::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") {
PluginOpRequest representation for JSON transfer.
std::optional< std::string > desired_state() const
Get desired_state value.
PluginOpResponse representation for JSON transfer.
static std::string api_version()
Get version of implemented API.
void set_message(const std::string &message)
Set message value.
void set_kind(const std::string &kind)
Set kind value.
void set_name(const std::string &name)
Set name value.
void set_state(const std::string &state)
Set state value.
void set_apiVersion(const std::string &apiVersion)
Set apiVersion value.
PluginRestApi()
Constructor.
virtual void loop()
Code to execute in the thread.
virtual void finalize()
Finalize the thread.
~PluginRestApi()
Destructor.
virtual void init()
Initialize the thread.
static std::string api_version()
Get version of implemented API.
Container to return array via REST.
void push_back(M &m)
Add item at the back of the container.
Base class for exceptions in Fawkes.
virtual const char * what_no_backtrace() const noexcept
Get primary string (does not implicitly print the back trace).
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
Logger * logger
This is the Logger member used to access the logger.
PluginManager * plugin_manager
This is the member used to access the PluginManager.
bool is_loaded(const std::string &plugin_name)
Check if plugin is loaded.
void unload(const std::string &plugin_name)
Unload plugin.
std::list< std::pair< std::string, std::string > > get_available_plugins()
Generate list of all available plugins.
void load(const std::string &plugin_list)
Load plugin.
std::list< std::string > get_meta_plugin_children(const std::string &plugin_name)
Get meta plugin children.
bool is_meta_plugin(const std::string &plugin_name)
Check if plugin is a meta plugin.
void set_name(const char *name)
Set plugin name.
Thread class encapsulation of pthreads.
const char * name() const
Get name of thread.
WebviewRestApiManager * webview_rest_api_manager
Webview REST API manager.
void unregister_api(WebviewRestApi *api)
Remove a request processor.
void register_api(WebviewRestApi *api)
Add a REST API.
Webview REST API component.
void add_handler(WebRequest::Method method, std::string path, Handler handler)
Add handler function.
REST processing exception.
REST parameters to pass to handlers.
bool has_query_arg(const std::string &what)
Check if query argument is set.
std::string path_arg(const std::string &what)
Get a path argument.
Fawkes library namespace.