Overview

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.

Methods

void insertData (const string& name, const int& data)

Allows any program to insert data into ALMemory. Overloaded method for 32bits type optimization

name

Name of the data to be inserted.

data

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

Name of the data to be inserted.

data

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

Name of the data to be inserted.

data

Value of the data

void dataChanged (const string& dataName, const AL::ALValue& data, const string& message)

Triggers a Synchronizer.

dataName

Name of the subscribed data.

data

Value of the the subscribed data

message

The message give when subscribing.

void insertData (const string& name, const AL::ALValue& data)

Allows any program to insert data into ALMemory.

name

Name of the data to be inserted.

data

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

Name of the event to raise.

data

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

Name of the data to be inserted.

data

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.

listOfInsertData

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

Name of the data.

Returns

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

Name of the data.

duration

All the data stored for "duration" seconds will be returned. If 0 returns the lastest value. If -1 returns all stored values.

Returns

an array containing all the retrieved data

AL::ALValue getData (const string& name)

Allows programs and modules to get data stored in ALMemory.

name

Name of the data.

Returns

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

Name of the data.

duration

All the data stored for "duration" seconds will be returned. If 0 returns the lastest value. If -1 returns all stored values.

Returns

an array containing all the retrieved data

string getType (const string& name)

Return variable type

name

Name of the variable

Returns

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

Name of the event or micro-event

Returns

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.

name

an array containing the datas' name and their durations.

Returns

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

Name of the data to be remove.

void removeMicroEvent (const string& name)

Remove micro event from ALMemory. Unsubscribe subscribers.

name

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

Name of the data.

moduleName

Name of the module.

message

message passed to the module when a notification is sent.

callback

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

name

Event name

moduleName

subscriber name

callback

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

name

Event name

moduleName

subscriber name

message

message to send with callback

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.

dataName

Name of the data.

condition

message passed to the module when a notification is sent.

void waitSynchronizer (const string& name)

Waits for a condition to be triggered.

name

Condition name

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

Name of the data.

moduleName

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

Name of the data.

moduleName

Name of the module.

void unsubscribeToEvent (const string& name, const string& moduleName)

Get event list generated by extractor

name

Event name

moduleName

subscriber name

AL::ALValue getDataListName ()

Allows programs to get an array containing all the data's name.

Returns

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

name

ALMemory data name

buffer

buffer in ALValue

bufferSize

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

Name of the destructed module.

void declareEvent (const string& eventName, const string& name)

Declare event to allow subscribe on the event

eventName

Event name

name

Name of extractor that create event

void declareEvent (const string& eventName)

Declare event to allow subscribe on the event

eventName

Event name

vector<string> getEventList ()

return all application event

Returns

return an array of data's string name.

vector<string> getMicroEventList ()

return all application event

Returns

return an array of data's string name.

vector<string> getExtractorEvent (const string& name)

Get event list generated by extractor

name

Name of extractor that create event

Returns

return an array of data's string name.


Methods inherited from ALModule

void exit ()

Exits and unregisters the module.

string version ()

Returns the version of the module.

Returns

A string containing the version of the module.

bool ping ()

Just a ping. Always returns true

Returns

returns true

vector<string> getMethodList ()

Retrieves the module's method list.

Returns

An array of method names.

AL::ALValue getMethodHelp (const string& methodName)

Retrieves a method's description.

methodName

The name of the method.

Returns

A structure containing the method's description.

AL::ALValue getModuleHelp ()

Retrieves the module's description.

Returns

A structure describing the module.

string getBrokerName ()

Gets the name of the parent broker.

Returns

The name of the parent broker.

string getUsage (const string& name)

Gets the method usage string. This summarise how to use the method.

name

The name of the method.

Returns

A string that summarises the usage of the method.


Copyright © 2010 Aldebaran Robotics - All rights reserved