2003-11-01 06:35:29 +01:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2009-02-01 16:50:58 +01:00
|
|
|
* Copyright 2001-2009 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"
|
2008-01-07 02:10:43 +01:00
|
|
|
#include "server.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 {
|
2007-12-09 02:59:15 +01:00
|
|
|
COMMS_CONN_NONE /* I want errors on uninited case */
|
|
|
|
,COMMS_CONN_IR
|
|
|
|
,COMMS_CONN_IP_DIRECT
|
|
|
|
,COMMS_CONN_RELAY
|
|
|
|
,COMMS_CONN_BT
|
2008-12-29 02:35:29 +01:00
|
|
|
,COMMS_CONN_SMS
|
2009-02-28 20:27:45 +01:00
|
|
|
|
|
|
|
,COMMS_CONN_NTYPES
|
2003-11-01 06:35:29 +01:00
|
|
|
} CommsConnType;
|
|
|
|
|
2009-09-12 23:39:13 +02:00
|
|
|
typedef enum {
|
|
|
|
COMMS_RELAYSTATE_UNCONNECTED
|
2009-12-04 09:14:03 +01:00
|
|
|
, COMMS_RELAYSTATE_DENIED /* terminal; new game or reset required to
|
|
|
|
fix */
|
2009-09-12 23:39:13 +02:00
|
|
|
, COMMS_RELAYSTATE_CONNECT_PENDING
|
|
|
|
, COMMS_RELAYSTATE_CONNECTED
|
2009-11-08 22:30:13 +01:00
|
|
|
, COMMS_RELAYSTATE_RECONNECTED
|
2009-09-12 23:39:13 +02:00
|
|
|
, COMMS_RELAYSTATE_ALLCONNECTED
|
|
|
|
} CommsRelayState;
|
|
|
|
|
2012-02-28 05:30:48 +01:00
|
|
|
#ifdef XWFEATURE_BLUETOOTH
|
|
|
|
# define XW_BT_UUID "7be0d084-ff89-4d6d-9c78-594773a6f963"
|
2007-11-03 23:04:06 +01:00
|
|
|
|
2012-02-28 05:30:48 +01:00
|
|
|
# define XW_BT_NAME "Crosswords"
|
|
|
|
#endif
|
2007-11-03 23:04:06 +01:00
|
|
|
|
2006-08-26 23:12:10 +02:00
|
|
|
/* on Palm BtLibDeviceAddressType is a 48-bit quantity. Linux's typeis the
|
|
|
|
same size. Goal is something all platforms support */
|
2006-09-14 03:25:40 +02:00
|
|
|
typedef struct XP_BtAddr { XP_U8 bits[6]; } XP_BtAddr;
|
|
|
|
typedef struct XP_BtAddrStr { XP_UCHAR chars[18]; } XP_BtAddrStr;
|
2006-08-26 23:12:10 +02:00
|
|
|
|
2007-11-19 00:43:27 +01:00
|
|
|
#ifdef COMMS_HEARTBEAT
|
|
|
|
# define IF_CH(a) a,
|
|
|
|
#else
|
|
|
|
# define IF_CH(a)
|
|
|
|
#endif
|
|
|
|
|
2005-01-31 04:31:50 +01:00
|
|
|
#define MAX_HOSTNAME_LEN 63
|
2008-12-29 02:35:29 +01:00
|
|
|
#define MAX_PHONE_LEN 31
|
|
|
|
|
2012-02-06 15:27:53 +01:00
|
|
|
typedef struct _CommsAddrRec {
|
2003-11-01 06:35:29 +01:00
|
|
|
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 {
|
2009-09-14 05:11:11 +02:00
|
|
|
XP_UCHAR invite[MAX_INVITE_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;
|
2010-09-03 15:38:46 +02:00
|
|
|
XP_Bool seeksPublicRoom;
|
|
|
|
XP_Bool advertiseRoom;
|
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 {
|
2006-08-26 23:12:10 +02:00
|
|
|
/* guests can browse for the host to connect to */
|
|
|
|
XP_UCHAR hostName[MAX_HOSTNAME_LEN + 1];
|
2012-02-01 03:43:26 +01:00
|
|
|
XP_BtAddrStr btAddr;
|
2005-03-19 22:46:51 +01:00
|
|
|
} bt;
|
2008-12-29 02:35:29 +01:00
|
|
|
struct {
|
|
|
|
XP_UCHAR phone[MAX_PHONE_LEN + 1];
|
|
|
|
XP_U16 port;
|
|
|
|
} sms;
|
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,
|
2012-01-26 03:27:37 +01:00
|
|
|
XP_U32 gameID, void* closure );
|
2009-09-12 23:39:13 +02:00
|
|
|
#ifdef COMMS_HEARTBEAT
|
2007-11-19 00:43:27 +01:00
|
|
|
typedef void (*TransportReset)( void* closure );
|
2009-09-12 23:39:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XWFEATURE_RELAY
|
|
|
|
typedef void (*RelayStatusProc)( void* closure, CommsRelayState newState );
|
2010-10-29 03:45:55 +02:00
|
|
|
typedef void (*RelayConndProc)( void* closure, XP_UCHAR* const room,
|
2011-05-19 14:51:00 +02:00
|
|
|
XP_Bool reconnect,
|
2010-10-29 15:31:33 +02:00
|
|
|
XP_U16 devOrder, /* 1 means created room, etc. */
|
2011-05-19 14:51:00 +02:00
|
|
|
XP_Bool allHere, XP_U16 nMissing );
|
2009-12-04 09:14:03 +01:00
|
|
|
typedef void (*RelayErrorProc)( void* closure, XWREASON relayErr );
|
2011-08-11 03:28:34 +02:00
|
|
|
typedef XP_Bool (*RelayNoConnProc)( const XP_U8* buf, XP_U16 len,
|
|
|
|
const XP_UCHAR* relayID, void* closure );
|
2009-09-12 23:39:13 +02:00
|
|
|
#endif
|
|
|
|
|
2011-08-17 04:36:23 +02:00
|
|
|
typedef enum {
|
|
|
|
COMMS_XPORT_FLAGS_NONE = 0
|
|
|
|
,COMMS_XPORT_FLAGS_HASNOCONN = 1
|
|
|
|
} CommsTransportFlags;
|
|
|
|
|
|
|
|
#ifdef COMMS_XPORT_FLAGSPROC
|
|
|
|
typedef XP_U32 (*FlagsProc)( void* closure );
|
|
|
|
#endif
|
|
|
|
|
2009-09-12 23:39:13 +02:00
|
|
|
typedef struct _TransportProcs {
|
2011-08-17 04:36:23 +02:00
|
|
|
# ifdef COMMS_XPORT_FLAGSPROC
|
|
|
|
FlagsProc getFlags;
|
|
|
|
#else
|
|
|
|
XP_U32 flags;
|
|
|
|
#endif
|
2009-09-12 23:39:13 +02:00
|
|
|
TransportSend send;
|
|
|
|
#ifdef COMMS_HEARTBEAT
|
|
|
|
TransportReset reset;
|
|
|
|
#endif
|
|
|
|
#ifdef XWFEATURE_RELAY
|
|
|
|
RelayStatusProc rstatus;
|
2009-12-14 05:03:17 +01:00
|
|
|
RelayConndProc rconnd;
|
2009-12-04 09:14:03 +01:00
|
|
|
RelayErrorProc rerror;
|
2011-08-11 03:28:34 +02:00
|
|
|
RelayNoConnProc sendNoConn;
|
2009-09-12 23:39:13 +02:00
|
|
|
#endif
|
|
|
|
void* closure;
|
|
|
|
} TransportProcs;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
CommsCtxt* comms_make( MPFORMAL XW_UtilCtxt* util,
|
2005-10-02 17:39:38 +02:00
|
|
|
XP_Bool isServer,
|
|
|
|
XP_U16 nPlayersHere, XP_U16 nPlayersTotal,
|
2011-08-01 07:23:46 +02:00
|
|
|
const TransportProcs* procs
|
|
|
|
#ifdef SET_GAMESEED
|
|
|
|
,XP_U16 gameSeed
|
|
|
|
#endif
|
|
|
|
);
|
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 );
|
2010-06-05 05:39:16 +02:00
|
|
|
void comms_resetSame( CommsCtxt* comms );
|
2009-02-01 16:50:58 +01:00
|
|
|
void comms_transportFailed( CommsCtxt* comms );
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
void comms_destroy( CommsCtxt* comms );
|
|
|
|
|
|
|
|
void comms_setConnID( CommsCtxt* comms, XP_U32 connID );
|
|
|
|
|
2008-01-07 02:10:43 +01:00
|
|
|
/* "static" methods work when no comms present */
|
2010-03-21 04:12:58 +01:00
|
|
|
void comms_getInitialAddr( CommsAddrRec* addr
|
|
|
|
#ifdef XWFEATURE_RELAY
|
|
|
|
, const XP_UCHAR* relayName
|
2010-03-25 05:50:19 +01:00
|
|
|
, XP_U16 relayPort
|
2010-03-21 04:12:58 +01:00
|
|
|
#endif
|
|
|
|
);
|
2008-01-07 02:10:43 +01:00
|
|
|
XP_Bool comms_checkAddr( DeviceRole role, const CommsAddrRec* addr,
|
|
|
|
XW_UtilCtxt* util );
|
|
|
|
|
2006-10-15 15:53:17 +02:00
|
|
|
void comms_getAddr( const CommsCtxt* comms, CommsAddrRec* addr );
|
2005-07-23 17:21:23 +02:00
|
|
|
void comms_setAddr( CommsCtxt* comms, const CommsAddrRec* addr );
|
2012-04-19 08:23:36 +02:00
|
|
|
void comms_getAddrs( const CommsCtxt* comms, CommsAddrRec addr[],
|
|
|
|
XP_U16* nRecs );
|
2014-03-01 03:59:12 +01:00
|
|
|
XP_U16 comms_countPendingPackets( const CommsCtxt* comms );
|
|
|
|
|
2005-03-19 22:46:51 +01:00
|
|
|
|
2010-08-22 21:16:57 +02:00
|
|
|
#ifdef XWFEATURE_RELAY
|
2010-10-11 15:20:30 +02:00
|
|
|
XP_Bool comms_getRelayID( const CommsCtxt* comms, XP_UCHAR* buf, XP_U16* len );
|
2010-08-22 21:16:57 +02:00
|
|
|
#endif
|
|
|
|
|
2006-10-15 15:53:17 +02:00
|
|
|
CommsConnType comms_getConType( const CommsCtxt* comms );
|
|
|
|
XP_Bool comms_getIsServer( const CommsCtxt* comms );
|
2005-06-27 07:45:28 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
CommsCtxt* comms_makeFromStream( MPFORMAL XWStreamCtxt* stream,
|
2011-08-01 07:23:46 +02:00
|
|
|
XW_UtilCtxt* util,
|
|
|
|
const TransportProcs* procs );
|
2005-07-06 02:58:20 +02:00
|
|
|
void comms_start( CommsCtxt* comms );
|
2013-01-16 15:31:09 +01:00
|
|
|
void comms_stop( CommsCtxt* comms );
|
2012-09-10 16:31:45 +02:00
|
|
|
void comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream,
|
|
|
|
XP_U16 saveToken );
|
|
|
|
void comms_saveSucceeded( CommsCtxt* comms, XP_U16 saveToken );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-03-19 22:46:51 +01:00
|
|
|
XP_S16 comms_send( CommsCtxt* comms, XWStreamCtxt* stream );
|
2012-11-14 06:25:03 +01:00
|
|
|
XP_Bool comms_resendAll( CommsCtxt* comms, XP_Bool force );
|
2010-11-09 02:22:38 +01:00
|
|
|
XP_U16 comms_getChannelSeed( CommsCtxt* comms );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2012-04-14 05:21:59 +02:00
|
|
|
#ifdef XWFEATURE_COMMSACK
|
|
|
|
void comms_ackAny( CommsCtxt* comms );
|
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-03-09 16:12:57 +01:00
|
|
|
XP_Bool comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
|
2006-09-14 03:25:40 +02:00
|
|
|
const CommsAddrRec* addr );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2010-10-22 04:14:10 +02:00
|
|
|
XP_Bool comms_checkComplete( const CommsAddrRec* const addr );
|
|
|
|
|
|
|
|
XP_Bool comms_canChat( const CommsCtxt* comms );
|
2010-10-28 05:50:11 +02:00
|
|
|
XP_Bool comms_isConnected( const CommsCtxt* const comms );
|
2009-09-05 15:08:46 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
# ifdef DEBUG
|
|
|
|
void comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream );
|
2009-03-06 14:43:03 +01:00
|
|
|
const char* ConnType2Str( CommsConnType typ );
|
2009-09-12 23:39:13 +02:00
|
|
|
const char* CommsRelayState2Str( CommsRelayState state );
|
2010-11-19 07:27:06 +01:00
|
|
|
const char* XWREASON2Str( XWREASON reason );
|
2003-11-01 06:35:29 +01:00
|
|
|
# endif
|
|
|
|
|
2005-01-31 04:31:50 +01:00
|
|
|
EXTERN_C_END
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
#endif /* _COMMS_H_ */
|