From 284ee38719c651791ee199c1b32008964d8ef455 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 27 Feb 2017 19:21:50 -0500 Subject: [PATCH] lttng-ctl: Implement the notification 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 | 4 +- .../notification/notification-internal.h | 34 ++++++++++ include/lttng/notification/notification.h | 10 ++- src/lib/lttng-ctl/Makefile.am | 3 +- src/lib/lttng-ctl/notification.c | 66 +++++++++++++++++++ 5 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 include/lttng/notification/notification-internal.h create mode 100644 src/lib/lttng-ctl/notification.c diff --git a/include/Makefile.am b/include/Makefile.am index ab104e4ab..8c12072a8 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -88,5 +88,5 @@ noinst_HEADERS = \ lttng/action/notify-internal.h \ lttng/condition/condition-internal.h \ lttng/condition/buffer-usage-internal.h \ - lttng/condition/evaluation-internal.h - + lttng/condition/evaluation-internal.h \ + lttng/notification/notification-internal.h diff --git a/include/lttng/notification/notification-internal.h b/include/lttng/notification/notification-internal.h new file mode 100644 index 000000000..d37db1ee5 --- /dev/null +++ b/include/lttng/notification/notification-internal.h @@ -0,0 +1,34 @@ +/* + * 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_NOTIFICATION_INTERNAL_H +#define LTTNG_NOTIFICATION_INTERNAL_H + +#include +#include + +struct lttng_notification { + struct lttng_condition *condition; + struct lttng_evaluation *evaluation; +}; + +LTTNG_HIDDEN +struct lttng_notification *lttng_notification_create( + struct lttng_condition *condition, + struct lttng_evaluation *evaluation); + +#endif /* LTTNG_NOTIFICATION_INTERNAL_H */ diff --git a/include/lttng/notification/notification.h b/include/lttng/notification/notification.h index 2f4cb1d59..100d0def4 100644 --- a/include/lttng/notification/notification.h +++ b/include/lttng/notification/notification.h @@ -24,12 +24,18 @@ extern "C" { struct lttng_condition; struct lttng_evaluation; +struct lttng_notification; +/* + * The notification retains ownership of both the condition and evaluation. + * Destroying the notification will also destroy the notification and evaluation + * objects. + */ extern struct lttng_condition *lttng_notification_get_condition( struct lttng_notification *notification); -extern struct lttng_evaluation * -lttng_notification_get_evaluation(struct lttng_notification *notification); +extern struct lttng_evaluation *lttng_notification_get_evaluation( + struct lttng_notification *notification); extern void lttng_notification_destroy(struct lttng_notification *notification); diff --git a/src/lib/lttng-ctl/Makefile.am b/src/lib/lttng-ctl/Makefile.am index abcbfee36..90252656a 100644 --- a/src/lib/lttng-ctl/Makefile.am +++ b/src/lib/lttng-ctl/Makefile.am @@ -6,7 +6,8 @@ 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 condition.c buffer-usage.c evaluation.c + action.c notify.c condition.c buffer-usage.c evaluation.c \ + notification.c liblttng_ctl_la_LDFLAGS = \ $(LT_NO_UNDEFINED) diff --git a/src/lib/lttng-ctl/notification.c b/src/lib/lttng-ctl/notification.c new file mode 100644 index 000000000..4d9640613 --- /dev/null +++ b/src/lib/lttng-ctl/notification.c @@ -0,0 +1,66 @@ +/* + * 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 + +LTTNG_HIDDEN +struct lttng_notification *lttng_notification_create( + struct lttng_condition *condition, + struct lttng_evaluation *evaluation) +{ + struct lttng_notification *notification = NULL; + + if (!condition || !evaluation) { + goto end; + } + + notification = zmalloc(sizeof(struct lttng_notification)); + if (!notification) { + goto end; + } + + notification->condition = condition; + notification->evaluation = evaluation; +end: + return notification; +} + +void lttng_notification_destroy(struct lttng_notification *notification) +{ + if (!notification) { + return; + } + + lttng_condition_destroy(notification->condition); + lttng_evaluation_destroy(notification->evaluation); + free(notification); +} + +struct lttng_condition *lttng_notification_get_condition( + struct lttng_notification *notification) +{ + return notification ? notification->condition : NULL; +} + +struct lttng_evaluation *lttng_notification_get_evaluation( + struct lttng_notification *notification) +{ + return notification ? notification->evaluation : NULL; +} -- 2.34.1