-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add first service registering decorator
- Loading branch information
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import functools | ||
|
||
from tmtccmd.tc.procedure import DefaultProcedureInfo | ||
from tmtccmd.tc.queue import DefaultPusQueueHelper | ||
|
||
SERVICE_HANDLER_DICT = dict() | ||
|
||
|
||
def service_provider(service: str): | ||
"""Decorator. TODO: Documentation""" | ||
global SERVICE_HANDLER_DICT | ||
|
||
def actual_service_decorator(handler): | ||
global SERVICE_HANDLER_DICT | ||
|
||
@functools.wraps(handler) | ||
def service_handler_wrapper( | ||
info: DefaultProcedureInfo, | ||
queue_helper: DefaultPusQueueHelper, | ||
op_code: str, | ||
): | ||
return handler(info, queue_helper, op_code) | ||
|
||
SERVICE_HANDLER_DICT.update({service: service_handler_wrapper}) | ||
return service_handler_wrapper | ||
|
||
return actual_service_decorator | ||
|
||
|
||
def route_to_registered_service_handlers( | ||
info: DefaultProcedureInfo, queue_helper: DefaultPusQueueHelper, op_code: str | ||
) -> bool: | ||
if info.service in SERVICE_HANDLER_DICT: | ||
SERVICE_HANDLER_DICT[info.service](info, queue_helper, op_code) | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters