Skip to content

Commit

Permalink
[Ontolopy] FeederPublisher registerNotificationCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthou committed Jan 22, 2024
1 parent b2762a7 commit 6eb7136
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/python_API/FeederPublisher.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ <h2 id="methods">Methods</h2>
<tr><td class="memItemLeft rightAlign topAlign"> str </td><td class="memItemRight bottomAlign"><b><a href="FeederPublisher.html#commit">commitAuto</a></b>(self, timeout = 100000000)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="FeederPublisher.html#commit2">commit</a></b>(self, commit_name, timeout = 100000000)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="FeederPublisher.html#checkout">checkout</a></b>(self, commit_name, timeout = 100000000)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="FeederPublisher.html#registerNotificationCallback">registerNotificationCallback</a></b>(self, callback)</td></tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -256,6 +257,10 @@ <h3 class="fn" id="checkout"><a name="checkout"></a><span class="name">checkout<
<p>Returns False if the function returns on a timeout.</p>
<p>This function can only be used on a copied ontology.</p>

<h3 class="fn" id="registerNotificationCallback"><a name="registerNotificationCallback"></a><span class="name">registerNotificationCallback</span>(self, callback)</h3>
<p>Register a callback function to get notifications from the feeder.</p>
<p>The parameter <i>callback</i> is the callback function taking a string.</p>

</div>
</div>
</div>
Expand Down
15 changes: 15 additions & 0 deletions ontopy/ontologenius/FeederPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down

0 comments on commit 6eb7136

Please sign in to comment.