[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] availability of output in remote control mode



hmlehman@es.unizh.ch (Hans Martin Lehmann) writes:
>>John_Peterson@byu.edu writes:
>>>How does one become aware that output is available from a
>>>remote-controlled MacPerl script.  Do you really just have to keep
>>>polling?
>>
>>Yes, there currently is no mechanism to "push" data from Perl other than
>>reading or the end of the script.

>Well, I don't know whether this is feasible. What would really make my day
>would be an option that allows me to send data directly to STDIN of a
>running script and have the AppleScript component wait for an application
>response with the data written to STDOUT from Perl. Vice versa Perl should
>just wait till it receives a data event.
>
>What would I use it for?
>
>I have > 10 MB of data that I can only get at in chunks < 32k (blessed be
>HyperCard's storage limits!). The data is linked to an index I need to
>consult after every chunk. At the moment I use one Do Script event per 32k
>chunk. With a Send Data event as described above I could avoid restarting
>one and the same perl script each time I process a chunk (or gobbling up
>processing power polling for the output).

This is possible, if a little awkward, to acheive with the current mechanism,
provided the calling application can receive, as well as send, Apple Events.
The basic outline goes like this:

Perl:

while (1) {
   $request = <STDIN>;

   print &reply($request);
}

Client, relaxed:

main()
{
        Start Perl in Duplex mode with SASE procedure
        while(1) {
           request_pending = 1;
           Send Data(request);
           do other stuff until request_pending = 0;
        }
}

SASE(event_from_perl)
{
        if (request_pending) {
            reply = Piggybacked Data contained in event_from_perl
            request_pending = 0;
        }
        reply(No Data);
}

Client, aggressive:

main()
{
        Start Perl in Remote Control mode without SASE procedure
        while(1) {
           Send Data(request);
           data in reply is response to repvious request
        }
}

The relaxed client uses 2 events per request, the aggressive client 1 (at the
cost of interleaving requests&replies.

BTW, the Mac::AppleEvents shared library for PowerPC compiled yesterday, so
at least PowerPC users should be able to handle arbitrary AppleEvents around
the end of this month.

Matthias

-----
Matthias Neeracher <neeri@iis.ee.ethz.ch> http://err.ethz.ch/members/neeri.html
  "And that's why I am going to turn this world upside down, and make
   of it a fire so *bright* that someone real will notice"
                                -- Vernor Vinge, _Tatja Grimm's World_