#include <sys/time.h>
#include <unistd.h>
#include <libubox/ustream.h>
#include "libubus.h"
#include "count.h"
Go to the source code of this file.
◆ anonymous enum
Enumerator |
---|
RETURN_CODE | |
__RETURN_MAX | |
Definition at line 59 of file client.c.
◆ client_main()
static void client_main |
( |
void |
| ) |
|
|
static |
Definition at line 174 of file client.c.
182 fprintf(stderr,
"Failed to add_object object: %s\n",
ubus_strerror(ret));
187 fprintf(stderr,
"Failed to look up test object\n");
191 blob_buf_init(&
b, 0);
196 blob_buf_init(&
b, 0);
197 blobmsg_add_string(&
b,
"msg",
"blah");
static struct uloop_timeout notify_timer
static struct ubus_context * ctx
static void test_client_fd_cb(struct ubus_request *req, int fd)
static void test_client_notify_cb(struct uloop_timeout *timeout)
static void test_client_complete_cb(struct ubus_request *req, int ret)
static struct uloop_timeout count_timer
static struct ubus_object test_client_object
int ubus_add_object(struct ubus_context *ctx, struct ubus_object *obj)
void ubus_complete_request_async(struct ubus_context *ctx, struct ubus_request *req)
int ubus_lookup_id(struct ubus_context *ctx, const char *path, uint32_t *id)
const char * ubus_strerror(int error)
static int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method, struct blob_attr *msg, struct ubus_request *req)
static 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)
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 208 of file client.c.
210 const char *ubus_socket = NULL;
213 while ((ch = getopt(argc, argv,
"cs:")) != -1) {
216 ubus_socket = optarg;
227 fprintf(stderr,
"Failed to connect to ubus\n");
static void client_main(void)
struct ubus_context * ubus_connect(const char *path)
void ubus_free(struct ubus_context *ctx)
static void ubus_add_uloop(struct ubus_context *ctx)
◆ test_client_complete_cb()
static void test_client_complete_cb |
( |
struct ubus_request * |
req, |
|
|
int |
ret |
|
) |
| |
|
static |
Definition at line 169 of file client.c.
171 fprintf(stderr,
"completed request, ret: %d\n", ret);
◆ test_client_fd_cb()
static void test_client_fd_cb |
( |
struct ubus_request * |
req, |
|
|
int |
fd |
|
) |
| |
|
static |
Definition at line 159 of file client.c.
161 static struct ustream_fd test_fd;
163 fprintf(stderr,
"Got fd from the server, watching...\n");
166 ustream_fd_init(&test_fd, fd);
static void test_client_fd_data_cb(struct ustream *s, int bytes)
◆ test_client_fd_data_cb()
static void test_client_fd_data_cb |
( |
struct ustream * |
s, |
|
|
int |
bytes |
|
) |
| |
|
static |
Definition at line 141 of file client.c.
146 data = ustream_get_read_buf(s, &len);
150 sep = strchr(data,
'\n');
155 fprintf(stderr,
"Got line: %s\n", data);
156 ustream_consume(s, sep + 1 - data);
◆ test_client_notify_cb()
static void test_client_notify_cb |
( |
struct uloop_timeout * |
timeout | ) |
|
|
static |
Definition at line 34 of file client.c.
36 static int counter = 0;
38 struct timeval tv1, tv2;
44 blobmsg_add_u32(&
b,
"counter", counter++);
46 gettimeofday(&tv1, NULL);
47 for (i = 0; i < max; i++)
49 gettimeofday(&tv2, NULL);
53 delta = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec);
54 fprintf(stderr,
"Avg time per iteration: %ld usec\n", delta / max);
56 uloop_timeout_set(
timeout, 1000);
int ubus_notify(struct ubus_context *ctx, struct ubus_object *obj, const char *type, struct blob_attr *msg, int timeout)
◆ test_client_subscribe_cb()
◆ test_count()
static void test_count |
( |
struct uloop_timeout * |
timeout | ) |
|
|
static |
Definition at line 88 of file client.c.
92 COUNT_TO_MAX = 1000000,
97 static uint32_t count_to = 100000;
98 static int count_progression = PROGRESSION;
101 if (count_to <= COUNT_TO_MIN)
102 count_progression = PROGRESSION;
103 else if (count_to >= COUNT_TO_MAX)
104 count_progression = -PROGRESSION;
106 count_to += count_progression;
110 fprintf(stderr,
"Could not allocate memory to count up to '%u'\n", count_to);
114 fprintf(stderr,
"Sending count up to '%u'; string has length '%u'\n",
115 count_to, (uint32_t)strlen(s));
116 blob_buf_init(&
b, 0);
117 blobmsg_add_u32(&
b,
"to", count_to);
118 blobmsg_add_string(&
b,
"string", s);
122 fprintf(stderr,
"Failed to look up test object\n");
130 uloop_timeout_set(
timeout, 2000);
static void test_count_data_cb(struct ubus_request *req, int type, struct blob_attr *msg)
char * count_to_number(uint32_t num)
◆ test_count_data_cb()
static void test_count_data_cb |
( |
struct ubus_request * |
req, |
|
|
int |
type, |
|
|
struct blob_attr * |
msg |
|
) |
| |
|
static |
Definition at line 68 of file client.c.
73 uint32_t count_to = *(uint32_t *)req->
priv;
78 fprintf(stderr,
"No return code received from server\n");
83 fprintf(stderr,
"Corruption of data with count up to '%u'\n", count_to);
85 fprintf(stderr,
"Server validated our count up to '%u'\n", count_to);
static const struct blobmsg_policy return_policy[__RETURN_MAX]
◆ count_timer
struct uloop_timeout count_timer |
|
static |
Initial value:= {
}
static void test_count(struct uloop_timeout *timeout)
Definition at line 88 of file client.c.
◆ ctx
◆ notify_timer
struct uloop_timeout notify_timer |
|
static |
Initial value:
Definition at line 88 of file client.c.
◆ return_policy
Initial value:= {
[
RETURN_CODE] = { .name =
"rc", .type = BLOBMSG_TYPE_INT32 },
}
Definition at line 34 of file client.c.
◆ test_client_object
Initial value:= {
}
static void test_client_subscribe_cb(struct ubus_context *ctx, struct ubus_object *obj)
Definition at line 25 of file client.c.