[comp.sys.mac] article about jGNEFilter in MacTuto

kkim@uiucdcsb.cs.uiuc.edu (08/10/87)

>> I would like to intercept calls to an Operating System or Toolbox routine 
>> (specifically, GetNextEvent) and do some pre- and/or post-processing of my 
>> own.  NGetTrapAddress and NSetTrapAddress seem useful to do it.
>
> Actually, there is a hook for GetNextEvent which may be used.  There was an
> article about it in MacTutor last year or so.  I believe the global is 
> JGNEFilter or something like that.  You might want to look up that issue.

I checked all tables of contents of MacTutor and got the following list:

vol/no year/month title                           author           page
2/12   86/dec     Trap Speed comments             ???              6
2/10   86/oct     Reduce your time in the traps   Mike Morton      21
1/10   85/sep     C Glue routines for Filter Procs Van Kichline    53
1/6    85/may     In line traps simulate OS calls ???              53
1/5    85/apr     In line traps create windows    ???              20
1/3    85/feb     traps and so FORTH              ???              23

Is there anybody out there who can tell me which article talks about 
"jGNEFilter" ?  Or is the article missing in the above list?

Also, any information about jGNEFilter/NGetTrapAddress/NSetTrapAddress
will be appreciated (I have already checked Inside Mac and Mac Tech Notes). 
Please e-mail to me. Thanks in advance.

Kyongsok KIM

Dept. of Computer Science; Univ. of Illinois at Urbana-Champaign

arpanet/csnet: kkim@a.cs.uiuc.edu
usenet/uucp  : {seismo, pur-ee, ihnp4}!uiucdcs!kkim

tim@hoptoad.uucp (Tim Maroney) (08/11/87)

All such filters are not long for this world and should be avoided.  I
believe that you never need to patch GetNextEvent or intercept it in any
case, since you can always do whatever extra processing is needed normally
inside your main event loop, and it is nearly trivial to install a filter
procedure in all your modal dialogs which will handle events as neccessary.
In TOPS Terminal, I have done just this, with the result that all background
type actions, such as receiving data on a terminal connection, take place
behind any modal dialogs that come up.  Don't ever patch a trap unless you
absolutely have to!  And *never* use a low-memory-global-based hook, because
it will stop working very soon if it hasn't already.

In fact (it should be kosher to say this now that MultiFinder is all over
the trades and being announced in Boston), all low-memory globals are going
away pretty soon.  This should cause some amusement among those who remember
that an Apple employee viciously flamed me here last year for my suggestion
that Apple should decommission all the low-memory globals over the space of
a year.  Don't worry, I don't expect an apology.
-- 
Tim Maroney, {ihnp4,sun,well,ptsfa,lll-crg,frog}!hoptoad!tim (uucp)
hoptoad!tim@lll-crg (arpa)

kkim@uiucdcsb.cs.uiuc.edu (08/12/87)

> /* Written Aug 11, 1987 by tim@hoptoad.uucp in uiucdcsb:comp.sys.mac */
> you never need to patch GetNextEvent or intercept it in any case, since you
> can always do whatever extra processing is needed normally inside your main
> event loop...  Don't ever patch a trap unless you absolutely have to! 

 my main objective is to modify event queue elements within a DESK ACCESSORY
so that an application can retrieve modified keydown events.  somebody
suggested me to use NGetTrapAddress/NSetTrapAddress.  i looked up the Inside 
Mac but could not figure how to patch GetNextEvent using these two traps.
 then i posted a question on comp.sys.mac how to patch GetNextEvent and 
somebody suggested to use jGNEFilter saying that there was an article about it
in MacTutor.  that is my story.

 therefore, if i can modify keydown events within a desk acc without patching
GetNextEvent, i will be happy to hear the method.  if i have to patch, i 
would like to know how to patch it (probably using these two traps).

 thanks.

Kyongsok KIM
arpanet/csnet: kkim@a.cs.uiuc.edu
usenet/uucp  : {seismo, pur-ee, ihnp4}!uiucdcs!kkim

jwhitnel@csib.UUCP (08/14/87)

In article <164500043@uiucdcsb> kkim@uiucdcsb.cs.uiuc.edu writes:
| therefore, if i can modify keydown events within a desk acc without patching
|GetNextEvent, i will be happy to hear the method.  if i have to patch, i 
|would like to know how to patch it (probably using these two traps).

I'm writting this without reference to IM, so take it with a small grain of
salt.  This is in C, translation to Pascal or other lanaguages is left as
an exercise for the reader.

#define GNE_TRAP 0xa??? /* Trap number for GetNextEvent (from IM) */

typedef int (*funcptr)();    /* Pointer to function returning an int */

functptr oldGetNextEvent;

/* initlization code */
    oldGetNextEvent = NGetTrapAddr( GNE_TRAP );
    NSetTrapAddr( myGetNextEvent );

/* This is the patch itself, parameters must match GetNextEvent */
pascal Boolean myGetNextEvent( event, mask )
EventRecord *event;
int mask; {
    Boolean retCode;

    /* First call real GetNextEvent to get the event.  CallPascalW calls
    ** indirectly a pascal function from C.  Your glue may differ here
    */
    retCode = CallPascalW( event, mask, oldGetNextEvent );
    if ( retCode )
    {
	/* We have an event, so preprocess it */
    }

    return( retCode );
}

/* termination code.  Must be executed before application termination or
** bad things will happen, not the least of which is your mac will crash
*/
     SetTrapAddr( GNE_TRAP, oldGetNextEvent );


That's it.  The initilzation code is executed once when your DA initlizes,
the termination code is executed once when your DA is closed and the patch
code is what is executed when the application calls GetNextEvent.  Caveat,
this method works only on Mac+ or newer system, it will not work on 64K ROM
systems (and no flames about that, please).

    
|
| thanks.
|
|Kyongsok KIM
|arpanet/csnet: kkim@a.cs.uiuc.edu
|usenet/uucp  : {seismo, pur-ee, ihnp4}!uiucdcs!kkim


Jerry Whitnell                           It's a damn poor mind that can only
Communication Solutions, Inc.            think of one way to spell a word.
						-- Andrew Jackson

glennr@cognos.uucp (Glenn D. Rasmussen) (08/17/87)

In article <164500042@uiucdcsb> kkim@uiucdcsb.cs.uiuc.edu writes:
>
>Is there anybody out there who can tell me which article talks about 
>"jGNEFilter" ?  Or is the article missing in the above list?
>
jGNEFilter was described in the article that implemented a screen blanker.
I can't remember which issue it was in, but I do know that it is in the
Best of MacTutor Volume 1.

-- 
Glenn D. Rasmussen    3755 Riverside Dr.
Cognos Incorporated   Ottawa, Ontario    {allegra,decvax,ihnp4,linus,pyramid}
(613) 738-1440        CANADA  K1G 3N3    !utzoo!dciem!nrcaer!cognos!glennr