use upoll for event loop
[src/app-framework-binder.git] / plugins / afm-main-plugin / afm-main-plugin.c
index d86e926..418cc50 100644 (file)
@@ -23,7 +23,9 @@
 
 #include "afb-plugin.h"
 #include "afb-req-itf.h"
+#include "afb-poll-itf.h"
 
+#include "utils-sbus.h"
 #include "utils-jbus.h"
 
 static const char _auto_[]      = "auto";
@@ -91,7 +93,7 @@ static void call_appid(struct afb_req request, const char *method)
 {
        struct json_object *obj;
        char *sid;
-       const char *id = afb_req_argument(request, _id_);
+       const char *id = afb_req_value(request, _id_);
        if (id == NULL) {
                afb_req_fail(request, "bad-request", "missing 'id'");
                return;
@@ -114,7 +116,7 @@ static void call_appid(struct afb_req request, const char *method)
 static void call_runid(struct afb_req request, const char *method)
 {
        struct json_object *obj;
-       const char *id = afb_req_argument(request, _runid_);
+       const char *id = afb_req_value(request, _runid_);
        if (id == NULL) {
                afb_req_fail(request, "bad-request", "missing 'runid'");
                return;
@@ -151,13 +153,13 @@ static void start(struct afb_req request)
        int rc;
 
        /* get the id */
-       id = afb_req_argument(request, _id_);
+       id = afb_req_value(request, _id_);
        if (id == NULL) {
                afb_req_fail(request, "bad-request", "missing 'id'");
                return;
        }
        /* get the mode */
-       mode = afb_req_argument(request, _mode_);
+       mode = afb_req_value(request, _mode_);
        if (mode == NULL || !strcmp(mode, _auto_)) {
                mode = interface->mode == AFB_MODE_REMOTE ? _remote_ : _local_;
        }
@@ -221,8 +223,8 @@ static void install(struct afb_req request)
 
        /* get the argument */
        arg = afb_req_get(request, "widget");
-       filename = arg.value;
-       if (filename == NULL || !arg.is_file) {
+       filename = arg.path;
+       if (filename == NULL) {
                afb_req_fail(request, "bad-request", "missing 'widget' file");
                return;
        }
@@ -276,14 +278,33 @@ static const struct AFB_plugin plug_desc = {
        .apis = plug_apis
 };
 
+static struct sbus_itf sbusitf;
+
 const struct AFB_plugin *pluginRegister(const struct AFB_interface *itf)
 {
+       struct sbus *sbus;
+
+       if (interface != NULL)
+               return NULL;
+
        interface = itf;
+       sbusitf.wait = itf->pollitf->wait;
+       sbusitf.open = itf->pollitf->open;
+       sbusitf.on_readable = itf->pollitf->on_readable;
+       sbusitf.on_writable = itf->pollitf->on_writable;
+       sbusitf.on_hangup = itf->pollitf->on_hangup;
+       sbusitf.close = itf->pollitf->close;
+
+       sbus = sbus_session(&sbusitf, itf->pollclosure);
+       if (sbus == NULL) {
+               fprintf(stderr, "ERROR: %s:%d: can't connect to DBUS session\n", __FILE__, __LINE__);
+               return NULL;
+       }
 
-       jbus = create_jbus_session("/org/AGL/afm/user");
+       jbus = create_jbus(sbus, "/org/AGL/afm/user");
         if (jbus)
                return &plug_desc;
-       fprintf(stderr, "ERROR: %s:%d: can't connect to DBUS session\n", __FILE__, __LINE__);
+       sbus_unref(sbus);
        return NULL;
 }