aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-06-08 10:41:29 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-06-08 11:49:58 +0200
commit80551a0405e8a208af587b6fff7f784a1a2ffbf4 (patch)
treeddbe35e36a9eb684b7658791ef1c487b56c70b2f
parentb57505f0f80f6394f04a041df6e808c857b01d4b (diff)
wsj1: minor API refactoring
Change-Id: I55e597a7c7cea295993326a6c4b362a136c05e4e Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-wsj1.c20
-rw-r--r--src/afb-wsj1.h39
2 files changed, 40 insertions, 19 deletions
diff --git a/src/afb-wsj1.c b/src/afb-wsj1.c
index 7f030a0c..5859bd36 100644
--- a/src/afb-wsj1.c
+++ b/src/afb-wsj1.c
@@ -477,24 +477,14 @@ int afb_wsj1_call_s(struct afb_wsj1 *wsj1, const char *api, const char *verb, co
return rc;
}
-
-int afb_wsj1_reply_ok_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token)
-{
- return afb_wsj1_reply_ok_s(msg, json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN), token);
-}
-
-int afb_wsj1_reply_ok_s(struct afb_wsj1_msg *msg, const char *object, const char *token)
-{
- return wsj1_send_isot(msg->wsj1, RETOK, msg->id, object, token);
-}
-
-int afb_wsj1_reply_error_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token)
+int afb_wsj1_reply_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token, int iserror)
{
- return afb_wsj1_reply_error_s(msg, json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN), token);
+ const char *objstr = json_object_to_json_string_ext(object, JSON_C_TO_STRING_PLAIN);
+ return afb_wsj1_reply_s(msg, objstr, token, iserror);
}
-int afb_wsj1_reply_error_s(struct afb_wsj1_msg *msg, const char *object, const char *token)
+int afb_wsj1_reply_s(struct afb_wsj1_msg *msg, const char *object, const char *token, int iserror)
{
- return wsj1_send_isot(msg->wsj1, RETERR, msg->id, object, token);
+ return wsj1_send_isot(msg->wsj1, iserror ? RETERR : RETOK, msg->id, object, token);
}
diff --git a/src/afb-wsj1.h b/src/afb-wsj1.h
index 44aa5656..ad734962 100644
--- a/src/afb-wsj1.h
+++ b/src/afb-wsj1.h
@@ -99,32 +99,63 @@ extern int afb_wsj1_call_s(struct afb_wsj1 *wsj1, const char *api, const char *v
extern int afb_wsj1_call_j(struct afb_wsj1 *wsj1, const char *api, const char *verb, struct json_object *object, void (*on_reply)(void *closure, struct afb_wsj1_msg *msg), void *closure);
/*
+ * Sends for message 'msg' the reply with the 'object' and, if not NULL, the token.
+ * When 'iserror' is zero a OK reply is send, otherwise an ERROR reply is sent.
+ * If not NULL, 'object' should be a valid JSON string.
+ * Return 0 in case of success. Otherwise, returns -1 and set errno.
+ */
+extern int afb_wsj1_reply_s(struct afb_wsj1_msg *msg, const char *object, const char *token, int iserror);
+
+/*
+ * Sends for message 'msg' the reply with the 'object' and, if not NULL, the token.
+ * When 'iserror' is zero a OK reply is send, otherwise an ERROR reply is sent.
+ * 'object' can be NULL.
+ * Return 0 in case of success. Otherwise, returns -1 and set errno.
+ */
+extern int afb_wsj1_reply_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token, int iserror);
+
+
+
+
+/*
* Sends for message 'msg' the OK reply with the 'object' and, if not NULL, the token.
* If not NULL, 'object' should be a valid JSON string.
* Return 0 in case of success. Otherwise, returns -1 and set errno.
*/
-extern int afb_wsj1_reply_ok_s(struct afb_wsj1_msg *msg, const char *object, const char *token);
+static inline int afb_wsj1_reply_ok_s(struct afb_wsj1_msg *msg, const char *object, const char *token)
+{
+ return afb_wsj1_reply_s(msg, object, token, 0);
+}
/*
* Sends for message 'msg' the OK reply with the 'object' and, if not NULL, the token.
* 'object' can be NULL.
* Return 0 in case of success. Otherwise, returns -1 and set errno.
*/
-extern int afb_wsj1_reply_ok_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token);
+static inline int afb_wsj1_reply_ok_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token)
+{
+ return afb_wsj1_reply_j(msg, object, token, 0);
+}
/*
* Sends for message 'msg' the ERROR reply with the 'object' and, if not NULL, the token.
* If not NULL, 'object' should be a valid JSON string.
* Return 0 in case of success. Otherwise, returns -1 and set errno.
*/
-extern int afb_wsj1_reply_error_s(struct afb_wsj1_msg *msg, const char *object, const char *token);
+static inline int afb_wsj1_reply_error_s(struct afb_wsj1_msg *msg, const char *object, const char *token)
+{
+ return afb_wsj1_reply_s(msg, object, token, 1);
+}
/*
* Sends for message 'msg' the ERROR reply with the 'object' and, if not NULL, the token.
* 'object' can be NULL.
* Return 0 in case of success. Otherwise, returns -1 and set errno.
*/
-extern int afb_wsj1_reply_error_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token);
+static inline int afb_wsj1_reply_error_j(struct afb_wsj1_msg *msg, struct json_object *object, const char *token)
+{
+ return afb_wsj1_reply_j(msg, object, token, 1);
+}
/*
* Increases by one the count of reference to 'msg'.