2003-11-01 06:35:29 +01:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2006-01-08 02:25:02 +01:00
|
|
|
* Copyright 2001 by Eric House (xwords@eehouse.org). All rights reserved.
|
2003-11-01 06:35:29 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _COMMS_H_
|
|
|
|
#define _COMMS_H_
|
|
|
|
|
|
|
|
#include "comtypes.h"
|
|
|
|
#include "mempool.h"
|
2005-03-19 22:46:51 +01:00
|
|
|
#include "xwrelay.h"
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-01-31 04:31:50 +01:00
|
|
|
EXTERN_C_START
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
#define CHANNEL_NONE ((XP_PlayerAddr)0)
|
|
|
|
#define CONN_ID_NONE 0L
|
|
|
|
|
2005-10-02 17:39:38 +02:00
|
|
|
typedef XP_U32 MsgID; /* this is too big!!! PENDING */
|
2005-10-01 18:01:39 +02:00
|
|
|
typedef XP_U8 XWHostID;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
COMMS_CONN_UNUSED, /* I want errors on uninited case */
|
2005-03-19 22:46:51 +01:00
|
|
|
COMMS_CONN_IP_NOUSE,
|
|
|
|
COMMS_CONN_RELAY,
|
2005-01-31 04:31:50 +01:00
|
|
|
COMMS_CONN_BT,
|
|
|
|
COMMS_CONN_IR,
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
LAST_____FOO
|
|
|
|
} CommsConnType;
|
|
|
|
|
2005-01-31 04:31:50 +01:00
|
|
|
#define MAX_HOSTNAME_LEN 63
|
2003-11-01 06:35:29 +01:00
|
|
|
typedef struct CommsAddrRec {
|
|
|
|
CommsConnType conType;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
2005-03-19 22:46:51 +01:00
|
|
|
XP_UCHAR hostName_ip[MAX_HOSTNAME_LEN + 1];
|
|
|
|
XP_U32 ipAddr_ip; /* looked up from above */
|
|
|
|
XP_U16 port_ip;
|
|
|
|
} ip;
|
|
|
|
struct {
|
|
|
|
XP_UCHAR cookie[MAX_COOKIE_LEN + 1];
|
2005-01-31 04:31:50 +01:00
|
|
|
XP_UCHAR hostName[MAX_HOSTNAME_LEN + 1];
|
|
|
|
XP_U32 ipAddr; /* looked up from above */
|
|
|
|
XP_U16 port;
|
2005-03-19 22:46:51 +01:00
|
|
|
} ip_relay;
|
2003-11-01 06:35:29 +01:00
|
|
|
struct {
|
|
|
|
/* nothing? */
|
|
|
|
XP_UCHAR foo; /* wince doesn't like nothing here */
|
|
|
|
} ir;
|
2005-03-19 22:46:51 +01:00
|
|
|
struct {
|
|
|
|
/* nothing? */
|
|
|
|
XP_UCHAR foo; /* wince doesn't like nothing here */
|
|
|
|
} bt;
|
2003-11-01 06:35:29 +01:00
|
|
|
} u;
|
|
|
|
} CommsAddrRec;
|
|
|
|
|
2006-08-23 06:44:55 +02:00
|
|
|
typedef XP_S16 (*TransportSend)( const XP_U8* buf, XP_U16 len,
|
2005-07-30 03:48:17 +02:00
|
|
|
const CommsAddrRec* addr,
|
2003-11-01 06:35:29 +01:00
|
|
|
void* closure );
|
|
|
|
|
|
|
|
CommsCtxt* comms_make( MPFORMAL XW_UtilCtxt* util,
|
2005-10-02 17:39:38 +02:00
|
|
|
XP_Bool isServer,
|
|
|
|
XP_U16 nPlayersHere, XP_U16 nPlayersTotal,
|
|
|
|
TransportSend sendproc, void* closure );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-10-02 17:39:38 +02:00
|
|
|
void comms_reset( CommsCtxt* comms, XP_Bool isServer,
|
|
|
|
XP_U16 nPlayersHere, XP_U16 nPlayersTotal );
|
2003-11-01 06:35:29 +01:00
|
|
|
void comms_destroy( CommsCtxt* comms );
|
|
|
|
|
|
|
|
void comms_setConnID( CommsCtxt* comms, XP_U32 connID );
|
|
|
|
|
2005-04-03 04:48:50 +02:00
|
|
|
/* "static" method provides default when no comms present */
|
|
|
|
void comms_getInitialAddr( CommsAddrRec* addr );
|
2005-06-27 07:45:28 +02:00
|
|
|
void comms_getAddr( CommsCtxt* comms, CommsAddrRec* addr );
|
2005-07-23 17:21:23 +02:00
|
|
|
void comms_setAddr( CommsCtxt* comms, const CommsAddrRec* addr );
|
2005-03-19 22:46:51 +01:00
|
|
|
|
2005-06-27 07:45:28 +02:00
|
|
|
CommsConnType comms_getConType( CommsCtxt* comms );
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
CommsCtxt* comms_makeFromStream( MPFORMAL XWStreamCtxt* stream,
|
|
|
|
XW_UtilCtxt* util, TransportSend sendproc,
|
|
|
|
void* closure );
|
2005-07-06 02:58:20 +02:00
|
|
|
void comms_start( CommsCtxt* comms );
|
2003-11-01 06:35:29 +01:00
|
|
|
void comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream );
|
|
|
|
|
2005-03-19 22:46:51 +01:00
|
|
|
XP_S16 comms_send( CommsCtxt* comms, XWStreamCtxt* stream );
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_S16 comms_resendAll( CommsCtxt* comms );
|
|
|
|
|
|
|
|
|
2005-03-09 16:12:57 +01:00
|
|
|
XP_Bool comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
|
|
|
|
CommsAddrRec* addr );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
# ifdef DEBUG
|
|
|
|
void comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream );
|
|
|
|
# endif
|
|
|
|
|
2005-01-31 04:31:50 +01:00
|
|
|
EXTERN_C_END
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
#endif /* _COMMS_H_ */
|