Skip to content

Commit

Permalink
Add new pkg_plugin_{errno,error,info} to emit information from the pl…
Browse files Browse the repository at this point in the history
…ugins

thought the event interface
  • Loading branch information
bapt committed Oct 30, 2012
1 parent c5799f6 commit fa5dd5d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
20 changes: 19 additions & 1 deletion libpkg/pkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,9 @@ int pkg_plugin_conf_integer(struct pkg_plugin *p, int key, int64_t *value);
int pkg_plugin_confs(struct pkg_plugin *p, struct pkg_config **conf);

int pkg_plugin_parse(struct pkg_plugin *p);

void pkg_plugin_errno(struct pkg_plugin *p, const char *func, const char *arg);
void pkg_plugin_error(struct pkg_plugin *p, const char *fmt, ...);
void pkg_plugin_info(struct pkg_plugin *p, const char *fmt, ...);
/**
* This is where plugin hook into the library using pkg_plugin_hook()
* @todo: Document
Expand Down Expand Up @@ -1016,6 +1018,9 @@ typedef enum {
PKG_EVENT_NOLOCALDB,
PKG_EVENT_FILE_MISMATCH,
PKG_EVENT_DEVELOPER_MODE,
PKG_EVENT_PLUGIN_ERRNO,
PKG_EVENT_PLUGIN_ERROR,
PKG_EVENT_PLUGIN_INFO,
} pkg_event_t;

struct pkg_event {
Expand Down Expand Up @@ -1074,6 +1079,19 @@ struct pkg_event {
struct pkg_file *file;
const char *newsum;
} e_file_mismatch;
struct {
struct pkg_plugin *plugin;
char *msg;
} e_plugin_info;
struct {
struct pkg_plugin *plugin;
const char *func;
const char *arg;
} e_plugin_errno;
struct {
struct pkg_plugin *plugin;
char *msg;
} e_plugin_error;
};
};

Expand Down
47 changes: 47 additions & 0 deletions libpkg/pkg_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,50 @@ pkg_emit_file_mismatch(struct pkg *pkg, struct pkg_file *f, const char *newsum)

pkg_emit_event(&ev);
}

void
pkg_plugin_errno(struct pkg_plugin *p, const char *func, const char *arg)
{
struct pkg_event ev;

ev.type = PKG_EVENT_PLUGIN_ERRNO;
ev.e_plugin_errno.plugin = p;
ev.e_plugin_errno.func = func;
ev.e_plugin_errno.arg = arg;

pkg_emit_event(&ev);
}

void
pkg_plugin_error(struct pkg_plugin *p, const char *fmt, ...)
{
struct pkg_event ev;
va_list ap;

ev.type = PKG_EVENT_PLUGIN_ERROR;
ev.e_plugin_error.plugin = p;

va_start(ap, fmt);
vasprintf(&ev.e_plugin_error.msg, fmt, ap);
va_end(ap);

pkg_emit_event(&ev);
free(ev.e_plugin_error.msg);
}

void
pkg_plugin_info(struct pkg_plugin *p, const char *fmt, ...)
{
struct pkg_event ev;
va_list ap;

ev.type = PKG_EVENT_PLUGIN_INFO;
ev.e_plugin_info.plugin = p;

va_start(ap, fmt);
vasprintf(&ev.e_plugin_info.msg, fmt, ap);
va_end(ap);

pkg_emit_event(&ev);
free(ev.e_plugin_info.msg);
}
11 changes: 11 additions & 0 deletions pkg/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ event_callback(void *data, struct pkg_event *ev)
PKG_VERSION, &version);
fprintf(stderr, "%s-%s: checksum mismatch for %s\n", name,
version, pkg_file_path(ev->e_file_mismatch.file));
case PKG_EVENT_PLUGIN_ERRNO:
warn("%s: %s(%s)", pkg_plugin_get(ev->e_plugin_errno.plugin, PKG_PLUGIN_NAME),ev->e_plugin_errno.func, ev->e_plugin_errno.arg);
break;
case PKG_EVENT_PLUGIN_ERROR:
warnx("%s: %s", pkg_plugin_get(ev->e_plugin_error.plugin, PKG_PLUGIN_NAME), ev->e_plugin_error.msg);
break;
case PKG_EVENT_PLUGIN_INFO:
if (quiet)
break;
printf("%s: %s\n", pkg_plugin_get(ev->e_plugin_info.plugin, PKG_PLUGIN_NAME), ev->e_plugin_info.msg);
break;
default:
break;
}
Expand Down

0 comments on commit fa5dd5d

Please sign in to comment.