From 5bcf7880a2c9648ad6e9abc7cbd1c10af36a1abc Mon Sep 17 00:00:00 2001 From: ISP akm Date: Tue, 24 Sep 2024 10:58:36 +0900 Subject: [PATCH 1/3] New class to edit message_context instead of AssignContextReader class Signed-off-by: ISP akm --- .../architecture/architecture.py | 68 +++++-------------- .../architecture/architecture_loaded.py | 9 ++- src/caret_analyze/architecture/util.py | 2 +- 3 files changed, 21 insertions(+), 58 deletions(-) diff --git a/src/caret_analyze/architecture/architecture.py b/src/caret_analyze/architecture/architecture.py index d2642ca52..4d34cc76e 100644 --- a/src/caret_analyze/architecture/architecture.py +++ b/src/caret_analyze/architecture/architecture.py @@ -23,7 +23,7 @@ from .combine_path import CombinePath from .graph_search import NodePathSearcher -from .reader_interface import ArchitectureReader, IGNORE_TOPICS +from .reader_interface import IGNORE_TOPICS from .struct import (CallbackStruct, CommunicationStruct, ExecutorStruct, NodePathStruct, NodeStruct, PathStruct, ServiceCallbackStruct, SubscriptionCallbackStruct, TimerCallbackStruct) @@ -389,13 +389,16 @@ def update_message_context(self, node_name: str, context_type: str, if subscribe_topic_name not in node.subscribe_topic_names: raise ItemNotFoundError('{sub_topic_name} is not found in {node_name}') - context_reader = AssignContextReader(node) - context_reader.update_message_context(context_type, - subscribe_topic_name, publish_topic_name) + context_updater = ContextUpdater(node) + context_updater.update_message_context( + context_type, + subscribe_topic_name, + publish_topic_name + ) node.update_node_path( NodeValuesLoaded._search_node_paths( node, - context_reader, + context_updater.get_message_contexts(node), self._max_callback_construction_order_on_path_searching) ) @@ -425,7 +428,7 @@ def insert_publisher_callback(self, node_name: str, node.update_node_path( NodeValuesLoaded._search_node_paths( node, - AssignContextReader(node), + ContextUpdater(node).get_message_contexts(node), self._max_callback_construction_order_on_path_searching) ) @@ -451,7 +454,7 @@ def insert_variable_passing(self, node_name: str, node.update_node_path( NodeValuesLoaded._search_node_paths( node, - AssignContextReader(node), + ContextUpdater(node).get_message_contexts(node), self._max_callback_construction_order_on_path_searching) ) @@ -481,7 +484,7 @@ def remove_publisher_callback(self, node_name: str, node.update_node_path( NodeValuesLoaded._search_node_paths( node, - AssignContextReader(node), + ContextUpdater(node).get_message_contexts(node), self._max_callback_construction_order_on_path_searching) ) @@ -510,10 +513,10 @@ def remove_variable_passing(self, node_name: str, Util.find_one(lambda x: x.callback_name == callback_name_write, self.callbacks) if callback_read.publish_topics: - context_reader = AssignContextReader(node) + context_updater = ContextUpdater(node) for publish_topic in callback_read.publish_topics: if callback_write.subscribe_topic_name and publish_topic is not None: - context_reader.remove_callback_chain( + context_updater.remove_callback_chain( callback_write.subscribe_topic_name, callback_write.construction_order, publish_topic.topic_name, @@ -521,7 +524,7 @@ def remove_variable_passing(self, node_name: str, node.update_node_path( NodeValuesLoaded._search_node_paths( node, - context_reader, + context_updater.get_message_contexts(node), self._max_callback_construction_order_on_path_searching) ) @@ -709,8 +712,8 @@ def diff_node_subs( return DiffNode(left_node, right_node).diff_node_subs() -class AssignContextReader(ArchitectureReader): - """MessageContext of NodeStruct implemented version of ArchitectureReader.""" +class ContextUpdater: + """MessageContext updater of NodeStruct.""" def __init__(self, node: NodeStruct) -> None: contexts = [path.message_context for path in node.paths] @@ -762,45 +765,6 @@ def remove_callback_chain( def get_message_contexts(self, _) -> Sequence[dict]: return self._contexts - def get_callback_groups(self, node: NodeValue): - pass - - def get_executors(self): - pass - - def get_node_names_and_cb_symbols(self, callback_group_id: str): - pass - - def get_nodes(self): - pass - - def get_paths(self): - pass - - def get_publishers(self, node: NodeValue): - pass - - def get_service_callbacks(self, node: NodeValue): - pass - - def get_services(self, node: NodeValue): - pass - - def get_subscription_callbacks(self, node: NodeValue): - pass - - def get_subscriptions(self, node: NodeValue): - pass - - def get_timer_callbacks(self, node: NodeValue): - pass - - def get_timers(self, node: NodeValue): - pass - - def get_variable_passings(self, node: NodeValue): - pass - # NOTE: DiffArchitecture may be changed when it is refactored. class DiffArchitecture: diff --git a/src/caret_analyze/architecture/architecture_loaded.py b/src/caret_analyze/architecture/architecture_loaded.py index bd2f6446a..313723701 100644 --- a/src/caret_analyze/architecture/architecture_loaded.py +++ b/src/caret_analyze/architecture/architecture_loaded.py @@ -484,7 +484,7 @@ def _create_node( node_paths = \ NodeValuesLoaded._search_node_paths( node_struct, - reader, + reader.get_message_contexts(node), max_callback_construction_order_on_path_searching ) node_path_added = NodeStruct( @@ -506,7 +506,7 @@ def _create_node( @staticmethod def _search_node_paths( node: NodeStruct, - reader: ArchitectureReader, + contexts: Sequence[dict], max_callback_construction_order: int ) -> list[NodePathStruct]: @@ -587,7 +587,7 @@ def _search_node_paths( ) message_contexts: list[MessageContextStruct] = [] - message_contexts += list(MessageContextsLoaded(reader, node, node_paths).data) + message_contexts += list(MessageContextsLoaded(contexts, node, node_paths).data) # assign message context to each node paths node_paths = NodeValuesLoaded._message_context_assigned( @@ -641,14 +641,13 @@ def _message_context_assigned( class MessageContextsLoaded: def __init__( self, - reader: ArchitectureReader, + context_dicts: Sequence[dict], node: NodeStruct, node_paths: Sequence[NodePathStruct] ) -> None: self._data: list[MessageContextStruct] data: list[MessageContextStruct] = [] - context_dicts = reader.get_message_contexts(NodeValue(node.node_name, None)) pub_sub_pairs: list[tuple[str | None, str | None]] = [] for context_dict in context_dicts: try: diff --git a/src/caret_analyze/architecture/util.py b/src/caret_analyze/architecture/util.py index f4128b609..72bd1e34a 100644 --- a/src/caret_analyze/architecture/util.py +++ b/src/caret_analyze/architecture/util.py @@ -41,7 +41,7 @@ def check_procedure( paths = NodeValuesLoaded._search_node_paths( node, - reader, + reader.get_message_contexts(node), app_arch._max_callback_construction_order_on_path_searching ) From 7fd9003cf6145dcb6f765b5d78b6d7e6394ddbe9 Mon Sep 17 00:00:00 2001 From: ISP akm Date: Tue, 24 Sep 2024 11:16:07 +0900 Subject: [PATCH 2/3] Delete unused import Signed-off-by: ISP akm --- src/caret_analyze/architecture/architecture.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/caret_analyze/architecture/architecture.py b/src/caret_analyze/architecture/architecture.py index 4d34cc76e..136d64c2c 100644 --- a/src/caret_analyze/architecture/architecture.py +++ b/src/caret_analyze/architecture/architecture.py @@ -31,7 +31,7 @@ from ..exceptions import InvalidArgumentError, ItemNotFoundError, UnsupportedTypeError from ..value_objects import (CallbackGroupStructValue, CallbackStructValue, CommunicationStructValue, DiffNode, ExecutorStructValue, - NodePathStructValue, NodeStructValue, NodeValue, PathStructValue, + NodePathStructValue, NodeStructValue, PathStructValue, PublisherStructValue, ServiceStructValue, SubscriptionStructValue) logger = logging.getLogger(__name__) From ada86f2a6c9613a66eefbbd408ed777d66a70130 Mon Sep 17 00:00:00 2001 From: ISP akm Date: Wed, 25 Sep 2024 15:15:33 +0900 Subject: [PATCH 3/3] ContextUpdater's get_message_contexts method argument should be removed Signed-off-by: ISP akm --- src/caret_analyze/architecture/architecture.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/caret_analyze/architecture/architecture.py b/src/caret_analyze/architecture/architecture.py index 136d64c2c..6469b8fd7 100644 --- a/src/caret_analyze/architecture/architecture.py +++ b/src/caret_analyze/architecture/architecture.py @@ -398,7 +398,7 @@ def update_message_context(self, node_name: str, context_type: str, node.update_node_path( NodeValuesLoaded._search_node_paths( node, - context_updater.get_message_contexts(node), + context_updater.get_message_contexts(), self._max_callback_construction_order_on_path_searching) ) @@ -428,7 +428,7 @@ def insert_publisher_callback(self, node_name: str, node.update_node_path( NodeValuesLoaded._search_node_paths( node, - ContextUpdater(node).get_message_contexts(node), + ContextUpdater(node).get_message_contexts(), self._max_callback_construction_order_on_path_searching) ) @@ -454,7 +454,7 @@ def insert_variable_passing(self, node_name: str, node.update_node_path( NodeValuesLoaded._search_node_paths( node, - ContextUpdater(node).get_message_contexts(node), + ContextUpdater(node).get_message_contexts(), self._max_callback_construction_order_on_path_searching) ) @@ -484,7 +484,7 @@ def remove_publisher_callback(self, node_name: str, node.update_node_path( NodeValuesLoaded._search_node_paths( node, - ContextUpdater(node).get_message_contexts(node), + ContextUpdater(node).get_message_contexts(), self._max_callback_construction_order_on_path_searching) ) @@ -524,7 +524,7 @@ def remove_variable_passing(self, node_name: str, node.update_node_path( NodeValuesLoaded._search_node_paths( node, - context_updater.get_message_contexts(node), + context_updater.get_message_contexts(), self._max_callback_construction_order_on_path_searching) ) @@ -762,7 +762,7 @@ def remove_callback_chain( 'callback_chain') ] - def get_message_contexts(self, _) -> Sequence[dict]: + def get_message_contexts(self) -> Sequence[dict]: return self._contexts