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.

 
AAPL
$103.30
Apple Inc.
+0.80
MSFT
$45.09
Microsoft Corpora
-0.34
GOOG
$577.33
Google Inc.
+5.73

MacTech Search:
Community Search:

Software Updates via MacUpdate

TextSoap 7.4.0 - Flexible text editing u...
TextSoap is for people who work with text. TextSoap effortlessly cleans up text from endlessly different formats. Wash away unwanted characters, spaces, tabs. Fix paragraphs with hard returns at the... Read more
NetShade 6.0.2 - Browse privately using...
NetShade is an Internet security tool that conceals your IP address on the web. NetShade routes your Web connection through either a public anonymous proxy server, or one of NetShade's own dedicated... Read more
Mac DVDRipper Pro 5.0 - Copy, backup, an...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
pwSafe 3.1 - Secure password management...
pwSafe provides simple and secure password management across devices and computers. pwSafe uses iCloud to keep your password databases backed-up and synced between Macs and iOS devices. It is... Read more
StatsBar 1.8 - Monitor system processes...
StatsBar gives you a comprehensive and detailed analysis of the following areas of your Mac: CPU usage Memory usage Disk usage Network and bandwidth usage Battery power and health (MacBooks only)... Read more
Path Finder 6.5.5 - Powerful, award-winn...
Path Finder is a file browser that combines the familiar Finder interface with the powerful utilities and innovative features. Just a small selection of the Path Finder 6 feature set: Dual pane... Read more
QuarkXPress 10.2.1 - Desktop publishing...
With QuarkXPress, you can communicate in all the ways you need to -- and always look professional -- in print and digital media, all in a single tool. Features include: Easy to Use -- QuarkXPress is... Read more
Skype 6.19.0.450 - Voice-over-internet p...
Skype allows you to talk to friends, family and co-workers across the Internet without the inconvenience of long distance telephone charges. Using peer-to-peer data transmission technology, Skype... Read more
VueScan 9.4.41 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
Cloud 3.0.0 - File sharing from your men...
Cloud is simple file sharing for the Mac. Drag a file from your Mac to the CloudApp icon in the menubar and we take care of the rest. A link to the file will automatically be copied to your clipboard... Read more

Latest Forum Discussions

See All

Modern Combat 5 Gets a Major Multiplayer...
Modern Combat 5 Gets a Major Multiplayer Update Posted by Jessica Fisher on September 2nd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Alien Creeps TD Review
Alien Creeps TD Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: EXPENSIVE DEFENSESUniversal App - Designed for iPhone and iPad Alien Creeps TD would be a fun if unremarkable Tower Defense game, but its heavy focus on... | Read more »
The Journey Down: Chapter Two Review
The Journey Down: Chapter Two Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: DARK YET ENTICINGUniversal App - Designed for iPhone and iPad It’s a little dark, in every sense of the word, but The Journey Down:... | Read more »
Function Space, a Social Network App for...
Function Space, a Social Network App for Science, Launches on iOS Posted by Ellis Spice on September 2nd, 2014 [ permalink ] | Read more »
Stupidfast – How Taylor Martinez Switche...
How do you make an Endless Running game more than just another Endless Running game? By adding real life prizes to it, of course! That’s the thinking behind StupidFast: a game designed for football enthusiasts, and the brainchild of former college... | Read more »
Little Raiders: Robin’s Revenge Review
Little Raiders: Robin’s Revenge Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: CASUAL RAIDINGUniversal App - Designed for iPhone and iPad Combining simple combat with village building is a potent combination for... | Read more »
Treasure Tombs: Ra Deal Coming from Bulk...
Treasure Tombs: Ra Deal Coming from Bulkypix and Dark Tonic This Fall Posted by Jessica Fisher on September 2nd, 2014 [ permalink ] Dark Tonic and | Read more »
Pirate Bash Review
Pirate Bash Review By Nadia Oxford on September 2nd, 2014 Our Rating: :: BAD PIRATES, GOOD TIMESUniversal App - Designed for iPhone and iPad Pirate Bash’s turn-based battles add an intriguing twist to a typical physics game.   | Read more »
Tiny Tower Vegas Review
Tiny Tower Vegas Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: STEADY DEVELOPMENTUniversal App - Designed for iPhone and iPad Build a huge tower again but Vegas-style in Tiny Tower Vegas.   | Read more »
The Manhattan Project Review
The Manhattan Project Review By Andrew Fisher on September 2nd, 2014 Our Rating: :: ROCKET SCIENCEUniversal App - Designed for iPhone and iPad The Manhattan Project offers a great Euro-style gameplay experience, but it is totally... | Read more »

Price Scanner via MacPrices.net

Apple refurbished iPads available for up to $...
Apple is offering Certified Refurbished iPad Airs for up to $140 off MSRP. Apple’s one-year warranty is included with each model, and shipping is free. Stock tends to come and go with some of these... Read more
Are We Now In The Post-Post-PC Era?
A longtime and thoroughgoing laptop aficionado, I was more than a little dismayed by Steve Jobs’s declaration back in 2010 when he sprang the iPad on an unsuspecting world. that we’d entered a “post-... Read more
PC Outlook Improves, But 2014 Shipments Still...
According to the International Data Corporation (IDC) Worldwide Quarterly PC Tracker, worldwide PC shipments are expected to fall by -3.7 percent in 2014. To hat’s actually an improvement from the... Read more
IDC Lowers Tablet Sales Projections for 2014...
Following a second consecutive quarter of softer than expected demand, International Data Corporation (IDC) has lowered its worldwide tablet plus 2-in-1 forecast for 2014 to 233.1 million units. The... Read more
Apple now offering refurbished 21-inch 1.4GHz...
The Apple Store is now offering Apple Certified Refurbished 21″ 1.4GHz iMacs for $929 including free shipping plus Apple’s standard one-year warranty. Their price is $170 off the cost of new models,... Read more
Save $50 on the 2.5GHz Mac mini, on sale for...
B&H Photo has the 2.5GHz Mac mini on sale for $549.99 including free shipping. That’s $50 off MSRP, and B&H will also include a free copy of Parallels Desktop software. NY sales tax only. Read more
Save up to $300 on an iMac with Apple refurbi...
The Apple Store has Apple Certified Refurbished iMacs available for up to $300 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free. These are the best prices on... Read more
The Rise of Phablets
Carlisle & Gallagher Consulting Group, a businesses and technology consulting firm focused solely on the financial services industry, has released an infographic depicting the convergence of... Read more
Bad Driver Database App Allows Good Drivers t...
Bad Driver Database 1.4 by Facile Group is a new iOS and Android app that lets users instantly input and see how many times a careless, reckless or just plain stupid driver has been added to the... Read more
Eddy – Cloud Music Player for iPhone/iPad Fre...
Ukraine based CapableBits announces the release of Eddy, its tiny, but smart and powerful cloud music player for iPhone and iPad that allows users to stream or download music directly from cloud... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.