Skip to content

Commit

Permalink
New class to edit message_context instead of AssignContextReader class
Browse files Browse the repository at this point in the history
Signed-off-by: ISP akm <[email protected]>
  • Loading branch information
xygyo77 committed Sep 24, 2024
1 parent 9ede8ba commit 5bcf788
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 58 deletions.
68 changes: 16 additions & 52 deletions src/caret_analyze/architecture/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
)

Expand Down Expand Up @@ -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)
)

Expand All @@ -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)
)

Expand Down Expand Up @@ -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)
)

Expand Down Expand Up @@ -510,18 +513,18 @@ 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,
publish_topic.construction_order)
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)
)

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions src/caret_analyze/architecture/architecture_loaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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]:

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/caret_analyze/architecture/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit 5bcf788

Please sign in to comment.