src/lib/service.h
branchnew-lib-errors
changeset 219 cefec18b8268
parent 175 a816950a6548
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/service.h	Thu May 28 01:17:36 2009 +0300
@@ -0,0 +1,50 @@
+#ifndef LIBQMSK_SERVICE_H
+#define LIBQMSK_SERVICE_H
+
+/**
+ * @file
+ *
+ * Defines a simple interface for creating services, which listen for connections and create transport_t's.
+ */
+#include "transport.h"
+
+/**
+ * Opaque state struct.
+ */
+typedef struct service service_t;
+
+/**
+ * User callbacks for services.
+ */
+struct service_callbacks {
+    /**
+     * The service broke.
+     *
+     * This is only called for errors which occur when called directly from the event loop, and never for errors that
+     * occur inside of calls to service_*.
+     */
+    void (*on_error) (service_t *service, const error_t *err, void *arg);
+};
+
+/**
+ * User info required to build a service
+ */
+struct service_info {
+    /** Callback table */
+    const struct service_callbacks *cb_tbl;
+
+    /** Callback context arg */
+    void *cb_arg;
+
+    /** Settings for the service's client transports */
+    struct transport_info trans_info;
+};
+
+/**
+ * Destroy a service to stop accepting any connections and release all resources.
+ *
+ * Any connected client transports should stay intact (?)
+ */
+void service_destroy (service_t *service);
+
+#endif