aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-api-dbus.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-04-12 17:00:33 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-04-12 17:00:33 +0200
commit03f863dd080d32f71c4a0755c02e23c72e4cb342 (patch)
tree27dd6f931b42311964d9179b10a2781a6a7edcce /src/afb-api-dbus.c
parenta05138e6bf1257b0e7b1ad90c974fb9e12f1d040 (diff)
Optimisation of xreq
Reduce the count of memory read Change-Id: Ie4dfa4bd30d6485be91961196294c43ffbd3b2a9 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-api-dbus.c')
-rw-r--r--src/afb-api-dbus.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/afb-api-dbus.c b/src/afb-api-dbus.c
index 593232b9..b8ec3d02 100644
--- a/src/afb-api-dbus.c
+++ b/src/afb-api-dbus.c
@@ -808,9 +808,9 @@ struct dbus_req {
};
/* decrement the reference count of the request and free/release it on falling to null */
-static void dbus_req_destroy(void *closure)
+static void dbus_req_destroy(struct afb_xreq *xreq)
{
- struct dbus_req *dreq = closure;
+ struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
afb_context_disconnect(&dreq->xreq.context);
json_object_put(dreq->json);
@@ -819,9 +819,9 @@ static void dbus_req_destroy(void *closure)
}
/* get the object of the request */
-static struct json_object *dbus_req_json(void *closure)
+static struct json_object *dbus_req_json(struct afb_xreq *xreq)
{
- struct dbus_req *dreq = closure;
+ struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
return dreq->json;
}
@@ -836,25 +836,25 @@ static void dbus_req_reply(struct dbus_req *dreq, uint8_t type, const char *firs
ERROR("sending the reply failed");
}
-static void dbus_req_success(void *closure, struct json_object *obj, const char *info)
+static void dbus_req_success(struct afb_xreq *xreq, struct json_object *obj, const char *info)
{
- struct dbus_req *dreq = closure;
+ struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
dbus_req_reply(dreq, RETOK, json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN), info);
}
-static void dbus_req_fail(void *closure, const char *status, const char *info)
+static void dbus_req_fail(struct afb_xreq *xreq, const char *status, const char *info)
{
- struct dbus_req *dreq = closure;
+ struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
dbus_req_reply(dreq, RETERR, status, info);
}
static void afb_api_dbus_server_event_send(struct origin *origin, char order, const char *event, int eventid, const char *data, uint64_t msgid);
-static int dbus_req_subscribe(void *closure, struct afb_event event)
+static int dbus_req_subscribe(struct afb_xreq *xreq, struct afb_event event)
{
- struct dbus_req *dreq = closure;
+ struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
uint64_t msgid;
int rc;
@@ -864,9 +864,9 @@ static int dbus_req_subscribe(void *closure, struct afb_event event)
return rc;
}
-static int dbus_req_unsubscribe(void *closure, struct afb_event event)
+static int dbus_req_unsubscribe(struct afb_xreq *xreq, struct afb_event event)
{
- struct dbus_req *dreq = closure;
+ struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
uint64_t msgid;
int rc;
@@ -976,6 +976,7 @@ static int api_dbus_server_on_object_called(sd_bus_message *message, void *userd
}
/* connect to the context */
+ afb_xreq_init(&dreq->xreq, &afb_api_dbus_xreq_itf);
if (afb_context_connect(&dreq->xreq.context, uuid, NULL) < 0)
goto out_of_memory;
session = dreq->xreq.context.session;
@@ -994,9 +995,6 @@ static int api_dbus_server_on_object_called(sd_bus_message *message, void *userd
dreq->json = json_object_new_string(dreq->request);
}
dreq->listener = listener;
- dreq->xreq.refcount = 1;
- dreq->xreq.query = dreq;
- dreq->xreq.queryitf = &afb_api_dbus_xreq_itf;
dreq->xreq.api = api->api;
dreq->xreq.verb = method;
afb_apis_call(&dreq->xreq);