/*
 	File:		Connections.h
 
 	Contains:	Communications Toolbox Connection Manager Interfaces.
 
 	Version:	Technology:	System 7.5
 				Release:	QuickTime 4.0
 
 	Copyright:	(c) 1988-1998 by Apple Computer, Inc., all rights reserved
 
 	Bugs?:		For bug reports, consult the following page on
 				the World Wide Web:
 
 					http://developer.apple.com/bugreporter/
 
*/
#ifndef __CONNECTIONS__
#define __CONNECTIONS__

#ifndef __CONDITIONALMACROS__
#include <ConditionalMacros.h>
#endif
#ifndef __MACTYPES__
#include <MacTypes.h>
#endif
#ifndef __MIXEDMODE__
#include <MixedMode.h>
#endif
#ifndef __DIALOGS__
#include <Dialogs.h>
#endif



#if PRAGMA_ONCE
#pragma once
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if PRAGMA_IMPORT
#pragma import on
#endif

#if PRAGMA_STRUCT_ALIGN
	#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
	#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
	#pragma pack(2)
#endif


enum {
	curCMVersion				= 2								/* current Connection Manager version*/
};


enum {
	curConnEnvRecVers			= 0								/*	current Connection Manager Environment Record version*/
};


enum {
																/* CMErr */
	cmGenericError				= -1,
	cmNoErr						= 0,
	cmRejected					= 1,
	cmFailed					= 2,
	cmTimeOut					= 3,
	cmNotOpen					= 4,
	cmNotClosed					= 5,
	cmNoRequestPending			= 6,
	cmNotSupported				= 7,
	cmNoTools					= 8,
	cmUserCancel				= 9,
	cmUnknownError				= 11
};

typedef OSErr 							CMErr;


enum {
	cmData						= 1L << 0,
	cmCntl						= 1L << 1,
	cmAttn						= 1L << 2,
	cmDataNoTimeout				= 1L << 4,
	cmCntlNoTimeout				= 1L << 5,
	cmAttnNoTimeout				= 1L << 6,
	cmDataClean					= 1L << 8,
	cmCntlClean					= 1L << 9,
	cmAttnClean					= 1L << 10,						/*		Only for CMRecFlags (not CMChannel) in the rest of this enum	*/
	cmNoMenus					= 1L << 16,
	cmQuiet						= 1L << 17,
	cmConfigChanged				= 1L << 18
};

/* CMRecFlags and CMChannel		*/
/*		Low word of CMRecFlags is same as CMChannel	*/
typedef long 							CMRecFlags;
typedef short 							CMChannel;



enum {
	cmStatusOpening				= 1L << 0,
	cmStatusOpen				= 1L << 1,
	cmStatusClosing				= 1L << 2,
	cmStatusDataAvail			= 1L << 3,
	cmStatusCntlAvail			= 1L << 4,
	cmStatusAttnAvail			= 1L << 5,
	cmStatusDRPend				= 1L << 6,						/* data read pending	*/
	cmStatusDWPend				= 1L << 7,						/* data write pending	*/
	cmStatusCRPend				= 1L << 8,						/* cntl read pending	*/
	cmStatusCWPend				= 1L << 9,						/* cntl write pending	*/
	cmStatusARPend				= 1L << 10,						/* attn read pending	*/
	cmStatusAWPend				= 1L << 11,						/* attn write pending	*/
	cmStatusBreakPend			= 1L << 12,
	cmStatusListenPend			= 1L << 13,
	cmStatusIncomingCallPresent	= 1L << 14,
	cmStatusReserved0			= 1L << 15
};

typedef unsigned long 					CMStatFlags;

enum {
	cmDataIn					= 0,
	cmDataOut					= 1,
	cmCntlIn					= 2,
	cmCntlOut					= 3,
	cmAttnIn					= 4,
	cmAttnOut					= 5,
	cmRsrvIn					= 6,
	cmRsrvOut					= 7
};

typedef unsigned short 					CMBufFields;
typedef Ptr 							CMBuffers[8];
typedef long 							CMBufferSizes[8];
typedef const long *					ConstCMBufferSizesParam;

enum {
	cmSearchSevenBit			= 1L << 0
};

typedef unsigned short 					CMSearchFlags;

enum {
	cmFlagsEOM					= 1L << 0
};

typedef unsigned short 					CMFlags;

struct ConnEnvironRec {
	short 							version;
	long 							baudRate;
	short 							dataBits;
	CMChannel 						channels;
	Boolean 						swFlowControl;
	Boolean 						hwFlowControl;
	CMFlags 						flags;
};
typedef struct ConnEnvironRec			ConnEnvironRec;
typedef ConnEnvironRec *				ConnEnvironRecPtr;
typedef struct ConnRecord 				ConnRecord;

typedef ConnRecord *					ConnPtr;
typedef ConnPtr *						ConnHandle;
typedef CALLBACK_API( long , ConnectionToolDefProcPtr )(ConnHandle hConn, short msg, long p1, long p2, long p3);
typedef CALLBACK_API( void , ConnectionSearchCallBackProcPtr )(ConnHandle hConn, Ptr matchPtr, long refNum);
typedef CALLBACK_API( void , ConnectionCompletionProcPtr )(ConnHandle hConn);
typedef CALLBACK_API( void , ConnectionChooseIdleProcPtr )(void );
typedef STACK_UPP_TYPE(ConnectionToolDefProcPtr) 				ConnectionToolDefUPP;
typedef STACK_UPP_TYPE(ConnectionSearchCallBackProcPtr) 		ConnectionSearchCallBackUPP;
typedef STACK_UPP_TYPE(ConnectionCompletionProcPtr) 			ConnectionCompletionUPP;
typedef STACK_UPP_TYPE(ConnectionChooseIdleProcPtr) 			ConnectionChooseIdleUPP;

struct ConnRecord {
	short 							procID;
	CMRecFlags 						flags;
	CMErr 							errCode;
	long 							refCon;
	long 							userData;
	ConnectionToolDefUPP 			defProc;
	Ptr 							config;
	Ptr 							oldConfig;
	long 							asyncEOM;
	long 							reserved1;
	long 							reserved2;
	Ptr 							cmPrivate;
	CMBuffers 						bufferArray;
	CMBufferSizes 					bufSizes;
	long 							mluField;
	CMBufferSizes 					asyncCount;
};


enum {
																/* CMIOPB constants and structure */
	cmIOPBQType					= 10,
	cmIOPBversion				= 0
};


struct CMIOPB {
	QElemPtr 						qLink;
	short 							qType;						/* cmIOPBQType */
	ConnHandle 						hConn;
	Ptr 							theBuffer;
	long 							count;
	CMFlags 						flags;
	ConnectionCompletionUPP 		userCompletion;
	long 							timeout;
	CMErr 							errCode;
	CMChannel 						channel;
	long 							asyncEOM;
	long 							reserved1;
	short 							reserved2;
	short 							version;					/* cmIOPBversion */
	long 							refCon;						/* for application */
	long 							toolData1;					/* for tool */
	long 							toolData2;					/* for tool */
};
typedef struct CMIOPB					CMIOPB;
typedef CMIOPB *						CMIOPBPtr;
enum { uppConnectionToolDefProcInfo = 0x0000FEF0 }; 			/* pascal 4_bytes Func(4_bytes, 2_bytes, 4_bytes, 4_bytes, 4_bytes) */
enum { uppConnectionSearchCallBackProcInfo = 0x00000FC0 }; 		/* pascal no_return_value Func(4_bytes, 4_bytes, 4_bytes) */
enum { uppConnectionCompletionProcInfo = 0x000000C0 }; 			/* pascal no_return_value Func(4_bytes) */
enum { uppConnectionChooseIdleProcInfo = 0x00000000 }; 			/* pascal no_return_value Func() */
#if MIXEDMODE_CALLS_ARE_FUNCTIONS
EXTERN_API(long)
CallConnectionToolDefProc	   (ConnectionToolDefUPP	userRoutine,
								ConnHandle				hConn,
								short					msg,
								long					p1,
								long					p2,
								long					p3);
EXTERN_API(void)
CallConnectionSearchCallBackProc    (ConnectionSearchCallBackUPP userRoutine,
								ConnHandle				hConn,
								Ptr						matchPtr,
								long					refNum);
EXTERN_API(void)
CallConnectionCompletionProc    (ConnectionCompletionUPP userRoutine,
								ConnHandle				hConn);
EXTERN_API(void)
CallConnectionChooseIdleProc    (ConnectionChooseIdleUPP userRoutine);
EXTERN_API(ConnectionToolDefUPP)
NewConnectionToolDefProc	   (ConnectionToolDefProcPtr userRoutine);
EXTERN_API(ConnectionSearchCallBackUPP)
NewConnectionSearchCallBackProc    (ConnectionSearchCallBackProcPtr userRoutine);
EXTERN_API(ConnectionCompletionUPP)
NewConnectionCompletionProc	   (ConnectionCompletionProcPtr userRoutine);
EXTERN_API(ConnectionChooseIdleUPP)
NewConnectionChooseIdleProc	   (ConnectionChooseIdleProcPtr userRoutine);
#else
#define CallConnectionToolDefProc(userRoutine, hConn, msg, p1, p2, p3)  CALL_FIVE_PARAMETER_UPP((userRoutine), uppConnectionToolDefProcInfo, (hConn), (msg), (p1), (p2), (p3))
#define CallConnectionSearchCallBackProc(userRoutine, hConn, matchPtr, refNum)  CALL_THREE_PARAMETER_UPP((userRoutine), uppConnectionSearchCallBackProcInfo, (hConn), (matchPtr), (refNum))
#define CallConnectionCompletionProc(userRoutine, hConn) 		CALL_ONE_PARAMETER_UPP((userRoutine), uppConnectionCompletionProcInfo, (hConn))
#define CallConnectionChooseIdleProc(userRoutine) 				CALL_ZERO_PARAMETER_UPP((userRoutine), uppConnectionChooseIdleProcInfo)
#define NewConnectionToolDefProc(userRoutine) 					(ConnectionToolDefUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppConnectionToolDefProcInfo, GetCurrentArchitecture())
#define NewConnectionSearchCallBackProc(userRoutine) 			(ConnectionSearchCallBackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppConnectionSearchCallBackProcInfo, GetCurrentArchitecture())
#define NewConnectionCompletionProc(userRoutine) 				(ConnectionCompletionUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppConnectionCompletionProcInfo, GetCurrentArchitecture())
#define NewConnectionChooseIdleProc(userRoutine) 				(ConnectionChooseIdleUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppConnectionChooseIdleProcInfo, GetCurrentArchitecture())
#endif


EXTERN_API( CMErr )
InitCM							(void);

EXTERN_API( Handle )
CMGetVersion					(ConnHandle 			hConn);

EXTERN_API( short )
CMGetCMVersion					(void);

EXTERN_API( ConnHandle )
CMNew							(short 					procID,
								 CMRecFlags 			flags,
								 ConstCMBufferSizesParam  desiredSizes,
								 long 					refCon,
								 long 					userData);

EXTERN_API( void )
CMDispose						(ConnHandle 			hConn);

EXTERN_API( CMErr )
CMListen						(ConnHandle 			hConn,
								 Boolean 				async,
								 ConnectionCompletionUPP  completor,
								 long 					timeout);

EXTERN_API( CMErr )
CMAccept						(ConnHandle 			hConn,
								 Boolean 				accept);

EXTERN_API( CMErr )
CMOpen							(ConnHandle 			hConn,
								 Boolean 				async,
								 ConnectionCompletionUPP  completor,
								 long 					timeout);

EXTERN_API( CMErr )
CMClose							(ConnHandle 			hConn,
								 Boolean 				async,
								 ConnectionCompletionUPP  completor,
								 long 					timeout,
								 Boolean 				now);

EXTERN_API( CMErr )
CMAbort							(ConnHandle 			hConn);

EXTERN_API( CMErr )
CMStatus						(ConnHandle 			hConn,
								 CMBufferSizes 			sizes,
								 CMStatFlags *			flags);

EXTERN_API( void )
CMIdle							(ConnHandle 			hConn);

EXTERN_API( void )
CMReset							(ConnHandle 			hConn);

EXTERN_API( void )
CMBreak							(ConnHandle 			hConn,
								 long 					duration,
								 Boolean 				async,
								 ConnectionCompletionUPP  completor);

EXTERN_API( CMErr )
CMRead							(ConnHandle 			hConn,
								 void *					theBuffer,
								 long *					toRead,
								 CMChannel 				theChannel,
								 Boolean 				async,
								 ConnectionCompletionUPP  completor,
								 long 					timeout,
								 CMFlags *				flags);

EXTERN_API( CMErr )
CMWrite							(ConnHandle 			hConn,
								 const void *			theBuffer,
								 long *					toWrite,
								 CMChannel 				theChannel,
								 Boolean 				async,
								 ConnectionCompletionUPP  completor,
								 long 					timeout,
								 CMFlags 				flags);

EXTERN_API( CMErr )
CMIOKill						(ConnHandle 			hConn,
								 short 					which);

EXTERN_API( void )
CMActivate						(ConnHandle 			hConn,
								 Boolean 				activate);

EXTERN_API( void )
CMResume						(ConnHandle 			hConn,
								 Boolean 				resume);

EXTERN_API( Boolean )
CMMenu							(ConnHandle 			hConn,
								 short 					menuID,
								 short 					item);

EXTERN_API( Boolean )
CMValidate						(ConnHandle 			hConn);

EXTERN_API( void )
CMDefault						(Ptr *					theConfig,
								 short 					procID,
								 Boolean 				allocate);

EXTERN_API( Handle )
CMSetupPreflight				(short 					procID,
								 long *					magicCookie);

EXTERN_API( Boolean )
CMSetupFilter					(short 					procID,
								 const void *			theConfig,
								 short 					count,
								 DialogPtr 				theDialog,
								 EventRecord *			theEvent,
								 short *				theItem,
								 long *					magicCookie);

EXTERN_API( void )
CMSetupSetup					(short 					procID,
								 const void *			theConfig,
								 short 					count,
								 DialogPtr 				theDialog,
								 long *					magicCookie);

EXTERN_API( void )
CMSetupItem						(short 					procID,
								 const void *			theConfig,
								 short 					count,
								 DialogPtr 				theDialog,
								 short *				theItem,
								 long *					magicCookie);

EXTERN_API( void )
CMSetupXCleanup					(short 					procID,
								 const void *			theConfig,
								 short 					count,
								 DialogPtr 				theDialog,
								 Boolean 				OKed,
								 long *					magicCookie);

EXTERN_API( void )
CMSetupPostflight				(short 					procID);

EXTERN_API( Ptr )
CMGetConfig						(ConnHandle 			hConn);

EXTERN_API( short )
CMSetConfig						(ConnHandle 			hConn,
								 const void *			thePtr);

EXTERN_API( OSErr )
CMIntlToEnglish					(ConnHandle 			hConn,
								 const void *			inputPtr,
								 Ptr *					outputPtr,
								 short 					language);

EXTERN_API( OSErr )
CMEnglishToIntl					(ConnHandle 			hConn,
								 const void *			inputPtr,
								 Ptr *					outputPtr,
								 short 					language);

EXTERN_API( long )
CMAddSearch						(ConnHandle 			hConn,
								 ConstStr255Param 		theString,
								 CMSearchFlags 			flags,
								 ConnectionSearchCallBackUPP  callBack);

EXTERN_API( void )
CMRemoveSearch					(ConnHandle 			hConn,
								 long 					refnum);

EXTERN_API( void )
CMClearSearch					(ConnHandle 			hConn);

EXTERN_API( CMErr )
CMGetConnEnvirons				(ConnHandle 			hConn,
								 ConnEnvironRec *		theEnvirons);

EXTERN_API( short )
CMChoose						(ConnHandle *			hConn,
								 Point 					where,
								 ConnectionChooseIdleUPP  idle);

EXTERN_API( void )
CMEvent							(ConnHandle 			hConn,
								 const EventRecord *	theEvent);

EXTERN_API( void )
CMGetToolName					(short 					procID,
								 Str255 				name);

EXTERN_API( short )
CMGetProcID						(ConstStr255Param 		name);

EXTERN_API( void )
CMSetRefCon						(ConnHandle 			hConn,
								 long 					refCon);

EXTERN_API( long )
CMGetRefCon						(ConnHandle 			hConn);

EXTERN_API( long )
CMGetUserData					(ConnHandle 			hConn);

EXTERN_API( void )
CMSetUserData					(ConnHandle 			hConn,
								 long 					userData);

EXTERN_API( void )
CMGetErrorString				(ConnHandle 			hConn,
								 short 					id,
								 Str255 				errMsg);

EXTERN_API( CMErr )
CMNewIOPB						(ConnHandle 			hConn,
								 CMIOPBPtr *			theIOPB);

EXTERN_API( CMErr )
CMDisposeIOPB					(ConnHandle 			hConn,
								 CMIOPBPtr 				theIOPB);

EXTERN_API( CMErr )
CMPBRead						(ConnHandle 			hConn,
								 CMIOPBPtr 				theIOPB,
								 Boolean 				async);

EXTERN_API( CMErr )
CMPBWrite						(ConnHandle 			hConn,
								 CMIOPBPtr 				theIOPB,
								 Boolean 				async);

EXTERN_API( CMErr )
CMPBIOKill						(ConnHandle 			hConn,
								 CMIOPBPtr 				theIOPB);


#if PRAGMA_STRUCT_ALIGN
	#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
	#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
	#pragma pack()
#endif

#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif

#ifdef __cplusplus
}
#endif

#endif /* __CONNECTIONS__ */

