Skip to content

Commit

Permalink
Merge pull request #652 from jean-roland/ft_background_declaration
Browse files Browse the repository at this point in the history
Add background declaration
  • Loading branch information
milyin authored Sep 12, 2024
2 parents eef549b + cdf7f49 commit 4150752
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 34 deletions.
44 changes: 16 additions & 28 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,14 +1053,7 @@ bool z_string_is_empty(const z_loaned_string_t *str) { return _z_string_is_empty
const z_loaned_slice_t *z_string_as_slice(const z_loaned_string_t *str) { return &str->_slice; }

#if Z_FEATURE_PUBLICATION == 1
int8_t _z_undeclare_and_clear_publisher(_z_publisher_t *pub) {
int8_t ret = _Z_RES_OK;
ret = _z_undeclare_publisher(pub);
_z_publisher_clear(pub);
return ret;
}

void _z_publisher_drop(_z_publisher_t *pub) { _z_undeclare_and_clear_publisher(pub); }
void _z_publisher_drop(_z_publisher_t *pub) { _z_publisher_clear(pub); }

_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_publisher_t, publisher, _z_publisher_check, _z_publisher_null,
_z_publisher_drop)
Expand Down Expand Up @@ -1191,7 +1184,11 @@ int8_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *z
return _Z_RES_OK;
}

int8_t z_undeclare_publisher(z_moved_publisher_t *pub) { return _z_undeclare_and_clear_publisher(&pub->_this._val); }
int8_t z_undeclare_publisher(z_moved_publisher_t *pub) {
int8_t ret = _z_undeclare_publisher(&pub->_this._val);
_z_publisher_clear(&pub->_this._val);
return ret;
}

void z_publisher_put_options_default(z_publisher_put_options_t *options) {
options->encoding = NULL;
Expand Down Expand Up @@ -1372,15 +1369,7 @@ _Bool z_reply_replier_id(const z_loaned_reply_t *reply, z_id_t *out_id) {
#if Z_FEATURE_QUERYABLE == 1
_Z_OWNED_FUNCTIONS_RC_IMPL(query)

int8_t _z_undeclare_and_clear_queryable(_z_queryable_t *queryable) {
int8_t ret = _Z_RES_OK;

ret = _z_undeclare_queryable(queryable);
_z_queryable_clear(queryable);
return ret;
}

void _z_queryable_drop(_z_queryable_t *queryable) { _z_undeclare_and_clear_queryable(queryable); }
void _z_queryable_drop(_z_queryable_t *queryable) { _z_queryable_clear(queryable); }

_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_queryable_t, queryable, _z_queryable_check, _z_queryable_null,
_z_queryable_drop)
Expand Down Expand Up @@ -1421,7 +1410,9 @@ int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_sessio
}

int8_t z_undeclare_queryable(z_moved_queryable_t *queryable) {
return _z_undeclare_and_clear_queryable(&queryable->_this._val);
int8_t ret = _z_undeclare_queryable(&queryable->_this._val);
_z_queryable_clear(&queryable->_this._val);
return ret;
}

void z_query_reply_options_default(z_query_reply_options_t *options) {
Expand Down Expand Up @@ -1585,14 +1576,7 @@ int8_t z_undeclare_keyexpr(z_moved_keyexpr_t *keyexpr, const z_loaned_session_t
}

#if Z_FEATURE_SUBSCRIPTION == 1
int8_t _z_undeclare_and_clear_subscriber(_z_subscriber_t *sub) {
int8_t ret = _Z_RES_OK;
ret = _z_undeclare_subscriber(sub);
_z_subscriber_clear(sub);
return ret;
}

void _z_subscriber_drop(_z_subscriber_t *sub) { _z_undeclare_and_clear_subscriber(sub); }
void _z_subscriber_drop(_z_subscriber_t *sub) { _z_subscriber_clear(sub); }

_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_subscriber_t, subscriber, _z_subscriber_check, _z_subscriber_null,
_z_subscriber_drop)
Expand Down Expand Up @@ -1649,7 +1633,11 @@ int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t
}
}

int8_t z_undeclare_subscriber(z_moved_subscriber_t *sub) { return _z_undeclare_and_clear_subscriber(&sub->_this._val); }
int8_t z_undeclare_subscriber(z_moved_subscriber_t *sub) {
int8_t ret = _z_undeclare_subscriber(&sub->_this._val);
_z_subscriber_clear(&sub->_this._val);
return ret;
}

const z_loaned_keyexpr_t *z_subscriber_keyexpr(const z_loaned_subscriber_t *sub) {
// Retrieve keyexpr from session
Expand Down
3 changes: 0 additions & 3 deletions src/net/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ int8_t _z_undeclare_publisher(_z_publisher_t *pub) {
// Clear publisher
_z_write_filter_destroy(pub);
_z_undeclare_resource(_Z_RC_IN_VAL(&pub->_zn), pub->_key._id);
_z_session_weak_drop(&pub->_zn);
return _Z_RES_OK;
}

Expand Down Expand Up @@ -250,7 +249,6 @@ int8_t _z_undeclare_subscriber(_z_subscriber_t *sub) {
// Only if message is successfully send, local subscription state can be removed
_z_undeclare_resource(_Z_RC_IN_VAL(&sub->_zn), _Z_RC_IN_VAL(s)->_key_id);
_z_unregister_subscription(_Z_RC_IN_VAL(&sub->_zn), _Z_RESOURCE_IS_LOCAL, s);
_z_session_weak_drop(&sub->_zn);
return _Z_RES_OK;
}
#endif
Expand Down Expand Up @@ -313,7 +311,6 @@ int8_t _z_undeclare_queryable(_z_queryable_t *qle) {
_z_n_msg_clear(&n_msg);
// Only if message is successfully send, local queryable state can be removed
_z_unregister_session_queryable(_Z_RC_IN_VAL(&qle->_zn), q);
_z_session_weak_drop(&qle->_zn);
return _Z_RES_OK;
}

Expand Down
1 change: 1 addition & 0 deletions src/net/publish.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#if Z_FEATURE_PUBLICATION == 1
void _z_publisher_clear(_z_publisher_t *pub) {
_z_keyexpr_clear(&pub->_key);
_z_session_weak_drop(&pub->_zn);
*pub = _z_publisher_null();
}

Expand Down
2 changes: 1 addition & 1 deletion src/net/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ _z_queryable_t _z_queryable_null(void) { return (_z_queryable_t){._entity_id = 0
_Bool _z_queryable_check(const _z_queryable_t *queryable) { return !_Z_RC_IS_NULL(&queryable->_zn); }

void _z_queryable_clear(_z_queryable_t *qbl) {
// Nothing to clear
_z_session_weak_drop(&qbl->_zn);
*qbl = _z_queryable_null();
}

Expand Down
3 changes: 1 addition & 2 deletions src/net/subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#if Z_FEATURE_SUBSCRIPTION == 1

void _z_subscriber_clear(_z_subscriber_t *sub) {
// Nothing to clear
(void)(sub);
_z_session_weak_drop(&sub->_zn);
*sub = _z_subscriber_null();
}

Expand Down

0 comments on commit 4150752

Please sign in to comment.