Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > triggering callback from "outside"

Reply
Thread Tools

triggering callback from "outside"

 
 
Hannes
Guest
Posts: n/a
 
      03-06-2004
Hi,

does anybody know if it is possible to trigger a callback from the "outside"
(another process).
The only method I know of, are (unix) signals, which won't work for me
(since signal handling is delayed in Perl/Tk MainLoop, and won't work on
win32 platforms).

Hannes
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      03-06-2004

Hannes <(E-Mail Removed)> wrote:
> does anybody know if it is possible to trigger a callback from the "outside"
> (another process).
> The only method I know of, are (unix) signals, which won't work for me
> (since signal handling is delayed in Perl/Tk MainLoop, and won't work on
> win32 platforms).


It depends on what the receiving process is waiting for... you can use
sockets (probably best for portablility), fifos... read perldoc perlipc
for some idea of the possible mechanisms.

Ben

--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces molit animos, tristesque mentes erigit. | http://www.velocityreviews.com/forums/(E-Mail Removed)
Musica vel ipsas arbores et horridas movet feras. |
 
Reply With Quote
 
 
 
 
ctcgag@hotmail.com
Guest
Posts: n/a
 
      03-06-2004
Hannes <(E-Mail Removed)> wrote:
> Hi,
>
> does anybody know if it is possible to trigger a callback from the
> "outside" (another process).


Isn't the point of a callback that the outside process decides when *it*
wants to trigger it? If you want to tell the outside process what to do,
isn't that just an ordinary call?

Maybe I don't understand the question...

> The only method I know of, are (unix) signals, which won't work for me
> (since signal handling is delayed in Perl/Tk MainLoop, and won't work on
> win32 platforms).


Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
Ala Qumsieh
Guest
Posts: n/a
 
      03-07-2004
Hannes wrote:

> The only method I know of, are (unix) signals, which won't work for me
> (since signal handling is delayed in Perl/Tk MainLoop, and won't work on
> win32 platforms).


As I suggested in comp.lang.perl.tk, why don't you use sockets? Did you
try that approach?

I would make the Tk process the server, and listen (in a non-blocking
manner) at a certain port and wait for data to be read. Then any other
app can connect to that port and trigger the callback by sending the
correct data.

--Ala

 
Reply With Quote
 
Hannes
Guest
Posts: n/a
 
      03-07-2004

> I would make the Tk process the server, and listen (in a non-blocking
> manner) at a certain port and wait for data to be read. Then any other
> app can connect to that port and trigger the callback by sending the
> correct data.


Is there a way in Perl to get a callback triggered by incoming data?
Keeping the process busy by polling the non-blocking socket in an
idle-callback wouldn't be very good...

Hannes

 
Reply With Quote
 
Ala Qumsieh
Guest
Posts: n/a
 
      03-07-2004
Hannes wrote:

> Is there a way in Perl to get a callback triggered by incoming data?
> Keeping the process busy by polling the non-blocking socket in an
> idle-callback wouldn't be very good...


Why not? That's very similar to what Tk::MainLoop() is doing. You have
to poll to find something (unless you're using signals, but in your case
you can't).

For your purposes, I would replace the call to Tk::MainLoop with
something like the following [untested - adapted from example in perldoc
IO::Select]:

use Tk qw/:eventtypes/;
use IO::Select;
use IO::Socket;

my $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 12345);
my $sel = new IO::Select($lsn);

while (1) { # this is your mainloop
# process any Tk events like mouse moves/button presses/etc
1 while $MW->DoOneEvent(ALL_EVENTS|DONT_WAIT);

# poll for any data in the sockets in a non-blocking way
if (my @ready = $sel->can_read(0.1)) {
for my $fh (@ready) {
if ($fh == $lsn) { # new connection
my $new = $lsn->accept;
$sel->add($new);
} else {
# somebody sent something
my $data = <$fh>;
if (defined $data) {
#
# trigger your callback based on what $data contains.
#
} else { # hung up
$sel->remove($fh);
$fh->close;
}
}
}
}
}

Now your clients can connect to port 12345 on the local machine and send
whatever data is needed to trigger the callbacks.

--Ala

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Client Side OnBlur Triggering Validation =?Utf-8?B?Sm9lLkRhdHRpbG8=?= ASP .Net 1 06-18-2004 09:06 PM
Triggering Button clicked event when I hit enter key at edit box.... Veeresh ASP .Net 1 06-16-2004 07:38 AM
Triggering dial-up Marco Wong Cisco 1 11-28-2003 02:23 PM
Triggering both client and server side scripts Karim ASP .Net 3 11-26-2003 04:20 PM
CustomControl - Not triggering on an empty field. Eric B ASP .Net 1 09-03-2003 09:24 AM



Advertisments