diff --git a/docs/python_API/FeederPublisher.html b/docs/python_API/FeederPublisher.html index 51da662c..df0aceff 100644 --- a/docs/python_API/FeederPublisher.html +++ b/docs/python_API/FeederPublisher.html @@ -153,6 +153,7 @@
Returns False if the function returns on a timeout.
This function can only be used on a copied ontology.
+Register a callback function to get notifications from the feeder.
+The parameter callback is the callback function taking a string.
+ diff --git a/ontopy/ontologenius/FeederPublisher.py b/ontopy/ontologenius/FeederPublisher.py index 4f1059ec..42fa38bd 100644 --- a/ontopy/ontologenius/FeederPublisher.py +++ b/ontopy/ontologenius/FeederPublisher.py @@ -37,6 +37,11 @@ def __init__(self, name): if self._name != '': sub_topic_name += '/' + self._name self._commit_sub = Ontoros.createSubscriber(sub_topic_name, String, self.commitCallback) + notif_topic_name = 'ontologenius/feeder_notifications' + if self._name != '': + notif_topic_name += '/' + self._name + self._notif_sub = Ontoros.createSubscriber(notif_topic_name, String, self._notifCallback) + self.user_notif_callback = None self._updated = False random.seed() self._commit_nb = random.randint(1, 100000) @@ -235,6 +240,12 @@ def checkout(self, commit_name, timeout = 100000000): return True else: return False + + def registerNotificationCallback(self, callback): + """Register a callback function to get notifications from the feeder. + callback is the callback function taking a string. + """ + self.user_notif_callback = callback def _sendNop(self): self._publish_stamped('[nop]nop|', Ontoros.getRosTime()) @@ -250,6 +261,10 @@ def commitCallback(self, data): if data.data == 'end': self._updated = True + def _notifCallback(self, data): + if not self.user_notif_callback is None: + self.user_notif_callback(data) + def millis_interval(self, start, end): diff = end - start millis = diff.days * 24 * 60 * 60 * 1000