Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/thingset.h
Original file line number Diff line number Diff line change
Expand Up @@ -1365,10 +1365,10 @@ enum thingset_callback_reason
};

/** Function to be called before/after read/write operations to groups. */
typedef void (*thingset_group_callback_t)(enum thingset_callback_reason cb_reason);
typedef int (*thingset_group_callback_t)(enum thingset_callback_reason cb_reason);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be useful to add the thingset_data_object as a parameter. You can then call this inside the first deserialize_child loop (where some validation is done already).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably have more of a think about value validation tbh. The more important part right now is state checking (which this MR should now allow), and I guess the idea in my head was to permit specific ranges for specific values (I'm thinking imposing the limits from the BQ reference manual on the corresponding values etc) but that functionality likely wouldn't be elegant when calling a group callback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately, that can probably be added separately regardless IMO as it's nice to have, but not absolutely required right now


/** Function to be called before/after read/write operations to records. */
typedef void (*thingset_records_callback_t)(enum thingset_callback_reason cb_reason, int index);
typedef int (*thingset_records_callback_t)(enum thingset_callback_reason cb_reason, int index);

/** @cond INTERNAL_HIDDEN */

Expand Down
10 changes: 8 additions & 2 deletions src/thingset_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ int thingset_common_update(struct thingset_context *ts)
ts->api->deserialize_map_start(ts);

if (ts->endpoint.object->data.group_callback != NULL) {
ts->endpoint.object->data.group_callback(THINGSET_CALLBACK_PRE_WRITE);
int ret = ts->endpoint.object->data.group_callback(THINGSET_CALLBACK_PRE_WRITE);
if (ret < 0) {
return ts->api->serialize_response(ts, THINGSET_ERR_BAD_REQUEST, "Callback error %i", ret);
}
}

/* actually write data */
Expand All @@ -364,7 +367,10 @@ int thingset_common_update(struct thingset_context *ts)
}

if (ts->endpoint.object->data.group_callback != NULL) {
ts->endpoint.object->data.group_callback(THINGSET_CALLBACK_POST_WRITE);
int ret = ts->endpoint.object->data.group_callback(THINGSET_CALLBACK_POST_WRITE);
if (ret < 0) {
return ts->api->serialize_response(ts, THINGSET_ERR_BAD_REQUEST, "Callback error %i", ret);
}
}

/*
Expand Down