Skip to content

Commit

Permalink
fix: fuse identical functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Feb 20, 2024
1 parent 18649c3 commit 68eca1f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 35 deletions.
1 change: 0 additions & 1 deletion include/zenoh-pico/session/interest.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ void _z_flush_interest(_z_session_t *zn);
#endif // Z_FEATURE_INTEREST == 1

int8_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *decl);
int8_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *decl);
int8_t _z_interest_process_final_interest(_z_session_t *zn, uint32_t id);
int8_t _z_interest_process_undeclare_interest(_z_session_t *zn, uint32_t id);
int8_t _z_interest_process_declare_interest(_z_session_t *zn, _z_keyexpr_t key, uint32_t id, uint8_t flags);
Expand Down
34 changes: 2 additions & 32 deletions src/session/interest.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,37 +127,6 @@ int8_t _z_interest_process_declares(_z_session_t *zn, const _z_declaration_t *de
msg.id = decl->_body._decl_queryable._id;
decl_key = &decl->_body._decl_queryable._keyexpr;
break;
default:
return _Z_ERR_MESSAGE_ZENOH_DECLARATION_UNKNOWN;
}
_zp_session_lock_mutex(zn);
_z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, decl_key);
if (key._suffix == NULL) {
_zp_session_unlock_mutex(zn);
return _Z_ERR_KEYEXPR_UNKNOWN;
}
_z_session_interest_rc_list_t *intrs = __unsafe_z_get_interest_by_key(zn, key);
_zp_session_unlock_mutex(zn);

// Parse session_interest list
_z_session_interest_rc_list_t *xs = intrs;
while (xs != NULL) {
_z_session_interest_rc_t *intr = _z_session_interest_rc_list_head(xs);
if (intr->in->val._callback != NULL) {
intr->in->val._callback(&msg, intr->in->val._arg);
}
xs = _z_session_interest_rc_list_tail(xs);
}
// Clean up
_z_keyexpr_clear(&key);
_z_session_interest_rc_list_free(&intrs);
return _Z_RES_OK;
}

int8_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *decl) {
const _z_keyexpr_t *decl_key = NULL;
_z_interest_msg_t msg;
switch (decl->_tag) {
case _Z_UNDECL_SUBSCRIBER:
msg.type = _Z_INTEREST_MSG_TYPE_UNDECL_SUBSCRIBER;
msg.id = decl->_body._undecl_subscriber._id;
Expand All @@ -173,7 +142,8 @@ int8_t _z_interest_process_undeclares(_z_session_t *zn, const _z_declaration_t *
}
_zp_session_lock_mutex(zn);
_z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, decl_key);
if (key._suffix != NULL) {
if (key._suffix == NULL) {
_z_keyexpr_clear(&key);
_zp_session_unlock_mutex(zn);
return _Z_ERR_KEYEXPR_UNKNOWN;

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
}
Expand Down
4 changes: 2 additions & 2 deletions src/session/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint
_z_interest_process_declares(zn, &decl._decl);
} break;
case _Z_UNDECL_SUBSCRIBER: {
_z_interest_process_undeclares(zn, &decl._decl);
_z_interest_process_declares(zn, &decl._decl);
} break;
case _Z_UNDECL_QUERYABLE: {
_z_interest_process_undeclares(zn, &decl._decl);
_z_interest_process_declares(zn, &decl._decl);
} break;
case _Z_DECL_TOKEN: {
// TODO: add support or explicitly discard
Expand Down

0 comments on commit 68eca1f

Please sign in to comment.