src package
Submodules
src.ubii_client_node module
- class src.ubii_client_node.UbiiClientNode(name='pythonNodeV2', service_endpoint='http://localhost:8102/services/binary', topicdata_endpoint='ws://localhost:8104')[source]
Bases:
object
This class represents the python client node v.2 https://github.com/SandroWeber/ubii-node-python-v2 for the UBI-Interact framework https://github.com/SandroWeber/ubi-interact/wiki.
- Variables:
events –
Four Events (‘onPublishError’, ‘onReadError’, ‘onServiceCallError’, ‘onConnectionError’) for error handling, each event can be subscribed to with a callback that takes exactly one Exception as parameter. Whenever an Error occurs the associated events gets called.
”Events”:
def handleExc(e): print(e) node = UbiiClientNode() node.events.onConnectionError += handleExc
- call_service(request: ServiceRequest) Future [source]
Makes a service request to the masternode.
This happens asynchronous but returns a future with the ServiceReply from the masternode once finished or None if the process raised an exception.
- Parameters:
request (ServiceRequest) – The ServiceRequest sent to the masternode.
- Returns:
The Future with the ServiceReply or with None.
- Return type:
Future
- getId()[source]
- Returns:
The id the node got from the masternode if connected, None else.
- Return type:
str or None
- publish(record: TopicDataRecord)[source]
Publishes the topicDataRecord in the next interval.
Ads the TopicDataRecord to a list of TopicDataRecords that will be sent to the masternode in the next publish interval. If the list already contains a TopicDataRecord with the specified topic the TopicDataRecord in the list will be overwritten with this one. The process of sending the TopicDataRecord to the masternode happens asynchronous in a different thread.
- Parameters:
record (TopicDataRecord) – The TopicDataRecord to publish.
- publishImmediately(data: TopicDataRecord)[source]
Publishes the topicDataRecord instantly.
Sends the TopicDataRecord directly to the masternode. The process of sending the topic to the masternode happens asynchronous in a different thread.
- Parameters:
data (TopicDataRecord) – The TopicDataRecord to publish.
- publishList(recordList: TopicDataRecordList)[source]
Publishes the elements of the TopicDataRecordList in the next interval.
Ads every TopicDataRecord from the TopicDataRecordList to a list of TopicDataRecords that will be sent to the masternode in the next publish interval. If the list already contains a TopicDataRecord with the specified topic the TopicDataRecord in the list will be overwritten with this one. The process of sending the TopicDataRecords to the masternode happens asynchronous in a different thread.
- Parameters:
recordList (TopicDataRecordList) – The TopicDataRecordList with the topics to publish
- setPublishFrequency(frequency)[source]
Changes the frequency the node sends the published topicdata to the masternode.
- Parameters:
frequency (float) – the time interval.
- stopNode()[source]
Needs to be called when the node is no longer used in any form to disconnect it from the masternode and to stop background threads. The disconnection process happens asynchronous in a different thread.
- subscribeRegex(regex: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken [source]
Subscribes to a regular expression.
Whenever a topicDataRecord is published at the masternode for a topic that fits this regular expression that topicDataRecord will be sent to this node and the callback passed is invoked for this topicDataRecord. The process to subscribe at the masternode happens asynchronous in a different thread.
- Parameters:
regex (str) – The regular expression that should be subscribed to.
callback (Callable[[TopicDataRecord], None]) – The callback that takes exactly one TopicDataRecord as parameter and returns nothing.
- Returns:
The SubscriptionToken that contains a unique token id, the regex, the callback, and the SubscriptionTokenTYPE.
- Return type:
- subscribeTopic(topic: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken [source]
Subscribes to a topic.
Whenever a topicDataRecord is published at the masternode for this topic, that topicData will be sent to this nodeand the callback passed is invoked for this topicDataRecord. The process to subscribe at the masternode happens asynchronous in a different thread.
- Parameters:
topic (str) – The topic that should be subscribed to
callback – The callback that takes exactly one TopicDataRecord as parameter and returns nothing
- Returns:
The SubscriptionToken that contains a unique token id, the regex, the callback, and the SubscriptionTokenTYPE.
- Return type:
- unsubscribe(token: SubscriptionToken) bool [source]
Unsubscribes the subscription token.
The callback that was passed when subscribing is no longer executed when a topicDataRecord is received for this topic. When there are no more subscribers for a topic at this node, the node unsubscribes at the masternode and won’t receive any published topicData. The callback will be unsubscribed synchronous, but the process to unsubscribe at the masternode happens asynchronous in a different thread.
- Parameters:
token (SubscriptionToken) – The subscriptionToken that was returned when subscribing.
- Returns:
The success of the operation.
- Return type:
bool
src.TopicDataBuffer module
- class src.TopicDataBuffer.SubscriptionToken(id: int, topic: str, callback: Callable[[TopicDataRecord], None], type: SubscriptionTokenTYPE)[source]
Bases:
object
- class src.TopicDataBuffer.SubscriptionTokenTYPE(value)[source]
Bases:
Enum
An enumeration.
- REGEX = 2
- TOPIC = 1
- class src.TopicDataBuffer.TopicDataBuffer[source]
Bases:
object
- generateToken(topic: str, callback: Callable[[TopicDataRecord], None], type: SubscriptionTokenTYPE) SubscriptionToken [source]
- getRegexSubscriptionTokens(regex: str) List[SubscriptionToken] [source]
- getTopicSubscriptionTokens(topic: str) List[SubscriptionToken] [source]
- subscribeRegex(regex: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken [source]
- subscribeTopic(topic: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken [source]
- unsubscribe(token: SubscriptionToken) bool [source]
src.TopicDataProxy module
- class src.TopicDataProxy.TopicDataProxy(topicDataBuffer: TopicDataBuffer, networkClient: UbiiNetworkClient, node)[source]
Bases:
object
- getRegexSubscriptionTokens(regex: str) List[SubscriptionToken] [source]
- getTopicSubscriptionTokens(topic: str) List[SubscriptionToken] [source]
- subscribeRegex(regex: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken [source]
- subscribeTopic(topic: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken [source]
- unsubscribe(token: SubscriptionToken) bool [source]