mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Align event schema
This commit is contained in:
parent
72207e3aa1
commit
3856d77dfd
8 changed files with 43 additions and 38 deletions
|
|
@ -889,7 +889,7 @@ enum {
|
|||
|
||||
static const struct blobmsg_policy dm_notify_event_policy[] = {
|
||||
[BBF_NOTIFY_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
|
||||
[BBF_NOTIFY_PRAMS] = { .name = "input", .type = BLOBMSG_TYPE_TABLE },
|
||||
[BBF_NOTIFY_PRAMS] = { .name = "input", .type = BLOBMSG_TYPE_ARRAY },
|
||||
};
|
||||
|
||||
static int bbfdm_notify_event(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
|
|
|
|||
|
|
@ -744,7 +744,7 @@
|
|||
"type": "string"
|
||||
},
|
||||
"input": {
|
||||
"type": "object",
|
||||
"type": "array",
|
||||
"properties": {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -886,7 +886,7 @@ All items must be of the type: Unknown type ``.
|
|||
|
||||
| Property | Type | Required |
|
||||
| -------- | ------ | ------------ |
|
||||
| `input` | object | Optional |
|
||||
| `input` | array | Optional |
|
||||
| `name` | string | **Required** |
|
||||
|
||||
#### input
|
||||
|
|
@ -894,15 +894,11 @@ All items must be of the type: Unknown type ``.
|
|||
`input`
|
||||
|
||||
- is optional
|
||||
- type: `object`
|
||||
- type: `array`
|
||||
|
||||
##### input Type
|
||||
|
||||
`object` with following properties:
|
||||
|
||||
| Property | Type | Required |
|
||||
| -------- | ---- | -------- |
|
||||
| None | None | None |
|
||||
Array type: `array`
|
||||
|
||||
#### name
|
||||
|
||||
|
|
@ -918,7 +914,7 @@ All items must be of the type: Unknown type ``.
|
|||
### Ubus CLI Example
|
||||
|
||||
```
|
||||
ubus call bbf notify_event {"name":"","input":{}}
|
||||
ubus call bbf notify_event {"name":"voluptate sit deserunt ut minim","input":[]}
|
||||
```
|
||||
|
||||
### JSONRPC Example
|
||||
|
|
@ -928,7 +924,7 @@ ubus call bbf notify_event {"name":"","input":{}}
|
|||
"jsonrpc": "2.0",
|
||||
"id": 0,
|
||||
"method": "call",
|
||||
"params": ["<SID>", "bbf", "notify_event", { "name": "", "input": {} }]
|
||||
"params": ["<SID>", "bbf", "notify_event", { "name": "voluptate sit deserunt ut minim", "input": [] }]
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ Following are the ubus methods exposed by `bbfdmd` main process:
|
|||
"add":{"path":"String","obj_path":"Table","optional":"Table"}
|
||||
"del":{"path":"String","paths":"Array","optional":"Table"}
|
||||
"service":{"cmd":"String","name":"String","parent_dm":"String","objects":"Array"}
|
||||
"notify_event":{"name":"String","input":"Table"}
|
||||
"notify_event":{"name":"String","input":"Array"}
|
||||
```
|
||||
|
||||
Each datamodel micro-service expose their own ubus object, which is slightly different from main `bbfdm` ubus object, following is an example of ubus methods exposed by datamodel micro-services.
|
||||
|
|
|
|||
|
|
@ -690,7 +690,7 @@ static void bb_add_flags_arr(struct blob_buf *bb, uint32_t dm_flags)
|
|||
blobmsg_close_array(bb, flags_arr);
|
||||
}
|
||||
|
||||
void fill_blob_param(struct blob_buf *bb, char *path, char *data, char *type, uint32_t dm_flags)
|
||||
void fill_blob_param(struct blob_buf *bb, const char *path, const char *data, const char *type, uint32_t dm_flags)
|
||||
{
|
||||
if (!bb || !path || !data || !type)
|
||||
return;
|
||||
|
|
@ -705,7 +705,7 @@ void fill_blob_param(struct blob_buf *bb, char *path, char *data, char *type, ui
|
|||
blobmsg_close_table(bb, table);
|
||||
}
|
||||
|
||||
void fill_blob_event(struct blob_buf *bb, char *path, char *type, void *data)
|
||||
void fill_blob_event(struct blob_buf *bb, const char *path, const char *type, void *data)
|
||||
{
|
||||
if (!bb || !path || !type)
|
||||
return;
|
||||
|
|
@ -737,7 +737,7 @@ void fill_blob_event(struct blob_buf *bb, char *path, char *type, void *data)
|
|||
blobmsg_close_table(bb, table);
|
||||
}
|
||||
|
||||
void fill_blob_operate(struct blob_buf *bb, char *path, char *data, char *type, void *in_out)
|
||||
void fill_blob_operate(struct blob_buf *bb, const char *path, const char *data, const char *type, void *in_out)
|
||||
{
|
||||
if (!bb || !path || !data || !type)
|
||||
return;
|
||||
|
|
@ -2710,11 +2710,11 @@ static int mparam_event(DMPARAM_ARGS)
|
|||
dmctx->stop = 1;
|
||||
|
||||
blobmsg_add_string(&dmctx->bb, "name", full_param);
|
||||
void *table = blobmsg_open_table(&dmctx->bb, "input");
|
||||
void *array = blobmsg_open_array(&dmctx->bb, "input");
|
||||
|
||||
fault = (leaf->setvalue)(full_param, dmctx, data, instance, (char *)j_input, EVENT_RUN);
|
||||
|
||||
blobmsg_close_table(&dmctx->bb, table);
|
||||
blobmsg_close_array(&dmctx->bb, array);
|
||||
|
||||
end:
|
||||
json_object_put(j_input);
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ char *handle_instance(struct dmctx *dmctx, DMNODE *parent_node, struct uci_secti
|
|||
char *handle_instance_without_section(struct dmctx *dmctx, DMNODE *parent_node, int inst_nbr);
|
||||
int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
|
||||
|
||||
void fill_blob_param(struct blob_buf *bb, char *path, char *data, char *type, uint32_t dm_flags);
|
||||
void fill_blob_event(struct blob_buf *bb, char *path, char *type, void *data);
|
||||
void fill_blob_operate(struct blob_buf *bb, char *path, char *data, char *type, void *in_out);
|
||||
void fill_blob_param(struct blob_buf *bb, const char *path, const char *data, const char *type, uint32_t dm_flags);
|
||||
void fill_blob_event(struct blob_buf *bb, const char *path, const char *type, void *data);
|
||||
void fill_blob_operate(struct blob_buf *bb, const char *path, const char *data, const char *type, void *in_out);
|
||||
|
||||
int string_to_bool(char *v, bool *b);
|
||||
char *get_value_by_reference(struct dmctx *ctx, char *value);
|
||||
|
|
|
|||
|
|
@ -386,33 +386,42 @@ static void send_transfer_complete_event(const char *command, const char *obj_pa
|
|||
{
|
||||
char start_time[32] = {0};
|
||||
char complete_time[32] = {0};
|
||||
unsigned fault_code = 0;
|
||||
struct blob_buf bb;
|
||||
|
||||
strftime(start_time, sizeof(start_time), "%Y-%m-%dT%H:%M:%SZ", gmtime(&start_t));
|
||||
strftime(complete_time, sizeof(complete_time), "%Y-%m-%dT%H:%M:%SZ", gmtime(&complete_t));
|
||||
|
||||
if (DM_STRLEN(fault_string) != 0)
|
||||
fault_code = USP_FAULT_GENERAL_FAILURE;
|
||||
memset(&bb, 0, sizeof(struct blob_buf));
|
||||
blob_buf_init(&bb, 0);
|
||||
|
||||
struct json_object *obj = json_object_new_object();
|
||||
blobmsg_add_string(&bb, "name", "Device.LocalAgent.TransferComplete!");
|
||||
void *arr = blobmsg_open_array(&bb, "input");
|
||||
|
||||
json_object_object_add(obj, "Command", json_object_new_string(command));
|
||||
fill_blob_param(&bb, "Command", command, DMT_TYPE[DMT_STRING], 0);
|
||||
if(commandKey)
|
||||
json_object_object_add(obj, "CommandKey", json_object_new_string(commandKey));
|
||||
fill_blob_param(&bb, "CommandKey", commandKey, DMT_TYPE[DMT_STRING], 0);
|
||||
else
|
||||
json_object_object_add(obj, "CommandKey", json_object_new_string(""));
|
||||
json_object_object_add(obj, "Requestor", json_object_new_string(""));
|
||||
json_object_object_add(obj, "TransferType", json_object_new_string(transfer_type));
|
||||
json_object_object_add(obj, "Affected", json_object_new_string(obj_path));
|
||||
json_object_object_add(obj, "TransferURL", json_object_new_string(transfer_url));
|
||||
json_object_object_add(obj, "StartTime", json_object_new_string(start_time));
|
||||
json_object_object_add(obj, "CompleteTime", json_object_new_string(complete_time));
|
||||
json_object_object_add(obj, "FaultCode", json_object_new_uint64(fault_code));
|
||||
json_object_object_add(obj, "FaultString", json_object_new_string(fault_string));
|
||||
fill_blob_param(&bb, "CommandKey", "", DMT_TYPE[DMT_STRING], 0);
|
||||
|
||||
dmubus_call_set("bbfdm", "notify_event", UBUS_ARGS{{"name", "Device.LocalAgent.TransferComplete!", String}, {"input", json_object_to_json_string(obj), Table}}, 2);
|
||||
fill_blob_param(&bb, "Requestor", "", DMT_TYPE[DMT_STRING], 0);
|
||||
fill_blob_param(&bb, "TransferType", transfer_type, DMT_TYPE[DMT_STRING], 0);
|
||||
fill_blob_param(&bb, "Affected", obj_path, DMT_TYPE[DMT_STRING], 0);
|
||||
fill_blob_param(&bb, "TransferURL", transfer_url, DMT_TYPE[DMT_STRING], 0);
|
||||
fill_blob_param(&bb, "StartTime", start_time, DMT_TYPE[DMT_STRING], 0);
|
||||
fill_blob_param(&bb, "CompleteTime", complete_time, DMT_TYPE[DMT_STRING], 0);
|
||||
|
||||
json_object_put(obj);
|
||||
if (DM_STRLEN(fault_string) == 0) {
|
||||
fill_blob_param(&bb, "FaultCode", "0", DMT_TYPE[DMT_STRING], 0);
|
||||
} else {
|
||||
fill_blob_param(&bb, "FaultCode", "7000", DMT_TYPE[DMT_STRING], 0);
|
||||
}
|
||||
|
||||
fill_blob_param(&bb, "FaultString", fault_string, DMT_TYPE[DMT_STRING], 0);
|
||||
blobmsg_close_array(&bb, arr);
|
||||
|
||||
dmubus_call_blob_msg_set("bbfdm", "notify_event", &bb);
|
||||
|
||||
blob_buf_free(&bb);
|
||||
}
|
||||
|
||||
const bool validate_file_system_size(const char *file_size)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ else:
|
|||
|
||||
ubus.listen(("bbfdm.event", callback))
|
||||
|
||||
ubus.call("bbfdm", "notify_event", {"name":"Device.LocalAgent.TransferComplete!", "input":{"param1":"val1", "param2":"val2"}})
|
||||
ubus.call("bbfdm", "notify_event", {"name":"Device.LocalAgent.TransferComplete!", "input":[{"path":"Command","data":"Backup()","type":"xsd:string"},{"path":"CommandKey","data":"","type":"xsd:string"}]})
|
||||
|
||||
ubus.loop()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue