Broker

A broker is an executable and a server that can listen to remote commands on IP and port. By default, on robot, "nao start" command makes /bin/naoqi executable listen on Ethernet IP if available or on wifi IP if Ethernet not available.

#shell example ./bin/naoqi -b 127.0.0.1 -p 9559 #listen on ip 127.0.0.1 and port 9559

Module generator ($AL_DIR/tools) will generate the project for you: generate an executable and connect it to the robot, or generate a library to link it to main executable (add it in autoload.ini). Module generator will manage the links and paths, so that you can really focus on the functions that you want to implement. (see the SDK section for more details about module generator).

Below is a figure illustrating a simple example with a user-created module called "myModule". myModule is run in a remote broker called 'myBroker' which can communicate with the main broker on 127.0.0.1:9559.

broker/module/proxy

Description of the figure:

Brokers are represented with pink rectangles. A broker is an executable launched with IP and port parameter. IP 0.0.0.0 can be used to listen on all the available IP's.

#shell command # IP 127.0.0.1 and port 9559 by default ./bin/naoqi -b 0.0.0.0

All the brokers show their API in the web browser. http://127.0.0.1:9559 (or other IP, port used in parameter). In the figure above, MyBroker is connected to mainBroker. To connect a broker to another, use the -pip command:

#shell command ./modules/bin/myBroker -pip 127.0.0.1 # connect to mainBroker 127.0.0.1

Modules are shown in green circle. They can be loaded at runtime with launcher module. They can also be loaded in setting file autoload.ini ($AL_DIR/modules/lib).

#autoload.ini sample [core] # required files albase [extra] # removable modules launcher # module that can launch other modules devicecommunicationmanager # interface with hardware motion # module that manage motion pythonbridge # embedded python interpreter [remote] # run executable from ($AL_DIR/modules/bin audioout

A broker is both an executable and a server. The server will listen to remote commands. ALProxy allows connections to a broker to send commands:

// C++ sample ALProxy p = ALProxy("module name", parentIP, parentPort); p.info("display it on remote broker parentIP and parentPort);

Modules can access their local broker with getParentBroker().

// C++ sample getParentBroker()->getIP(); // get my IP address

ALModuleInfo: Module or broker description structure

ALModuleInfo field Description
std::string name; Name of the module/broker
int architecture; linux/win32/macOSX
std::string ip; broker IP address (if broker)
int port; broker port (if broker)
int processId; deprecated
int modulePointer; Address of the module
bool isABroker; is broker (true) or module (false)?
bool keepAlive; automatically destroys broker when parent broker dies

ALBroker

Method Description
int getModuleByName( const std::string& pModuleName, al__ALModuleInfo& pModInfo ); Find a module in the network of module
int getLocalModuleByName(const std::string& pModuleName, ALModuleInfo& pModInfo); Find a module in the local process
int registerModule(ALPtr<ALModule> pModule); Add a module in the local process (automatically called when loading a library)
int unregisterModule(const std::string& pModuleName); Remove a module in the local process (will not be removed if a module function is running)
int removeProxy(const std::string& pModuleName); Remove a reference to a module (automatically called when unregistering a module)
int getModuleList( TALModuleInfoVector &pModuleList ); Get the local module list
int getBrokerList( TALModuleInfoVector &pBrokerList ); Get the local broker (executable) connected
int getGlobalModuleList( TALModuleInfoVector &pModuleList ); Get all module list (also remote modules)
int init(const std::string& pBrokerName, const std::string& pIP, int pPort, const std::string& pParentBrokerIP, int pParentBrokerPort, bool pKeepAlive = false); Reset broker to listen on IP and port. Use module generator or createBroker for easy broker creations.
int registerBroker( ALModuleInfo pBrokerToRegister); Add an executable to the current broker
int getBrokerInfo( ALModuleInfo &pModuleInfo); Get current broker information
int exploreToGetModuleByName(const std::string& pModuleName, bool pSearchUp, bool pSearchDown, const std::string& pDontLookIntoBrokerName, ALModuleInfo &pModInfo); Generic function to find a module in the process tree
int getMethodList(const std::string& pModuleName, std::vector<std::string> &pMethodListName) const; Get the API of the pModuleName module
int getMethodHelp( const std::string& pModuleName, const std::string& pMethodName, AL::ALValue &pMethodHelp ) const; Get documentation of pModuleName, pMethodName
int getInfo( const std::string& pModuleName, ALModuleInfo &pModuleInfo) const; Get pModuleName information
int shutdown(); Stop listening to IP and port. Kill all local modules. Unregister current broker in others process/broker
bool HasParent() False if main broker (NAOqi)
std::string getName() Get executable/broker name
std::string getIP() Get broker IP
int getPort() Get broker port
ALPtr<ALProxy> getProxy(const std::string& pProxyName); Get a pointer on pProxyName (local module) or get remote access to pProxyName (remote module)





Copyright © 2010 Aldebaran-Robotics - All rights reserved