src/lib/msg_proto.h
branchnew-lib-errors
changeset 219 cefec18b8268
parent 196 873796250c60
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/msg_proto.h	Thu May 28 01:17:36 2009 +0300
@@ -0,0 +1,54 @@
+#ifndef LIBQMSK_MSG_PROTO_H
+#define LIBQMSK_MSG_PROTO_H
+
+/**
+ * @param
+ *
+ * Support for simple protocols that send/recieve length-prefixed messages over a transport stream.
+ *
+ * This implementation is mostly geared towards handling a reasonable number of reasonably sized messages in a
+ * reasonable way. Hence, 
+ */
+#include "transport.h"
+
+/** 
+ * Protocol state struct
+ */
+struct msg_proto;
+
+/**
+ * User callbacks
+ */
+struct msg_proto_callbacks {
+    /**
+     * Message recieved.
+     *
+     * XXX: currently you must not call msg_proto_destroy from within this callback
+     */
+    void (*on_msg) (struct msg_proto *proto, void *data, size_t len, void *arg);
+
+    /**
+     * Transport/protocol error occured in event handling.
+     */
+    void (*on_error) (struct msg_proto *proto, const error_t *err, void *arg);
+};
+
+/**
+ * Create a msg_proto state using the given transport.
+ *
+ * This will install our callback handlers on the given transport.
+ */
+err_t msg_proto_create (struct msg_proto **proto_ptr, transport_t *transport, const struct msg_proto_callbacks *cb_tbl, void *cb_arg, error_t *err);
+
+/**
+ * Send a message to the other endpoint
+ */
+err_t msg_proto_send (struct msg_proto *proto, const void *data, size_t len, error_t *err);
+
+/**
+ * Destroy the protocol state and transport
+ */
+void msg_proto_destroy (struct msg_proto *proto);
+
+
+#endif