IPCListCode.c

/*
    File:       IPCListCode.c
 
    Contains:   
 
    Written by: Jim Luther  
 
    Copyright:  Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                7/21/1999   Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                
 
*/
#include "IPCListCode.h"
#include <Types.h>
#include <memory.h>
#include <Packages.h>
#include <Errors.h>
#include <quickdraw.h>
#include <fonts.h>
#include <dialogs.h>
#include <windows.h>
#include <menus.h>
#include <events.h>
#include <OSEvents.h>
#include <Desk.h>
#include <diskinit.h>
#include <OSUtils.h>
#include <resources.h>
#include <toolutils.h>
#include <AppleEvents.h>
#include <EPPC.h>
#include <GestaltEqu.h>
#include <PPCToolbox.h> 
#include <Processes.h>
#include <Balloons.h>
#include <ALiases.h>
#include <Processes.h>
#include <StandardFile.h>
#include <Folders.h>
#include <AppleTalk.h> 
 
 
#if 0
/* Jim's orignal comment */
{*********************************************************************}
{*}
{*  IPCListPorts:  Return a list of PortInfoRecs in the buffer pointed}
{*            to by thePortInfoBufferPtr.  The actual number of}
{*            PortInfoRecs returned will be in theActualCount.}
{*  }
{*  myIPCListPorts}
{*    The function returns with any errors from IPCListPorts.}
{*  theStartIndex}
{*    The index into the port entry list.  To start at the}
{*    beginning, use 0.}
{*  theRequestCount}
{*    The maximum number of portInfoRecs that can be returned.  Make}
{*    sure the buffer pointed to by thePortInfoBufferPtr is at least}
{*    SizeOf(PortInfoRec) * theRequestCount.}
{*  theActualCount}
{*    This returns the actual number of PortInfoRecs returned in }
{*    the buffer pointed to by thePortInfoBufferPtr.}
{*  theObjStr}
{*    The NBP object to be used in the LocationNameRec.}
{*  theZoneStr}
{*    The NBP zone to be used in the LocationNameRec.}
{*  thePortInfoBufferPtr}
{*    This points to an array of PortInfoRecs.  IPCListPorts fills it}
{*    with a list of ports matching thePPCPortRec at the location}
{*    specified by theLocationNameRec.  The size of this array must}
{*    be at least SizeOf(PortInfoRec) * theRequestCount.}
{*  theIPCListPortsPBRec}
{*    The parameter block passed to the IPCListPorts call.  The}
{*    startIndex, requestCount, portName, locationName, and bufferPtr}
{*    fields must be supplied.  If the IPCListPorts call is made}
{*    asynchronously, the ioCompletion field must be supplied.}
{*  thePPCPortRec}
{*    IPCListPorts will only list ports that match the PPC port name}
{*    supplied.  An equal sign (=) can be used for the name and/or}
{*    portTypeStr as a wildcard to match all ports names.}
{*  theLocationNameRec}
{*    IPCListPorts will list the ports at this location.  The}
{*    NBP object and NBP zone must be chosen from the lists returned}
{*    by NBPLookup and GetZoneList.  The NBP type can be application}
{*    specific.  If you don't supply your own NBP type, you should}
{*    use "PPCToolBox" for the NBP type string.  The}
{*    locationKindSelector field must be set to either ppcNoLocation}
{*    (which specifies the local computer) or ppcNBPLocation (which}
{*    specifies the complete NBP entity).}
{*....................................................................}
 
#endif
 
 
OSErr myIPCListPorts(short theStartIndex, short theRequestCount, short *theActualCount, Str32 theObjStr, Str32 theZoneStr,
                     PortInfoArrayPtr thePortInfoBufferPtr)
{
    
    OSErr myErr;
    IPCListPortsPBRec theIPCListPortsPBRec;
    PPCPortRec thePPCPortRec;
    LocationNameRec theLocationNameRec;
    Str32 ppcWord = "\pPPCToolBox";
    /* List all PPC ports at the specified location */
    thePPCPortRec.nameScript = 0;
    thePPCPortRec.name[0] = 1;
    thePPCPortRec.name[1] = '=';                            /* match all names */
    thePPCPortRec.portKindSelector = ppcByString;
    thePPCPortRec.u.portTypeStr[0] = 1;                     /* match all names */
    thePPCPortRec.u.portTypeStr[1] = '=';                   /* match all names */
    
    theLocationNameRec.locationKindSelector = ppcNBPLocation; /* using an NBP construct */
    /* Move the passed infomation into the location name */
    BlockMove((Ptr)&theObjStr[0], (Ptr)&theLocationNameRec.u.nbpEntity.objStr, theObjStr[0] + 1);
    BlockMove((Ptr)&ppcWord[0], (Ptr)&theLocationNameRec.u.nbpEntity.typeStr, ppcWord[0] + 1);
    BlockMove((Ptr)&theZoneStr[0], (Ptr)&theLocationNameRec.u.nbpEntity.zoneStr, theZoneStr[0] + 1);
    /* last parameters */
    theIPCListPortsPBRec.startIndex = theStartIndex;
    theIPCListPortsPBRec.requestCount = theRequestCount;
    theIPCListPortsPBRec.portName = &thePPCPortRec;
    theIPCListPortsPBRec.locationName = &theLocationNameRec;
    theIPCListPortsPBRec.bufferPtr = thePortInfoBufferPtr;
    
    /* Call IPCListPorts synchronously */
    myErr = IPCListPortsSync(&theIPCListPortsPBRec);
    
    *theActualCount = theIPCListPortsPBRec.actualCount;
    return(myErr);
}
 
OSErr GetAllPPCAbleMachines(MPPParamBlock *paramblk)
{
    /* This used to be the main section of the code.  Now I call it to fill in */
    /* my list */
    xppParamblk.XCALL.csCode = xCall;
    xppParamblk.XCALL.xppSubCode = zipGetMyZone;
    xppParamblk.XCALL.xppTimeout = 3;
    xppParamblk.XCALL.xppRetry = 4;
    xppParamblk.XCALL.zipBuffPtr = &zoneName;
    xppParamblk.XCALL.zipInfoField[1] = 0;
    gErr = GetMyZone(&xppParamblk, false);
    
    if (gErr != noErr) {
        DebugStr("\pZone fail");
        zoneName[0] = 1;
        zoneName[1] = '*';
    }
    /* noZone is '*' */
    
    
    NBPSetEntity((Ptr)&myEntityName, "\p=", "\pPPCToolBox", zoneName);
    
    paramblk->NBP.interval = 5;
    paramblk->NBP.count = 5;
    paramblk->NBP.nbpPtrs.entityPtr = (Ptr)&myEntityName;
    paramblk->NBP.parm.Lookup.retBuffPtr = (Ptr)&myRetBuff;
    paramblk->NBP.parm.Lookup.retBuffSize = sizeof(myRetBuff);
    paramblk->NBP.parm.Lookup.maxToGet = MaxTuples;
    paramblk->NBP.parm.Lookup.numGotten = 0;
    gErr = PLookupName(paramblk, false);
    return gErr;
}
 
OSErr GetPortsOnMachine(MPPParamBlock *paramblk)
{
    if (paramblk->NBP.parm.Lookup.numGotten > 0) {
        for (i = 1; i < paramblk->NBP.parm.Lookup.numGotten; i++) {
            //  {extract the NBP name}
            gErr = NBPExtract((Ptr)&myRetBuff, paramblk->NBP.parm.Lookup.numGotten, i, &myEntityName, &myAddrBlock);
            
            //  writeln('Getting ports on ', myEntityName.objStr);
            //  {get the list of PPC ports}
            gErr = myIPCListPorts(0, MaxPorts, &gCount, myEntityName.objStr, myEntityName.zoneStr, gPortInfoBuffer);
            
            //  FOR j = 1 TO gCount DO
            //  Writeln('  ', gPortInfoBuffer[j].name.name);
            
        }
    }
    return gErr;
}