+static void f_subscribe(afb_req_t req)
+{
+ struct json_object *args = afb_req_json(req);
+ int revoke, ok;
+
+ revoke = json_object_is_type(args, json_type_boolean)
+ && !json_object_get_boolean(args);
+
+ ok = 1;
+ if (!revoke) {
+ ok = !afb_req_subscribe(req, event_add_pid)
+ && !afb_req_subscribe(req, event_del_pid);
+ }
+ if (revoke || !ok) {
+ afb_req_unsubscribe(req, event_add_pid);
+ afb_req_unsubscribe(req, event_del_pid);
+ }
+ afb_req_reply(req, NULL, ok ? NULL : "error", NULL);
+}