Skip to content
This repository has been archived by the owner on Sep 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #12 from mwielpue/bugfix/EAF-665-pending-subscript…
Browse files Browse the repository at this point in the history
…ions

(EAF-665) Fixed subscription to later added nodes in C-SDK
  • Loading branch information
fuersten authored Dec 12, 2017
2 parents 7277758 + 2df1719 commit 0bb33f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
32 changes: 17 additions & 15 deletions sdk/src/msg/sub_response.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,31 @@ int dslink_response_sub(DSLink *link, json_t *paths, json_t *rid) {
json_t *value;
json_array_foreach(paths, index, value) {
const char *path = json_string_value(json_object_get(value, "path"));
DSNode *node = dslink_node_get_path(root, path);
if (!node) {
continue;
}
uint32_t *sid = dslink_malloc(sizeof(uint32_t));
if (!sid) {
return DSLINK_ALLOC_ERR;
}
*sid = (uint32_t) json_integer_value(json_object_get(value, "sid"));
ref_t *ref = dslink_int_ref(*sid);
if (dslink_map_set(link->responder->value_path_subs,
dslink_ref((char *) node->path, NULL),
ref) != 0) {
dslink_free(sid);
return 1;
ref_t *pathRef = dslink_str_ref( path );
if (dslink_map_set(link->responder->value_path_subs, pathRef, ref) != 0) {
dslink_free(sid);
dslink_decref(ref);
dslink_decref(pathRef);
return 1;
}
if (dslink_map_set(link->responder->value_sid_subs,
dslink_incref(ref),
dslink_ref((char *) node->path, NULL)) != 0) {
dslink_map_remove(link->responder->value_path_subs,
(char *) node->path);
dslink_free(sid);
return 1;
dslink_incref(ref), dslink_incref(pathRef)) != 0) {
dslink_map_remove(link->responder->value_path_subs, (void*)path);
dslink_free(sid);
dslink_decref(ref);
dslink_decref(pathRef);
return 1;
}

DSNode *node = dslink_node_get_path(root, path);
if (!node) {
continue;
}

dslink_response_send_val(link, node, *sid);
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ int dslink_node_add_child(DSLink *link, DSNode *node) {
}
}

ref_t *sid = dslink_map_get(link->responder->value_path_subs,
(void *) node->path);
if (sid && node->on_subscribe) {
node->on_subscribe(link, node);
}

if (!link->_ws) {
return ret;
}
Expand Down

0 comments on commit 0bb33f8

Please sign in to comment.