iacreceive.c

Go to the documentation of this file.
00001 
00002 /*  $Id: iacreceive.c 355 2005-01-11 22:48:55Z andreradke $    */
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 8/24/92 DW: This file includes routines that are likely to be used by code 
00015 that receives Apple Events.
00016 */
00017 
00018 
00019 Boolean IACreturnerror (short errn, Str255 errs) {
00020     
00021     /*
00022     return an error string and number in an AppleEvent.
00023     
00024     SDK 2.0: if the string is nil or empty, don't push it on the reply.
00025     */
00026     
00027     AppleEvent *savedevent;
00028     Boolean fl;
00029     
00030     savedevent = IACglobals.event;
00031     
00032     IACglobals.event = IACglobals.reply; /*push params on the reply record*/
00033     
00034     fl = true;
00035     
00036     if (errs != nil) 
00037         if (errs [0] > 0)
00038             fl = IACpushstringparam (errs, keyErrorString);
00039             
00040     if (fl)
00041         fl = IACpushshortparam (errn, keyErrorNumber);
00042     
00043     IACglobals.event = savedevent; /*restore*/
00044     
00045     return (fl);
00046     } /*IACreturnerror*/
00047     
00048 
00049 void IACnothandlederror (void) {
00050     
00051     /*
00052     call this if you receive an Apple event that you are not set up to handle.
00053     
00054     we return the standard "event not handled" error return. you can safely 
00055     return noErr to the Apple Event Manager.
00056     */
00057     
00058     IACreturnerror (errAEEventNotHandled, nil);
00059     } /*IACnothandlederror*/
00060     
00061     
00062 Boolean IACnextparamisoptional (void) {
00063     
00064     IACglobals.nextparamoptional = true;
00065     
00066     return (true);
00067     } /*IACnextparamisoptional*/
00068 
00069 
00070 void IACparamerror (OSErr errn, Str255 typestring, OSType paramkey) {
00071 
00072     /*
00073     build an error string that looks like:
00074     
00075         The 'read' verb requires a string parameter with a key of '----'
00076     
00077     And return it to the caller.
00078     */
00079     
00080     Str255 errs;
00081     Str255 bs;
00082     OSType verbtoken;
00083     
00084     if (IACglobals.nextparamoptional) { /*it's not an error, since the caller set this flag*/
00085     
00086         IACglobals.nextparamoptional = false; /*must be reset for each param*/
00087     
00088         return;
00089         }
00090         
00091     verbtoken = IACgetverbtoken ();
00092     
00093     IACcopystring ("\pThe '", errs);
00094     
00095     bs [0] = 4;
00096     
00097     BlockMove (&verbtoken, &bs [1], 4);
00098     
00099     IACpushstring (bs, errs);
00100     
00101     IACpushstring ("\p' verb requires a ", errs);
00102     
00103     IACpushstring (typestring, errs);
00104     
00105     IACpushstring ("\p parameter with a key of '", errs);
00106     
00107     bs [0] = 4;
00108     
00109     BlockMove (&paramkey, &bs [1], 4);
00110     
00111     IACpushstring (bs, errs);
00112     
00113     IACpushstring ("\p'", errs);
00114     
00115     IACreturnerror (errn, errs);
00116     } /*IACparamerror*/
00117     
00118     
00119 OSType IACgetverbtoken (void) {
00120     
00121     /*
00122     get the id/token of a verb from an AppleEvent
00123     */
00124     
00125     OSType verbtoken;
00126     
00127     if (!IACgetlongattr (IACglobals.event, keyEventIDAttr, typeType, (long *) &verbtoken))
00128         verbtoken = (OSType) 0;
00129     
00130     return (verbtoken);
00131     } /*IACgetverbtoken*/
00132 
00133 
00134 OSType IACgetverbclass (void) {
00135     
00136     /*
00137     get the id/token of a verb from an AppleEvent
00138     */
00139     
00140     OSType verbclass;
00141     
00142     if (!IACgetlongattr (IACglobals.event, keyEventClassAttr, typeType, (long *) &verbclass))
00143         verbclass = (OSType) 0;
00144     
00145     return (verbclass);
00146     } /*IACgetverbclass*/
00147 
00148 
00149 OSType IACgetsender (void) { 
00150 
00151     /*
00152     get application signature from address attribute. automatically
00153     invokes our coercion handlers.
00154     
00155     this is needed by the Menu Sharing Toolkit -- when the user presses
00156     cmd-period to halt a script, the next time we get a message from the
00157     Menu Sharing server (usually Frontier) we return an error. but we only
00158     return the error if the call came from Frontier, we use this routine
00159     to identify the sender of the message.
00160     
00161     thanks to Kevin Calhoun of Apple Computer for providing this code! 
00162     */
00163 
00164     OSType sender;
00165     Size actualsize;
00166     DescType actualtype;
00167     OSErr errcode;
00168     
00169     errcode = AEGetAttributePtr (
00170         IACglobals.event, keyAddressAttr, typeType, &actualtype, (Ptr) &sender, 
00171         
00172         (long) sizeof (sender), &actualsize);
00173 
00174     IACglobals.errorcode = errcode;
00175     
00176     return (sender);
00177     } /*IACgetsender*/
00178 
00179         

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