From 4c5c8fc801789ccc2e9288296d018838f077869f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 27 Feb 2017 14:01:35 -0500 Subject: [PATCH] lttng-ctl: Implement the condition 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/condition/condition-internal.h | 37 +++++++++++++ src/lib/lttng-ctl/Makefile.am | 2 +- src/lib/lttng-ctl/condition.c | 58 ++++++++++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 include/lttng/condition/condition-internal.h create mode 100644 src/lib/lttng-ctl/condition.c diff --git a/include/Makefile.am b/include/Makefile.am index 82fd8d466..a784c081b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 index 000000000..a0a7c7793 --- /dev/null +++ b/include/lttng/condition/condition-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_CONDITION_INTERNAL_H +#define LTTNG_CONDITION_INTERNAL_H + +#include +#include +#include + +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 */ diff --git a/src/lib/lttng-ctl/Makefile.am b/src/lib/lttng-ctl/Makefile.am index 91f37f418..a939d2c83 100644 --- a/src/lib/lttng-ctl/Makefile.am +++ b/src/lib/lttng-ctl/Makefile.am @@ -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 index 000000000..76f416d42 --- /dev/null +++ b/src/lib/lttng-ctl/condition.c @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include + +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; +} -- 2.34.1