iacasynch.c

Go to the documentation of this file.
00001 
00002 /*  $Id: iacasynch.c 1198 2006-04-05 22:03:52Z karstenw $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "frontier.h"
00008 #include "standard.h"
00009 
00010 #include "iacinternal.h"
00011 
00012 
00013 /*
00014 7/16/94 dmb: Updated for Univeral Headers, PowerPC
00015 */
00016 
00017 
00018 #define ctreplyhandlers 10
00019 
00020 typedef struct tyreplyhandler {
00021     
00022     long id;
00023     
00024     tyAsynchCallback callback;
00025     } tyreplyhandler;
00026     
00027 tyreplyhandler replyhandlers [ctreplyhandlers];
00028 
00029 
00030 
00031 
00032 static Boolean IACaddreplyhandler (tyAsynchCallback pcallback, long id) {
00033     
00034     short i;
00035     
00036     for (i = 0; i < ctreplyhandlers; i++) { /*find an empty slot*/
00037         
00038         if (replyhandlers [i].id == 0) {
00039             
00040             replyhandlers [i].id = id;
00041             
00042             replyhandlers [i].callback = pcallback;
00043             
00044             return (true);
00045             }
00046         } /*for*/
00047     
00048     return (false); /*all slots are in use*/
00049     } /*IACaddreplyhandler*/
00050 
00051 
00052 static pascal OSErr IAChandleanswer (AppleEvent *event, AppleEvent *reply, long refcon) {
00053 #pragma unused(reply, refcon)
00054 
00055     long replyid;
00056     short i;
00057     
00058     if (!IACgetlongattr (event, keyReturnIDAttr, typeLongInteger, &replyid))
00059         return (errAEEventNotHandled);
00060         
00061     for (i = 0; i < ctreplyhandlers; i++) {
00062         
00063         if (replyhandlers [i].id == replyid) {
00064             
00065             replyhandlers [i].id = 0;
00066             
00067             (*replyhandlers [i].callback) (event);
00068             }
00069         } /*for*/
00070         
00071     return (errAEEventNotHandled);
00072     } /*IAChandleanswer*/
00073 
00074 
00075 static Boolean IACasynchinitcheck (void) {
00076     
00077     static Boolean fl = false;
00078     short i;
00079     
00080     if (fl) /*it's already been initialized*/
00081         return (true);
00082 
00083     for (i = 0; i < ctreplyhandlers; i++)   
00084         replyhandlers [i].id = 0;
00085         
00086     fl = IACinstallhandler (kCoreEventClass, kAEAnswer, (ProcPtr) &IAChandleanswer);
00087     
00088     return (fl);
00089     } /*IACasynchinitcheck*/
00090     
00091 
00092 Boolean IACsendasynch (AppleEvent *event, tyAsynchCallback pcallback) {
00093 
00094     AppleEvent reply;
00095     OSErr ec;
00096     long replyid;
00097     
00098     if (!IACasynchinitcheck ())
00099         return (false);
00100     
00101     if (!IACgetlongattr (event, keyReturnIDAttr, typeLongInteger, &replyid))
00102         return (false);
00103     
00104     if (pcallback != nil) { /*DW 7/30/93*/
00105     
00106         if (!IACaddreplyhandler (pcallback, replyid))
00107             return (false);
00108         }
00109     
00110     ec = AESend (
00111         
00112         event, &reply, kAEQueueReply + kAECanInteract + kAECanSwitchLayer, 
00113         
00114         kAENormalPriority, kNoTimeOut, IACwaitroutineUPP, nil);
00115     
00116     AEDisposeDesc (event);  
00117     
00118     IACglobals.errorcode = ec;
00119     
00120     return (ec == noErr);
00121     } /*IACsendasynch*/
00122 
00123 

Generated on Wed May 31 18:19:47 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6