project_files/frontlib/ipcconn.h
changeset 7162 fe76d24a25d7
parent 7160 c42949cfdd92
child 7171 906e72caea7b
equal deleted inserted replaced
7160:c42949cfdd92 7162:fe76d24a25d7
     3  */
     3  */
     4 
     4 
     5 #ifndef IPCCONN_H_
     5 #ifndef IPCCONN_H_
     6 #define IPCCONN_H_
     6 #define IPCCONN_H_
     7 
     7 
       
     8 #include "buffer.h"
       
     9 
     8 #include <stddef.h>
    10 #include <stddef.h>
       
    11 #include <stdbool.h>
     9 
    12 
    10 typedef enum {IPC_NOT_CONNECTED, IPC_LISTENING, IPC_CONNECTED} IpcConnState;
    13 typedef enum {IPC_NOT_CONNECTED, IPC_LISTENING, IPC_CONNECTED} IpcConnState;
    11 
    14 
    12 /**
    15 /**
    13  * Called by flib_init(). Initialize everything related to ipc.
    16  * Called by flib_init(). Initialize everything related to ipc.
    19  */
    22  */
    20 void flib_ipcconn_quit();
    23 void flib_ipcconn_quit();
    21 
    24 
    22 /**
    25 /**
    23  * Start listening for a connection from the engine. The system has to be in state
    26  * Start listening for a connection from the engine. The system has to be in state
    24  * IPC_NOT_CONNECTED when calling this function.
    27  * IPC_NOT_CONNECTED when calling this function, and will be in state IPC_LISTENING
       
    28  * if the function returns successfully.
       
    29  *
       
    30  * The parameter "recordDemo" can be used to control whether demo recording should
       
    31  * be enabled for this connection.
    25  *
    32  *
    26  * Returns the port we started listening on, or a negative value if there is an error.
    33  * Returns the port we started listening on, or a negative value if there is an error.
    27  *
    34  *
    28  * We stop listening once a connection has been established, so if you want to start
    35  * 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
    36  * the engine again and talk to it you need to call this function again after the old
    30  * connection is closed.
    37  * connection is closed.
    31  */
    38  */
    32 int flib_ipcconn_listen();
    39 int flib_ipcconn_start(bool recordDemo);
    33 
    40 
    34 /**
    41 /**
    35  * Close the current IPC connection and/or stop listening for an incoming one.
    42  * Close the current IPC connection and/or stop listening for an incoming one.
    36  * This also discards all unread messages.
    43  * This also discards all unread messages.
    37  */
    44  */
    44 
    51 
    45 /**
    52 /**
    46  * Receive a single message (up to 255 bytes) and copy it into the data buffer.
    53  * 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
    54  * Returns the length of the received message, a negative value if no message could
    48  * be read.
    55  * be read.
       
    56  *
       
    57  * Note: When a connection is closed, you probably want to call this function until
       
    58  * no further message is returned, to ensure you see all messages that were sent
       
    59  * before the connection closed.
    49  */
    60  */
    50 int flib_ipcconn_recv_message(void *data);
    61 int flib_ipcconn_recv_message(void *data);
    51 
    62 
    52 /**
    63 /**
    53  * Write a single message (up to 255 bytes) to the engine. This call blocks until the
    64  * Write a single message (up to 255 bytes) to the engine. This call blocks until the
    57  * Returns a negative value on failure.
    68  * Returns a negative value on failure.
    58  */
    69  */
    59 int flib_ipcconn_send_message(void *data, size_t len);
    70 int flib_ipcconn_send_message(void *data, size_t len);
    60 
    71 
    61 /**
    72 /**
       
    73  * Convenience function for sending a 0-delimited string.
       
    74  */
       
    75 int flib_ipcconn_send_messagestr(char *data);
       
    76 
       
    77 /**
    62  * Call regularly to allow background work to proceed
    78  * Call regularly to allow background work to proceed
    63  */
    79  */
    64 void flib_ipcconn_tick();
    80 void flib_ipcconn_tick();
    65 
    81 
       
    82 /**
       
    83  * Get a demo record of the last connection. This should be called after
       
    84  * the connection is closed and all messages have been received.
       
    85  *
       
    86  * If demo recording was not enabled in the last call to flib_ipcconn_start(),
       
    87  * or if the recording failed for some reason, the buffer will be empty.
       
    88  *
       
    89  * The buffer is only valid until the next call to flib_ipcconn_start() or
       
    90  * a call to flib_ipcconn_getsave() (save and demo records have some minor
       
    91  * differences, and those are performed directly on the buffer before returning it).
       
    92  */
       
    93 flib_constbuffer flib_ipcconn_getdemo();
       
    94 
       
    95 /**
       
    96  * Get a savegame record of the last connection. This should be called after
       
    97  * the connection is closed and all messages have been received.
       
    98  *
       
    99  * If demo recording was not enabled in the last call to flib_ipcconn_start(),
       
   100  * or if the recording failed for some reason, the buffer will be empty.
       
   101  *
       
   102  * The buffer is only valid until the next call to flib_ipcconn_start() or
       
   103  * a call to flib_ipcconn_getdemo() (save and demo records have some minor
       
   104  * differences, and those are performed directly on the buffer before returning it).
       
   105  */
       
   106 flib_constbuffer flib_ipcconn_getsave();
       
   107 
    66 #endif /* IPCCONN_H_ */
   108 #endif /* IPCCONN_H_ */
    67 
   109