project_files/frontlib/ipc/ipcbase.h
changeset 7271 5608ac657362
parent 7234 613998625a3c
child 7314 6171f0bad318
equal deleted inserted replaced
7269:5b0aeef8ba2a 7271:5608ac657362
    11 
    11 
    12 #define IPCBASE_MAPMSG_BYTES 4097
    12 #define IPCBASE_MAPMSG_BYTES 4097
    13 
    13 
    14 typedef enum {IPC_NOT_CONNECTED, IPC_LISTENING, IPC_CONNECTED} IpcState;
    14 typedef enum {IPC_NOT_CONNECTED, IPC_LISTENING, IPC_CONNECTED} IpcState;
    15 
    15 
    16 struct _flib_ipcbase;
       
    17 typedef struct _flib_ipcbase flib_ipcbase;
    16 typedef struct _flib_ipcbase flib_ipcbase;
    18 
    17 
    19 /**
    18 /**
    20  * Start an engine connection by listening on a random port. The selected port can
    19  * Start an engine connection by listening on a random port. The selected port can
    21  * be queried with flib_ipcbase_port and has to be passed to the engine.
    20  * be queried with flib_ipcbase_port and has to be passed to the engine.
    25  * We stop accepting new connections once a connection has been established, so you
    24  * We stop accepting new connections once a connection has been established, so you
    26  * need to create a new ipcbase in order to start a new connection.
    25  * need to create a new ipcbase in order to start a new connection.
    27  */
    26  */
    28 flib_ipcbase *flib_ipcbase_create();
    27 flib_ipcbase *flib_ipcbase_create();
    29 
    28 
       
    29 /**
       
    30  * Return the listening port
       
    31  */
    30 uint16_t flib_ipcbase_port(flib_ipcbase *ipc);
    32 uint16_t flib_ipcbase_port(flib_ipcbase *ipc);
    31 
    33 
    32 /**
    34 /**
    33  * Free resources and close sockets.
    35  * Free resources and close sockets. NULL safe.
    34  */
    36  */
    35 void flib_ipcbase_destroy(flib_ipcbase *ipc);
    37 void flib_ipcbase_destroy(flib_ipcbase *ipc);
    36 
    38 
    37 /**
    39 /**
    38  * Determine the current connection state
    40  * Determine the current connection state
    59  * twocolor image of the map (256x128), the last byte is the number of hogs that
    61  * twocolor image of the map (256x128), the last byte is the number of hogs that
    60  * fit on the map.
    62  * fit on the map.
    61  */
    63  */
    62 int flib_ipcbase_recv_map(flib_ipcbase *ipc, void *data);
    64 int flib_ipcbase_recv_map(flib_ipcbase *ipc, void *data);
    63 
    65 
       
    66 /**
       
    67  * Blocking send bytes over the socket. No message framing will be added.
       
    68  * Returns 0 on success.
       
    69  */
    64 int flib_ipcbase_send_raw(flib_ipcbase *ipc, const void *data, size_t len);
    70 int flib_ipcbase_send_raw(flib_ipcbase *ipc, const void *data, size_t len);
    65 
    71 
    66 /**
    72 /**
    67  * Write a single message (up to 255 bytes) to the engine. This call blocks until the
    73  * Write a single message (up to 255 bytes) to the engine. This call blocks until the
    68  * message is completely written or the connection is closed or an error occurs.
    74  * message is completely written or the connection is closed or an error occurs.
    69  *
    75  *
    70  * Calling this function in a state other than IPC_CONNECTED will fail immediately.
    76  * Calling this function in a state other than IPC_CONNECTED will fail immediately.
    71  * Returns a negative value on failure.
    77  * Returns 0 on success.
    72  */
    78  */
    73 int flib_ipcbase_send_message(flib_ipcbase *ipc, void *data, size_t len);
    79 int flib_ipcbase_send_message(flib_ipcbase *ipc, void *data, size_t len);
    74 
       
    75 /**
       
    76  * Convenience function for sending a 0-delimited string.
       
    77  */
       
    78 int flib_ipcbase_send_messagestr(flib_ipcbase *ipc, char *data);
       
    79 
    80 
    80 /**
    81 /**
    81  * Try to accept a connection. Only has an effect in state IPC_LISTENING.
    82  * Try to accept a connection. Only has an effect in state IPC_LISTENING.
    82  */
    83  */
    83 void flib_ipcbase_accept(flib_ipcbase *ipc);
    84 void flib_ipcbase_accept(flib_ipcbase *ipc);