1 /* 2 * Notification-related functions. 3 * 4 * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <notifier/notifier.h> 23 24 #include "notify.h" 25 26 27 28 /* Opaque notifier type for notifier_t. */ 29 30 struct notifier 31 { 32 ObjectNotifier *obj; 33 }; 34 35 /* Return the notifiable details from a compatible object. */ 36 37 notifiable_t *notify_notifiable(notifiable_base_t *notifiable) 38 { 39 return ¬ifiable->notifiable; 40 } 41 42 /* Return the notification flags for an object. */ 43 44 notify_flags_t notify_notifications(notifiable_base_t *notifiable) 45 { 46 return notifiable->notifiable.notifications; 47 } 48 49 /* Return the notification values for an object. */ 50 51 notify_values_t notify_notification_values(notifiable_base_t *notifiable) 52 { 53 return notifiable->notifiable.values; 54 } 55 56 /* Close a notifier object. */ 57 58 void notify_close(notifier_t *notifier) 59 { 60 delete notifier->obj; 61 delete notifier; 62 } 63 64 /* Obtain a local notifier object. */ 65 66 notifier_t *notify_get_local() 67 { 68 notifier_t *notifier = new notifier_t; 69 70 notifier->obj = notifier_get_local_notifier(); 71 return notifier; 72 } 73 74 /* Obtain the task-wide notifier object. */ 75 76 notifier_t *notify_get_task() 77 { 78 notifier_t *notifier = new notifier_t; 79 80 notifier->obj = notifier_get_task_notifier(); 81 return notifier; 82 } 83 84 /* Subscribe to notification events. */ 85 86 long notify_subscribe(notifiable_t *notifiable, notify_flags_t flags, notifier_t *notifier) 87 { 88 return notifier->obj->subscribe(notifiable, flags); 89 } 90 91 /* Unsubscribe from notification events. */ 92 93 long notify_unsubscribe(notifiable_t *notifiable, notifier_t *notifier) 94 { 95 return notifier->obj->unsubscribe(notifiable); 96 } 97 98 /* Wait for a notification event on a single object. */ 99 100 long notify_wait(notifiable_t *notifiable, notifier_t *notifier) 101 { 102 return notifier->obj->wait_object(notifiable); 103 } 104 105 /* Wait for notification events on multiple objects. */ 106 107 long notify_wait_many(notifiable_t **notifiable, notifier_t *notifier) 108 { 109 return notifier->obj->wait(notifiable); 110 } 111 112 // vim: tabstop=2 expandtab shiftwidth=2