summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2016-12-24 14:35:58 +0100
committerFelix Fietkau <nbd@nbd.name>2016-12-24 14:35:58 +0100
commitd5fabacba1f701cab27bbee907d7c4a2ab74cb4d (patch)
tree4e01ad7781da1daca465ccb8e704cf48bc6c246c
parentdf088f03c02aebba304a371486f09e95ed34bf5f (diff)
downloadubus-d5fabacba1f701cab27bbee907d7c4a2ab74cb4d.tar.gz
libubus: reduce code duplication, fix indentation
Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--libubus-req.c41
-rw-r--r--libubus.h21
2 files changed, 18 insertions, 44 deletions
diff --git a/libubus-req.c b/libubus-req.c
index 5180a6f..3eeae40 100644
--- a/libubus-req.c
+++ b/libubus-req.c
@@ -220,24 +220,9 @@ int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req,
return 0;
}
-int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
- struct blob_attr *msg, struct ubus_request *req)
-{
- blob_buf_init(&b, 0);
- blob_put_int32(&b, UBUS_ATTR_OBJID, obj);
- blob_put_string(&b, UBUS_ATTR_METHOD, method);
- if (msg)
- blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg));
-
- if (ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, obj) < 0)
- return UBUS_STATUS_INVALID_ARGUMENT;
-
- return 0;
-}
-
-
-int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, const char *method,
- struct blob_attr *msg, struct ubus_request *req, int fd)
+int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj,
+ const char *method, struct blob_attr *msg,
+ struct ubus_request *req, int fd)
{
blob_buf_init(&b, 0);
blob_put_int32(&b, UBUS_ATTR_OBJID, obj);
@@ -252,25 +237,9 @@ int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, const char *met
return 0;
}
-int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method,
- struct blob_attr *msg, ubus_data_handler_t cb, void *priv,
- int timeout)
-{
- struct ubus_request req;
- int rc;
-
- rc = ubus_invoke_async(ctx, obj, method, msg, &req);
- if (rc)
- return rc;
-
- req.data_cb = cb;
- req.priv = priv;
- return ubus_complete_request(ctx, &req, timeout);
-}
-
int ubus_invoke_fd(struct ubus_context *ctx, uint32_t obj, const char *method,
- struct blob_attr *msg, ubus_data_handler_t cb, void *priv,
- int timeout, int fd)
+ struct blob_attr *msg, ubus_data_handler_t cb, void *priv,
+ int timeout, int fd)
{
struct ubus_request req;
int rc;
diff --git a/libubus.h b/libubus.h
index 350e694..ea53272 100644
--- a/libubus.h
+++ b/libubus.h
@@ -331,21 +331,26 @@ int ubus_register_acl(struct ubus_context *ctx);
/* ----------- rpc ----------- */
/* invoke a method on a specific object */
-int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method,
- struct blob_attr *msg, ubus_data_handler_t cb, void *priv,
- int timeout);
-
-/* asynchronous version of ubus_invoke() */
-int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
- struct blob_attr *msg, struct ubus_request *req);
-
int ubus_invoke_fd(struct ubus_context *ctx, uint32_t obj, const char *method,
struct blob_attr *msg, ubus_data_handler_t cb, void *priv,
int timeout, int fd);
+static inline int
+ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method,
+ struct blob_attr *msg, ubus_data_handler_t cb, void *priv,
+ int timeout)
+{
+ return ubus_invoke_fd(ctx, obj, method, msg, cb, priv, timeout, -1);
+}
/* asynchronous version of ubus_invoke() */
int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, const char *method,
struct blob_attr *msg, struct ubus_request *req, int fd);
+static inline int
+ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,
+ struct blob_attr *msg, struct ubus_request *req)
+{
+ return ubus_invoke_async_fd(ctx, obj, method, msg, req, -1);
+}
/* send a reply to an incoming object method call */
int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req,