lttng-ctl: Implement the action interface
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 27 Feb 2017 18:38:58 +0000 (13:38 -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/action/action-internal.h [new file with mode: 0644]
src/lib/lttng-ctl/Makefile.am
src/lib/lttng-ctl/action.c [new file with mode: 0644]

index 0536dcdf00e328a1f83433df310e7a37c888c622..90ee41882dba38e6bf98b18d6b26a8e55387c9e5 100644 (file)
@@ -83,4 +83,5 @@ noinst_HEADERS = \
        lttng/snapshot-internal.h \
        lttng/health-internal.h \
        lttng/save-internal.h \
-       lttng/load-internal.h
+       lttng/load-internal.h \
+       lttng/action/action-internal.h
diff --git a/include/lttng/action/action-internal.h b/include/lttng/action/action-internal.h
new file mode 100644 (file)
index 0000000..9a06bc8
--- /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_ACTION_INTERNAL_H
+#define LTTNG_ACTION_INTERNAL_H
+
+#include <lttng/action/action.h>
+#include <common/macros.h>
+#include <stdbool.h>
+
+typedef bool (*action_validate_cb)(struct lttng_action *action);
+typedef void (*action_destroy_cb)(struct lttng_action *action);
+
+struct lttng_action {
+       enum lttng_action_type type;
+       action_validate_cb validate;
+       action_destroy_cb destroy;
+};
+
+LTTNG_HIDDEN
+bool lttng_action_validate(struct lttng_action *action);
+
+#endif /* LTTNG_ACTION_INTERNAL_H */
index 6b6a6eed127525f17a2a94454ea18e8fbf3dacc1..1b5895a3debb8a87f8df075068b0d8ffb5f2cee8 100644 (file)
@@ -5,7 +5,8 @@ SUBDIRS = filter
 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
+               lttng-ctl-health.c save.c load.c deprecated-symbols.c \
+               action.c
 
 liblttng_ctl_la_LDFLAGS = \
                $(LT_NO_UNDEFINED)
diff --git a/src/lib/lttng-ctl/action.c b/src/lib/lttng-ctl/action.c
new file mode 100644 (file)
index 0000000..cfad633
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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/action/action-internal.h>
+#include <assert.h>
+
+enum lttng_action_type lttng_action_get_type(struct lttng_action *action)
+{
+       return action ? action->type : LTTNG_ACTION_TYPE_UNKNOWN;
+}
+
+void lttng_action_destroy(struct lttng_action *action)
+{
+       if (!action) {
+               return;
+       }
+
+       assert(action->destroy);
+       action->destroy(action);
+}
+
+LTTNG_HIDDEN
+bool lttng_action_validate(struct lttng_action *action)
+{
+       bool valid;
+
+       if (!action) {
+               valid = false;
+               goto end;
+       }
+
+       if (!action->validate) {
+               /* Sub-class guarantees that it can never be invalid. */
+               valid = true;
+               goto end;
+       }
+
+       valid = action->validate(action);
+end:
+       return valid;
+}
This page took 0.029615 seconds and 5 git commands to generate.