System-reserved channel message types

- a message handler can return logical True to prevent subsequent message handlers from running
- Message types >= 0xff00 are reserved for system/framework messages
This commit is contained in:
Aaron Heise 2023-02-26 11:39:49 -06:00
parent e005826151
commit c00b592ed9
No known key found for this signature in database
GPG key ID: 6BA54088C41DE8BF
3 changed files with 22 additions and 2 deletions

View file

@ -149,7 +149,7 @@ class Channel(contextlib.AbstractContextManager):
self.shutdown()
return False
def register_message_type(self, message_class: Type[MessageBase]):
def register_message_type(self, message_class: Type[MessageBase], *, is_system_type: bool = False):
with self._lock:
if not issubclass(message_class, MessageBase):
raise ChannelException(CEType.ME_INVALID_MSG_TYPE,
@ -157,6 +157,9 @@ class Channel(contextlib.AbstractContextManager):
if message_class.MSGTYPE is None:
raise ChannelException(CEType.ME_INVALID_MSG_TYPE,
f"{message_class} has invalid MSGTYPE class attribute.")
if message_class.MSGTYPE >= 0xff00 and not is_system_type:
raise ChannelException(CEType.ME_INVALID_MSG_TYPE,
f"{message_class} has system-reserved message type.")
try:
message_class()
except Exception as ex: