ALMemory is a class that implements an event-based storage base.
Users can store data inside ALMemory, they can store groups, or relationships.Modules can then subscribe to data and receive notifications when data get changed with callback.
void insertData (const string& name, const int& data)
Allows any program to insert data into ALMemory. Overloaded method for 32bits type optimization
Name of the data to be inserted.
Value of the data
Example in python :
from naoqi import ALProxy try: # create proxy on ALMemory memProxy = ALProxy("ALMemory","localhost",9559) #insertData memProxy.insertListData([["myValueName1","myValue1"], ["myValueName2","myValue2"]) #getData print memProxy.getData("myValueName") except RuntimeError,e: # catch exception print "error insert data", e
void insertData (const string& name, const float& data)
Allows any program to insert data into ALMemory. Overloaded method for type optimization
Name of the data to be inserted.
Value of the data
Example in C++ :
getParentBroker()->getMemoryProxy()->insertData("naoqi/memoryExample", 1.2f); getParentBroker()->getProxy("ALMemory")->callVoid("insertData",std::string("naoqi/memoryExample"),1.1f);
void insertData (const string& name, const string& data)
Allows any program to insert data into ALMemory.
Name of the data to be inserted.
Value of the data
void dataChanged (const string& dataName, const AL::ALValue& data, const string& message)
Triggers a Synchronizer.
Name of the subscribed data.
Value of the the subscribed data
The message give when subscribing.
void insertData (const string& name, const AL::ALValue& data)
Allows any program to insert data into ALMemory.
Name of the data to be inserted.
Value of the data. Data type is an ALValue. Could be int, double, string, or an array of any of these types.
void raiseEvent (const string& name, const AL::ALValue& data)
Raise an event, insert data associated to event. Call user callback
Name of the event to raise.
Value of the data. could be int, double, string, or an array of any of these types.
void raiseMicroEvent (const string& name, const AL::ALValue& data)
Raise a micro-event, insert data associated to event. Call user callback
Name of the data to be inserted.
Value of the data. could be int, double, string, or an array of any of these types.
Example in python :
""" with sample of python documentation """ import os import sys import time import naoqi from naoqi import ALBroker from naoqi import ALModule from naoqi import ALProxy from naoqi import ALBehavior from naoqi import ALDocable # create python module class myModule(ALModule): """python class myModule test auto documentation""" def pythondatachanged(self, strVarName, value,message): """callback when data change""" print "Micro-event is raise callback is called by ALMemory" print value #print "datachanged", strVarName, " ", value, " ", strMessage # connect brokers (we suppose naoqi run) broker = ALBroker("newBroker","127.0.0.1",9999,"127.0.0.1",9559) print("ok broker") # don't forget to call all methods in try catch bloc #we create a proxy without IP adress because be have already connected brokers memory = ALProxy("ALMemory") print "[ RUN ] create python module" # create an ALModule pythonModule = myModule("pythonModule") # subscribe to micro-event to be notified when event is raised print "Subscribe to micro-event" memory.subscribeToMicroEvent("myMicroEvent", "pythonModule", "message", "pythondatachanged") # raise micro-event event print "raise micro-event" memory.raiseMicroEvent("myMicroEvent", 42) time.sleep(2)
void insertListData (const AL::ALValue& listOfInsertData)
Allows any program to insert a list of data into ALMemory.
list of [Name, Value, lifespan, waitforAnswer, group] for each data to be inserted.
Example in Python :
from naoqi import ALProxy try: # create proxy on ALMemory memProxy = ALProxy("ALMemory","localhost",9559) #insertData memProxy.insertListData([["myValueName1","myValue1",0], ["myValueName2","myValue2",0]]) #getData print memProxy.getData("myValueName1") #getListData print memProxy.getListData(["myValueName1", "myValueName2"]) except RuntimeError,e: # catch exception print "error insert data", e
void * getDataPtr (const string& name)
get pointer on 32bits data. Carrefull dangerous function. It's an heavy call, make it only function at initialization, not at every cycle
Name of the data.
a pointer converted to int
Example in C++ :
getParentBroker()->getProxy("ALMemory")->callVoid("insertData",std::string("naoqi/memoryExample"),1.1f); float *pData = (float *) getParentBroker()->getMemoryProxy()->getDataPtr(std::string("naoqi/memoryExample"));
AL::ALValue getData (const string& name, const int& duration)
Allows programs and modules to get data stored in ALMemory.
Name of the data.
All the data stored for "duration" seconds will be returned. If 0 returns the lastest value. If -1 returns all stored values.
an array containing all the retrieved data
AL::ALValue getData (const string& name)
Allows programs and modules to get data stored in ALMemory.
Name of the data.
an array containing all the retrieved data
AL::ALValue getDataOnChange (const string& name, const int& duration)
Allows programs and modules to retrieve data stored in ALMemory, but waits until the data has changed.
Name of the data.
All the data stored for "duration" seconds will be returned. If 0 returns the lastest value. If -1 returns all stored values.
an array containing all the retrieved data
string getType (const string& name)
Return variable type
Name of the variable
String type: Data, ShmData, Event, MicroEvent
Example in Python :
from naoqi import ALBroker from naoqi import ALModule from naoqi import ALProxy try: lProxy = ALProxy("ALMemory","127.0.0.1",9559) lProxy.insertData("data",1) lProxy.declareEvent("Event","yo") lProxy.raiseMicroEvent("Micro","slipquipu") type = lProxy.getType("data") if (type != "Data"): print "bad type ", "data: ", type exit(1) type = lProxy.getType("Event") if (type != "Event"): print "bad type ", "Event", type exit(1) type = lProxy.getType("Micro") if (type != "MicroEvent"): print "bad type ", "MicroEvent", type exit(1) except RuntimeError,e: # catch exception print "error in getType", e exit(1)
vector<string> getSubscribers (const string& name)
Returns the names of subscribers
Name of the event or micro-event
List of subscriber names
AL::ALValue getListData (const AL::ALValue& name)
Allows programs and modules to retrieve multiple datas stored in ALMemory at the same time.
an array containing the datas' name and their durations.
an array containing all the retrieved values of requested data
void removeData (const string& name)
Allows programs and modules to retrieve data stored in ALMemory.
Name of the data to be remove.
void removeMicroEvent (const string& name)
Remove micro event from ALMemory. Unsubscribe subscribers.
Name of the data to remove.
void subscribeToMicroEvent (const string& name, const string& moduleName, const string& message, const string& callback)
Allows modules to subscribe to a piece of data, in order to get notified when the data changes. Subscribers are called whenever the data has been set, even if the new value is the same as the previous one.
Name of the data.
Name of the module.
message passed to the module when a notification is sent.
name of function to call when a data is changed
void subscribeToEvent (const string& name, const string& moduleName, const string& callback)
Subscribe to event and automaticaly launch module function that generate the event. WARNING THERE IS NO MESSAGE parameter
Event name
subscriber name
name of function to call when a data is changed
Example in python :
""" with sample of python documentation """ import os import sys import time import naoqi from naoqi import ALBroker from naoqi import ALModule from naoqi import ALProxy from naoqi import ALBehavior from naoqi import ALDocable # create python module class myModule(ALModule): """python class myModule test auto documentation""" def pythondatachanged(self, strVarName, value,message): """callback when data change""" print "Event is raise callback is called by ALMemory" print value #print "datachanged", strVarName, " ", value, " ", strMessage # connect brokers (we suppose naoqi run) broker = ALBroker("newBroker","127.0.0.1",9999,"127.0.0.1",9559) print("ok broker") # don't forget to call all methods in try catch bloc #we create a proxy without IP adress because be have already connected brokers memory = ALProxy("ALMemory") print "[ RUN ] create python module" # create an ALModule pythonModule = myModule("pythonModule") # Optional: declare it only if you want to create your own event print "pythonModule declare event" memory.declareEvent("myEvent", "pythonModule") # subscribe to event to be notified when event is raised print "Another client/module Subscribe to event" memory.subscribeToEvent("myEvent", "pythonModule", "pythondatachanged") # Optional: raise event only if you manage your own event. print "raise event" memory.raiseEvent("myEvent", 42) time.sleep(2)
void subscribeToEvent (const string& name, const string& moduleName, const string& message, const string& callback)
Subscribe to event and automaticaly launch module function that generate the event. WARNING THERE IS NO MESSAGE parameter
Event name
subscriber name
message to send with callback
name of function to call when a data is changed
void waitOnCondition (const string& dataName, const string& condition)
Allows modules to subscribe to a piece of data, in order to get notified when the data changes. Subscribers are called whenever the data has been set, even if the new value is the same as the previous one.
Name of the data.
message passed to the module when a notification is sent.
void unsubscribeToMicroEvent (const string& name, const string& moduleName)
Allows modules to unsubscribe from a piece of data, in order to stop getting notified when the data changes.
Name of the data.
Name of the module.
void unsubscribeOnDataChange (const string& name, const string& moduleName)
Allows modules to unsubscribe from a piece of data and stop getting notified when the data changes.
Name of the data.
Name of the module.
void unsubscribeToEvent (const string& name, const string& moduleName)
Get event list generated by extractor
Event name
subscriber name
AL::ALValue getDataListName ()
Allows programs to get an array containing all the data's name.
return an array of data's string name.
void insertObject (const string& name, const AL::ALValue& buffer, const int& bufferSize)
Insert object in ALMemory. Please use ALMemoryFastAccess
ALMemory data name
buffer in ALValue
buffer size
Example in C++ :
getFactoryInstance()->addObjectToFactory<ALMethodInfo>(); ALMethodInfo sample, sample2; sample.moduleName = "testModule"; sample.methodName = "testMethod"; ALMemoryFastAccess fastAccess; fastAccess.insertObject<ALMethodInfo>("naoqi/ALMethodInfoSample",sample); sample2 = fastAccess.getObject<ALMethodInfo>("naoqi/ALMethodInfoSample");
void unregisterModuleReference (const string& name)
Informs ALMemory that a module doesn't exists anymore.
Name of the destructed module.
void declareEvent (const string& eventName, const string& name)
Declare event to allow subscribe on the event
Event name
Name of extractor that create event
void declareEvent (const string& eventName)
Declare event to allow subscribe on the event
Event name
vector<string> getEventList ()
return all application event
return an array of data's string name.
vector<string> getMicroEventList ()
return all application event
return an array of data's string name.
vector<string> getExtractorEvent (const string& name)
Get event list generated by extractor
Name of extractor that create event
return an array of data's string name.
string version ()
Returns the version of the module.
A string containing the version of the module.
AL::ALValue getMethodHelp (const string& methodName)
Retrieves a method's description.
The name of the method.
A structure containing the method's description.
AL::ALValue getModuleHelp ()
Retrieves the module's description.
A structure describing the module.
string getUsage (const string& name)
Gets the method usage string. This summarise how to use the method.
The name of the method.
A string that summarises the usage of the method.