Initializing an Ivy agent with the Ivy-Perl library is done by calling function Ivy::start
. In theory, initialization is then over. However in
practice, as for any asynchronous communication or interaction library, nothing
happens until your application has reached the main loop.
The Ivy Perl library provides two kind of main loop: a "local" loop for perl code, and a "Tk" loop for perl-tk code.
Here is more details on Ivy::start
function:
Ivy::start(-loopMode => 'TK',
-ivyBus => '2011',
-appName => "TOTO",
-neededApp => "TITI",
-statusFunc => \&statusScan);
initializes and connects your application to the bus specified in ivyBus
. The string provided
should follow the convention described in section XX. Example: "127:2010"
..
MainLoop;
makes your application enter the main loop in which it will handle asynchronous
communications and signals.
Ivy::stop ();
makes your application exit the main loop.
Emitting a message on an Ivy bus is much like printing a message on the standard
output. However, do not forget that your message will not be emitted if Ivy has
not been properly initialized and if you do not have a main loop of some sort
running. To emit a message, use IvySendMsg
, which works like printf
:
Ivy::sendMsg ("...");
sends a message on the bus.
Subscribing to messages consists in binding a callback function to a message
pattern. Patterns are described by regular expressions with captures. When a
message matching the regular expression is detected on the bus, the callback
function is called. The captures (ie the bits of the message that match the
parts of regular expression delimited by brackets) are passed to the callback
function much like options are passed to main
. Use function Ivy::bindRegexp
to bind a callback to a pattern.
Ivy::bindRegexp ("^HELLO WORLD", [\&Start]);
binds callback function Start
to the regular expression specified by
regex_format
.
Ivy::bindRegexp ("^HELLO WORLD", NULL);
deletes the binding.