Skip to content

Commit

Permalink
added topics property to SystemState (fixes #374)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTimperley committed Jun 23, 2020
1 parent 7fc56b8 commit 0c11be7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/roswire/proxy/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,30 @@ class SystemState:
A mapping from topics to the names of subscribers to that topic.
services: Mapping[str, Collection[str]]
A mapping from services to the names of providers of that service.
nodes: AbstractSet[str]
The names of all known nodes running on the system.
topics: AbstractSet[str]
The names of all known topics on the system with at least one
publisher or one subscriber.
"""
publishers: Mapping[str, Collection[str]]
subscribers: Mapping[str, Collection[str]]
services: Mapping[str, Collection[str]]
nodes: AbstractSet[str] = attr.ib(init=False, repr=False)
topics: AbstractSet[str] = attr.ib(init=False, repr=False)

def __attrs_post_init__(self) -> None:
nodes: Set[str] = set()
nodes = nodes.union(*self.publishers.values())
nodes = nodes.union(*self.subscribers.values())
nodes = nodes.union(*self.services.values())

topics: Set[str] = set()
topics = topics.union(self.publishers)
topics = topics.union(self.subscribers)

object.__setattr__(self, 'nodes', frozenset(nodes))
object.__setattr__(self, 'topics', frozenset(topics))


@attr.s(frozen=True, auto_attribs=True)
Expand Down

0 comments on commit 0c11be7

Please sign in to comment.