src/transport_internal.h
branchnew-transport
changeset 154 f4472119de3b
child 155 c59d3eaff0fb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/transport_internal.h	Tue Apr 28 17:52:48 2009 +0300
@@ -0,0 +1,60 @@
+#ifndef TRANSPORT_INTERNAL_H
+#define TRANSPORT_INTERNAL_H
+
+/**
+ * @file
+ *
+ * The internal interface for transport implementations.
+ */ 
+#include "transport.h"
+
+/**
+ * Method table for implementation stuff
+ */
+struct transport_methods {
+    /** For transport_read() */
+    err_t (*read) (transport_t *transport, void *buf, size_t *len, error_t *err);
+
+    /** For transport_write() */
+    err_t (*write) (transport_t *transport, const void *buf, size_t *len, error_t *err);
+
+    /** Release the transport's state, but not the transport itself */
+    void (*destroy) (transport_t *transport);
+};
+
+/**
+ * The definition of a transport type
+ */
+struct transport_type {
+    /** Method table */
+    struct transport_methods methods;
+};
+
+/**
+ * The base transport type
+ */
+struct transport {
+    /** The type info, or NULL if not yet bound */
+    const struct transport_type *type;
+
+    /** User info */
+    struct transport_info info;
+};
+
+/**
+ * Bind the given transport to the given type with the given user info.
+ *
+ * It is a bug to call this with a transport that is already bound.
+ */
+void transport_bind (transport_t *transport, const struct transport_type *type, const struct transport_info *info);
+
+/**
+ * Check the type of the transport, and return the transport as a void* suitable for casting to the appropriate struct
+ * for the type.
+ *
+ * It is a bug to call this with a transport of a different type.
+ */
+void* transport_check (transport_t *transport, const struct transport_type *type);
+
+
+#endif /* TRANSPORT_INTERNAL_H */