TweetFollow Us on Twitter

HyperAppleTalk 4
Volume Number:5
Issue Number:4
Column Tag:HyperChat™

Related Info: AppleTalk Mgr

XCMD Corner: HyperAppleTalk IV

By Donald Koscheka, Arthur Young & Co., MacTutor Contributing Editor

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

I sometimes think that, to most programmers, the network is best left to the handful of specialists that ply their craft on this arcane art.

Think of the network as adding a new dimension to your programs, much as perspective enabled medieval artists to add depth and realism to their paintings. While many artists may have scoffed at perspective, I have no trouble believing that the populace was awed by its discovery. Perhaps networking will shine the same light as we enter the renaissance of computer programming.

If you’ve been following this column over the last three months, you may be asking yourself, “Are we there yet?” This month, we tie the pieces together by introducing the rest of AppleTalk XCMDs. I apologize for publishing listings last month that you can’t really use until this month. I hope this issue makes up for it and in the future I will do my best to provide “soup to nuts” code in each issue.

Conceptually, an AppleTalk interface can be reduced to the six steps: (1) Open access to the transaction protocol and allocate any memory that will be needed to interface to it. I chose the AppleTalk Data Stream Protocol(ADSP). ADSPOpen hooks us up to ADSP, establishes a connection listener and returns the connection listener’s socket address to Hypercard. NBPOpen initializes a data structure that we use to interface to NBP. The January ’89 issue of this column provides the code for these XCMDs.

(2) Given the address of the connection listener, register a name and type with the network using the name binding protocol. Once registered, our entity’s name and address will be listed in the “directory”.

(3) If we want to be able to “dial up” other entities, we next perform a lookup which returns all current names in the lookup table which acts just like a directory. The names are returned as a list of items to Hypercard without their addresses. This step is optional, if all you expect to do is respond to requests (as in the case of a server), then you don’t need to know the names of the requesting entities.

(4) To call another entity, invoke the ADSPCall XCMD with the entity’s name. ADSPCall extracts the network address from the lookup table using the routine “NBPGetAddress”. This technique allows us to de-couple names and addresses; your stacks need never be concerned with the address of an entity, the name is sufficient at the Hypercard script level.

(5) Once a connection is established with another entity (called the remote end), you send information to that entity using ADSPTalk. You receive information from the remote end using ADSPListen. ADSPListen is the heart of the interface, in addition to checking for incoming messages, it also monitors the status of all open connections.

(6) When the session completes, remove your name from the names table using the NBPUnregister XFCN. Once unregistered, close down the interface to ADSP with the ADSPClose and then close down your NBP interface with NBPClose.

--The XCMDS--

While the process is conceptually quite simple, the amount of code needed to implement this interface may seem overwhelming. The rest of this article focuses on ADSPCall, ADSPTalk, ADSPListen and ADSPHangup. Information on both NBP and the open and close xcmds are available in that last two installments of this column as well as in recently published literature from APDA.

(1) ADSPCall

ADSPCall (listing 1) first extracts the address of the entity from the lookup table using NBPGetAddress. If you pass it the name of a currently visible entity, you have a reasonable assurance that the call will complete.

Upon retrieving the address, adspcall walks the connection list checking to see if a connection already exists with the remote end. If not, it creates a connection by calling DSPCreate.

Outgoing calls are placed asynchronously, control is passed back to Hypercard while the call completes in the “background”. Asynchronous communications pays big dividends, adspcall attempts to establish the connection as many times as you request in the retry field. Waiting for a call to complete can “hang” the system, a particularly uncomfortable state for the user. If for any reason, the remote end has gone off line, Hypercard won’t be stuck with an unbearable delay waiting for the call to timeout.

Outgoing calls, like all other transactions on the network, must be monitored by the listener. ADSPListen detects when the remote end picks up the phone.

To invoke ADSPCall from your script, use the following command line:

--1

-- get the name of the entity from the lookup table.
-- We let HyperAppleTalk handle the defaults for
-- retry, interval and buffer size. 
--
-- The two above globals will have been initialized by
-- NBPOpen and ADSPOpen respectively.
--
global globalNBPData, globalADSPData
ADSPCall theEntity

(2) ADSPTalk

Once a connection is established with a remote end, we can send messages to that entity. Like ADSPCall, ADSPTalk uses NBPGetAddress to get the address given a name. Because NBPGetAddress returns 0 if the name had no corresponding address in the lookup table, we can determine whether we have a connection to the remote end. ADSPTalk scans the connection list to match the address with that of an entity in our connection list (pointed to bey adsp^.ends). AdspTalk calls DSPTalk (covered last month) to send the information. Outgoing messages are also sent asynchronously so that the user is not made to suffer any delays while the transmission completes.

Like ADSPCall, the method of invoking ADSPTalk is straightforward:

--2

-- “theEntity” is the name of the remote end that you
-- called using ADSPCall and the card field contains the 
-- data that you wish to send to the remote end.
--
global globalNBPData, globalADSPData
ADSPTalk theEntity, card field “outgoing message”

(3) ADSPListen

The quality of any conversation depends more on the skill of the listener than that of the talker. This is no less true for the network - talking is the easy part, the listener does the hard part. Like any good listener, ADSPListen must perform several tasks at once -- (1) Answer incoming calls, (2) Monitor the status of outgoing calls, (3) Receive incoming messages and (4) periodically check the status of each connection.

Putting ADSPListen in the idle method of a card or stack provides a method for periodically checking up on each connection.

For each established connection an entry exists in our adsp^.ends list. While most of the data stored in the connection (cn) block is for our own use, the network keeps us apprised of the connection’s status via two records: the parameter block (pb) and the connection control block (ccb). The parameter block behaves as it would for any low-level I/O on the Macintosh, it is the interface to the ADSP device driver. The connection block is used by adsp to keep us up to date on the status of each connection. In essence, we relinquish control of the parameter block and the connection control block to ADSP. The rest of the structures in the connection data are for our own use.

To determine what is going on in any connection, we check the state field in the connection control block. The following states are currently supported (see listing 2 for the corresponding code):

sClosed: The connection went down for some reason or other. At this point, we have no choice but to Hang up.

sOpen: A connection opens in stages. When we first create or detect an opening connection, we set the mode to NOP indicating the connection is only “half open”. A half open connection is one in which only one of the two ends is ready. Receiving the sOpen state from the remote end informs us that our connection is now open.

A connection that is already open signals that it’s closing with the “eClosed” message. If a connection is closing, hang up on it.

The next two tasks, talking and listening, are monitored by Checkmessages. Recall that ADSPTalk queues outgoing calls; they complete some time in the future. Similarly, incoming messages can complete at any time. To determine whether any incoming or outgoing messages need attention, we issue a Status call to adsp. The ioCrefNum field of the dspParamBlock in checkMessages gets the driver number of the adsp driver. The ccbRefnum field gets the connection number of the connection we are checking.

The status call is issued synchronously, we must wait for it to complete before testing the status of a connection. If recvQPending is not 0, we have an incoming block of data. On input, we call ReadADSPData which will accumulate the data into the connection’s input buffer until ADSP signals that there is no more data with the end-of-message flag (eom).

ReadADSPData will read data from the connection’s input buffer into the handle we stored in conn^.inbuf (see listing 3). Accumulating data is a simple task : resize the handle by the number of bytes that we need to read in (given to us by adsp in recvQpending. If recvQpending is 0, there are no bytes to read). Once the handle is resized, point to the old end of the handle, and read the data directly into that are in memory. The read returns the exact number of bytes read in. If that number differs from recvQPending (under ordinary circumstances this won’t happen), then resize the handle to reflect the actual number of bytes read in.

After reading the data, we check the end-of-message flag (eom) which ADSP sets only after it sends the last block of the message down stream. If eom is set, there is no more data to read. We can now send the data back to hypercard. If we know the name of the connection, we send it back to hypercard via the ‘ADSPCaller’ global container. This gives your stack a way of determining who sent the input data. The data itself is put in the hypercard container, ‘HyperADSPData’. Once the data and name have been reported to Hypercard, we can optionally send a message back, perhaps to invoke some special input processing. If the connection stored a message in its ‘callme’ field, we now invoke that message via a callback.

Monitoring outgoing calls is a bit simpler. If the connection’s sendQPending field is not 0, we still have outgoing data in the output buffer. In this case, don’t do anything. If on the other hand, the send queue has emptied out and there was data in it (the connection outbuf field is not nil), then dispose the memory currently occupied by the output data.

The last task that ADSPListen must handle is responding to incoming calls. It does this by calling its respondtoListen Procedure. If a connection request is pending, the connection listener’s ioResult will be set to noErr (a negative result means an error occurred, a positive result means that no connection requests are pending, the listener still has its ears to the wall).

If a connection request is pending, we can open up a connection to the remote end whose address is passed in the remoteCID field. Once the connection is established,we can try to discover its name by issuing a call to NBPGetName with the pending connection’s name. Knowing the name of an incoming caller is optional so we don’t take extraordinary efforts to discover the name. If however, you needed the entities name (as in the case of a game), then you can do a lookup if NBPGetName turns up empty-handed. This is an advanced feature and, in the interest of space, I’ve omitted it. If you absolutely need this capability, drop me a line.

Once the pending request is serviced, the connection listener can put its ear back to the wall by requeuing the connection listener call. The information needed to queue a listening request is already stored in the connection listener’s parameter block (adsp^.pb). Requeuing the request becomes a simple call to PBControl with the connections parameter block.

The following script, added to your card, will do the trick:

--3

on idle

global globalNBPdata, globalADSPData
global adspCaller-- name of the caller global HyperADSPData    
 -- where incoming data goes
--
 ADSPListen “ShowData”

end idle

-- Show data is the method to invoke to handle
-- incoming data.  Assuming that we have a card field
-- named “show me”, the following method will display the
-- incoming message:
--
on ShowData
 global HyperADSPData

 put HyperAdspData into card field “show me”
end showdata

(4) ADSPHangup

We’ve already seen how to detect and respond to a connection hanging up on us. Use ADSPHangup (listing 4) to inform the remote end that the connection is going down. Once again, the drill is the same: get the address from the lookup table, check to see that a connection exists with this entity and call DSPHangup to inform the entity that the connection is going down. We don’t remove the connection from the connection list at this point because we have to wait for the remote end to acknowledge our disconnection request. ADSPListen receives this acknowledgement in the form of an eClosed message. Once closed, we can tear down the connection and deallocate its memory (dspRemove).

--4

--
-- A simple script for hanging up a connection
--
on Disconnect
 global HyperADSPData, globalNBPData

 ADSPHangup theEntity
End Disconnect

You now have a reasonably complete interface to AppleTalk. ADSP and NBP both offer more features than I’ve been able to show you in a short time. Notably, the out of stream and forward reset features of ADSP enable some very powerful enhancements to the basic protocol. I chose not to discuss these features in this series because the average application can get by quite well without them. If, however, you are writing a network server in Hypercard, you may want to explore these features in more detail. I will be happy to present the code for a full implementation of ADSP. In keeping with the spirit of MacTutor, contact me immediately to report any bugs in the code. I can be reached through this Magazine or on AppleLink (N0735) or MacNet.

Next month, I’m going to switch gears back into low and explore the file manager from within Hypercard.

Listing 1:  ADSPCall.p

(********************************)
(* file:  ADSPCall.p *)
(* *)
(* Establish a connection with*)
(* the entity whose name is *)
(* passed as a parameter. *)
(* *)
(* params[1] = Name of entity *)
(* params[2] = listen message *)
(* params[3] = number of retries*)
(* params[4] = retry interval *)
(* params[5] = Input buffer siz  *)
(* params[6] = Output buffer siz*)
(* *)
(* If  already connected, just*)
(* return with noErr *)
(* *)
(* Defaults:*)
(* Input Buffer  = 578    *)
(* Output Buffer = 578    *)
(* Retry count   = 0 *)
(* Retry interval= 0 *)
(* Out: the Result ::= error  *)
(* message, empty if none.*)
(* *)
(* ----------------------------  *)
(* By:  Donald Koscheka   *)
(* Date:9-Jan-89 *)
(* All Rights Reserved    *)
(* *)
(********************************)

(********************************
 Build Sequence

pascal ADSPCall.p -o ADSPCall.p.o 
link -m ENTRYPOINT  -rt XCMD=1302 -sn Main=ADSPCall
 ADSPCall.p.o
 “{libraries}”Interface.o 
 -o YourStackNameHere
  
*********************************)

{$R-}
{$S ADSPCall}
UNIT Koscheka;

(*********************************)
 INTERFACE 
(*********************************)

Uses  MemTypes, QuickDraw, OSIntf, 
 ToolIntf, PackIntf, HyperXCmd,
 AppleTalk, ADSP, adspxcmd;

Procedure EntryPoint( paramPtr : XCmdPtr );

(*********************************)
 IMPLEMENTATION
(*********************************)
TYPE Str31 = String[31];

PROCEDURE ADSPCall( paramPtr: XCmdPtr ); FORWARD;

Procedure EntryPoint( paramPtr : XCmdPtr );
Begin
 ADSPCall( paramPtr );
End;
 
Procedure ADSPCall( paramPtr : XCmdPtr );
VAR
 adsp   : ADSPPtr;
 error, terr: OSErr;
 inBufSiz : Integer;
 outBufSiz: Integer;
 retry  : Integer;
 interval : Integer;
 eAddr  : AddrBlock; 
 cn: CBPtr;
 nbp    : NBPPtr;
 found  : BOOLEAN;
 
{$I XCmdGlue.inc }
{$I XCMDADSP.inc } 

(*********************************)
BEGIN
 error  := noErr;
 found  := TRUE; {*** true if  already established ***}
 
WITH paramPtr^ DO
BEGIN
 IF (paramCount <> 0) AND (params[1]^ <> NIL) THEN 
 BEGIN
 adsp := ADSPPtr(RetrieveData( ‘GLOBALDSPDATA’ ));
 IF adsp <> NIL THEN
 BEGIN
 adsp^.checkPoint := RECEIVING;
 
 {**** Before we go too far, let’s ***}
 {*** look at some of the settings ***}
 {*** set the retransmit count***}
 IF params[3] <> NIL THEN
 retry := StringToSHort( params[3]^ )
 ELSE
 retry  := 0;
 
 {*** Set the retransmit interval  ***}
 IF params[4] <> NIL THEN 
 interval := StringToSHort( params[4]^ )
 ELSE
 interval := 0;
 
 {*** Set the input buffer size    ***}
 IF params[5] <> NIL THEN
 inBufSiz := StringToSHort( params[5]^ )
 ELSE
 inBufSiz := ATPBSIZE;
 
 {*** Set the output buffer size   ***}
 IF params[6] <> NIL THEN
 outBufSiz := StringToSHort( params[6]^ )
 ELSE
 outBufSiz:= ATPBSIZE;
 
 {*** (1) Get the entity’s address ***}
 HLock( Handle( params[1]) );
 eAddr := NBPGetAddress( params[1]^ );
 HUnlock( Handle( params[1] ) );

 {*** Walk through the connection  ***}
 {*** list to see if the connection***}
 {*** already exists.***}
 
 IF LongInt(eAddr) <> 0 THEN
 BEGIN
 cn := adsp^.ends;
 found := FALSE;
 
 WHILE (NOT found) DO
 IF cn = NIL THEN
 found := TRUE
 ELSE
 IF LongInt( eAddr ) = LongInt( cn^.adr ) THEN
 found := TRUE
 ELSE
 cn := cn^.next;
 
 {*** If connection already exists ***}
 {*** cn will not be NIL  so we won’t ***}
 {*** have to reconnect the two ends,***}
 {*** just fall out, otherwise, try to***}
 {*** make the connection.***}
 
 IF cn = NIL  THEN {*** establish connection ***}
 BEGIN
 cn^.remName:= NBPGetName( eAddr );
 cn := DSPCreate(eAddr,inBufSiz,
 outBufSiz,retry,interval,params[2] );
 IF cn <> NIL THEN
 BEGIN
 cn^.remName := NBPGetName( eAddr );
 
 {*** try to discover the name   ***}
 IF cn^.remName = NIL THEN
 BEGIN
 nbp := NBPPtr(RetrieveData(‘GLOBALNBPDATA’));
 IF nbp <> NIL THEN 
 BEGIN
 SendCardMessage(‘DoALookUp’);
 cn^.remName := NBPGetName( eAddr );
 END;
 END;
 
 {*** Now “dial for dollars”***}
 WITH cn^.dspPB DO 
 BEGIN
 ioCRefNum  := adsp^.dspRefNum;
 ccbRefNum:= cn^.ccbRef;
 csCode := dspOpen;
 ocMode := ocRequest;
 ioCompletion:= NIL;
 remoteCID:= 0;{*** don’t know this yet***}
 localCID := 0;{*** adsp allocates id***}
 remoteAddress:= eAddr; 
 filterAddress.aNet:= 0;
 filterAddress.aNode := 0;
 filterAddress.aSocket:= 0;
 SendSeq:= 0;
 RecvSeq:= 0;
 SendWindow := 0;
 attnSendSeq:= 0;
 attnRecvSeq:= 0;
 ocInterval := INTERVAL;
 ocMaximum:= RETRY;
 error  := PBControl( @cn^.dspPB, ASYNC );
 END;
 END;
 END;
 END; {(LongInt(eAddr) <> 0) }
 adsp^.checkPoint := CLOSE_OK;
 END;
 END;
 returnValue := PasToZero( NumToStr( LongInt(error) ) );
END; {*** with paramPtr^ ***}
END;

end.
Listing 2:  ADSPTalk.p

(****************************)
(* file:  ADSPTalk.p *)
(* *)
(* Send information to an *)
(* established connection.  *)
(* The connection must be *)
(* been established via the *)
(* ADSPCALL xcmd.*)
(* *)
(* In:  *)
(* params[1] = entity name*)
(* of the remote end.*)
(* *)
(* ------------------------ *)
(* By:  Donald Koscheka   *)
(* Date:2-Mar-89 *)
(* All Rights Reserved    *)
(* *)
(* ------------------------ *)
(****************************)

(*****************************
 Build Sequence

pascal -o ADSPTalk.p.o ADSPTalk.p
link -m ENTRYPOINT  -rt XCMD=1305 -sn Main=ADSPTalk
 ADSPTalk.p.o
 “{libraries}”Interface.o 
 -o YourStackNameHere
  
*****************************)

{$R-}
{$S ADSPTalk}
UNIT DummyUnit;

(****************************)
 INTERFACE 
(****************************)

Uses  MemTypes, QuickDraw, OSIntf,
 ToolIntf, PackIntf, HyperXCmd,
 AppleTalk, ADSP, adspxcmd;


Procedure EntryPoint( paramPtr : XCmdPtr );

(****************************)
 IMPLEMENTATION
(****************************)
TYPE Str31 = String[31];

PROCEDURE ADSPTalk( paramPtr: XCmdPtr ); FORWARD;

Procedure EntryPoint( paramPtr : XCmdPtr );
 Begin
 ADSPTalk( paramPtr );
 End;
 
Procedure ADSPTalk( paramPtr : XCmdPtr );
VAR
 adsp   : ADSPPtr;
 error  : OSErr;
 eAddr  : AddrBlock;
 cb: cbPtr;
 
{$I XCmdGlue.inc }
{$I XCMDADSP.inc } 

BEGIN
 error := noErr;
 adsp := ADSPPtr(RetrieveData( ‘GLOBALDSPDATA’ ));
 IF(adsp <> NIL) 
 AND  (paramPtr^.params[1] <> NIL)
 AND  (paramPtr^.params[2] <> NIL) THEN
 BEGIN
 adsp^.checkPoint := RECEIVING;
 {*** (1) Get the entity’s address ***}
 HLock( paramPtr^.params[1] );

 eAddr := NBPGetAddress( paramPtr^.params[1]^ );
 cb := adsp^.ends;

  {*** (2) Find entity in connection list***}
 
 IF LongInt( eAddr ) <> 0 THEN
 WHILE cb <> NIL DO
 IF (LongInt(cb^.adr)=LongInt(eAddr)) 
 AND (cb^.ccb.state=sOpen) THEN  
 BEGIN
 error := DSPTalk(cb, paramPtr^.params[2] );
 cb := NIL;
 END
 ELSE
 cb := cb^.next;
 
 adsp^.checkPoint := CLOSE_OK;
 HUnlock( Handle(paramPtr^.params[1]) );
 END;
 paramPtr^.returnValue := PasToZero( NumToStr( LongInt(error) ) );
END;

end.
Listing 3:  ADSPListen.p

(****************************)
(* file:  ADSPListen.p    *)
(* *)
(* Perform the following: *)
(* (1) Listen for incoming*)
(* calls on the connection*)
(* listener *)
(* (2) Check to see if any*)
(* outgoing calls have been*)
(* answered *)
(* (3) Check connections  *)
(* for incoming data *)
(* (4) Check connections for*)
(* attention messages*)
(* *)
(* In:  *)
(* params[1] = name of    *)
(* message to call hypercard*)
(* with on incoming data  *)
(* *)
(* Defaults:*)
(* container = HyperADSPData*)
(* message  = none.*)
(* *)
(* ---------------------- *)
(* All Rights Reserved    *)
(* *)
(* ------------------------ *)
(* By:  Donald Koscheka   *)
(* Date:2-Mar-89 *)
(* All Rights Reserved    *)
(* *)
(* ------------------------ *)
(****************************)

(*****************************
 Build Sequence

pascal -o “{hpo}”ADSPListen.p.o “{adsp}”ADSPListen.p
link -m ENTRYPOINT  -rt XCMD=1303 -sn Main=ADSPListen
 ADSPListen.p.o
 “{libraries}”Interface.o 
 -o YourStackNameHere
  
******************************)

{$R-}
{$S ADSPListen}
UNIT Koscheka;

(****************************)
 INTERFACE 
(****************************)

Uses MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, HyperXCmd, AppleTalk, 
ADSP, adspxcmd;

Procedure EntryPoint( paramPtr : XCmdPtr );

(****************************)
 IMPLEMENTATION
(****************************)
TYPE Str31 = String[31];

PROCEDURE ADSPListen( paramPtr: XCmdPtr ); FORWARD;

Procedure EntryPoint( paramPtr : XCmdPtr );
 Begin
 ADSPListen( paramPtr );
 End;
 
Procedure ADSPListen( paramPtr : XCmdPtr );
VAR
 myFlags: SignedByte;
{ flags from incoming unsolicited message    }
 adsp   : ADSPPtr; { pointer to ADSP Control block}
 error  : OSErr; 
 err    : OSErr;
 cn,nn  : cbPtr; { pointers to established conections}
 nbp    : NBPPtr;{ pointer to the memory  NBP interface}
 mybPtr : Ptr;   { used for getting and setting flags}
 
{$I XCmdGlue.inc }
{$I XCMDADSP.inc } 

PROCEDURE RespondToListen;
(********************************)
(* If the connection listener *)
(* has completed, then someone*)
(* is trying to call. If we can  *)
(* initialize a connection, *)
(* acknowledge receipt of  call.*)
(********************************)
VAR
 err    : Integer;
 conn : CBPtr;
 tH: Handle;
 
BEGIN
 IF  adsp^.pb.ioResult = noErr THEN 
 BEGIN  {*** We Have an incoming call.***}
 {*** Create a connection end to***}
 {*** the caller and set the***}
 {*** state to active indicating ***}
 {*** the connection is accepted ***}
 conn := DSPCreate(adsp^.pb.remoteAddress,
 ATPBSIZE,ATPBSIZE,RETRY,INTERVAL,NIL );
 
 IF conn <> NIL THEN
 WITH conn^.dspPB DO
 BEGIN  {*** accept the connection request***}
 ioCRefNum  := adsp^.dspRefNum;
 ioCompletion    := NIL;
 csCode := dspOpen;
 ocMode := ocAccept;
 ccbRefNum:= conn^.ccbRef;
 remoteCID:= adsp^.pb.remoteCID;
 localCID := 0;
 remoteAddress   := adsp^.pb.remoteAddress;  
 filterAddress.aNet:= 0;
 filterAddress.aNode := 0;
 filterAddress.aSocket := 0;
 RecvSeq:= 0;
 attnRecvSeq:= 0;
 SendSeq:= adsp^.pb.SendSeq;
 attnSendSeq:= adsp^.pb.attnSendSeq;
 SendWindow := adsp^.pb.SendWindow;
 ocInterval := INTERVAL;
 ocMaximum:= RETRY;
 err := PBControl( @conn^.dspPB, ASYNC );
 
 {*** Call back Hypercard to inform  ***}
 {***it of an incoming call.***}
 
 conn^.remName := NBPGetName( adsp^.pb.remoteAddress );
 END;
 
 {*** Reset connection listener to ***}
 {*** wait for more calls ***}
 err := PBControl( @adsp^.pb, ASYNC );
 END
END;

PROCEDURE ReadADSPData( conn:CBPtr; cnt:Integer; callMe:Handle );
(********************************)
(* Poll the connection to *)
(* determine whether any  *)
(* data is pending.  If so, *)
(* read it and pass it  back to *)
(* hypercard via the callback *)
(* mechanism.    *)
(* *)
(* IN:  *)
(* conn : pointer to connection *)
(* cnt  : num. of bytes to read  *)
(* callMe : callback method *)
(********************************)
VAR
 Tempb  : dspParamBlock;
 err    : Integer;
 temp   : LongInt;
 inSize : LongInt;
 globName: Str255; 
 tp: Ptr;
 tH: Handle;
 
BEGIN
 globName:= ‘HyperADSPData’;
 
 WITH conn^ DO
 BEGIN  {*** read the data ***}
 IF inBuf = NIL THEN
 BEGIN
 inBuf := NewHandle( LongInt(cnt) );
 MoveHHi( inBuf );
 HLock( inBuf );
 tp:= inBuf^;
 END
 ELSE {*** inBuf already allocated, add to end of it***}
 BEGIN
 HUnlock( inBuf );
 inSize := GetHandleSize(inBuf);
 temp   := inSize;
 inSize := inSize + LongInt( cnt );
 SetHandleSize( inBuf, inSize );
 MoveHHi( inBuf );
 HLock( inBuf );
 temp   := temp + Ord4( inBuf^ );
 tp:= Pointer(temp);
 END;
 
 WITH Tempb DO {*** now read the data ***}
 BEGIN
 ioCRefNum  := adsp^.dspRefNum;
 ccbRefNum  := conn^.ccbRef;
 csCode := dspRead;
 reqCount := cnt;
 dataPtr  := tp; 
 END;
 err := PBControl( @Tempb, SYNC );
 HUnlock( inBuf );

 IF err=noErr THEN
 BEGIN
 inSize := GetHandleSize( inBuf );
 inSize := inSize - (cnt-Tempb.actCount);
 SetHandleSize( inBuf, inSize );
 END;
 
 IF (err=noErr) AND (Tempb.eom=1) THEN
 BEGIN
 IF inBuf <> NIL THEN {***Call back with data***}
 BEGIN
 IF remName <> NIL THEN
 SetGlobal( ‘ADSPCaller’, remName );

 tp     := Pointer( Ord4( inBuf^ ) + LongInt(inSize) );
 tp^    := 0;
 
 SetGlobal( globName, inbuf );
 DisposHandle( inbuf );
 inbuf := NIL;
 END;
 
 IF callMe <> NIL THEN {***Set remote-end name***}
 BEGIN
 HLock( callMe );
 ZeroToPas( Pointer( callMe^ ), globName );
 HUnlock( callMe );
 SendCardMessage(  globName );
 END;
 END;
 END;{*** read the data ***}
END;

Function CheckMessages( cb : cbPtr ): OSErr;
(************************************)
(* check this connection for: *)
(* (1) Completed Incoming Messages *)
(* (2) Completed Outgoing Messages *)
(************************************)
VAR
 myErr  : OSErr;
 tpb    : dspParamBlock;
BEGIN
 WITH tpb DO
 BEGIN
 csCode := dspStatus;
 ioCRefNum:= adsp^.dspRefNum;
 ccbRefNum:= cn^.ccbRef;
 END;
 myErr := PBControl( @tpb, SYNC );
 
 IF myErr = noErr THEN
 BEGIN
 {*** (3) Check for pending incoming data    ***}
 IF tpb.recvQPending <> 0  THEN
 ReadADSPData( cn, tpb.recvQPending, paramPtr^.params[1] );

 {***(4) See if any write operations have completed***}
 IF (tpb.SendQPending = 0) AND (cn^.OutBuf <> NIL ) THEN
 BEGIN
 HUnlock( cn^.outBuf );
 DisposHandle( cn^.outBuf );
 cn^.outBuf := NIL;
 END;
 END; { myErr <> noErr }
 CheckMessages := myErr;
END;

(**********************************)
(* ADSPListen    *)
(**********************************)

BEGIN
 error  := noErr;
 adsp := ADSPPtr(RetrieveData( ‘GLOBALDSPDATA’ ));

 IF adsp <> NIL THEN
 BEGIN
 adsp^.checkPoint := RECEIVING;
 cn := adsp^.ends;

 {***(2) Monitor status on all connections***}
 WHILE cn <> NIL DO WITH cn^ DO 
 BEGIN
 nn := next;
 err := noErr;
 
 CASE ccb.state OF { connection states } 
 sClosed: err := DSPHangUp( cn );
 
 sOpen:
 BEGIN
 IF mode = NOP THEN {***connection is opening ***}
 BEGIN  {***inform Hypercard of connection***}
 SetGlobal( ‘ADSPCaller’, remName );
 SendCardMessage( ‘ConnectionMade’ );
 mode := EST;
 END
 ELSE
 BEGIN  {*** Check an established connection ***}
 myBPtr := @cn^.ccb.userFlags;
 
 IF BAND(myBPtr^, eClosed)=eClosed THEN 
 err := DSPHangUp( cn )
 ELSE
 BEGIN
 err := CheckMessages( cn );
 
 myBPtr^ := 0;   { clear user flags}
 END;
 END;
 END;
 END; { case of connection states }
 
 IF err <> noErr THEN error := err;
 cn := nn;
 END;
 RespondToListen;{*** check for opening calls ***}
 adsp^.checkPoint := CLOSE_OK;
 END; {*** IF adsp <> NIL ***}

 paramPtr^.returnValue := PasToZero( NumToStr( LongInt(err) ) );;
END;

end.
Listing 4:  ADSPHangUp.p

(****************************)
(* file:  ADSPHangUp.p    *)
(* *)
(* Disconnect an established*)
(* connection and deallocate*)
(* the data  associated with*)
(* the connection. *)
(* *)
(* In:  params[1] Name of *)
(* the entity to hangup on*)
(* *)
(* Out: error message,    *)
(* empty if none.*)
(* *)
(* ------------------------ *)
(* By:  Donald Koscheka   *)
(* Date:2-Mar-89 *)
(* All Rights Reserved    *)
(* *)
(* ------------------------ *)
(****************************)

(*****************************
 Build Sequence

pascal -o ADSPHangUp.p.o ADSPHangUp.p
link -m ENTRYPOINT  -rt XCMD=1304 -sn Main=ADSPHangUp
 ADSPHangUp.p.o
 “{libraries}”Interface.o 
 -o YourStackNameHere
  
******************************)

{$R-}
{$S ADSPHangUp}
UNIT DummyUnit;

(****************************)
 INTERFACE 
(****************************)

Uses  MemTypes, QuickDraw, OSIntf,
 ToolIntf, PackIntf, HyperXCmd, 
 AppleTalk, ADSP, adspxcmd;

Procedure EntryPoint( paramPtr : XCmdPtr );

(****************************)
 IMPLEMENTATION
(****************************)
TYPE Str31 = String[31];

PROCEDURE ADSPHangUp( paramPtr: XCmdPtr ); FORWARD;
Procedure EntryPoint( paramPtr : XCmdPtr );
 Begin
 ADSPHangUp( paramPtr );
 End;
 
Procedure ADSPHangUp( paramPtr : XCmdPtr );
VAR
 adsp   : ADSPPtr;
 error  : OSErr;
 pb: DSPParamBlock;
 eAddr  : AddrBlock;
 cb: CBPtr;

{$I XCmdGlue.inc }
{$I XCMDADSP.inc } 
(****************************)
BEGIN
 error := noErr;
 IF ( paramPtr^.paramCount > 0 )
 AND ( paramPtr^.params[1] <> NIL ) THEN           
 BEGIN
 adsp := ADSPPtr(RetrieveData( ‘GLOBALDSPDATA’ ));
 IF adsp <> NIL THEN
 BEGIN
 adsp^.checkPoint := RECEIVING;
 {*** (1) Get the entity’s address ***}
 HLock( Handle(paramPtr^.params[1]) );
 eAddr := NBPGetAddress( paramPtr^.params[1]^ );
 cb := adsp^.ends;
 
 {*** match the entity to the list ***}
 IF LongInt(eAddr) <> 0 THEN
 WHILE cb <> NIL DO
 IF LongInt(cb^.adr ) = LongInt( eAddr ) THEN
 BEGIN
 error := DSPHangUp( cb );
 cb := NIL;
 END
 ELSE
 cb := cb^.next;
 
 HUnlock( Handle(paramPtr^.params[1]) );
 adsp^.checkPoint := CLOSE_OK;
 END
 END;
 paramPtr^.returnValue := PasToZero( NumToStr( LongInt(error) ) );
END;

end.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »

Price Scanner via MacPrices.net

You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more

Jobs Board

Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.