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