/*
- Copyright 2015 IoT.bzh
+ Copyright 2015, 2016 IoT.bzh
author: José Bollo <jose.bollo@iot.bzh>
#include <getopt.h>
#include <errno.h>
-#include <json.h>
+#include <systemd/sd-bus.h>
+#include <systemd/sd-event.h>
+#include <json-c/json.h>
#include "verbose.h"
#include "utils-jbus.h"
const char error_not_found[] = "\"not found\"";
const char error_cant_start[] = "\"can't start\"";
-static void on_install(struct jreq *jreq, struct json_object *req, void *unused)
+static void on_install(struct sd_bus_message *smsg, struct json_object *req, void *unused)
{
const char *wgtfile;
const char *root;
break;
}
default:
- jbus_reply_error_s(jreq, error_bad_request);
+ jbus_reply_error_s(smsg, error_bad_request);
return;
}
/* install the widget */
ifo = install_widget(wgtfile, root, force);
if (ifo == NULL)
- jbus_reply_error_s(jreq, "\"installation failed\"");
+ jbus_reply_error_s(smsg, "\"installation failed\"");
else {
/* build the response */
resp = json_object_new_object();
if(!resp || !j_add_string(resp, "added", wgt_info_desc(ifo)->idaver))
- jbus_reply_error_s(jreq, "\"out of memory but installed!\"");
+ jbus_reply_error_s(smsg, "\"out of memory but installed!\"");
else {
jbus_send_signal_s(jbus, "changed", "true");
- jbus_reply_j(jreq, resp);
+ jbus_reply_j(smsg, resp);
}
/* clean-up */
}
}
-static void on_uninstall(struct jreq *jreq, struct json_object *req, void *unused)
+static void on_uninstall(struct sd_bus_message *smsg, struct json_object *req, void *unused)
{
const char *idaver;
const char *root;
break;
}
default:
- jbus_reply_error_s(jreq, error_bad_request);
+ jbus_reply_error_s(smsg, error_bad_request);
return;
}
/* install the widget */
rc = uninstall_widget(idaver, root);
if (rc)
- jbus_reply_error_s(jreq, "\"uninstallation had error\"");
+ jbus_reply_error_s(smsg, "\"uninstallation had error\"");
else {
jbus_send_signal_s(jbus, "changed", "true");
- jbus_reply_s(jreq, "true");
+ jbus_reply_s(smsg, "true");
}
}
int main(int ac, char **av)
{
- int i, daemon = 0;
+ int i, daemon = 0, rc;
+ struct sd_event *evloop;
+ struct sd_bus *sysbus;
LOGAUTH(appname);
return 1;
}
+ /* get systemd objects */
+ rc = sd_event_new(&evloop);
+ if (rc < 0) {
+ ERROR("can't create event loop");
+ return 1;
+ }
+ rc = sd_bus_open_system(&sysbus);
+ if (rc < 0) {
+ ERROR("can't create system bus");
+ return 1;
+ }
+ rc = sd_bus_attach_event(sysbus, evloop, 0);
+ if (rc < 0) {
+ ERROR("can't attach system bus to event loop");
+ return 1;
+ }
+
/* init service */
- jbus = create_jbus_system(AFM_SYSTEM_DBUS_PATH);
+ jbus = create_jbus(sysbus, AFM_SYSTEM_DBUS_PATH);
if (!jbus) {
ERROR("create_jbus failed");
return 1;
}
/* start and run */
- if (jbus_start_serving(jbus)) {
+ if (jbus_start_serving(jbus) < 0) {
ERROR("can't start server");
return 1;
}
- while (!jbus_read_write_dispatch(jbus, -1));
+ for(;;)
+ sd_event_run(evloop, (uint64_t)-1);
return 0;
}
-