#include <unistd.h>
#include <signal.h>
#include <libubox/blobmsg_json.h>
#include "libubus.h"
#include "count.h"
Go to the source code of this file.
|
static void | test_hello_fd_reply (struct uloop_timeout *t) |
|
static void | test_hello_reply (struct uloop_timeout *t) |
|
static int | test_hello (struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) |
|
static void | test_handle_remove (struct ubus_context *ctx, struct ubus_subscriber *s, uint32_t id) |
|
static int | test_notify (struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) |
|
static int | test_watch (struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) |
|
static int | test_count (struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) |
|
static void | server_main (void) |
|
int | main (int argc, char **argv) |
|
◆ anonymous enum
Enumerator |
---|
HELLO_ID | |
HELLO_MSG | |
__HELLO_MAX | |
Definition at line 25 of file server.c.
◆ anonymous enum
Enumerator |
---|
WATCH_ID | |
WATCH_COUNTER | |
__WATCH_MAX | |
Definition at line 108 of file server.c.
◆ anonymous enum
Enumerator |
---|
COUNT_TO | |
COUNT_STRING | |
__COUNT_MAX | |
Definition at line 160 of file server.c.
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 229 of file server.c.
231 const char *ubus_socket = NULL;
234 while ((ch = getopt(argc, argv,
"cs:")) != -1) {
237 ubus_socket = optarg;
245 signal(SIGPIPE, SIG_IGN);
249 fprintf(stderr,
"Failed to connect to ubus\n");
struct ubus_context * ubus_connect(const char *path)
void ubus_free(struct ubus_context *ctx)
static void ubus_add_uloop(struct ubus_context *ctx)
static struct ubus_context * ctx
static void server_main(void)
◆ server_main()
static void server_main |
( |
void |
| ) |
|
|
static |
Definition at line 214 of file server.c.
220 fprintf(stderr,
"Failed to add object: %s\n",
ubus_strerror(ret));
224 fprintf(stderr,
"Failed to add watch handler: %s\n",
ubus_strerror(ret));
int ubus_add_object(struct ubus_context *ctx, struct ubus_object *obj)
int ubus_register_subscriber(struct ubus_context *ctx, struct ubus_subscriber *s)
const char * ubus_strerror(int error)
static struct ubus_object test_object
static struct ubus_subscriber test_event
◆ test_count()
Definition at line 171 of file server.c.
183 num = blobmsg_get_u32(tb[
COUNT_TO]);
190 blob_buf_init(&
b, 0);
191 blobmsg_add_u32(&
b,
"rc", strcmp(s1, s2));
char * count_to_number(uint32_t num)
int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req, struct blob_attr *msg)
static const struct blobmsg_policy count_policy[__COUNT_MAX]
@ UBUS_STATUS_INVALID_ARGUMENT
@ UBUS_STATUS_UNKNOWN_ERROR
◆ test_handle_remove()
Definition at line 120 of file server.c.
123 fprintf(stderr,
"Object %08x went away\n",
id);
◆ test_hello()
Definition at line 81 of file server.c.
87 const char format[] =
"%s received a message: %s";
88 const char *msgstr =
"(unknown)";
95 size_t len =
sizeof(*hreq) +
sizeof(format) + strlen(obj->
name) + strlen(msgstr) + 1;
96 hreq = calloc(1, len);
100 snprintf(hreq->
data, len, format, obj->
name, msgstr);
103 uloop_timeout_set(&hreq->
timeout, 1000);
static void ubus_defer_request(struct ubus_context *ctx, struct ubus_request_data *req, struct ubus_request_data *new_req)
static const struct blobmsg_policy hello_policy[]
static void test_hello_reply(struct uloop_timeout *t)
struct ubus_request_data req
struct uloop_timeout timeout
◆ test_hello_fd_reply()
static void test_hello_fd_reply |
( |
struct uloop_timeout * |
t | ) |
|
|
static |
Definition at line 44 of file server.c.
49 data = alloca(strlen(
req->data) + 32);
50 sprintf(
data,
"msg%d: %s\n", ++
req->idx,
req->data);
57 uloop_timeout_set(&
req->timeout, 1000);
◆ test_hello_reply()
static void test_hello_reply |
( |
struct uloop_timeout * |
t | ) |
|
|
static |
Definition at line 60 of file server.c.
66 blobmsg_add_string(&
b,
"message",
req->data);
69 if (pipe(fds) == -1) {
70 fprintf(stderr,
"Failed to create pipe\n");
void ubus_complete_deferred_request(struct ubus_context *ctx, struct ubus_request_data *req, int ret)
static void ubus_request_set_fd(struct ubus_context *ctx, struct ubus_request_data *req, int fd)
static void test_hello_fd_reply(struct uloop_timeout *t)
◆ test_notify()
Definition at line 127 of file server.c.
134 str = blobmsg_format_json(msg,
true);
135 fprintf(stderr,
"Received notification '%s': %s\n", method, str);
◆ test_watch()
Definition at line 142 of file server.c.
int ubus_subscribe(struct ubus_context *ctx, struct ubus_subscriber *obj, uint32_t id)
static const struct blobmsg_policy watch_policy[__WATCH_MAX]
static int test_notify(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg)
static void test_handle_remove(struct ubus_context *ctx, struct ubus_subscriber *s, uint32_t id)
ubus_remove_handler_t remove_cb
◆ count_policy
Initial value:= {
[
COUNT_TO] = { .name =
"to", .type = BLOBMSG_TYPE_INT32 },
[
COUNT_STRING] = { .name =
"string", .type = BLOBMSG_TYPE_STRING },
}
Definition at line 142 of file server.c.
◆ ctx
◆ hello_policy
const struct blobmsg_policy hello_policy[] |
|
static |
Initial value:= {
[
HELLO_ID] = { .name =
"id", .type = BLOBMSG_TYPE_INT32 },
[
HELLO_MSG] = { .name =
"msg", .type = BLOBMSG_TYPE_STRING },
}
Definition at line 21 of file server.c.
◆ test_event
◆ test_methods
Initial value:= {
}
#define UBUS_METHOD(_name, _handler, _policy)
static int test_count(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg)
static int test_hello(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg)
static int test_watch(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg)
Definition at line 171 of file server.c.
◆ test_object
Initial value:= {
.name = "test",
}
static struct ubus_object_type test_object_type
static const struct ubus_method test_methods[]
const struct ubus_method * methods
Definition at line 171 of file server.c.
◆ test_object_type
Initial value:=
#define UBUS_OBJECT_TYPE(_name, _methods)
Definition at line 171 of file server.c.
◆ watch_policy
Initial value:= {
[
WATCH_ID] = { .name =
"id", .type = BLOBMSG_TYPE_INT32 },
[
WATCH_COUNTER] = { .name =
"counter", .type = BLOBMSG_TYPE_INT32 },
}
Definition at line 81 of file server.c.