Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
interface.c
/* |
TCP Client/Server Queuing Example |
Steve Falkenburg, MacDTS, Apple Computer |
3/11/92 |
this client/server sample uses MacTCP to implement a simple "greeting" server. the server |
opens up several listeners on kGreetingPort (1235). when a client connects, the data entered |
in the greeting dialog is sent to the remote connection, and the connection is closed. |
connection management is done through the use of Operating System queues to simplify tracking |
and usage. |
*/ |
#include "const.h" |
#include "globals.h" |
#include "utils.h" |
#include "interface.h" |
/* initializes the user interface by loading our dialog into memory, and drawing the initial |
queue numbers into the dialog |
*/ |
void InitInterface(void) |
{ |
gMainDialog = GetNewDialog(kMainDialog,nil,(WindowPtr)-1L); |
UpdateNumberList(); |
} |
/* displays the current values for the number of parameter blocks in each of the queues |
(unused, running, completed) |
*/ |
void UpdateNumberList(void) |
{ |
short iType; |
Handle iHndl; |
Rect iRect; |
Str255 iText; |
long lastValue; |
GetDItem(gMainDialog,kServicedItem,&iType,&iHndl,&iRect); |
GetIText(iHndl,iText); |
StringToNum(iText,&lastValue); |
if (lastValue!=gServiced) { |
NumToString(gServiced,iText); |
SetIText(iHndl,iText); |
} |
GetDItem(gMainDialog,kFreeItem,&iType,&iHndl,&iRect); |
GetIText(iHndl,iText); |
StringToNum(iText,&lastValue); |
if (lastValue!=gFree) { |
NumToString(gFree,iText); |
SetIText(iHndl,iText); |
} |
GetDItem(gMainDialog,kRunningItem,&iType,&iHndl,&iRect); |
GetIText(iHndl,iText); |
StringToNum(iText,&lastValue); |
if (lastValue!=gRunning) { |
NumToString(gRunning,iText); |
SetIText(iHndl,iText); |
} |
GetDItem(gMainDialog,kCompletedItem,&iType,&iHndl,&iRect); |
GetIText(iHndl,iText); |
StringToNum(iText,&lastValue); |
if (lastValue!=gCompleted) { |
NumToString(gCompleted,iText); |
SetIText(iHndl,iText); |
} |
GetDItem(gMainDialog,kGreetingItem,&iType,&iHndl,&iRect); |
GetIText(iHndl,gGreetingData); |
} |
/* handles events important to our dialog |
*/ |
Boolean HandleDialogEvents(EventRecord *ev) |
{ |
DialogPtr theDlg; |
short item; |
if (!IsDialogEvent(ev)) |
return false; |
if (DialogSelect(ev,&theDlg,&item)) { |
if (item==kQuitItem) |
gDone = true; |
} |
return true; |
} |
/* handles mouse down events. we only do dragging, and nothing else |
*/ |
void HandleMouseDown(Point mouseHit) |
{ |
WindowPtr window; |
Rect limit; |
SetRect(&limit,-32000,-32000,32000,32000); |
switch (FindWindow(mouseHit,&window)) { |
case inDrag: |
DragWindow(window,mouseHit,&limit); |
case inGoAway: |
if (TrackGoAway(window,mouseHit)) |
gDone = true; |
} |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14