Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in unregister_listener method #17

Merged
merged 1 commit into from
Aug 26, 2024
Merged
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
12 changes: 6 additions & 6 deletions up_transport_zenoh/uptransportzenoh.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,33 +340,33 @@ async def unregister_listener(
# Publish & Notification
if flag & (MessageFlag.PUBLISH | MessageFlag.NOTIFICATION):
# Get Zenoh key
zenoh_key = ZenohUtils.to_zenoh_key_string(source_filter, sink_filter)
zenoh_key = ZenohUtils.to_zenoh_key_string(self.authority_name, source_filter, sink_filter)
return self._remove_publish_listener(zenoh_key, listener)
# RPC request
if flag & MessageFlag.REQUEST:
# Get Zenoh key
zenoh_key = ZenohUtils.to_zenoh_key_string(source_filter, sink_filter)
zenoh_key = ZenohUtils.to_zenoh_key_string(self.authority_name, source_filter, sink_filter)
return self._remove_request_listener(zenoh_key, listener) # RPC response
if flag & MessageFlag.RESPONSE:
if sink_filter is not None:
# Get Zenoh key
zenoh_key = ZenohUtils.to_zenoh_key_string(sink_filter, source_filter)
zenoh_key = ZenohUtils.to_zenoh_key_string(self.authority_name, sink_filter, source_filter)
return self._remove_response_listener(zenoh_key)
else:
return UStatus(code=UCode.INVALID_ARGUMENT, message="Sink should not be None in Response")

def _remove_response_listener(self, zenoh_key: str) -> UStatus:
with self.rpc_callback_lock:
if self.rpc_callback_map.pop(zenoh_key, None) is None:
msg = "RPC response callback doesn't exist"
msg = f"RPC response callback doesn't exist for : {zenoh_key}"
logging.error(msg)
return UStatus(code=UCode.NOT_FOUND, message=msg)
return UStatus(code=UCode.OK)

def _remove_publish_listener(self, zenoh_key: str, listener: UListener) -> UStatus:
with self.subscriber_lock:
if self.subscriber_map.pop((zenoh_key, listener), None) is None:
msg = "Listener not registered for filters: {source_filter}, {sink_filter}"
msg = f"Listener not registered for : {zenoh_key}"
logging.error(msg)
return UStatus(code=UCode.NOT_FOUND, message=msg)

Expand All @@ -375,7 +375,7 @@ def _remove_publish_listener(self, zenoh_key: str, listener: UListener) -> UStat
def _remove_request_listener(self, zenoh_key: str, listener: UListener) -> UStatus:
with self.queryable_lock:
if self.queryable_map.pop((zenoh_key, listener), None) is None:
msg = "RPC request listener doesn't exist"
msg = f"RPC request listener doesn't exist for : {zenoh_key}"
logging.error(msg)
return UStatus(code=UCode.NOT_FOUND, message=msg)
return UStatus(code=UCode.OK, message="Listener removed successfully")
Loading