lttng-ctl: Implement the condition interface
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 27 Feb 2017 19:01:35 +0000 (14:01 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 1 Mar 2017 03:10:48 +0000 (22:10 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/Makefile.am
include/lttng/condition/condition-internal.h [new file with mode: 0644]
src/lib/lttng-ctl/Makefile.am
src/lib/lttng-ctl/condition.c [new file with mode: 0644]

index 82fd8d4667099937993fe53fdc73c372d036243f..a784c081b0fd93ee13a83ad57513747bc9bd89db 100644 (file)
@@ -85,4 +85,5 @@ noinst_HEADERS = \
        lttng/save-internal.h \
        lttng/load-internal.h \
        lttng/action/action-internal.h \
-       lttng/action/notify-internal.h
+       lttng/action/notify-internal.h \
+       lttng/condition/condition-internal.h
diff --git a/include/lttng/condition/condition-internal.h b/include/lttng/condition/condition-internal.h
new file mode 100644 (file)
index 0000000..a0a7c77
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License, version 2.1 only,
+ * as published by the Free Software Foundation.
+ *
+ * This library 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 Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef LTTNG_CONDITION_INTERNAL_H
+#define LTTNG_CONDITION_INTERNAL_H
+
+#include <lttng/condition/condition.h>
+#include <common/macros.h>
+#include <stdbool.h>
+
+typedef void (*condition_destroy_cb)(struct lttng_condition *condition);
+typedef bool (*condition_validate_cb)(struct lttng_condition *condition);
+
+struct lttng_condition {
+       enum lttng_condition_type type;
+       condition_validate_cb validate;
+       condition_destroy_cb destroy;
+};
+
+LTTNG_HIDDEN
+bool lttng_condition_validate(struct lttng_condition *condition);
+
+#endif /* LTTNG_CONDITION_INTERNAL_H */
index 91f37f418a08985af3535a205060f3ce13f4c804..a939d2c837fb6290f897240b8a303cd84619d7c5 100644 (file)
@@ -6,7 +6,7 @@ lib_LTLIBRARIES = liblttng-ctl.la
 
 liblttng_ctl_la_SOURCES = lttng-ctl.c snapshot.c lttng-ctl-helper.h \
                lttng-ctl-health.c save.c load.c deprecated-symbols.c \
-               action.c notify.c
+               action.c notify.c condition.c
 
 liblttng_ctl_la_LDFLAGS = \
                $(LT_NO_UNDEFINED)
diff --git a/src/lib/lttng-ctl/condition.c b/src/lib/lttng-ctl/condition.c
new file mode 100644 (file)
index 0000000..76f416d
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License, version 2.1 only,
+ * as published by the Free Software Foundation.
+ *
+ * This library 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 Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <lttng/condition/condition-internal.h>
+#include <common/macros.h>
+#include <stdbool.h>
+#include <assert.h>
+
+enum lttng_condition_type lttng_condition_get_type(
+               struct lttng_condition *condition)
+{
+       return condition ? condition->type : LTTNG_CONDITION_TYPE_UNKNOWN;
+}
+
+void lttng_condition_destroy(struct lttng_condition *condition)
+{
+       if (!condition) {
+               return;
+       }
+
+       assert(condition->destroy);
+       condition->destroy(condition);
+}
+
+LTTNG_HIDDEN
+bool lttng_condition_validate(struct lttng_condition *condition)
+{
+       bool valid;
+
+       if (!condition) {
+               valid = false;
+               goto end;
+       }
+
+       if (!condition->validate) {
+               /* Sub-class guarantees that it can never be invalid. */
+               valid = true;
+               goto end;
+       }
+
+       valid = condition->validate(condition);
+end:
+       return valid;
+}
This page took 0.031366 seconds and 5 git commands to generate.