1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/libfsclient/lib/src/notify.cc Sat Dec 09 01:27:19 2023 +0100
1.3 @@ -0,0 +1,112 @@
1.4 +/*
1.5 + * Notification-related functions.
1.6 + *
1.7 + * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#include <notifier/notifier.h>
1.26 +
1.27 +#include "notify.h"
1.28 +
1.29 +
1.30 +
1.31 +/* Opaque notifier type for notifier_t. */
1.32 +
1.33 +struct notifier
1.34 +{
1.35 + ObjectNotifier *obj;
1.36 +};
1.37 +
1.38 +/* Return the notifiable details from a compatible object. */
1.39 +
1.40 +notifiable_t *notify_notifiable(notifiable_base_t *notifiable)
1.41 +{
1.42 + return ¬ifiable->notifiable;
1.43 +}
1.44 +
1.45 +/* Return the notification flags for an object. */
1.46 +
1.47 +notify_flags_t notify_notifications(notifiable_base_t *notifiable)
1.48 +{
1.49 + return notifiable->notifiable.notifications;
1.50 +}
1.51 +
1.52 +/* Return the notification values for an object. */
1.53 +
1.54 +notify_values_t notify_notification_values(notifiable_base_t *notifiable)
1.55 +{
1.56 + return notifiable->notifiable.values;
1.57 +}
1.58 +
1.59 +/* Close a notifier object. */
1.60 +
1.61 +void notify_close(notifier_t *notifier)
1.62 +{
1.63 + delete notifier->obj;
1.64 + delete notifier;
1.65 +}
1.66 +
1.67 +/* Obtain a local notifier object. */
1.68 +
1.69 +notifier_t *notify_get_local()
1.70 +{
1.71 + notifier_t *notifier = new notifier_t;
1.72 +
1.73 + notifier->obj = notifier_get_local_notifier();
1.74 + return notifier;
1.75 +}
1.76 +
1.77 +/* Obtain the task-wide notifier object. */
1.78 +
1.79 +notifier_t *notify_get_task()
1.80 +{
1.81 + notifier_t *notifier = new notifier_t;
1.82 +
1.83 + notifier->obj = notifier_get_task_notifier();
1.84 + return notifier;
1.85 +}
1.86 +
1.87 +/* Subscribe to notification events. */
1.88 +
1.89 +long notify_subscribe(notifiable_t *notifiable, notify_flags_t flags, notifier_t *notifier)
1.90 +{
1.91 + return notifier->obj->subscribe(notifiable, flags);
1.92 +}
1.93 +
1.94 +/* Unsubscribe from notification events. */
1.95 +
1.96 +long notify_unsubscribe(notifiable_t *notifiable, notifier_t *notifier)
1.97 +{
1.98 + return notifier->obj->unsubscribe(notifiable);
1.99 +}
1.100 +
1.101 +/* Wait for a notification event on a single object. */
1.102 +
1.103 +long notify_wait(notifiable_t *notifiable, notifier_t *notifier)
1.104 +{
1.105 + return notifier->obj->wait_object(notifiable);
1.106 +}
1.107 +
1.108 +/* Wait for notification events on multiple objects. */
1.109 +
1.110 +long notify_wait_many(notifiable_t **notifiable, notifier_t *notifier)
1.111 +{
1.112 + return notifier->obj->wait(notifiable);
1.113 +}
1.114 +
1.115 +// vim: tabstop=2 expandtab shiftwidth=2