tevent: add private_print function feature to tevent_req
authorStefan Metzmacher <metze@samba.org>
Wed, 25 Feb 2009 13:29:31 +0000 (14:29 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 25 Feb 2009 13:30:55 +0000 (14:30 +0100)
metze

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

index b3611228aa219b8f2c5a5d0f64965c21f1191d54..185a8fa193e3f2d47dea546f43c01a507a271c94 100644 (file)
@@ -211,6 +211,15 @@ struct tevent_req {
         */
        void *private_state;
 
+       /**
+        * @brief A function to overwrite the default print function
+        *
+        * The implementation doing the work may want to imeplement a
+        * custom function to print the text representation of the async
+        * request.
+        */
+       char *(*private_print)(struct tevent_req *req, TALLOC_CTX *mem_ctx);
+
        /**
         * @brief Internal state of the request
         *
@@ -267,6 +276,8 @@ struct tevent_req {
        } internal;
 };
 
+char *tevent_req_default_print(struct tevent_req *req, TALLOC_CTX *mem_ctx);
+
 char *tevent_req_print(TALLOC_CTX *mem_ctx, struct tevent_req *req);
 
 struct tevent_req *_tevent_req_create(TALLOC_CTX *mem_ctx,
index c17587b16c1d38223f2e09ce231c8c8251e4fb66..e243c7de5de3d4787bf4a3a962be9022dfe5c42c 100644 (file)
 #include "tevent_util.h"
 
 /**
- * @brief Print an tevent_req structure in debug messages
- * @param[in] mem_ctx  The memory context for the result
+ * @brief The default print function for creating debug messages
  * @param[in] req      The request to be printed
+ * @param[in] mem_ctx  The memory context for the result
  * @retval             Text representation of req
  *
+ * The function should not be used by users of the asynx API,
+ * but custom print function can use it and append custom text
+ * to the string.
  */
 
-char *tevent_req_print(TALLOC_CTX *mem_ctx, struct tevent_req *req)
+char *tevent_req_default_print(struct tevent_req *req, TALLOC_CTX *mem_ctx)
 {
        return talloc_asprintf(mem_ctx,
                               "tevent_req[%p/%s]: state[%d] error[%lld (0x%llX)] "
@@ -50,6 +53,24 @@ char *tevent_req_print(TALLOC_CTX *mem_ctx, struct tevent_req *req)
                               );
 }
 
+/**
+ * @brief Print an tevent_req structure in debug messages
+ * @param[in] mem_ctx  The memory context for the result
+ * @param[in] req      The request to be printed
+ * @retval             Text representation of req
+ *
+ * This function should be used by callers of the async API
+ */
+
+char *tevent_req_print(TALLOC_CTX *mem_ctx, struct tevent_req *req)
+{
+       if (!req->private_print) {
+               return tevent_req_default_print(req, mem_ctx);
+       }
+
+       return req->private_print(req, mem_ctx);
+}
+
 /**
  * @brief Create an async request
  * @param[in] mem_ctx  The memory context for the result