23#include <netcomm/fawkes/client.h>
24#include <plugin/net/list_message.h>
25#include <plugin/net/messages.h>
26#include <tools/plugin/plugin_tool.h>
27#include <utils/system/argparser.h>
54 plugin_name = argp->
arg(
"l");
55 }
else if (argp->
has_arg(
"u")) {
57 plugin_name = argp->
arg(
"u");
58 }
else if (argp->
has_arg(
"R")) {
60 plugin_name = argp->
arg(
"R");
61 }
else if (argp->
has_arg(
"w")) {
63 }
else if (argp->
has_arg(
"a")) {
64 opmode = M_LIST_AVAIL;
66 opmode = M_LIST_LOADED;
100 printf(
"Usage: %s [-l plugin|-u plugin|-R plugin|-w|-a|-L] [-r host[:port]]\n"
101 " -l plugin Load plugin with given name\n"
102 " -u plugin Unload plugin with given name\n"
103 " -R plugin Reload plugin with given name\n"
104 " -w Watch all load/unload operations\n"
105 " -a List available plugins\n"
106 " -L List loaded plugins (default)\n\n"
107 " -r host[:port] Remote host (and optionally port) to connect to\n\n"
108 " If called without any option list currently loaded plugins\n\n",
120 this->plugin_name = plugin_name;
132 this->plugin_name = plugin_name;
151 opmode = M_LIST_LOADED;
160 c->
wake(FAWKES_CID_PLUGINMANAGER);
168 printf(
"Requesting loading of plugin %s\n", plugin_name);
170 strncpy(l->
name, plugin_name, PLUGIN_MSG_NAME_LENGTH - 1);
179 c->
wait(FAWKES_CID_PLUGINMANAGER);
187 printf(
"Requesting unloading of plugin %s\n", plugin_name);
189 strncpy(m->
name, plugin_name, PLUGIN_MSG_NAME_LENGTH - 1);
198 c->
wait(FAWKES_CID_PLUGINMANAGER);
204PluginTool::list_avail()
206 printf(
"Request the list of all available plugins\n");
212 c->
wait(FAWKES_CID_PLUGINMANAGER);
218PluginTool::list_loaded()
221 printf(
"Request the list of all loaded plugins\n");
227 c->
wait(FAWKES_CID_PLUGINMANAGER);
238 printf(
"Watching for plugin events\n");
239 printf(
"%-10s %-40s\n",
"Event",
"Plugin Name/ID");
241 c->
wait(FAWKES_CID_PLUGINMANAGER);
252PluginTool::deregistered(
unsigned int id)
noexcept
263 if (msg->
cid() != FAWKES_CID_PLUGINMANAGER)
266 if (msg->
msgid() == MSG_PLUGIN_LOADED) {
268 printf(
"Invalid message size (load succeeded)\n");
271 if (opmode == M_WATCH) {
272 printf(
"%-10s %s\n",
"loaded", m->
name);
274 if (strncmp(m->
name, plugin_name, PLUGIN_MSG_NAME_LENGTH) == 0) {
275 printf(
"Loading of %s succeeded\n", plugin_name);
280 }
else if (msg->
msgid() == MSG_PLUGIN_LOAD_FAILED) {
282 printf(
"Invalid message size (load failed)\n");
285 if (opmode == M_WATCH) {
286 printf(
"%-10s %s\n",
"loadfail", m->
name);
288 if (strncmp(m->
name, plugin_name, PLUGIN_MSG_NAME_LENGTH) == 0) {
289 printf(
"Loading of %s failed, see log for reason\n", plugin_name);
294 }
else if (msg->
msgid() == MSG_PLUGIN_UNLOADED) {
296 printf(
"Invalid message size (unload succeeded)\n");
299 if (opmode == M_WATCH) {
300 printf(
"%-10s %s\n",
"unloaded", m->
name);
302 if (strncmp(m->
name, plugin_name, PLUGIN_MSG_NAME_LENGTH) == 0) {
303 printf(
"Unloading of %s succeeded\n", plugin_name);
308 }
else if (msg->
msgid() == MSG_PLUGIN_UNLOAD_FAILED) {
310 printf(
"Invalid message size (unload failed)\n");
313 if (opmode == M_WATCH) {
314 printf(
"%-10s %s\n",
"unloadfail", m->
name);
316 if (strncmp(m->
name, plugin_name, PLUGIN_MSG_NAME_LENGTH) == 0) {
317 printf(
"Unloading of %s failed, see log for reason\n", plugin_name);
322 }
else if (msg->
msgid() == MSG_PLUGIN_AVAIL_LIST) {
325 printf(
"Available plugins:\n");
327 char *plugin_name = plm->
next();
328 char *plugin_desc = NULL;
330 plugin_desc = plm->
next();
332 printf(
"Invalid plugin list received");
335 printf(
" %-16s (%s)\n", plugin_name, plugin_desc);
340 printf(
"No plugins available\n");
344 }
else if (msg->
msgid() == MSG_PLUGIN_LOADED_LIST) {
347 printf(
"Loaded plugins:\n");
349 char *p = plm->
next();
354 printf(
"No plugins loaded\n");
358 }
else if (msg->
msgid() == MSG_PLUGIN_AVAIL_LIST_FAILED) {
359 printf(
"Obtaining list of available plugins failed\n");
360 }
else if (msg->
msgid() == MSG_PLUGIN_LOADED_LIST_FAILED) {
361 printf(
"Obtaining list of loaded plugins failed\n");
366PluginTool::connection_established(
unsigned int id)
noexcept
372PluginTool::connection_died(
unsigned int id)
noexcept
374 printf(
"Connection died, exiting\n");
385 case M_LOAD: load();
break;
387 case M_UNLOAD: unload();
break;
395 case M_LIST_AVAIL: list_avail();
break;
397 case M_LIST_LOADED: list_loaded();
break;
399 case M_WATCH: watch();
break;
Parse command line arguments.
const char * program_name() const
Get name of program.
const char * arg(const char *argn)
Get argument value.
bool has_arg(const char *argn)
Check if argument has been supplied.
Simple Fawkes network client.
void wake(unsigned int component_id)
Wake a waiting thread.
void register_handler(FawkesNetworkClientHandler *handler, unsigned int component_id)
Register handler.
void wait(unsigned int component_id, unsigned int timeout_sec=15)
Wait for messages for component ID.
void deregister_handler(unsigned int component_id)
Deregister handler.
void enqueue(FawkesNetworkMessage *message)
Enqueue message to send.
Representation of a message that is sent over the network.
unsigned short int msgid() const
Get message type ID.
unsigned short int cid() const
Get component ID.
void * payload() const
Get payload buffer.
size_t payload_size() const
Get payload size.
MT * msgc() const
Get correctly parsed output.
bool has_next()
Check if more list elements are available.
char * next()
Get next plugin from list.
Fawkes library namespace.
char name[PLUGIN_MSG_NAME_LENGTH]
name of plugin that could not be unloaded
char name[PLUGIN_MSG_NAME_LENGTH]
name of the plugin to load.
char name[PLUGIN_MSG_NAME_LENGTH]
name of the plugin that has been loaded
char name[PLUGIN_MSG_NAME_LENGTH]
name of plugin that could not be unloaded
char name[PLUGIN_MSG_NAME_LENGTH]
name of te plugin to unload.
char name[PLUGIN_MSG_NAME_LENGTH]
name of the plugin that has been unloaded