2005-07-06 00:05:37 +02:00
|
|
|
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
|
|
|
/*
|
2009-07-30 14:54:17 +02:00
|
|
|
* Copyright 2005-2009 by Eric House (xwords@eehouse.org). All rights
|
|
|
|
* reserved.
|
2005-07-06 00:05:37 +02: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 _STATES_H_
|
|
|
|
#define _STATES_H_
|
|
|
|
|
|
|
|
|
|
|
|
/* states */
|
2005-09-05 17:50:49 +02:00
|
|
|
typedef
|
|
|
|
enum {
|
2005-10-02 18:08:42 +02:00
|
|
|
XWS_NONE
|
2005-10-19 05:40:40 +02:00
|
|
|
,XWS_ANY /* wildcard */
|
2005-07-06 00:05:37 +02:00
|
|
|
|
2010-09-17 03:59:56 +02:00
|
|
|
/* ,XWS_CHKCOUNTS_INIT */ /* from initial state, check if all players
|
2005-10-02 17:39:38 +02:00
|
|
|
are here. Success should be an error,
|
|
|
|
actually: 1-device game. */
|
|
|
|
|
2010-09-14 22:54:52 +02:00
|
|
|
,XWS_WAITING_ACKS
|
2005-10-02 17:39:38 +02:00
|
|
|
|
2010-09-17 03:59:56 +02:00
|
|
|
/* ,XWS_CHK_ALLHERE */ /* Need to see if all expected devices/players
|
2005-10-02 17:39:38 +02:00
|
|
|
are on board. */
|
|
|
|
|
2010-09-17 03:59:56 +02:00
|
|
|
/* ,XWS_CHK_ALLHERE_2 */ /* same as above, but triggered by a reconnect
|
2005-10-02 17:39:38 +02:00
|
|
|
rather than a connect request */
|
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWS_INITED /* Relay's running and the object's been
|
2005-07-06 00:05:37 +02:00
|
|
|
created, but nobody's signed up yet. This
|
|
|
|
is a very short-lived state since an
|
|
|
|
incoming connection is why the object was
|
|
|
|
created. */
|
|
|
|
|
2010-09-10 10:30:40 +02:00
|
|
|
,XWS_WAITMORE /* At least one device has connected, but no
|
2005-07-06 00:05:37 +02:00
|
|
|
packets have yet arrived to be
|
|
|
|
forwarded. */
|
|
|
|
|
2009-07-29 06:25:21 +02:00
|
|
|
,XWS_ALLCONND /* All devices are connected and ready for the
|
2005-07-06 00:05:37 +02:00
|
|
|
relay to do its work. This is the state
|
|
|
|
we're in most of the time. */
|
|
|
|
|
2010-09-17 03:59:56 +02:00
|
|
|
/* ,XWS_MISSING */ /* We've been fully connected before but lost
|
2005-09-05 17:50:49 +02:00
|
|
|
somebody. Once [s]he's back we can be
|
|
|
|
fully connected again. */
|
|
|
|
|
2010-09-11 10:40:40 +02:00
|
|
|
,XWS_MSGONLY /* We have no connections but still messages to
|
|
|
|
send */
|
|
|
|
|
2010-09-17 03:59:56 +02:00
|
|
|
/* ,XWS_ROOMCHK */ /* do we have room for as many players as are
|
2009-12-14 05:10:23 +01:00
|
|
|
being provided */
|
2005-09-02 08:56:34 +02:00
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWS_DEAD /* About to kill the object */
|
2005-07-06 00:05:37 +02:00
|
|
|
} XW_RELAY_STATE;
|
|
|
|
|
|
|
|
|
|
|
|
/* events */
|
|
|
|
typedef enum {
|
2005-10-02 18:08:42 +02:00
|
|
|
XWE_NONE
|
2005-07-06 00:05:37 +02:00
|
|
|
|
2009-12-04 09:03:27 +01:00
|
|
|
,XWE_ALLHERE /* notify that all expected players are arrived */
|
2010-09-17 03:59:56 +02:00
|
|
|
/* ,XWE_SOMEMISSING */ /* notify that some expected players are still missing */
|
|
|
|
,XWE_ALLGONE
|
|
|
|
/* ,XWE_HAVE_ROOM */
|
|
|
|
/* ,XWE_TOO_MANY */
|
2005-10-02 17:39:38 +02:00
|
|
|
|
2010-09-10 10:30:40 +02:00
|
|
|
,XWE_DEVCONNECT /* A device is connecting using the cookie for */
|
|
|
|
/*,XWE_HOSTCONNECT*/ /* this object, as host or guest */
|
2005-07-06 00:05:37 +02:00
|
|
|
|
2009-12-04 09:03:27 +01:00
|
|
|
,XWE_RECONNECT /* A device is re-connecting using the connID for
|
|
|
|
this object */
|
2005-07-06 00:05:37 +02:00
|
|
|
|
2010-09-14 22:54:52 +02:00
|
|
|
,XWE_GOTONEACK
|
|
|
|
,XWE_GOTLASTACK
|
|
|
|
,XWE_ACKTIMEOUT
|
|
|
|
|
2009-12-04 09:03:27 +01:00
|
|
|
,XWE_DISCONN /* disconnect socket from this game/cref */
|
2005-09-05 17:50:49 +02:00
|
|
|
|
2010-11-11 15:40:50 +01:00
|
|
|
/* DEVGONE: a device tells us it will never connect again. It may be the
|
|
|
|
only device in the game or may not */
|
|
|
|
,XWE_DEVGONE
|
|
|
|
/* Joined a game where a device has already generated DEVGONE */
|
|
|
|
,XWE_GAMEDEAD
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWE_FORWARDMSG /* A message needs forwarding */
|
2005-07-06 00:05:37 +02:00
|
|
|
|
2007-11-19 00:38:56 +01:00
|
|
|
#ifdef RELAY_HEARTBEAT
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWE_HEARTRCVD /* A heartbeat message arrived */
|
|
|
|
,XWE_HEARTFAILED
|
2007-11-19 00:38:56 +01:00
|
|
|
#endif
|
|
|
|
,XWE_CONNTIMER /* timer for did we get all players hooked
|
|
|
|
up */
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWE_REMOVESOCKET /* Need to remove socket from this cref */
|
2005-09-02 08:56:34 +02:00
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWE_NOTIFYDISCON /* Send a discon */
|
2005-09-03 08:55:08 +02:00
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWE_NOMORESOCKETS /* last socket's been removed */
|
2005-09-02 08:56:34 +02:00
|
|
|
|
2009-11-08 22:35:39 +01:00
|
|
|
,XWE_NOMOREMSGS /* No messages are stored here for disconnected
|
|
|
|
hosts */
|
2005-10-30 06:07:58 +01:00
|
|
|
,XWE_SHUTDOWN /* shutdown this game */
|
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWE_ANY /* wildcard; matches all */
|
2005-07-06 00:05:37 +02:00
|
|
|
} XW_RELAY_EVENT;
|
|
|
|
|
|
|
|
|
|
|
|
/* actions */
|
|
|
|
typedef enum {
|
2005-10-02 18:08:42 +02:00
|
|
|
XWA_NONE
|
2005-07-06 00:05:37 +02:00
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWA_SEND_1ST_RERSP
|
2005-09-02 08:56:34 +02:00
|
|
|
|
2009-12-04 09:03:27 +01:00
|
|
|
,XWA_SEND_DUP_ROOM /* host comes in while game open */
|
|
|
|
,XWA_SEND_NO_ROOM /* guest comes in when no game open */
|
|
|
|
,XWA_SEND_TOO_MANY
|
2010-09-14 22:54:52 +02:00
|
|
|
|
|
|
|
// ,XWA_ADDDEVICE /* got ack, so device is in for sure */
|
|
|
|
,XWA_NOTEACK
|
|
|
|
,XWA_NOTEACKCHECK
|
|
|
|
,XWA_DROPDEVICE /* no ack; remove all traces of device */
|
|
|
|
|
2010-09-10 10:30:40 +02:00
|
|
|
,XWA_SEND_INITRSP /* response to first to connect */
|
|
|
|
,XWA_SEND_CONNRSP /* response to rest that connect */
|
2005-10-02 17:39:38 +02:00
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWA_SEND_RERSP
|
2010-09-14 22:54:52 +02:00
|
|
|
,XWA_GOTALLACKS
|
2005-07-06 00:05:37 +02:00
|
|
|
|
2009-12-14 05:10:23 +01:00
|
|
|
,XWA_CHECK_HAVE_ROOM /* check for number of players still sought */
|
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWA_SENDALLHERE /* Let all devices know we're in business */
|
2005-10-06 04:36:45 +02:00
|
|
|
,XWA_SNDALLHERE_2 /* Ditto, but for a reconnect */
|
2005-10-02 17:39:38 +02:00
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWA_FWD /* Forward a message */
|
2005-07-06 00:05:37 +02:00
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWA_NOTEHEART /* Record heartbeat received */
|
2005-07-06 00:05:37 +02:00
|
|
|
|
2009-11-08 22:35:39 +01:00
|
|
|
,XWA_NOTE_EMPTY /* No sockets left; check if can delete */
|
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWA_TIMERDISCONN /* disconnect all because of a timer */
|
2005-07-06 00:05:37 +02:00
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWA_DISCONNECT
|
2005-09-05 17:50:49 +02:00
|
|
|
|
2010-11-11 15:40:50 +01:00
|
|
|
,XWA_RMDEV /* remove the resigning */
|
|
|
|
,XWA_TELLGAMEDEAD /* tell the device */
|
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWA_NOTIFYDISCON
|
2005-09-03 08:55:08 +02:00
|
|
|
|
2009-12-14 05:10:23 +01:00
|
|
|
,XWA_REMOVESOCK_1 /* remove when not yet in allcond state */
|
|
|
|
,XWA_REMOVESOCK_2 /* remove after have reached allCond */
|
2005-09-02 08:56:34 +02:00
|
|
|
|
2005-10-02 18:08:42 +02:00
|
|
|
,XWA_HEARTDISCONN
|
2005-09-03 08:55:08 +02:00
|
|
|
|
2005-10-30 06:07:58 +01:00
|
|
|
,XWA_SHUTDOWN
|
|
|
|
|
2005-07-06 00:05:37 +02:00
|
|
|
} XW_RELAY_ACTION;
|
|
|
|
|
2007-11-10 06:41:49 +01:00
|
|
|
bool getFromTable( XW_RELAY_STATE curState, XW_RELAY_EVENT curEvent,
|
|
|
|
XW_RELAY_ACTION* takeAction, XW_RELAY_STATE* nextState );
|
2005-07-06 00:05:37 +02:00
|
|
|
|
|
|
|
|
2007-11-13 04:53:10 +01:00
|
|
|
const char* stateString( XW_RELAY_STATE state );
|
|
|
|
const char* eventString( XW_RELAY_EVENT evt );
|
|
|
|
const char* actString( XW_RELAY_ACTION act );
|
2005-07-06 00:05:37 +02:00
|
|
|
|
|
|
|
#endif
|