NAOqi Core - Overview | API | Tutorial
This tutorial explains how to use the ALResourceManager module.
Note
The tutorial is written in Python.
# create proxy on resource manager
proxy = ALProxy("ALResourceManager","localhost",9559)
#createResource in root (parent resource is "")
proxy.createResource("newResource","")
#check resource is free
free = proxy.areResourcesFree(["newResource"])
# take resource
# acquireResource(resource name, owner name, callback to notify you that someone want the resource, timeout)
proxy.acquireResource("newResource", "myFooModule", "", 1)
class MyFooModule:
def myFooCallback(self, resource, currentOwner):
#decide what to do with the ressource.
#either call releaseResource or pass
if iwanttoreleasetheresource:
releaseResource(resource, currentOwner)
# alternatively, you can specify a callback on myFooModule as third parameter that will be called in case of conflict.
proxy.acquireResource("newResource", "MyFooModule", "myFooCallback", 1)
#release resource
proxy.releaseResource("newResource", "myFooModule")