summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Ivy.pm299
1 files changed, 176 insertions, 123 deletions
diff --git a/Ivy.pm b/Ivy.pm
index 742aff5..b9224ae 100644
--- a/Ivy.pm
+++ b/Ivy.pm
@@ -1,7 +1,7 @@
#
# Ivy, Perl interface
#
-# Copyright 1997-2000
+# Copyright 1997-2001
# Centre d'Études de la Navigation Aérienne
#
# Authors: Alexandre Bustico <bustico@cena.fr>
@@ -97,6 +97,7 @@ sub exit (); # methode de classe : on delete tous les
sub after ($$;$); # temps en millisecondes, callback
sub repeat ($$;$); # temps en millisecondes, callback
sub afterCancel ($;$); # l'id d'un cancel ou d'un repeat
+sub afterResetTimer ($;$); # pour ré-armer un timer non-encore déclenché à sa valeur initiale
sub fileEvent ($$;$); # associe un fd a un callback pour la mainloop locale
@@ -862,7 +863,7 @@ sub mainLoop ()
############### METHODE AFTER
sub after ($$;$)
{
- # test du premier argument au cas ou la fonction soit
+ # test du premier argument au cas où la fonction est
# appelee de maniere objet : premier argument = class ou une instance
# de classe
shift if ((ref ($_[0]) eq __PACKAGE__) || ($_[0] eq __PACKAGE__)) ;
@@ -882,7 +883,7 @@ sub after ($$;$)
############### METHODE REPEAT
sub repeat ($$;$)
{
- # test du premier argument au cas ou la fonction soit
+ # test du premier argument au cas où la fonction est
# appelee de maniere objet : premier argument = class ou une instance
# de classe
shift if ((ref ($_[0]) eq __PACKAGE__) || ($_[0] eq __PACKAGE__)) ;
@@ -900,7 +901,7 @@ sub repeat ($$;$)
############### METHODE AFTER CANCEL
sub afterCancel ($;$)
{
- # test du premier argument au cas ou la fonction soit
+ # test du premier argument au cas où la fonction est
# appelee de maniere objet : premier argument = class ou une instance
# de classe
shift if ((ref ($_[0]) eq __PACKAGE__) || ($_[0] eq __PACKAGE__)) ;
@@ -923,10 +924,28 @@ sub afterCancel ($;$)
}
}
+############### METHODE AFTER RESET TIMER
+# permet de gérer des timout plus facilement en permettant de
+# réarmer un after non encore déclenché à sa valeur initiale
+# cela évite le aftercancel suivi d'un nouvel after
+sub afterResetTimer ($;$)
+{
+ # test du premier argument au cas où la fonction est
+ # appelee de maniere objet : premier argument = class ou une instance
+ # de classe
+ shift if ((ref ($_[0]) eq __PACKAGE__) || ($_[0] eq __PACKAGE__)) ;
+
+ my $id = shift;
+ if (defined ($id) && defined $afterList{$id}) {
+ $afterList{$id}->[2] = $afterList{$id}->[1] + timeofday();
+ }
+}
+
+
############### METHODE FILE EVENT
sub fileEvent ($$;$)
{
- # test du premier argument au cas ou la fonction soit
+ # test du premier argument au cas où la fonction est
# appelee de maniere objet : premier argument = class ou une instance
# de classe
shift if ((ref ($_[0]) eq __PACKAGE__) || ($_[0] eq __PACKAGE__)) ;
@@ -1647,9 +1666,12 @@ When you quit your application don't forget to call 'exit' class methods.
=head1 CLASS METHODS
-=head2 Ivy->init(...)
+=over 2
+
+=item B<init>
-Ivy::init(...)
+ Ivy->init(...);
+ Ivy::init(...);
Allows one to define global parameters which may be used as default ones
at object creation time.
@@ -1689,34 +1711,34 @@ Do not call exit() in the callback, Ivy will do it for you.
The prototype of your callback must be as follows:
-sub MyCallback {
- my @parameters = @_;
-
- ...
-}
+ sub MyCallback {
+ my @parameters = @_;
+ ...
+ }
The prototype of your method must be as follows:
-sub MyMethod {
- my ($self, @parameters) = @_;
-
- ...
-}
+ sub MyMethod {
+ my ($self, @parameters) = @_;
+ ...
+ }
=item B<-pruneRegexp =E<gt> ['subject 1', ..., 'subject n']>
Optimize communication using this option. Regexps
which don't match these subjects are removed.
-Example :
-
- Ivy->init(-loopMode =E<gt> 'TK',
- -appName =E<gt> 'MyWonderfulApp',
- -onDieFunc =E<gt> [\&restorecontext]);
+ Example :
+ Ivy->init(-loopMode =E<gt> 'TK',
+ -appName =E<gt> 'MyWonderfulApp',
+ -onDieFunc =E<gt> [\&restorecontext]);
=back
-=head2 Ivy->new(...);
+=item B<new>
+
+ Ivy::new(...);
+ Ivy->new(...);
Check parameters, and create an Ivy bus object. You must call
Ivy->init before creating a bus.
@@ -1748,17 +1770,17 @@ A callback or method called when your application receives a suicide request.
Do not call exit() in the callback, Ivy will do it for you.
The prototype of your callback must be as follows:
- sub MyCallback {
- my @parameters = @_;
- ...
- }
+ sub MyCallback {
+ my @parameters = @_;
+ ...
+ }
The prototype of your method must be as follows:
- sub MyMethod {
- my ($self, @parameters) = @_;
- ...
- }
+ sub MyMethod {
+ my ($self, @parameters) = @_;
+ ...
+ }
=item B<-pruneRegexp =E<gt> ['subject 1', ..., 'subject n']>
@@ -1775,80 +1797,92 @@ A callback which will be called every time an appli is connected or deconnected
Your callback could be:
- sub MyCallback {
- my ($ref_array_present, $ref_array_absent, $ref_hash_present, $appname, $status, $host) = @_;
+ sub MyCallback {
+ my ($ref_array_present, $ref_array_absent, $ref_hash_present,
+ $appname, $status, $host) = @_;
- # $status is either new or died
+ # $status is either new or died
- my %present=%$ref_hash_present;
- foreach my $remoteapp (keys %present) {
- if ($present{$remoteapp} > 1) {
- print "n apps $remoteapp are presents on bus\n";
- }
- }
- if ($status eq "new") {
- print "$appname connected from $host\n";
- }
- elsif ($status eq "died") {
- print "$appname disconnected from $host\n";
- }
- }
+ my %present=%$ref_hash_present;
+ foreach my $remoteapp (keys %present) {
+ if ($present{$remoteapp} > 1) {
+ print "n apps $remoteapp are presents on bus\n";
+ }
+ }
+ if ($status eq "new") {
+ print "$appname connected from $host\n";
+ }
+ elsif ($status eq "died") {
+ print "$appname disconnected from $host\n";
+ }
+ }
Example:
- Ivy->new(-ivyBus => '156,157:2204',
- -onDieFunc => [\&restorecontext],
- -neededApp => ["DataServer", "HMI"],
- -statusFunc => \&startwhenpresents);
+ Ivy->new(-ivyBus => '156,157:2204',
+ -onDieFunc => [\&restorecontext],
+ -neededApp => ["DataServer", "HMI"],
+ -statusFunc => \&startwhenpresents);
=back
-=head2 Ivy->mainLoop;
+=item B<mainLoop>
+
+ Ivy->mainLoop;
+ Ivy::mainLoop;
Local main events loop. Use it if you don't use the Tk library.
-=head2 $ivyobj->stop;
+=item B<stop>
+
+ $ivyobj->stop;
+ Ivy::stop;
-Ivy::stop;
+To stop the Ivy main loop.
+
+=back
=head1 OBJECT METHODS
-=head2 $ivyobj->start;
+=over 2
+
+=item B<start>
-Ivy::start;
+ $ivyobj->start;
+ Ivy::start;
You must call this after you are ready to communicate through an Ivy bus
-and before you really communicate.
+and before you really communicate. The method returns the $ivyobj.
-=head2 $ivyobj->sendMsgs(@messages);
+=item B<sendMsgs>
-Ivy::sendMsgs(@messages);
+ $ivyobj->sendMsgs(@messages);
+ Ivy::sendMsgs(@messages);
Send a list of messages
-Example :
+ Example :
+ $ivyobj->sendMsgs("Hello", "Don't Bother", "Y2K is behind us");
- $ivyobj->sendMsgs("Hello World", "Don't Bother", "Y2K is behind us");
+=item B<sendAppNameMsgs>
-=head2 $ivyobj->sendAppNameMsgs(@messages);
-
-Ivy::sendAppNameMsgs(@messages);
+ $ivyobj->sendAppNameMsgs(@messages);
+ Ivy::sendAppNameMsgs(@messages);
Send a list of messages preceded by your application's name.
-Example :
-
- $ivyobj->sendMsgs("Hello World");
- # it will send "$appName Hello World" over the Ivy bus
-
-=head2 $ivyobject->bindRegexp($regexp, [\&callback, @cb_parameters]);
+ Example :
+ $ivyobj->sendMsgs("Hello World");
+ # it will send "$appName Hello World" over the Ivy bus
-Ivy::bindRegexp($regexp, [\&callback, @cb_parameters]);
+=item B<bindRegexp>
-=head2 $ivyobject->bindRegexp($regexp, [$an_obj, \&method, @cb_parameters]);
+ $ivyobject->bindRegexp($regexp, [\&callback, @cb_parameters]);
+ Ivy::bindRegexp($regexp, [\&callback, @cb_parameters]);
-Ivy::bindRegexp($regexp, [$an_obj, \&method, @cb_parameters]);
+ $ivyobject->bindRegexp($regexp, [$an_obj, \&method, @cb_parameters]);
+ Ivy::bindRegexp($regexp, [$an_obj, \&method, @cb_parameters]);
This allows you to bind a regular expression to a
callback or method. The callback or method will be called for every
@@ -1857,97 +1891,116 @@ See perlre(1) to find how to write regexps.
Use the bracketing construct ( ... ) so that your callback is
called with the captured bits of text as parameters.
-Example :
+ Example :
+ $ivyobject->bindRegexp("\w+ (\d+)", [\&callback, @cb_parameters]);
- $ivyobject->bindRegexp("\w+ (\d+)", [\&callback, @cb_parameters]);
- # Your callback will be called with one more parameter which will be
- # the name of appli who send the message
+ # Your callback will be called with one more parameter which will be
+ # the name of appli who send the message
-Your callback and method must be like:
+ # Your callback and method must be like:
+ sub cb {
+ my ($sendername, @cb_parameters,
+ @matched_regexps_in_brackets) = @_;
+ ...
+ }
- sub cb {
- my ($sendername, @cb_parameters,
- @matched_regexps_in_brackets) = @_;
- ...
- }
-
- sub method {
- my ($self, $sendername, @cb_parameters,
- @matched_regexps_in_brackets) = @_;
- ...
- }
+ sub method {
+ my ($self, $sendername, @cb_parameters,
+ @matched_regexps_in_brackets) = @_;
+ ...
+ }
-=head2 $ivyobj->sendDirectMsgs($to, $id, @msgs);
+=item B<sendDirectMsgs>
-Ivy::sendDirectMsgs($to, $id, @msgs);
+ $ivyobj->sendDirectMsgs($to, $id, @msgs);
+ Ivy::sendDirectMsgs($to, $id, @msgs);
Send a message a message to appli $to. This appli must have done a bindDirect before to accept this message. regexp matching is not used with direct Messages
-=head2 $ivyobj->bindDirect($regexp, $id, [\&callback, @cb_parameters]);
+=item B<bindDirect>
-Ivy::bindDirect($id, [\&callback, @cb_parameters]);
+ $ivyobj->bindDirect($regexp, $id, [\&callback, @cb_parameters]);
+ Ivy::bindDirect($id, [\&callback, @cb_parameters]);
The callback will be called with both the @msgs and the @cb_parameters.
-Example :
+ Example :
+ $ivyobject->bindDirectMessage("id1", [\&callback, @cb_parameters]);
- $ivyobject->bindDirectMessage("id1", [\&callback, @cb_parameters]);
+ # Your callback and method must be like:
+ sub cb {
+ my (@cb_parameters, @msgs) = @_;
+ ...
+ }
-Your callback and method must be like:
+ sub method {
+ my ($self, @cb_parameters, @msgs) = @_;
+ ...
+ }
- sub cb {
- my (@cb_parameters, @msgs) = @_;
- ...
- }
-
- sub method {
- my ($self, @cb_parameters, @msgs) = @_;
- ...
- }
+=item B<sendDieTo>
-=head2 $ivyobj->sendDieTo($to)
-
-Ivy::sendDieTo($to)
+ $ivyobj->sendDieTo($to);
+ Ivy::sendDieTo($to);
Send a suicide to the application named $to.
-=head2 $ivyobj->ping($to, $timeout);
+=item B<ping>
-Ivy::ping($to, $timeout);
+ $ivyobj->ping($to, $timeout);
+ Ivy::ping($to, $timeout);
Send a ping message and wait until timeout to receive a pong.
-=head2 $after_id = $ivyobj->after($timeAfter, \@callbacks_list);
+=item B<after>
-$after_id = Ivy::after($timeAfter, \@callbacks_list);
+ $after_id = $ivyobj->after($timeAfter, \@callbacks_list);
+ $after_id = Ivy::after($timeAfter, \@callbacks_list);
Call a list of callbacks after $timeAfter milliseconds.
-=head2 $repeat_id = $ivyobj->repeat($timeAfter, \@callbacks_list);
+=item B<repeat>
-$repeat_id = Ivy:repeat($timeAfter, \@callbacks_list);
+ $repeat_id = $ivyobj->repeat($timeAfter, \@callbacks_list);
+ $repeat_id = Ivy:repeat($timeAfter, \@callbacks_list);
Have a list of callbacks repeatedly called every $timeAfter milliseconds.
-=head2 $ivyobj->afterCancel($after_or_repeat_id);
+=item B<afterCancel>
-Ivy::afterCancel($after_or_repeat_id);
+ $ivyobj->afterCancel($after_or_repeat_id);
+ Ivy::afterCancel($after_or_repeat_id);
Cancel an after callback call.
-=head2 $ivyobj->fileEvent($fd, $cb);
+=item B<afterResetTimer>
+
+ $ivyobj->afterResetTimer($after_id);
+ Ivy::afterResetTimer($after_id);
+
+Reset a timer if this timer has not yet been triggered.
-Ivy::fileEvent($fd, $cb);
+=item B<fileEvent>
+
+ $ivyobj->fileEvent($fd, $cb);
+ Ivy::fileEvent($fd, $cb);
Add a fileEvent handler (or remove any handler associated to $fd if $cb paramter is omitted).
The callback $cb will get the filehandle $fd as parameter.
-=head2 $ivyobj->DESTROY;
+=item B<DESTROY>
+
+ $ivyobj->DESTROY;
+
+Destroy the $ivyobj object. No other method should be applied to the reference of this deleted object. This method should not be used directly.
+
+=back
=head1 BUGS
-The stop method does not work!
-No know bugs at this time. Report them to author.
+The stop method does not work!
+
+No other known bugs at this time. If you find one, please report them to the authors.
=head1 SEE ALSO
@@ -1956,11 +2009,11 @@ perl(1), perlre(1), ivyprobe.pl(1)
=head1 AUTHORS
Alexandre Bustico <bustico@cena.fr>, Herve Damiano <damiano@cena.fr>,
-Stephane Chtatty <chatty@cena.fr>, Christophe Mertz <mertz@@cena.fr>
+Stephane Chatty <chatty@cena.fr>, Christophe Mertz <mertz@@cena.fr>
=head1 COPYRIGHT
-CENA (C) 1997-2000
+CENA (C) 1997-2001
=head1 HISTORY