aboutsummaryrefslogtreecommitdiff
path: root/callback.h
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2012-09-25 14:46:44 +0200
committerPetr Machata <pmachata@redhat.com>2012-09-25 14:46:44 +0200
commita24021c5abfa8c2482e3224f14ac191cd0826a8f (patch)
tree6f40cb1d91c9870ee6fe00b7b7fb8a46b09fbadd /callback.h
parent9eb1c0695cf95966a4b27355527691a2b7b7fe92 (diff)
downloadltrace-a24021c5abfa8c2482e3224f14ac191cd0826a8f.tar.gz
Extract enum callback_status to a separate module
Document the interface, refer to this documentation at declarations of each_* functions.
Diffstat (limited to 'callback.h')
-rw-r--r--callback.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/callback.h b/callback.h
new file mode 100644
index 0000000..31e5c8f
--- /dev/null
+++ b/callback.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _CALLBACK_H_
+#define _CALLBACK_H_
+
+/* Notes on the iteration interface used across ltrace. Typically the
+ * iteration function looks something like this:
+ *
+ * foo *each_foo(foo *start_after,
+ * enum callback_status (*cb)(foo *f, void *data),
+ * void *data);
+ *
+ * The iteration starts after the element designated by START_AFTER,
+ * or at the first element if START_AFTER is NULL. CB is then called
+ * for each element of the collection. DATA is passed verbatim to CB.
+ * If CB returns CBS_STOP, the iteration stops and the current element
+ * is returned. That element can then be passed as START_AFTER to
+ * restart the iteration. NULL is returned when iteration ends.
+ *
+ * CBS_FAIL is not currently handled, and essentially means the same
+ * thing as CBS_STOP. There's no provision for returning error
+ * states. Errors need to be signaled to the caller via DATA,
+ * together with any other data that the callback needs.
+ */
+enum callback_status {
+ CBS_STOP, /* The iteration should stop. */
+ CBS_CONT, /* The iteration should continue. */
+ CBS_FAIL, /* There was an error. The iteration should stop
+ * and return error. */
+};
+
+#endif /* _CALLBACK_H_ */