summaryrefslogtreecommitdiff
path: root/doc/ivy-perl-3.html
blob: bee7734c9048254a9704701e02038facfb77a6e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
 <TITLE>The Ivy C library guide: Basic functions</TITLE>
 <LINK HREF="ivy-perl-4.html" REL=next>
 <LINK HREF="ivy-perl-2.html" REL=previous>
 <LINK HREF="ivy-perl.html#toc3" REL=contents>
</HEAD>
<BODY>
<A HREF="ivy-perl-4.html">Next</A>
<A HREF="ivy-perl-2.html">Previous</A>
<A HREF="ivy-perl.html#toc3">Contents</A>
<HR>
<H2><A NAME="s3">3. Basic functions</A></H2>

<H2><A NAME="ss3.1">3.1 Initialization and main loop</A>
</H2>

<P>Initializing an Ivy agent with the Ivy-Perl library is done by calling function <CODE>Ivy::start</CODE>. 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.
<P>The Ivy Perl library provides two kind of main loop: a "local" loop 
      for perl code, and a "Tk" loop for perl-tk code.
<P>Here is more details on <CODE>Ivy::start</CODE> function:
<P>
<BLOCKQUOTE><CODE>
<PRE>
  Ivy::start(-loopMode => 'TK', 
             -ivyBus => '2011', 
             -appName => "TOTO",
             -neededApp => "TITI",
             -statusFunc    => \&statusScan);

</PRE>
</CODE></BLOCKQUOTE>

initializes and connects your application to the bus specified in <CODE>ivyBus</CODE>. The string provided
should follow the convention described in section XX. Example: <CODE>"127:2010"</CODE>..
<P>

<BLOCKQUOTE><CODE>
<PRE>
MainLoop;
</PRE>
</CODE></BLOCKQUOTE>

makes your application enter the main loop in which it will handle asynchronous
communications and signals.
<P>
<BLOCKQUOTE><CODE>
<PRE>
Ivy::stop ();
</PRE>
</CODE></BLOCKQUOTE>

makes your application exit the main loop.
<P>
<P>
<H2><A NAME="ss3.2">3.2 Emitting messages</A>
</H2>

<P>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 <CODE>IvySendMsg</CODE>, which works like <CODE>printf</CODE>:
<P>
<BLOCKQUOTE><CODE>
<PRE>
Ivy::sendMsg ("...");
</PRE>
</CODE></BLOCKQUOTE>

sends a message on the bus.
<P>
<P>
<H2><A NAME="ss3.3">3.3 Subscribing to messages</A>
</H2>

<P>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 <CODE>main</CODE>. Use function <CODE>Ivy::bindRegexp</CODE> 
to bind a callback to a pattern.
<BLOCKQUOTE><CODE>
<PRE>
Ivy::bindRegexp ("^HELLO WORLD", [\&Start]);
</PRE>
</CODE></BLOCKQUOTE>

binds callback function <CODE>Start</CODE> to the regular expression specified by
<CODE>regex_format</CODE>.
<P>
<BLOCKQUOTE><CODE>
<PRE>
Ivy::bindRegexp ("^HELLO WORLD", NULL);
</PRE>
</CODE></BLOCKQUOTE>

deletes the binding.
<P>
<P>
<P>
<HR>
<A HREF="ivy-perl-4.html">Next</A>
<A HREF="ivy-perl-2.html">Previous</A>
<A HREF="ivy-perl.html#toc3">Contents</A>
</BODY>
</HTML>