Return result from plugin calls

closes #739
This commit is contained in:
James Booth
2016-02-21 02:06:09 +00:00
parent 3705437a60
commit 1654f16a2f
6 changed files with 157 additions and 59 deletions

View File

@@ -53,22 +53,32 @@ api_cons_alert(void)
cons_alert(); cons_alert();
} }
void int
api_cons_show(const char * const message) api_cons_show(const char * const message)
{ {
if (message) { if (message == NULL) {
char *parsed = str_replace(message, "\r\n", "\n"); log_warning("%s", "prof_cons_show failed, message is NULL");
cons_show("%s", parsed); return 0;
free(parsed);
} }
char *parsed = str_replace(message, "\r\n", "\n");
cons_show("%s", parsed);
free(parsed);
return 1;
} }
void int
api_cons_bad_cmd_usage(const char *const cmd) api_cons_bad_cmd_usage(const char *const cmd)
{ {
if (cmd) { if (cmd == NULL) {
cons_bad_cmd_usage(cmd); log_warning("%s", "prof_cons_bad_cmd_usage failed, cmd is NULL");
return 0;
} }
cons_bad_cmd_usage(cmd);
return 1;
} }
void void
@@ -213,49 +223,141 @@ api_win_create(const char *tag, void *callback,
status_bar_active(num); status_bar_active(num);
} }
void int
api_win_focus(const char *tag) api_win_focus(const char *tag)
{ {
if (tag == NULL) {
log_warning("%s", "prof_win_focus failed, tag is NULL");
return 0;
}
ProfPluginWin *pluginwin = wins_get_plugin(tag); ProfPluginWin *pluginwin = wins_get_plugin(tag);
if (pluginwin == NULL) {
log_warning("prof_win_focus failed, no window with tag: %s", tag);
return 0;
}
ui_focus_win((ProfWin*)pluginwin); ui_focus_win((ProfWin*)pluginwin);
return 1;
} }
void int
api_win_show(const char *tag, const char *line) api_win_show(const char *tag, const char *line)
{ {
if (tag == NULL) {
log_warning("%s", "prof_win_show failed, tag is NULL");
return 0;
}
if (line == NULL) {
log_warning("%s", "prof_win_show failed, line is NULL");
return 0;
}
ProfPluginWin *pluginwin = wins_get_plugin(tag); ProfPluginWin *pluginwin = wins_get_plugin(tag);
if (pluginwin == NULL) {
log_warning("prof_win_show failed, no window with tag: %s", tag);
return 0;
}
ProfWin *window = (ProfWin*)pluginwin; ProfWin *window = (ProfWin*)pluginwin;
win_print(window, '!', 0, NULL, 0, 0, "", line); win_print(window, '!', 0, NULL, 0, 0, "", line);
return 1;
} }
void int
api_win_show_green(const char *tag, const char *line) api_win_show_green(const char *tag, const char *line)
{ {
if (tag == NULL) {
log_warning("%s", "prof_win_show_green failed, tag is NULL");
return 0;
}
if (line == NULL) {
log_warning("%s", "prof_win_show_green failed, line is NULL");
return 0;
}
ProfPluginWin *pluginwin = wins_get_plugin(tag); ProfPluginWin *pluginwin = wins_get_plugin(tag);
if (pluginwin == NULL) {
log_warning("prof_win_show_green failed, no window with tag: %s", tag);
return 0;
}
ProfWin *window = (ProfWin*)pluginwin; ProfWin *window = (ProfWin*)pluginwin;
win_print(window, '!', 0, NULL, 0, THEME_GREEN, "", line); win_print(window, '!', 0, NULL, 0, THEME_GREEN, "", line);
return 1;
} }
void int
api_win_show_red(const char *tag, const char *line) api_win_show_red(const char *tag, const char *line)
{ {
if (tag == NULL) {
log_warning("%s", "prof_win_show_red failed, tag is NULL");
return 0;
}
if (line == NULL) {
log_warning("%s", "prof_win_show_red failed, line is NULL");
return 0;
}
ProfPluginWin *pluginwin = wins_get_plugin(tag); ProfPluginWin *pluginwin = wins_get_plugin(tag);
if (pluginwin == NULL) {
log_warning("prof_win_show_red failed, no window with tag: %s", tag);
return 0;
}
ProfWin *window = (ProfWin*)pluginwin; ProfWin *window = (ProfWin*)pluginwin;
win_print(window, '!', 0, NULL, 0, THEME_RED, "", line); win_print(window, '!', 0, NULL, 0, THEME_RED, "", line);
return 1;
} }
void int
api_win_show_cyan(const char *tag, const char *line) api_win_show_cyan(const char *tag, const char *line)
{ {
if (tag == NULL) {
log_warning("%s", "prof_win_show_cyan failed, tag is NULL");
return 0;
}
if (line == NULL) {
log_warning("%s", "prof_win_show_cyan failed, line is NULL");
return 0;
}
ProfPluginWin *pluginwin = wins_get_plugin(tag); ProfPluginWin *pluginwin = wins_get_plugin(tag);
if (pluginwin == NULL) {
log_warning("prof_win_show_cyan failed, no window with tag: %s", tag);
return 0;
}
ProfWin *window = (ProfWin*)pluginwin; ProfWin *window = (ProfWin*)pluginwin;
win_print(window, '!', 0, NULL, 0, THEME_CYAN, "", line); win_print(window, '!', 0, NULL, 0, THEME_CYAN, "", line);
return 1;
} }
void int
api_win_show_yellow(const char *tag, const char *line) api_win_show_yellow(const char *tag, const char *line)
{ {
if (tag == NULL) {
log_warning("%s", "prof_win_show_yellow failed, tag is NULL");
return 0;
}
if (line == NULL) {
log_warning("%s", "prof_win_show_yellow failed, line is NULL");
return 0;
}
ProfPluginWin *pluginwin = wins_get_plugin(tag); ProfPluginWin *pluginwin = wins_get_plugin(tag);
if (pluginwin == NULL) {
log_warning("prof_win_show_yellow failed, no window with tag: %s", tag);
return 0;
}
ProfWin *window = (ProfWin*)pluginwin; ProfWin *window = (ProfWin*)pluginwin;
win_print(window, '!', 0, NULL, 0, THEME_YELLOW, "", line); win_print(window, '!', 0, NULL, 0, THEME_YELLOW, "", line);
return 1;
} }

View File

@@ -38,8 +38,8 @@
#include "plugins/callbacks.h" #include "plugins/callbacks.h"
void api_cons_alert(void); void api_cons_alert(void);
void api_cons_show(const char * const message); int api_cons_show(const char * const message);
void api_cons_bad_cmd_usage(const char *const cmd); int api_cons_bad_cmd_usage(const char *const cmd);
void api_notify(const char *message, const char *category, int timeout_ms); void api_notify(const char *message, const char *category, int timeout_ms);
void api_send_line(char *line); void api_send_line(char *line);
char * api_get_current_recipient(void); char * api_get_current_recipient(void);
@@ -60,11 +60,11 @@ void api_log_error(const char *message);
int api_win_exists(const char *tag); int api_win_exists(const char *tag);
void api_win_create(const char *tag, void *callback, void api_win_create(const char *tag, void *callback,
void(*callback_func)(PluginWindowCallback *window_callback, char *tag, char *line)); void(*callback_func)(PluginWindowCallback *window_callback, char *tag, char *line));
void api_win_focus(const char *tag); int api_win_focus(const char *tag);
void api_win_show(const char *tag, const char *line); int api_win_show(const char *tag, const char *line);
void api_win_show_green(const char *tag, const char *line); int api_win_show_green(const char *tag, const char *line);
void api_win_show_red(const char *tag, const char *line); int api_win_show_red(const char *tag, const char *line);
void api_win_show_cyan(const char *tag, const char *line); int api_win_show_cyan(const char *tag, const char *line);
void api_win_show_yellow(const char *tag, const char *line); int api_win_show_yellow(const char *tag, const char *line);
#endif #endif

View File

@@ -59,20 +59,16 @@ c_api_cons_alert(void)
api_cons_alert(); api_cons_alert();
} }
static void static int
c_api_cons_show(const char * const message) c_api_cons_show(const char * const message)
{ {
if (message) { return api_cons_show(message);
api_cons_show(message);
}
} }
static void static int
c_api_cons_bad_cmd_usage(const char *const cmd) c_api_cons_bad_cmd_usage(const char *const cmd)
{ {
if (cmd) { return api_cons_bad_cmd_usage(cmd);
api_cons_bad_cmd_usage(cmd);
}
} }
static void static void
@@ -162,40 +158,40 @@ c_api_win_create(char *tag, void(*callback)(char *tag, char *line))
api_win_create(tag, wrapper, c_window_callback); api_win_create(tag, wrapper, c_window_callback);
} }
void int
c_api_win_focus(char *tag) c_api_win_focus(char *tag)
{ {
api_win_focus(tag); return api_win_focus(tag);
} }
void int
c_api_win_show(char *tag, char *line) c_api_win_show(char *tag, char *line)
{ {
api_win_show(tag, line); return api_win_show(tag, line);
} }
void int
c_api_win_show_green(char *tag, char *line) c_api_win_show_green(char *tag, char *line)
{ {
api_win_show_green(tag, line); return api_win_show_green(tag, line);
} }
void int
c_api_win_show_red(char *tag, char *line) c_api_win_show_red(char *tag, char *line)
{ {
api_win_show_red(tag, line); return api_win_show_red(tag, line);
} }
void int
c_api_win_show_cyan(char *tag, char *line) c_api_win_show_cyan(char *tag, char *line)
{ {
api_win_show_cyan(tag, line); return api_win_show_cyan(tag, line);
} }
void int
c_api_win_show_yellow(char *tag, char *line) c_api_win_show_yellow(char *tag, char *line)
{ {
api_win_show_yellow(tag, line); return api_win_show_yellow(tag, line);
} }
void void

View File

@@ -69,7 +69,7 @@ c_plugin_create(const char * const filename)
handle = dlopen (path->str, RTLD_NOW | RTLD_GLOBAL); handle = dlopen (path->str, RTLD_NOW | RTLD_GLOBAL);
if (!handle) { if (!handle) {
log_warning ("dlopen failed to open `%s', %s", filename, dlerror ()); log_warning("dlopen failed to open `%s', %s", filename, dlerror ());
g_string_free(path, TRUE); g_string_free(path, TRUE);
return NULL; return NULL;
} }

View File

@@ -38,8 +38,8 @@
#include "plugins/callbacks.h" #include "plugins/callbacks.h"
void (*prof_cons_alert)(void) = NULL; void (*prof_cons_alert)(void) = NULL;
void (*prof_cons_show)(const char * const message) = NULL; int (*prof_cons_show)(const char * const message) = NULL;
void (*prof_cons_bad_cmd_usage)(const char *const cmd) = NULL; int (*prof_cons_bad_cmd_usage)(const char *const cmd) = NULL;
void (*prof_register_command)(const char *command_name, int min_args, int max_args, void (*prof_register_command)(const char *command_name, int min_args, int max_args,
const char **synopsis, const char *description, const char *arguments[][2], const char **examples, const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
@@ -63,9 +63,9 @@ void (*prof_log_error)(const char *message) = NULL;
int (*prof_win_exists)(PROF_WIN_TAG win) = NULL; int (*prof_win_exists)(PROF_WIN_TAG win) = NULL;
void (*prof_win_create)(PROF_WIN_TAG win, void(*input_handler)(PROF_WIN_TAG win, char *line)) = NULL; void (*prof_win_create)(PROF_WIN_TAG win, void(*input_handler)(PROF_WIN_TAG win, char *line)) = NULL;
void (*prof_win_focus)(PROF_WIN_TAG win) = NULL; int (*prof_win_focus)(PROF_WIN_TAG win) = NULL;
void (*prof_win_show)(PROF_WIN_TAG win, char *line) = NULL; int (*prof_win_show)(PROF_WIN_TAG win, char *line) = NULL;
void (*prof_win_show_green)(PROF_WIN_TAG win, char *line) = NULL; int (*prof_win_show_green)(PROF_WIN_TAG win, char *line) = NULL;
void (*prof_win_show_red)(PROF_WIN_TAG win, char *line) = NULL; int (*prof_win_show_red)(PROF_WIN_TAG win, char *line) = NULL;
void (*prof_win_show_cyan)(PROF_WIN_TAG win, char *line) = NULL; int (*prof_win_show_cyan)(PROF_WIN_TAG win, char *line) = NULL;
void (*prof_win_show_yellow)(PROF_WIN_TAG win, char *line) = NULL; int (*prof_win_show_yellow)(PROF_WIN_TAG win, char *line) = NULL;

View File

@@ -38,8 +38,8 @@
typedef char* PROF_WIN_TAG; typedef char* PROF_WIN_TAG;
void (*prof_cons_alert)(void); void (*prof_cons_alert)(void);
void (*prof_cons_show)(const char * const message); int (*prof_cons_show)(const char * const message);
void (*prof_cons_bad_cmd_usage)(const char *const cmd); int (*prof_cons_bad_cmd_usage)(const char *const cmd);
void (*prof_register_command)(const char *command_name, int min_args, int max_args, void (*prof_register_command)(const char *command_name, int min_args, int max_args,
const char **synopsis, const char *description, const char *arguments[][2], const char **examples, const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
@@ -63,11 +63,11 @@ void (*prof_log_error)(const char *message);
int (*prof_win_exists)(PROF_WIN_TAG win); int (*prof_win_exists)(PROF_WIN_TAG win);
void (*prof_win_create)(PROF_WIN_TAG win, void(*input_handler)(PROF_WIN_TAG win, char *line)); void (*prof_win_create)(PROF_WIN_TAG win, void(*input_handler)(PROF_WIN_TAG win, char *line));
void (*prof_win_focus)(PROF_WIN_TAG win); int (*prof_win_focus)(PROF_WIN_TAG win);
void (*prof_win_show)(PROF_WIN_TAG win, char *line); int (*prof_win_show)(PROF_WIN_TAG win, char *line);
void (*prof_win_show_green)(PROF_WIN_TAG win, char *line); int (*prof_win_show_green)(PROF_WIN_TAG win, char *line);
void (*prof_win_show_red)(PROF_WIN_TAG win, char *line); int (*prof_win_show_red)(PROF_WIN_TAG win, char *line);
void (*prof_win_show_cyan)(PROF_WIN_TAG win, char *line); int (*prof_win_show_cyan)(PROF_WIN_TAG win, char *line);
void (*prof_win_show_yellow)(PROF_WIN_TAG win, char *line); int (*prof_win_show_yellow)(PROF_WIN_TAG win, char *line);
#endif #endif