mirror of
https://github.com/emqx/neuron.git
synced 2026-10-27 04:19:50 +08:00
feat(core): support plugin synchronous read
This commit is contained in:
@@ -769,6 +769,7 @@ static inline void neu_req_inst_templates_fini(neu_req_inst_templates_t *req)
|
||||
typedef struct neu_req_read_group {
|
||||
char driver[NEU_NODE_NAME_LEN];
|
||||
char group[NEU_GROUP_NAME_LEN];
|
||||
bool sync;
|
||||
} neu_req_read_group_t;
|
||||
|
||||
typedef struct neu_req_write_tag {
|
||||
|
||||
@@ -124,6 +124,7 @@ typedef enum {
|
||||
NEU_ERR_PLUGIN_DEVICE_NOT_RESPONSE = 3015,
|
||||
NEU_ERR_PLUGIN_NOT_SUPPORT_TEMPLATE = 3016,
|
||||
NEU_ERR_PLUGIN_NOT_SUPPORT_WRITE_TAGS = 3017,
|
||||
NEU_ERR_PLUGIN_NOT_SUPPORT_READ_SYNC = 3018,
|
||||
|
||||
NEU_ERR_MQTT_FAILURE = 4000,
|
||||
NEU_ERR_MQTT_NO_CERTFILESET = 4001,
|
||||
|
||||
@@ -85,6 +85,7 @@ typedef struct neu_plugin_intf_funs {
|
||||
struct {
|
||||
int (*validate_tag)(neu_plugin_t *plugin, neu_datatag_t *tag);
|
||||
int (*group_timer)(neu_plugin_t *plugin, neu_plugin_group_t *group);
|
||||
int (*group_sync)(neu_plugin_t *plugin, neu_plugin_group_t *group);
|
||||
int (*write_tag)(neu_plugin_t *plugin, void *req,
|
||||
neu_datatag_t *tag, neu_value_u value);
|
||||
int (*write_tags)(
|
||||
|
||||
@@ -405,6 +405,30 @@ void neu_adapter_driver_read_group(neu_adapter_driver_t *driver,
|
||||
|
||||
utarray_push_back(resp.tags, &tag_value);
|
||||
}
|
||||
} else if (cmd->sync) {
|
||||
if (NULL == driver->adapter.module->intf_funs->driver.group_sync) {
|
||||
// plugin does not support sync read
|
||||
utarray_foreach(tags, neu_datatag_t *, tag)
|
||||
{
|
||||
neu_resp_tag_value_meta_t tag_value = { 0 };
|
||||
strcpy(tag_value.tag, tag->name);
|
||||
tag_value.value.type = NEU_TYPE_ERROR;
|
||||
tag_value.value.value.i32 =
|
||||
NEU_ERR_PLUGIN_NOT_SUPPORT_READ_SYNC;
|
||||
|
||||
utarray_push_back(resp.tags, &tag_value);
|
||||
}
|
||||
} else {
|
||||
// sync read to update cache
|
||||
driver->adapter.module->intf_funs->driver.group_sync(
|
||||
driver->adapter.plugin, &g->grp);
|
||||
// fetch updated data from cache
|
||||
read_group(global_timestamp,
|
||||
neu_group_get_interval(group) *
|
||||
NEU_DRIVER_TAG_CACHE_EXPIRE_TIME,
|
||||
neu_adapter_get_tag_cache_type(&driver->adapter),
|
||||
driver->cache, cmd->group, tags, resp.tags);
|
||||
}
|
||||
} else {
|
||||
read_group(global_timestamp,
|
||||
neu_group_get_interval(group) *
|
||||
|
||||
Reference in New Issue
Block a user