frontlib/ipcconn.h
changeset 7158 a0573014ff4f
equal deleted inserted replaced
7155:273ad375d64e 7158:a0573014ff4f
       
     1 /*
       
     2  * Low-level protocol support for the IPC connection to the engine.
       
     3  */
       
     4 
       
     5 #ifndef IPCCONN_H_
       
     6 #define IPCCONN_H_
       
     7 
       
     8 #include <stddef.h>
       
     9 
       
    10 typedef enum {IPC_NOT_CONNECTED, IPC_LISTENING, IPC_CONNECTED} IpcConnState;
       
    11 
       
    12 /**
       
    13  * Called by flib_init(). Initialize everything related to ipc.
       
    14  */
       
    15 void flib_ipcconn_init();
       
    16 
       
    17 /**
       
    18  * Called by flib_quit(). Free resources and shut down.
       
    19  */
       
    20 void flib_ipcconn_quit();
       
    21 
       
    22 /**
       
    23  * Start listening for a connection from the engine. The system has to be in state
       
    24  * IPC_NOT_CONNECTED when calling this function.
       
    25  *
       
    26  * Returns the port we started listening on, or a negative value if there is an error.
       
    27  *
       
    28  * We stop listening once a connection has been established, so if you want to start
       
    29  * the engine again and talk to it you need to call this function again after the old
       
    30  * connection is closed.
       
    31  */
       
    32 int flib_ipcconn_listen();
       
    33 
       
    34 /**
       
    35  * Close the current IPC connection and/or stop listening for an incoming one.
       
    36  * This also discards all unread messages.
       
    37  */
       
    38 void flib_ipcconn_close();
       
    39 
       
    40 /**
       
    41  * Determine the current connection state
       
    42  */
       
    43 IpcConnState flib_ipcconn_state();
       
    44 
       
    45 /**
       
    46  * Receive a single message (up to 255 bytes) and copy it into the data buffer.
       
    47  * Returns the length of the received message, a negative value if no message could
       
    48  * be read.
       
    49  */
       
    50 int flib_ipcconn_recv_message(void *data);
       
    51 
       
    52 /**
       
    53  * Write a single message (up to 255 bytes) to the engine. This call blocks until the
       
    54  * message is completely written or the connection is closed or an error occurs.
       
    55  *
       
    56  * Calling this function in a state other than IPC_CONNECTED will fail immediately.
       
    57  * Returns a negative value on failure.
       
    58  */
       
    59 int flib_ipcconn_send_message(void *data, size_t len);
       
    60 
       
    61 /**
       
    62  * Call regularly to allow background work to proceed
       
    63  */
       
    64 void flib_ipcconn_tick();
       
    65 
       
    66 #endif /* IPCCONN_H_ */
       
    67