home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-30 | 19.9 KB | 995 lines | [TEXT/KAHL] |
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
-
- CConnection.c
-
- CommToolbox connection class.
-
- SUPERCLASS = CBureaucrat.
-
- Original copyright © 1992-93 Romain Vignes. All rights reserved.
- Modifications copyright © 1994-95 Ithran Einhorn. All rights reserved.
-
- ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- #include <CommResources.h> /* Apple includes */
- #include <Connections.h>
-
- #include <CBartender.h> /* TCL includes */
- #include <CCluster.h>
- #include <CError.h>
- #include <Constants.h>
- #include <TBUtilities.h>
- #include <TCLUtilities.h>
-
- #include "CConnection.h" /* Other includes */
- #include "CFileTransfer.h"
- #include "CTermPane.h"
-
- /* Constants & Macros */
-
- #define CONN_STR_RES_ID 2100 /* Connection message resource ID */
-
- #define NO_TOOL_STR_INDEX 1 /* No connection tool */
- #define BAD_TOOL_STR_INDEX 2 /* Bad connection tool */
- #define NO_REC_STR_INDEX 3 /* Connection record allocation error */
- #define CHOOSE_STR_INDEX 4 /* Tool setup error */
- #define OPEN_ERR_STR_INDEX 5 /* Error on opening */
- #define CLOSE_ERR_STR_INDEX 6 /* Error on closing */
- #define WAIT_ERR_STR_INDEX 7 /* Waiting impossible */
-
- #define H_CHOOSE_POS 10 /* Setup dialog position */
- #define V_CHOOSE_POS 40
-
- #define BREAK_DELAY 5 /* Approximately 80 ms */
-
- #define FIRST_CONN_CMD cmdConnChoose /* First connection command */
- #define LAST_CONN_CMD cmdConnListen /* Last connection command */
-
- #define RESET_ALRT_ID 2100 /* Reset alert resource ID */
-
-
- /* Application globals */
-
- extern CBartender *gBartender;
- extern CError *gError;
-
-
- /* Class variables initialization */
-
- CCluster *CConnection::cConnList = NULL;
-
-
-
- /*
- * cIsConnectionCmd
- *
- * Command related to the connection object
- *
- * theCmd: command to analyse
- *
- * Return TRUE if the command is a connection command
- *
- */
-
- Boolean CConnection::cIsConnectionCmd(long theCmd)
- {
- return ((theCmd >= FIRST_CONN_CMD) && (theCmd <= LAST_CONN_CMD));
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * cCheckToolName
- *
- * Checking existence of a tool by its name
- *
- * toolName: name of the tool (Pascal string)
- *
- * Return cmGenericError if the tool is not present
- *
- */
-
- OSErr CConnection::cCheckToolName(Str31 toolName)
- {
- return(CMGetProcID(toolName));
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * cTestToolEvent
- *
- * Test if the event is related to a connection tool
- *
- * macEvent: pointer on the event record
- * theWindow: pointer on the window record
- *
- * Return TRUE if the event is a terminal event
- */
-
- typedef struct {
- EventRecord *theEvent;
- WindowPtr theWindow;
- Boolean isToolEvent;
- } TestParamRec;
-
-
- /* Test routine */
-
- static void ConnEvtTest(CConnection *theConnection,TestParamRec *params)
- {
- if (params->isToolEvent == FALSE)
- params->isToolEvent = theConnection->DoEvent(params->theEvent,
- params->theWindow);
- }
-
-
- Boolean CConnection::cTestToolEvent(EventRecord *macEvent,WindowPtr theWindow)
- {
- TestParamRec params;
-
- params.theEvent = macEvent;
- params.theWindow = theWindow;
- params.isToolEvent = FALSE;
-
- if (cConnList == NULL)
- return FALSE;
- else {
- cConnList->DoForEach1((EachFunc1) ConnEvtTest,(long) ¶ms);
-
- return params.isToolEvent;
- }
- }
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * cConnIdle
- *
- * Idle time for each connection object
- *
- *
- */
-
- /* Idle routine for each connection object */
-
- static void Conn_Idle(CConnection *theConn)
- {
- theConn->DoIdle();
- }
-
-
- void CConnection::cConnIdle(void)
- {
- if (cConnList != NULL) /* List exists ? */
- cConnList->DoForEach((EachFunc) Conn_Idle);
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * cInitManager
- *
- * Connection Manager Initialization
- *
- */
-
- void CConnection::cInitManager(void)
- {
- InitCM();
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * cGetCMVersion
- *
- * return the version of the Connection Manager
- *
- */
-
- short CConnection::cGetCMVersion(void)
- {
- return CMGetCMVersion();
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * IConnection
- *
- * Initialisation of the connection object
- *
- * aSupervisor: object supervisor in the command chain
- * toolName: name of the connection tool to be used ("" -> défault)
- * flags:(CM) how to use the connection tool
- * desiredSizes:(CM) desired sizes of sending and receiving buffers
- * refcon:(CM) available for the application
- * userData:(CM) available for the application
- *
- * Parameters followed by CM are exact required parameters for creating a
- * connection record.
- *
- */
-
- void CConnection::IConnection(CBureaucrat *aSupervisor,Str31 toolName,
- CMRecFlags flags,CMBufferSizes desiredSizes,
- long refCon, long userData)
- {
- ConnHandle theConn;
- OSErr theErr;
- Str31 tName;
- short toolProcID;
- Boolean savedAlloc;
-
- CBureaucrat::IBureaucrat(aSupervisor); /* Initialize superclass */
-
- if (toolName[0] == 0) /* Default tool ? */
- {
- theErr = CRMGetIndToolName(classCM,1,tName);
-
- if ((tName[0] == 0) || (theErr != cmNoErr)) /* Error checking */
- Failure(cmNoTools,SpecifyMsg(CONN_STR_RES_ID,NO_TOOL_STR_INDEX));
-
- toolProcID = cCheckToolName(tName); /* Default tool ID */
- }
- else
- {
- toolProcID = cCheckToolName(toolName); /* Specified tool ID */
- }
-
- if (toolProcID == cmGenericError) /* No corresponding tool */
- {
- Failure(cmNoTools,SpecifyMsg(CONN_STR_RES_ID,BAD_TOOL_STR_INDEX));
- }
-
- savedAlloc = SetAllocation(kAllocCanFail);
-
- theConn = CMNew(toolProcID,flags,desiredSizes,(long)this,userData);
-
- SetAllocation(savedAlloc);
-
- FailNIL(theConn); /* Connection created ? */
-
- MoveHHi((Handle)theConn); /* Heap fragmentation… */
-
- itsConn = theConn;
-
- if (cConnList == NULL) { /* first connection object ? */
- cConnList = new(CCluster);
- cConnList->ICluster();
- }
-
- cConnList->Add(this); /* Connection addition */
-
- this->connOpen = FALSE;
- this->active = FALSE;
-
- #ifdef __USETHREADS__
- if (CThread::cIsPresent())
- {
- itsIdleThread = new(CThread);
- itsIdleThread->IThread(kCooperativeThread, (ThreadEntryProcPtr)cOneConnIdle, this);
- }
- #endif
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * Dispose
- *
- * Dispose of a connection object
- *
- */
-
- void CConnection::Dispose(void)
- {
- ASSERT(cConnList != NULL);
-
- #ifdef __USETHREADS__
- if (CThread::cIsPresent())
- {
- itsIdleThread->Dispose();
- }
- #endif
-
- cConnList->Remove(this); /* Dispose of the Connection */
-
- if (cConnList->IsEmpty())
- ForgetObject(cConnList); /* Dispose of the cluster */
-
- CMDispose(itsConn); /* Dispose of the connection record */
- itsConn = NULL;
-
- inherited::Dispose(); /* Pass message to its superclass */
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * UpdateMenus
- *
- * Connection related menus updating
- *
- */
-
- void CConnection::UpdateMenus(void)
- {
-
- gBartender->EnableCmd(cmdConnChoose); /* Setup command */
-
- gBartender->EnableCmd(cmdConnReset); /* Connection reset */
-
- if (this->IsOpen()) { /* Connection open ? */
- gBartender->EnableCmd(cmdConnClose);
- gBartender->EnableCmd(cmdConnBreak);
- }
- else {
- gBartender->EnableCmd(cmdConnOpen);
- gBartender->EnableCmd(cmdConnListen);
- }
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * DoCommand
- *
- * Handle connection related commands
- *
- * theCommand: command to be executed
- *
- */
-
- void CConnection::DoCommand(long theCommand)
- {
- switch (theCommand) {
-
- case cmdConnChoose: /* Connection tool setup */
- this->ConnectionChoose();
- break;
-
- case cmdConnOpen: /* Connection opening */
- this->OpenConnection(FALSE,NULL,0L);
- break;
-
- case cmdConnListen: /* Connection listening */
- this->ListenConnection(FALSE,NULL,0L);
- break;
-
- case cmdConnClose: /* Connection waiting */
- this->CloseConnection(FALSE,NULL,0L,TRUE);
- break;
-
- case cmdConnReset: /* Connection reset */
- this->Reset();
- break;
-
- case cmdConnBreak: /* BREAK signal send */
- this->SendBreak();
- break;
-
- default: /* Unknown command */
- break;
- }
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * DoEvent
- *
- * Connection tool related events
- *
- * theEvent: Pointeur on the event
- * theWindow: Window associated with the event
- *
- * Return TRUE if it is a tool event
- *
- */
-
- Boolean CConnection::DoEvent(EventRecord *theEvent,WindowPtr theWindow)
- {
- Boolean isToolEvent;
- ConnHandle theConn;
-
- isToolEvent = FALSE;
-
- theConn = (ConnHandle) GetWRefCon(theWindow);
-
- if (theConn == itsConn) { /* Tool window ? */
- CMEvent(itsConn,theEvent);
- isToolEvent = TRUE;
- }
-
- return isToolEvent;
- }
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * ConnectionChoose
- *
- * Connection tool setup
- *
- */
-
- void CConnection::ConnectionChoose(void)
- {
- short retCode;
- Point where;
- ConnHandle hConn;
-
- hConn = this->itsConn;
-
- SetPt(&where,H_CHOOSE_POS,V_CHOOSE_POS); /* Dialog position */
-
- retCode = CMChoose(&hConn,where,NULL);
-
- this->itsConn = hConn;
-
- switch (retCode) {
- case chooseCancel: /* Forget changes */
- break;
-
- case chooseOKMajor: /* Changed tool */
-
- // if we belong to a terminal pane, get its file transfer object
- if (member(itsSupervisor, CTermPane))
- {
- CFileTransfer *itsFileTransfer = nil;
-
- itsFileTransfer = ((CTermPane *)itsSupervisor)->GetFileTransfer ();
-
- if (itsFileTransfer)
- itsFileTransfer->AddSearch();
- }
- // fall through to chooseOKMinor processing
-
- case chooseOKMinor: /* Same tool, changed config */
-
- active = FALSE;
- Activate();
-
- itsSupervisor->Notify(NULL); /* Document updated */
-
- break;
-
- default: /* Unknown code (error) */
- SysBeep(3);
- gError->PostAlert(CONN_STR_RES_ID,CHOOSE_STR_INDEX);
- break;
- }
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * SetConfig
- *
- * Connection configuration change
- *
- * theConfig: new configuration (C string)
- *
- * Return: negative value: error (-1 -> unknown error)
- * positive value: stop index of the parser
- * cmNoErr if everything is OK
- *
- */
-
- short CConnection::SetConfig(char *theConfig)
- {
- short retCode;
-
- retCode = CMSetConfig(itsConn,theConfig);
-
- return retCode;
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * GetToolName
- *
- * Return the name of the current tool
- *
- * toolName: tool name (Pascal string)
- *
- */
-
- void CConnection::GetToolName(Str31 toolName)
- {
- SignedByte savedState;
-
- savedState = (SignedByte)HGetState((Handle)itsConn);
- HLock((Handle)itsConn);
-
- CMGetToolName((*itsConn)->procID,toolName);
-
- HSetState((Handle)itsConn,(char)savedState);
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * AddSearch
- *
- * Add auto download search pattern
- *
- *
- *
- */
-
- long CConnection::AddSearch(Str255 theString, CMSearchFlags flags, CommSearchPtr callBack)
- {
- if (callBack == nil)
- callBack = (CommSearchPtr)DefAutoRecCallback;
-
- return CMAddSearch(itsConn, theString, flags, callBack);
- }
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * RemoveSearch
- *
- * Remove auto download search pattern
- *
- */
-
- void CConnection::RemoveSearch(long refNum)
- {
- CMRemoveSearch(itsConn, refNum);
- }
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * ClearSearch
- *
- * Clear all auto download search patterns
- *
- *
- */
-
- void CConnection::ClearSearch(void)
- {
- CMClearSearch(itsConn);
- }
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * GetConfig
- *
- * Return a C string describing the current config of the connection
- *
- * Return a pointer on the string
- *
- */
-
- Ptr CConnection::GetConfig(void)
- {
- return(CMGetConfig(itsConn));
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * getStatus
- *
- * Return the connection status
- *
- * sizes: Buffers sizes (sortie)
- * flags: Connection status (sortie)
- *
- * Return an error code
- *
- */
-
- OSErr CConnection::getStatus(CMBufferSizes *sizes,CMStatFlags *flags)
- {
- return(CMStatus(itsConn,*sizes,flags));
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * OpenConnection
- *
- * Connection opening
- *
- * async: Opening mode (synchrone or asynchrone)
- * completor: asynchrone callback
- * timeOut: time period within which the opening must be completed
- *
- */
-
- void CConnection::OpenConnection(Boolean async,CommProcPtr completor,long timeOut)
- {
- OSErr theErr;
-
- theErr = CMOpen(itsConn,async,completor,timeOut);
-
- if (theErr == cmNoErr) {
- this->connOpen = TRUE;
- BroadcastChange(connOpenInd,NULL);
- }
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * ListenConnection
- *
- * Connection listening
- *
- * async: Listening mode (synchrone or asynchrone)
- * completor: asynchrone callback
- * timeOut: time period within which the listening must be completed
- *
- */
-
- void CConnection::ListenConnection(Boolean async,CommProcPtr completor,long timeOut)
- {
- OSErr theErr;
-
- theErr = CMListen(itsConn,async,completor,timeOut);
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * CloseConnection
- *
- * Connection closing
- *
- * async: Closing mode (synchrone or asynchrone)
- * completor: asynchrone callback
- * timeOut: time period within which the closing must be completed
- * now: immediately closing
- *
- */
-
- void CConnection::CloseConnection(Boolean async,CommProcPtr completor,long timeOut,
- Boolean now)
- {
- OSErr theErr;
-
- if (*itsConn != nil)
- { /* have a good connection? */
- if (CMValidate(itsConn) == false)
- {
- theErr = CMAbort(itsConn); /* just in case, abort open call */
- theErr = CMIOKill(itsConn,cmDataIn); /* ...and, pending read */
- theErr = CMIOKill(itsConn,cmDataOut); /* ...and, pending write */
- theErr = CMClose(itsConn,async,completor,timeOut,now); /* ...close, it */
- }
- else
- theErr = cmUnknownError;
- }
- else
- theErr = nilHandleErr;
-
- if (theErr == cmNoErr) {
- this->connOpen = FALSE;
- BroadcastChange(connCloseInd,NULL);
- };
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * IsOpen
- *
- * Connection opening test
- *
- * Return TRUE if the connection is open
- *
- */
-
- Boolean CConnection::IsOpen(void)
- {
- CMBufferSizes sizes;
- CMStatFlags flags;
- OSErr theErr;
-
- theErr = this->getStatus(&sizes,&flags);
-
- if (theErr == cmNoErr)
- if (flags & cmStatusOpen) /* Connection open ? */
- return TRUE;
- else
- return FALSE;
- else
- return FALSE;
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * DataAvail
- *
- * Data available
- *
- * Return the number of available characters
- *
- */
-
- long CConnection::DataAvail(void)
- {
- CMBufferSizes sizes;
- CMStatFlags flags;
- OSErr theErr;
-
- theErr = this->getStatus(&sizes,&flags);
-
- if (theErr == cmNoErr)
- if (flags & cmStatusDataAvail) /* Data available ? */
- return sizes[cmDataIn]; /* Return receiving buffer size */
- else
- return 0;
- else
- return 0;
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * DataRead
- *
- * Reading of available data
- *
- * inBuffer: Receiving buffer
- * buffSize: Number of chars to read
- * async: Reading mode (asynchrone or synchrone)
- * completor: Reading callback
- * timeOut: time period within which the reading must be completed
- * flags: end-of-message indicator
- *
- * Return an error code
- *
- */
-
- OSErr CConnection::DataRead(Ptr inBuffer,long *buffSize,Boolean async,
- CommProcPtr completor,long timeOut,CMFlags *flags,CMChannel channel)
- {
- CMBufferSizes sizes;
- CMStatFlags statFlags;
-
- getStatus (&sizes, &statFlags);
-
- return ((statFlags & cmStatusDRPend) == 0L ?
- CMRead(itsConn,inBuffer,buffSize,channel,async,completor,timeOut,flags) : 0);
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * DoIdle
- *
- * Idle time of the application
- *
- */
-
- void CConnection::DoIdle(void)
- {
- CMIdle(itsConn);
-
- if (!(this->IsOpen()) && this->connOpen) {
- this->connOpen = FALSE;
- BroadcastChange(connCloseInd,NULL);
- };
- }
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * cOneConnIdle
- *
- * terminal idle time
- *
- */
-
- pascal void *CConnection::cOneConnIdle (void *threadParam)
- {
- CConnection *aConn = (CConnection *)threadParam;
-
- #ifdef __USETHREADS__
- for (;;)
- {
- ThreadBeginCritical();
- #endif
-
- aConn->DoIdle();
-
- #ifdef __USETHREADS__
- ThreadEndCritical();
- YieldToAnyThread();
- }
- #endif
-
- return nil;
- }
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * DataWrite
- *
- * Data writing
- *
- * inBuffer: Sending buffer
- * buffSize: Number of chars to send
- * async: Writing mode (synchrone or asychrone)
- * completor: Asynchrone writing callback
- * timeOut: time period within which the writing must be completed
- * flags: end-of-message indicator
- *
- * Return an error code
- *
- */
-
- OSErr CConnection::DataWrite(Ptr inBuffer,long *buffSize,Boolean async,
- CommProcPtr completor,long timeOut,CMFlags flags)
- {
- return (CMWrite(itsConn,inBuffer,buffSize,cmData,async,completor,timeOut,flags));
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * Activate
- *
- * Connection activation
- *
- */
-
- void CConnection::Activate(void)
- {
- if (!active)
- {
- CMActivate(itsConn,TRUE);
- active = TRUE;
- }
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * Deactivate
- *
- * Connection desactivation
- *
- */
-
- void CConnection::Deactivate(void)
- {
- if (active)
- {
- CMActivate(itsConn,FALSE);
- active = FALSE;
- }
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * Reset
- *
- * Connection reset
- *
- */
-
- void CConnection::Reset(void)
- {
- short response;
-
- PositionDialog('ALRT', RESET_ALRT_ID);
-
- InitCursor();
-
- response = Alert(RESET_ALRT_ID, NULL);
-
- if (response == answerNO)
- CMReset(itsConn);
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * SendBreak
- *
- * BREAK signal sending
- *
- */
-
- void CConnection::SendBreak(void)
- {
- CMBreak(itsConn,BREAK_DELAY,FALSE,NULL);
- }
-
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-
- /*
- * GetEnvirons
- *
- * Return the connection environs
- *
- * theEnvirons: Pointer on the environs record
- *
- * Return an error code
- *
- */
-
- OSErr CConnection::GetEnvirons(ConnEnvironRecPtr theEnvirons)
- {
- return(CMGetConnEnvirons(itsConn,theEnvirons));
- }
-
- /*
- * get the connection handle
- */
-
- ConnHandle CConnection::GetConnHandle (void)
- {
- return itsConn;
- }
-
- /*******************************************************************
- * DefAutoRecCallback - Sets the file transfer flag if an auto-
- * receive string was found.
- *
- * theConn - which connection tool found it
- * data - ptr to last character in the match
- * refNum - which search was found
- *
- **********************************************************************/
-
- pascal void CConnection::DefAutoRecCallback(ConnHandle theConn, Ptr data, long refNum)
- {
- CConnection *theConnection = (CConnection *)CMGetRefCon (theConn);
- CFileTransfer *itsFileTransfer = nil;
-
- // if we belong to a terminal pane, get its file transfer object
- if (member(theConnection->itsSupervisor, CTermPane))
- itsFileTransfer = ((CTermPane *)(theConnection->itsSupervisor))->GetFileTransfer ();
-
- // We can't call _FTStart or _CMRemoveSearch here as
- // this proc might be called from Interrupt level
-
- if (itsFileTransfer)
- {
- if (itsFileTransfer->GetSearchNum () == refNum)
- itsFileTransfer->SetAutoDownload (true); // Set the flag to call FTStart in Idle
- }
- } // DefAutoRecCallBack
-
- /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
-