-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathevent.c
More file actions
87 lines (70 loc) · 2.47 KB
/
event.c
File metadata and controls
87 lines (70 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (C) 2016-2017 prpl Foundation
* Written by Felix Fietkau <nbd@nbd.name>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "scald.h"
struct blob_buf *scald_event_new(struct ubus_object *obj)
{
static struct blob_buf b;
if (!obj->has_subscribers)
return NULL;
blob_buf_init(&b, 0);
return &b;
}
void scald_event_add_ptr(struct blob_buf *buf, struct scapi_ptr *ptr,
enum scapi_ptr_type type)
{
struct scald_model *m = container_of(ptr->model, struct scald_model, scapi);
void *c;
if (!buf)
return;
blobmsg_add_string(buf, "model", m->scapi.name);
blobmsg_add_string(buf, "plugin", ptr->plugin->name);
if (type == SCAPI_PTR_PLUGIN)
return;
c = blobmsg_open_array(buf, "path");
if (ptr->path)
blob_put_raw(buf, blobmsg_data(ptr->path), blobmsg_data_len(ptr->path));
if (type == SCAPI_PTR_OBJ_ENTRY)
blobmsg_add_string(buf, NULL, ptr->obj->name);
blobmsg_close_array(buf, c);
if (ptr->plugin->object_get_acl)
ptr->plugin->object_get_acl(ptr, buf);
if (type < SCAPI_PTR_PARAM)
return;
blobmsg_add_string(buf, "param", ptr->par->name);
if (ptr->plugin->param_get_acl)
ptr->plugin->param_get_acl(ptr, buf);
if (type == SCAPI_PTR_PARAM_VALUE)
blobmsg_add_field(buf, blobmsg_type(ptr->value), "value",
blobmsg_data(ptr->value),
blobmsg_data_len(ptr->value));
}
void scald_event_notify(const char *type, struct scapi_ptr *ptr,
enum scapi_ptr_type ptr_type)
{
struct scald_model *m = container_of(ptr->model, struct scald_model, scapi);
struct blob_buf *buf;
buf = scald_event_new(&m->ubus);
if (!buf)
buf = scald_event_new(&main_object);
if (!buf) {
fprintf(stderr, "no buf\n");
return;
}
scald_event_add_ptr(buf, ptr, ptr_type);
ubus_notify(ubus_ctx, &m->ubus, type, buf->head, -1);
ubus_notify(ubus_ctx, &main_object, type, buf->head, -1);
}