home *** CD-ROM | disk | FTP | other *** search
- // Copyright: © 1993 Apple Computer, Inc. All rights reserved.
- // Author: Scott Searle (original)
- // Victor J. Hnyp (extensions)
- // Date: 24-Mar-93
-
- // Revisions
- // 4/25/94 SG 3.01 Fixed: Replace hard coded strings LaserWriter and AppleTalk ImageWriter with 2 char[32]s
- //
- // 4/22/94 SG 3.00 New: New Projector database
- //
- // 9/3/93 JJ 2.06 Added: IsAnyZones
- //
- // 03/24/93 VJH 2.05 Fixed: isPortInUse
- //
- // 03/15/93 VJH 2.04 Fixed: IsPortSelected, isPortInUse
- //
- // 02/08/93 VJH 2.03 Fixed: AppleTalk related states
- //
- // 01/18/93 VJH 2.02 Fixed: AppleTalk related states
- //
- // 12/14/92 VJH 2.01 Added: Is a printer connected directly to this Macintosh?
- // Is the number of network printers connected to our zone...?
- // Is a serial printer connected to this Macintosh through ModemPort/PrinterPort?
- // Is a printer connected to this Macintosh through a SCSI port?
- // Is the number of printers connected...?
- // Is a printer currently selected through the Chooser?
- // Is the selected print driver "..."?
- // Is AppleTalk on/off?
- // Does the network have any zones?
- // Is ModemPort/PrinterPort currently selected?
- // Is ModemPort/PrinterPort currently in use?
- #pragma load "AllHeaders.dump"
-
- #include "Utility.h"
- #include "Proto.h"
- #include "Context.h"
- #include "Chooser.h"
-
- #define kPrinterNameStrID (-8192)
- #define kMaxResponses 8
- #define UTableBase 0x11C
-
-
- /* ------------------ Forward declaration -------------------- */
- pascal Boolean IsPrinterName(PrinterInfoPtr msg);
- pascal Boolean DetermineATState(ATStateInfoPtr msg);
- pascal Boolean NumZonePrintersConnected(CompareInfoPtr msg);
- pascal Boolean NumberOfZonesCompare(CompareInfoPtr msg);
- pascal Boolean IsPortSelectedCompare(ATStateInfoPtr msg);
- pascal Boolean IsPortInUseCompare(ATStateInfoPtr msg);
- pascal Boolean IsAnyZones();
- SPortSel GetPrinterConnection(void);
-
-
- //const char printer1[32] = "\pLaserWriter"; /* allocate 2 strings long enough for localization purpose */
- //const char printer2[32] = "\pAppleTalk ImageWriter";
-
-
- pascal OSErr main(ContextSelectorPtr msg, Size inSize,
- void* outMessage, Size* outSize, Handle /*startGlobals*/)
- {
- Boolean ret = false;
- OSErr err = errAECorruptData;
-
- if(inSize < sizeof(ContextSelector)) /* If inSize is < length of selector (a long), */
- return(err); /* return an error. Would be nice to have a specific error # */
-
- switch (msg->selector)
- {
- case isPrinterDirect: // Is a printer connected directly to this Macintosh?
- ret = false;
- break;
-
- case isPrintersOnZone: // Is the number of network printers connected to our zone...?
- ret = NumZonePrintersConnected((CompareInfoPtr) msg);
- break;
-
- case isPrinterSerial: // Is a serial printer connected to this Macintosh through ModemPort/PrinterPort?
- ret = false;
- break;
-
- case isPrinterSCSI: // Is a printer connected to this Macintosh through a SCSI port?
- ret = false;
- break;
-
- case isPrinterType: // Is the type of the selected printer "..."?
- ret = IsPrinterName((PrinterInfoPtr)msg);
- break;
-
- case isAppleTalk: // Is AppleTalk on/off?
- ret = DetermineATState((ATStateInfoPtr)msg);
- break;
-
- case isNumberOfZones: // Does the network have any zones?
- ret = NumberOfZonesCompare((CompareInfoPtr) msg);
- break;
-
- case isPortSelected: // Is ModemPort/PrinterPort currently selected?
- ret = IsPortSelectedCompare((ATStateInfoPtr) msg);
- break;
-
- case isPortInUse: // Is ModemPort/PrinterPort currently in use?
- ret = IsPortInUseCompare((ATStateInfoPtr) msg);
- break;
-
- case isAnyZones: // Are there 2 or 3 boxes in the Chooser?
- ret = IsAnyZones();
- break;
-
- default: /* None of the pre-defined types. Exit with error */
- return(err); /* Would be nice to have a specific error # */
- }
-
- err = SetContextResult(&ret, sizeof(Boolean), outMessage, outSize);
- return(err);
- }
-
-
-
- pascal Boolean IsPrinterName(PrinterInfoPtr msg)
- {
- Str255 name;
- Boolean ret = false;
- OSErr err = noErr;
-
- if ((err = GetTheString(kPrinterNameStrID, name)) == noErr)
- {
- ret = CompareStringSpec(name, &msg->printerName);
- }
-
- return(ret);
- }
-
-
-
- pascal Boolean DetermineATState(ATStateInfoPtr msg)
- {
- Boolean ret = false;
- OSErr err = noErr;
-
- err = ATPLoad(); // Attempt to load AppleTalk
-
- if((msg->wantedATState) && // If checking for AppleTalk ON
- (!err)) // and no error opening the driver
- ret = true;
-
- if(!(msg->wantedATState) && // If checking for AppleTalk OFF
- (err)) // and error opening the driver
- ret = true;
-
- return(ret);
- }
-
-
-
- pascal Boolean NumZonePrintersConnected(CompareInfoPtr msg)
- {
- Boolean ret = false;
- OSErr err = noErr;
- short totalCount;
- char addressBook[kMaxResponses*sizeof(EntityName)]; /* ATP Max buffer */
- EntityName lookupEntity; /* entity currently being looked up */
- NBPparms NBPPB; /* used for general NBP stuff */
- const char printer1[32] = "\pLaserWriter"; /* allocate 2 strings long enough for localization purpose */
- const char printer2[32] = "\pAppleTalk ImageWriter";
-
- if( ATPLoad() ) // AppleTalk is not active!
- return( ret );
-
- NBPSetEntity( (Ptr)&lookupEntity, "\p=", printer1, "\p*"); /* Only within this zone */
-
- totalCount = 0; /* We got no replies yet */
-
- /* Set up the NBP lookup */
- NBPPB.interval = 4; /* Try for 4 seconds */
- NBPPB.count = 4; /* Try up to 4 times */
- NBPPB.NBPPtrs.entityPtr = (Ptr)&lookupEntity; /* This is what we're looking for */
- NBPPB.parm.Lookup.retBuffPtr = addressBook; /* Put responses here */
- NBPPB.parm.Lookup.retBuffSize = kMaxResponses*sizeof(EntityName); /* Buffer size */
- NBPPB.parm.Lookup.maxToGet = kMaxResponses; /* How many will we accept? */
- NBPPB.parm.Lookup.numGotten = 0; /* Didn't get any yet */
-
- /* Perform the lookup, SYNCHRONOUSLY */
- err = PLookupName((MPPPBPtr)&NBPPB,false);
-
- if( !(err) )
- {
- totalCount = NBPPB.parm.Lookup.numGotten; /* Save off # of laserWriters */
-
- NBPSetEntity( (Ptr)&lookupEntity, "\p=", printer2, "\p*"); /* Only within this zone */
-
- /* Set up the NBP lookup */
- NBPPB.interval = 4; /* Try for 4 seconds */
- NBPPB.count = 4; /* Try up to 4 times */
- NBPPB.NBPPtrs.entityPtr = (Ptr)&lookupEntity; /* This is what we're looking for */
- NBPPB.parm.Lookup.retBuffPtr = addressBook; /* Put responses here */
- NBPPB.parm.Lookup.retBuffSize = kMaxResponses*sizeof(EntityName); /* Buffer size */
- NBPPB.parm.Lookup.maxToGet = kMaxResponses; /* How many will we accept? */
- NBPPB.parm.Lookup.numGotten = 0; /* Didn't get any yet */
-
- /* Perform the lookup, SYNCHRONOUSLY */
- err = PLookupName((MPPPBPtr)&NBPPB,false);
- }
-
- if( err ) /* For lookups, not unregistering! */
- return( ret );
-
- totalCount = totalCount + NBPPB.parm.Lookup.numGotten;
-
- switch (msg->compareSelector)
- {
- case equals:
- ret = totalCount == msg->compareValue;
- break;
-
- case notEqualTo:
- ret = totalCount != msg->compareValue;
- break;
-
- case greaterThan:
- ret = totalCount > msg->compareValue;
- break;
-
- case lessThan:
- ret = totalCount < msg->compareValue;
- break;
-
- case greaterThanOrEqualTo:
- ret = totalCount >= msg->compareValue;
- break;
-
- case lessThanOrEqualTo:
- ret = totalCount <= msg->compareValue;
- break;
- }
-
- return( ret );
-
- } // NumZonePrintersConnected
-
-
-
- pascal Boolean NumberOfZonesCompare(CompareInfoPtr msg)
- {
- Boolean ret = false;
- OSErr err = noErr;
- XCallParam xpb;
- char theBufferPtr[578];
-
- if( ATPLoad() ) // AppleTalk is not active!
- return( ret );
-
- xpb.zipInfoField[0] = 0;
- xpb.zipInfoField[1] = 0;
-
- xpb.ioRefNum = xppRefNum; // driver refNum -41
- xpb.csCode = xCall;
- xpb.xppSubCode = zipGetZoneList;
- xpb.xppTimeout = 4;
- xpb.xppRetry = 4;
- xpb.zipBuffPtr = (Ptr)theBufferPtr;
-
- err = PBControl((ParmBlkPtr)&xpb, false); // Asynchronous call
- if( err )
- return( ret );
-
- // At this point, xpb.zipNumZones returns the number of zones we found.
-
- switch (msg->compareSelector)
- {
- case equals:
- ret = xpb.zipNumZones == msg->compareValue;
- break;
-
- case notEqualTo:
- ret = xpb.zipNumZones != msg->compareValue;
- break;
-
- case greaterThan:
- ret = xpb.zipNumZones > msg->compareValue;
- break;
-
- case lessThan:
- ret = xpb.zipNumZones < msg->compareValue;
- break;
-
- case greaterThanOrEqualTo:
- ret = xpb.zipNumZones >= msg->compareValue;
- break;
-
- case lessThanOrEqualTo:
- ret = xpb.zipNumZones <= msg->compareValue;
- break;
- }
-
- return( ret );
-
- } // NumberOfZonesCompare
-
-
-
- pascal Boolean IsPortSelectedCompare(ATStateInfoPtr msg)
- {
- Boolean ret = false;
- OSErr err = noErr;
- SPortSel whichPort;
-
- whichPort = GetPrinterConnection();
-
- switch (msg->wantedATState)
- {
- case ModemPort:
- ret = whichPort == sPortA;
- break;
-
- case PrinterPort:
- ret = whichPort == sPortB;
- break;
- }
-
- return(ret);
- } // IsPortSelectedCompare
-
-
-
- pascal Boolean IsPortInUseCompare(ATStateInfoPtr msg)
- {
- Boolean ret = false;
- OSErr err = noErr;
- AuxDCE** dceh;
-
- switch (msg->wantedATState)
- {
- case ModemPort:
- dceh = (*(AuxDCE****)UTableBase)[5]; // .AIn
- if((*dceh)->dCtlFlags & 0x20)
- ret = true;
-
- dceh = (*(AuxDCE****)UTableBase)[6]; // .AOut
- if((*dceh)->dCtlFlags & 0x20)
- ret = true;
- break;
-
- case PrinterPort:
- err = ATPLoad(); // Attempt to load AppleTalk
- if(!err)
- ret = true; // AppleTalk is on
-
- dceh = (*(AuxDCE****)UTableBase)[7]; // .BIn
- if((*dceh)->dCtlFlags & 0x20)
- ret = true;
-
- dceh = (*(AuxDCE****)UTableBase)[8]; // .BOut
- if((*dceh)->dCtlFlags & 0x20)
- ret = true;
- break;
- } // switch
-
- return(ret);
- } // IsPortInUseCompare
-
-
-
- SPortSel GetPrinterConnection()
- /*
- This function returns sPortA or sPortB, whichever
- the printer is connected to, as determined from
- parameter RAM. Note: the result is only valid in
- the case where you have a printer that is connected
- directly to the Macintosh.
- */
- {
- SysPPtr pRAMptr; /* See IM-II pg. 370 */
-
- pRAMptr = GetSysPPtr(); /* See IM-II pg. 381 */
-
- /* bit zero indicates which port */
- /* bit zero = 0 = printer port */
- /* bit zero = 1 = modem port */
- if(pRAMptr->kbdPrint & 0x0001)
- return sPortA; /* Modem Port */
- else
- return sPortB; /* Printer Port */
- }
-
-
- pascal Boolean IsAnyZones()
- {
- Boolean ret = false;
- OSErr err = noErr;
- XPPParamBlock myXPPPB;
- char ignoredName[33]; // we could care less about the zone name
-
- if( ATPLoad() ) // AppleTalk is not active!
- return( ret );
-
- myXPPPB.XCALL.xppTimeout = 2;
- myXPPPB.XCALL.xppRetry = 2;
- myXPPPB.XCALL.zipBuffPtr = ignoredName;
- myXPPPB.XCALL.zipInfoField[0] = 0;
- myXPPPB.XCALL.zipInfoField[1] = 0;
-
- err = GetMyZone( &myXPPPB, false ); // returns error if no router available
-
- ret = (Boolean)(err == noErr); // if noErr than we are on a zone,
-
- return(ret);
- }
-
-
-