linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tzvetomir Stoyanov <tstoyanov@vmware.com>
To: "rostedt@goodmis.org" <rostedt@goodmis.org>
Cc: "linux-trace-devel@vger.kernel.org" <linux-trace-devel@vger.kernel.org>
Subject: [PATCH 2/3] tools/lib/traceevent: Changed return logic of tep_register_event_handler() API
Date: Fri, 23 Nov 2018 13:40:01 +0000	[thread overview]
Message-ID: <20181123133946.16239-3-tstoyanov@vmware.com> (raw)
In-Reply-To: <20181123133946.16239-1-tstoyanov@vmware.com>

In order to make libtraceevent into a proper library, its API
should be straightforward. The tep_register_event_handler()
functions returns -1 in case it successfully registers the
new event handler. Such return code is used by the other library
APIs in case of an error. To unify the return logic of
tep_register_event_handler() with the other APIs, this patch
introduces enum tep_reg_handler, which is used by this function
as return value, to handle all possible successful return cases.

Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
---
 .../libtraceevent-reg_event_handler.txt              | 12 +++++++++---
 tools/lib/traceevent/event-parse.c                   | 10 ++++++++--
 tools/lib/traceevent/event-parse.h                   |  5 +++++
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/tools/lib/traceevent/Documentation/libtraceevent-reg_event_handler.txt b/tools/lib/traceevent/Documentation/libtraceevent-reg_event_handler.txt
index 1a9269039f6c..ee9aa3a4151b 100644
--- a/tools/lib/traceevent/Documentation/libtraceevent-reg_event_handler.txt
+++ b/tools/lib/traceevent/Documentation/libtraceevent-reg_event_handler.txt
@@ -12,6 +12,11 @@ SYNOPSIS
 --
 *#include <event-parse.h>*
 
+enum *tep_reg_handler* {
+	_TEP_REGISTER_SUCCESS_,
+	_TEP_REGISTER_SUCCESS_OVERWRITE_,
+};
+
 int *tep_register_event_handler*(struct tep_handle pass:[*]_tep_, int _id_, const char pass:[*]_sys_name_, const char pass:[*]_event_name_, tep_event_handler_func _func_, void pass:[*]_context_);
 int *tep_unregister_event_handler*(struct tep_handle pass:[*]tep, int id, const char pass:[*]sys_name, const char pass:[*]event_name, tep_event_handler_func func, void pass:[*]_context_);
 
@@ -48,9 +53,10 @@ _context_ is custom context, set when the custom event handler is registered.
  
 RETURN VALUE
 ------------
-The _tep_register_event_handler()_ function returns 0 in case of success. 
-If there is not  enough memory to complete the registration, 
-TEP_ERRNO__MEM_ALLOC_FAILED is returned. 
+The _tep_register_event_handler()_ function returns _TEP_REGISTER_SUCCESS_
+if the new handler is registered successfully or _TEP_REGISTER_SUCCESS_OVERWRITE_ if
+an existing handler is overwritten. If there is not  enough memory to complete 
+the registration, TEP_ERRNO__MEM_ALLOC_FAILED is returned. 
 
 The _tep_unregister_event_handler()_ function returns 0 if _func_ was removed 
 successful or, -1 if the event was not found.
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 2970358b4c10..a5048c1b9bec 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -6624,6 +6624,12 @@ static struct tep_event *search_event(struct tep_handle *pevent, int id,
  *
  * If @id is >= 0, then it is used to find the event.
  * else @sys_name and @event_name are used.
+ *
+ * Returns:
+ *  TEP_REGISTER_SUCCESS_OVERWRITE if an existing handler is overwritten
+ *  TEP_REGISTER_SUCCESS if a new handler is registered successfully
+ *  negative TEP_ERRNO_... in case of an error
+ *
  */
 int tep_register_event_handler(struct tep_handle *pevent, int id,
 			       const char *sys_name, const char *event_name,
@@ -6641,7 +6647,7 @@ int tep_register_event_handler(struct tep_handle *pevent, int id,
 
 	event->handler = func;
 	event->context = context;
-	return 0;
+	return TEP_REGISTER_SUCCESS_OVERWRITE;
 
  not_found:
 	/* Save for later use. */
@@ -6671,7 +6677,7 @@ int tep_register_event_handler(struct tep_handle *pevent, int id,
 	pevent->handlers = handle;
 	handle->context = context;
 
-	return -1;
+	return TEP_REGISTER_SUCCESS;
 }
 
 static int handle_matches(struct event_handler *handler, int id,
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index c6bdebf0a0ed..e5bdce43b3b4 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -484,6 +484,11 @@ int tep_print_func_field(struct trace_seq *s, const char *fmt,
 			 struct tep_event *event, const char *name,
 			 struct tep_record *record, int err);
 
+enum tep_reg_handler {
+	TEP_REGISTER_SUCCESS = 0,
+	TEP_REGISTER_SUCCESS_OVERWRITE,
+};
+
 int tep_register_event_handler(struct tep_handle *pevent, int id,
 			       const char *sys_name, const char *event_name,
 			       tep_event_handler_func func, void *context);
-- 
2.19.1

  parent reply	other threads:[~2018-11-24  0:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-23 13:39 [PATCH 0/3] libtraceevent: Various API fixes Tzvetomir Stoyanov
2018-11-23 13:40 ` [PATCH 1/3] tools/lib/traceevent: Remove tep_data_event_from_type() API Tzvetomir Stoyanov
2018-11-23 13:40 ` Tzvetomir Stoyanov [this message]
2018-11-23 13:40 ` [PATCH 3/3] tools/lib/traceevent: Changed return logic of trace_seq_printf() and trace_seq_vprintf() APIs Tzvetomir Stoyanov
2018-11-26 14:34 ` [PATCH 0/3] libtraceevent: Various API fixes Steven Rostedt

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=20181123133946.16239-3-tstoyanov@vmware.com \
    --to=tstoyanov@vmware.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).