project_files/frontlib/ipcconn.h
changeset 7175 038e3415100a
parent 7173 7c2eb284f9f1
equal deleted inserted replaced
7173:7c2eb284f9f1 7175:038e3415100a
     7 
     7 
     8 #include "buffer.h"
     8 #include "buffer.h"
     9 
     9 
    10 #include <stddef.h>
    10 #include <stddef.h>
    11 #include <stdbool.h>
    11 #include <stdbool.h>
       
    12 
       
    13 #define IPCCONN_MAPMSG_BYTES 4097
    12 
    14 
    13 typedef enum {IPC_NOT_CONNECTED, IPC_LISTENING, IPC_CONNECTED} IpcConnState;
    15 typedef enum {IPC_NOT_CONNECTED, IPC_LISTENING, IPC_CONNECTED} IpcConnState;
    14 
    16 
    15 struct _flib_ipcconn;
    17 struct _flib_ipcconn;
    16 typedef struct _flib_ipcconn *flib_ipcconn;
    18 typedef struct _flib_ipcconn *flib_ipcconn;
    54  * no further message is returned, to ensure you see all messages that were sent
    56  * no further message is returned, to ensure you see all messages that were sent
    55  * before the connection closed.
    57  * before the connection closed.
    56  */
    58  */
    57 int flib_ipcconn_recv_message(flib_ipcconn ipc, void *data);
    59 int flib_ipcconn_recv_message(flib_ipcconn ipc, void *data);
    58 
    60 
       
    61 /**
       
    62  * Try to receive 4097 bytes. This is the size of the reply the engine sends
       
    63  * when successfully queried for map data. The first 4096 bytes are a bit-packed
       
    64  * twocolor image of the map (256x128), the last byte is the number of hogs that
       
    65  * fit on the map.
       
    66  */
       
    67 int flib_ipcconn_recv_map(flib_ipcconn ipc, void *data);
       
    68 
    59 int flib_ipcconn_send_raw(flib_ipcconn ipc, void *data, size_t len);
    69 int flib_ipcconn_send_raw(flib_ipcconn ipc, void *data, size_t len);
    60 
    70 
    61 /**
    71 /**
    62  * Write a single message (up to 255 bytes) to the engine. This call blocks until the
    72  * Write a single message (up to 255 bytes) to the engine. This call blocks until the
    63  * message is completely written or the connection is closed or an error occurs.
    73  * message is completely written or the connection is closed or an error occurs.
    73 int flib_ipcconn_send_messagestr(flib_ipcconn ipc, char *data);
    83 int flib_ipcconn_send_messagestr(flib_ipcconn ipc, char *data);
    74 
    84 
    75 /**
    85 /**
    76  * Call regularly to allow background work to proceed
    86  * Call regularly to allow background work to proceed
    77  */
    87  */
    78 void flib_ipcconn_tick(flib_ipcconn ipc);
    88 void flib_ipcconn_accept(flib_ipcconn ipc);
    79 
    89 
    80 /**
    90 /**
    81  * Get a demo record of the connection. This should be called after
    91  * Get a record of the connection. This should be called after
    82  * the connection is closed and all messages have been received.
    92  * the connection is closed and all messages have been received.
    83  *
    93  *
    84  * If demo recording was not enabled, or if the recording failed for some reason,
    94  * If demo recording was not enabled, or if the recording failed for some reason,
    85  * the buffer will be empty.
    95  * the buffer will be empty.
    86  *
    96  *
    87  * The buffer is only valid until a call to flib_ipcconn_getsave(), since save
    97  * If save=true is passed, the result will be a savegame, otherwise it will be a
    88  * and demo records have some minor differences, and those are performed directly
    98  * demo.
    89  * on the buffer before returning it).
    99  *
       
   100  * The buffer is only valid until flib_ipcconn_getsave is called again or the ipcconn
       
   101  * is destroyed.
    90  */
   102  */
    91 flib_constbuffer flib_ipcconn_getdemo(flib_ipcconn ipc);
   103 flib_constbuffer flib_ipcconn_getrecord(flib_ipcconn ipc, bool save);
    92 
       
    93 /**
       
    94  * Get a savegame record of the connection. This should be called after
       
    95  * the connection is closed and all messages have been received.
       
    96  *
       
    97  * If demo recording was not enabled, or if the recording failed for some reason,
       
    98  * the buffer will be empty.
       
    99  *
       
   100  * The buffer is only valid until a call to flib_ipcconn_getdemo(), since save
       
   101  * and demo records have some minor differences, and those are performed directly
       
   102  * on the buffer before returning it).
       
   103  */
       
   104 flib_constbuffer flib_ipcconn_getsave(flib_ipcconn ipc);
       
   105 
   104 
   106 #endif /* IPCCONN_H_ */
   105 #endif /* IPCCONN_H_ */
   107 
   106