#include "afb-plugin.h"
#include "afb-req-itf.h"
+#include "afb-poll-itf.h"
+
#include "session.h"
#include "afb-apis.h"
+#include "verbose.h"
+#include "utils-upoll.h"
struct api_desc {
struct AFB_plugin *plugin; /* descriptor */
static const char plugin_register_function[] = "pluginRegister";
+static const struct afb_poll_itf upoll_itf = {
+ .on_readable = (void*)upoll_on_readable,
+ .on_writable = (void*)upoll_on_writable,
+ .on_hangup = (void*)upoll_on_hangup,
+ .close = (void*)upoll_close
+};
+
+
int afb_apis_count()
{
return apis_count;
free(context);
}
+static struct afb_poll itf_poll_open(int fd, void *closure)
+{
+ struct afb_poll result;
+ result.data = upoll_open(fd, closure);
+ result.itf = result.data ? &upoll_itf : NULL;
+ return result;
+}
+
+
int afb_apis_add_plugin(const char *path)
{
struct api_desc *apis;
fprintf(stderr, "[%s] not an AFB plugin, continuing...\n", path);
goto error2;
}
- if (verbose)
+ if (verbosity)
fprintf(stderr, "[%s] is a valid AFB plugin\n", path);
/* allocates enough memory */
fprintf(stderr, "ERROR: plugin [%s] memory missing. continuing...\n", path);
goto error2;
}
- interface->verbose = 0;
+ interface->verbosity = 0;
interface->mode = AFB_MODE_LOCAL;
+ interface->poll_open = itf_poll_open;
/* init the plugin */
plugin = pluginRegisterFct(interface);
}
/* record the plugin */
- if (verbose)
+ if (verbosity)
fprintf(stderr, "Loading plugin[%lu] prefix=[%s] info=%s\n", (unsigned long)apis_count, plugin->prefix, plugin->info);
apis = &apis_array[apis_count];
apis->plugin = plugin;
fprintf(stderr, "ERROR in scanning plugin directory %s, %m\n", path);
return -1;
}
- if (verbose)
+ if (verbosity)
fprintf(stderr, "Scanning dir=[%s] for plugins\n", path);
/* scan each entry */
v = a->plugin->apis;
for (j = 0 ; v->name ; j++, v++) {
if (!strncasecmp(v->name, verb, lenverb) && !v->name[lenverb]) {
- req.context = context->contexts[i];
+ req.context = &context->contexts[i];
handle(req, v);
- context->contexts[i] = req.context;
return 1;
}
}