project_files/frontlib/ipcconn.h
changeset 7162 fe76d24a25d7
parent 7160 c42949cfdd92
child 7171 906e72caea7b
--- a/project_files/frontlib/ipcconn.h	Thu May 31 18:54:40 2012 +0200
+++ b/project_files/frontlib/ipcconn.h	Sat Jun 02 14:26:52 2012 +0200
@@ -5,7 +5,10 @@
 #ifndef IPCCONN_H_
 #define IPCCONN_H_
 
+#include "buffer.h"
+
 #include <stddef.h>
+#include <stdbool.h>
 
 typedef enum {IPC_NOT_CONNECTED, IPC_LISTENING, IPC_CONNECTED} IpcConnState;
 
@@ -21,7 +24,11 @@
 
 /**
  * Start listening for a connection from the engine. The system has to be in state
- * IPC_NOT_CONNECTED when calling this function.
+ * IPC_NOT_CONNECTED when calling this function, and will be in state IPC_LISTENING
+ * if the function returns successfully.
+ *
+ * The parameter "recordDemo" can be used to control whether demo recording should
+ * be enabled for this connection.
  *
  * Returns the port we started listening on, or a negative value if there is an error.
  *
@@ -29,7 +36,7 @@
  * the engine again and talk to it you need to call this function again after the old
  * connection is closed.
  */
-int flib_ipcconn_listen();
+int flib_ipcconn_start(bool recordDemo);
 
 /**
  * Close the current IPC connection and/or stop listening for an incoming one.
@@ -46,6 +53,10 @@
  * Receive a single message (up to 255 bytes) and copy it into the data buffer.
  * Returns the length of the received message, a negative value if no message could
  * be read.
+ *
+ * Note: When a connection is closed, you probably want to call this function until
+ * no further message is returned, to ensure you see all messages that were sent
+ * before the connection closed.
  */
 int flib_ipcconn_recv_message(void *data);
 
@@ -59,9 +70,40 @@
 int flib_ipcconn_send_message(void *data, size_t len);
 
 /**
+ * Convenience function for sending a 0-delimited string.
+ */
+int flib_ipcconn_send_messagestr(char *data);
+
+/**
  * Call regularly to allow background work to proceed
  */
 void flib_ipcconn_tick();
 
+/**
+ * Get a demo record of the last connection. This should be called after
+ * the connection is closed and all messages have been received.
+ *
+ * If demo recording was not enabled in the last call to flib_ipcconn_start(),
+ * or if the recording failed for some reason, the buffer will be empty.
+ *
+ * The buffer is only valid until the next call to flib_ipcconn_start() or
+ * a call to flib_ipcconn_getsave() (save and demo records have some minor
+ * differences, and those are performed directly on the buffer before returning it).
+ */
+flib_constbuffer flib_ipcconn_getdemo();
+
+/**
+ * Get a savegame record of the last connection. This should be called after
+ * the connection is closed and all messages have been received.
+ *
+ * If demo recording was not enabled in the last call to flib_ipcconn_start(),
+ * or if the recording failed for some reason, the buffer will be empty.
+ *
+ * The buffer is only valid until the next call to flib_ipcconn_start() or
+ * a call to flib_ipcconn_getdemo() (save and demo records have some minor
+ * differences, and those are performed directly on the buffer before returning it).
+ */
+flib_constbuffer flib_ipcconn_getsave();
+
 #endif /* IPCCONN_H_ */