From: Jérémie Galarneau Date: Mon, 27 Feb 2017 18:38:58 +0000 (-0500) Subject: lttng-ctl: Implement the action interface X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=a87af0fdea0d8ca540032510cca548d222fa295a lttng-ctl: Implement the action interface Signed-off-by: Jérémie Galarneau --- 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; +}