From a87af0fdea0d8ca540032510cca548d222fa295a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 27 Feb 2017 13:38:58 -0500 Subject: [PATCH] lttng-ctl: Implement the action interface MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- include/Makefile.am | 3 +- include/lttng/action/action-internal.h | 37 +++++++++++++++++ src/lib/lttng-ctl/Makefile.am | 3 +- src/lib/lttng-ctl/action.c | 55 ++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 include/lttng/action/action-internal.h create mode 100644 src/lib/lttng-ctl/action.c diff --git a/include/Makefile.am b/include/Makefile.am index 0536dcdf0..90ee41882 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 index 000000000..9a06bc8d8 --- /dev/null +++ b/include/lttng/action/action-internal.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2017 - Jérémie Galarneau + * + * 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 +#include +#include + +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 */ diff --git a/src/lib/lttng-ctl/Makefile.am b/src/lib/lttng-ctl/Makefile.am index 6b6a6eed1..1b5895a3d 100644 --- a/src/lib/lttng-ctl/Makefile.am +++ b/src/lib/lttng-ctl/Makefile.am @@ -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 index 000000000..cfad63372 --- /dev/null +++ b/src/lib/lttng-ctl/action.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2017 - Jérémie Galarneau + * + * 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 +#include + +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; +} -- 2.34.1