All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Jackson <Ian.Jackson@eu.citrix.com>
To: Ian Campbell <ian.campbell@citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Xen-devel <xen-devel@lists.xen.org>,
	Wei Liu <wei.liu2@citrix.com>
Subject: Re: [PATCH] tools/toollog: Drop XTL_NEW_LOGGER()
Date: Tue, 19 Jan 2016 17:36:48 +0000	[thread overview]
Message-ID: <22174.29744.755487.990490@mariner.uk.xensource.com> (raw)
In-Reply-To: <22174.28455.949231.257126@mariner.uk.xensource.com>

Ian Jackson writes ("Re: [PATCH] tools/toollog: Drop XTL_NEW_LOGGER()"):
> Ian Campbell writes ("Re: [PATCH] tools/toollog: Drop XTL_NEW_LOGGER()"):
> > The underlying issue with all of these is the _undocumented_ nature of the
> > assumptions, which is certainly a bug, however those assumptions are not in
> > themselves "unreasonable" as was claimed.
> 
> Maybe I should submit a counter-patch providing documentation.

I think this macro is useful because if you wanted to write (say)
xtl_logger_syslog, you would want to use it to help you with some
boilerplate.

Ian.

>From f749eea51c35c787b8ca7514a21ac145e2946ff8 Mon Sep 17 00:00:00 2001
From: Ian Jackson <ian.jackson@eu.citrix.com>
Date: Tue, 19 Jan 2016 17:29:30 +0000
Subject: [PATCH] xentoollog: Document XTL_NEW_LOGGER convenience macro

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
 tools/libs/toollog/include/xentoollog.h |   53 +++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/tools/libs/toollog/include/xentoollog.h b/tools/libs/toollog/include/xentoollog.h
index 853e9c7..95f7482 100644
--- a/tools/libs/toollog/include/xentoollog.h
+++ b/tools/libs/toollog/include/xentoollog.h
@@ -113,6 +113,59 @@ void xtl_progress(struct xentoollog_logger *logger,
 const char *xtl_level_to_string(xentoollog_level); /* never fails */
 
 
+/*
+ * To use this macro:
+ *
+ *   Define your own logger struct, containing the vtable.
+ *
+ *       typedef struct {
+ *            xentoollog_logger vtable; // must come first
+ *            [ state your logger needs ]
+ *       } xentoolog_logger_mine;
+ *
+ *   Write the logging functions:
+ *
+ *       static void mine_vmessage([ see above ]);
+ *       static void mine_progress([ see above ]);
+ *       static void mine_destroy(struct xentoollog_logger *logger);
+ *
+ *   Write a constructor:
+ *
+ *       mine_xentoollog_logger *tl_createlogger_mine([whatever]) {
+ *           mine_xentoolllog_logger newlogger;
+ *
+ *           [ fill in fields of newlogger ]
+ *
+ *           return XTL_NEW_LOGGER(mine, newlogger);
+ *       }
+ *
+ *   If newlogger contains resources that might need to be released,
+ *   the constructor must check the return value from XTL_NEW_LOGGER:
+ *   if it is NULL, the constructor must release the resources.
+ *
+ *
+ * Formally:
+ *
+ *   xentoollog_logger_MINE*
+ *   XTL_NEW_LOGGER(MINE, xentoollog_logger_MINE contents);
+ *
+ *     Fills in contents.vtable.  Allocates a new struct.  Copies
+ *     contents into it.  Finally, returns a pointer to the copy.
+ *
+ *     If allocation fails, uses contents to report this failure, and
+ *     returns NULL.
+ *
+ *   Expects that xentoollog_logger_MINE is a struct whose
+ *   first member is
+ *            xentoollog_logger vtable;
+ *
+ *   Expects that
+ *      MINE_vmessage
+ *      MINE_progress
+ *      MINE_destroy
+ *   are in scope, with types compatible with the vtable members.
+ *
+ */
 #define XTL_NEW_LOGGER(LOGGER,buffer) ({                                \
     xentoollog_logger_##LOGGER *new_consumer;                           \
                                                                         \
-- 
1.7.10.4

  parent reply	other threads:[~2016-01-19 17:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14 20:13 [PATCH] tools/toollog: Drop XTL_NEW_LOGGER() Andrew Cooper
2016-01-19  9:46 ` Wei Liu
2016-01-19 16:24 ` Ian Campbell
2016-01-19 16:40   ` Andrew Cooper
2016-01-19 17:04     ` Ian Campbell
2016-01-19 17:15       ` Ian Jackson
2016-01-19 17:18         ` Ian Jackson
2016-01-19 17:36         ` Ian Jackson [this message]
2016-01-19 17:45           ` Andrew Cooper
2016-01-19 17:58             ` Ian Jackson
2016-01-20 17:21               ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22174.29744.755487.990490@mariner.uk.xensource.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.