index 7726e75fa92c7d6df025bb5139a92b8d155b9231..955180f0872daad53cd3ac4714bd278d2bcd52f0 100644 (file)
extern "C" {
#endif
-/* a generic connection object */
-typedef struct {
- /* file-descriptor of the open connection */
- int fd;
+/* status codes returned to a client */
+typedef enum {
+ CONNECTION_OK = 0,
+ CONNECTION_ERROR
+} sdb_conn_status_t;
- /* read buffer */
- sdb_strbuf_t *buf;
+/* accepted commands / state of the connection */
+typedef enum {
+ /* connection handling */
+ CONNECTION_IDLE = 0,
+ CONNECTION_PING,
+ CONNECTION_STARTUP,
- /* connection / protocol state information */
- uint32_t cmd;
- uint32_t cmd_len;
-} sdb_conn_t;
+ /* querying */
+ CONNECTION_LIST,
+} sdb_conn_state_t;
+
+typedef struct sdb_conn sdb_conn_t;
+
+/*
+ * sdb_connection_accpet:
+ * Accept a new connection on the specified file-descriptor 'fd' and return a
+ * newly allocated connection object.
+ *
+ * Returns:
+ * - 0 on success
+ * - a negative value else
+ */
+sdb_conn_t *
+sdb_connection_accept(int fd);
+
+/*
+ * sdb_connection_close:
+ * Close a open connection and deallocate any memory. The connection object is
+ * no longer valid after calling this function.
+ */
+void
+sdb_connection_close(sdb_conn_t *conn);
/*
* sdb_connection_read:
ssize_t
sdb_connection_read(sdb_conn_t *conn);
+/*
+ * sdb_connection_send:
+ * Send to an open connection.
+ *
+ * Returns:
+ * - the number of bytes written
+ * - a negative value on error
+ */
+ssize_t
+sdb_connection_send(sdb_conn_t *conn, uint32_t code,
+ uint32_t msg_len, const char *msg);
+
+/*
+ * sdb_connection_ping:
+ * Send back a backend status indicator to the connected client.
+ *
+ * Returns:
+ * - 0 on success
+ * - a negative value else
+ */
+int
+sdb_connection_ping(sdb_conn_t *conn);
+
+/*
+ * session handling
+ */
+
+/*
+ * sdb_fe_session_start:
+ * Start a new user session on the specified connection.
+ *
+ * Returns:
+ * - 0 on success
+ * - a negative value else
+ */
+int
+sdb_fe_session_start(sdb_conn_t *conn);
+
+/*
+ * store access
+ */
+
+/*
+ * sdb_fe_list:
+ * Send a complete listing of the store, serialized as JSON, to the client.
+ *
+ * Returns:
+ * - 0 on success
+ * - a negative value else
+ */
+int
+sdb_fe_list(sdb_conn_t *conn);
+
#ifdef __cplusplus
} /* extern "C" */
#endif