tevent: expose tevent_context_init_ops
authorStefan Metzmacher <metze@samba.org>
Fri, 11 May 2012 13:19:55 +0000 (15:19 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 8 Jun 2012 17:00:05 +0000 (19:00 +0200)
This can be used to implement wrapper backends,
while passing a private pointer to the backens init function
via ev->additional_data.

metze

lib/tevent/tevent.c
lib/tevent/tevent.h

index 5247b5ec1c17218985c6ff2f290c79a1738e7f5a..61ffc7edaa5683e03f4d57c20eb6d5d58e077b30 100644 (file)
@@ -210,8 +210,9 @@ int tevent_common_context_destructor(struct tevent_context *ev)
 
   NOTE: use tevent_context_init() inside of samba!
 */
-static struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx,
-                                                     const struct tevent_ops *ops)
+struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx,
+                                              const struct tevent_ops *ops,
+                                              void *additional_data)
 {
        struct tevent_context *ev;
        int ret;
@@ -222,6 +223,7 @@ static struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx,
        talloc_set_destructor(ev, tevent_common_context_destructor);
 
        ev->ops = ops;
+       ev->additional_data = additional_data;
 
        ret = ev->ops->context_init(ev);
        if (ret != 0) {
@@ -253,7 +255,7 @@ struct tevent_context *tevent_context_init_byname(TALLOC_CTX *mem_ctx,
 
        for (e=tevent_backends;e;e=e->next) {
                if (strcmp(name, e->name) == 0) {
-                       return tevent_context_init_ops(mem_ctx, e->ops);
+                       return tevent_context_init_ops(mem_ctx, e->ops, NULL);
                }
        }
        return NULL;
index c8719fa4f194cdaeca7a448ce84fa5bf8f80ceb0..dc61912be7439f341b3e8d34eaee210964a3691d 100644 (file)
@@ -125,6 +125,20 @@ struct tevent_context *tevent_context_init(TALLOC_CTX *mem_ctx);
  */
 struct tevent_context *tevent_context_init_byname(TALLOC_CTX *mem_ctx, const char *name);
 
+/**
+ * @brief Create a custom event context
+ *
+ * @param[in]  mem_ctx  The memory context to use.
+ * @param[in]  ops      The function pointer table of the backend.
+ * @param[in]  additional_data  The additional/private data to this instance
+ *
+ * @return              An allocated tevent context, NULL on error.
+ *
+ */
+struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx,
+                                              const struct tevent_ops *ops,
+                                              void *additional_data);
+
 /**
  * @brief List available backends.
  *