1.1 --- a/libfsclient/include/fsclient/notifier.h Thu Feb 16 23:36:52 2023 +0100
1.2 +++ b/libfsclient/include/fsclient/notifier.h Fri Feb 17 18:39:43 2023 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 - * File event notification support.
1.6 + * Generic object event notification support.
1.7 *
1.8 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
1.9 + * Copyright (C) 2021, 2022, 2023 Paul Boddie <paul@boddie.org.uk>
1.10 *
1.11 * This program is free software; you can redistribute it and/or
1.12 * modify it under the terms of the GNU General Public License as
1.13 @@ -31,9 +31,9 @@
1.14
1.15
1.16
1.17 -/* File-specific notification details. */
1.18 +/* Object-specific notification details. */
1.19
1.20 -class FileNotificationState
1.21 +class ObjectNotificationState
1.22 {
1.23 public:
1.24 /* Synchronisation primitives for state access and notification. */
1.25 @@ -41,11 +41,11 @@
1.26 std::mutex lock;
1.27 std::condition_variable condition;
1.28
1.29 - /* Pending notifications for monitored files. */
1.30 + /* Pending notifications for monitored objects. */
1.31
1.32 notify_flags_t pending = 0;
1.33
1.34 - /* Endpoints associated with monitored files. */
1.35 + /* Endpoints associated with monitored objects. */
1.36
1.37 l4_cap_idx_t endpoint = L4_INVALID_CAP;
1.38
1.39 @@ -56,53 +56,53 @@
1.40
1.41 /* Collection types. */
1.42
1.43 -typedef std::map<file_t *, FileNotificationState> FileNotificationStates;
1.44 -typedef std::map<file_t *, std::mutex> FileStateLocks;
1.45 +typedef std::map<notifiable_t *, ObjectNotificationState> ObjectNotificationStates;
1.46 +typedef std::map<notifiable_t *, std::mutex> ObjectStateLocks;
1.47
1.48
1.49
1.50 -/* An object for monitoring file event notifications. */
1.51 +/* An object for monitoring object event notifications. */
1.52
1.53 -class FileNotifier
1.54 +class ObjectNotifier
1.55 {
1.56 protected:
1.57 /* General state access locking. */
1.58
1.59 std::mutex _state_lock;
1.60
1.61 - /* File-specific state locking. */
1.62 + /* Object-specific state locking. */
1.63
1.64 - FileStateLocks _file_locks;
1.65 + ObjectStateLocks _object_locks;
1.66
1.67 /* Notification state. */
1.68
1.69 - FileNotificationStates _state;
1.70 + ObjectNotificationStates _state;
1.71
1.72 /* Notifier thread details. */
1.73
1.74 l4_cap_idx_t _thread = L4_INVALID_CAP;
1.75 bool _started = false;
1.76
1.77 - /* Convenience method to access file state. */
1.78 + /* Convenience method to access object state. */
1.79
1.80 - virtual FileNotificationState &file_state(file_t *file, bool create);
1.81 + virtual ObjectNotificationState &object_state(notifiable_t *object, bool create);
1.82
1.83 /* Helper methods. */
1.84
1.85 - virtual void _notify(file_t *file, notify_flags_t flags) = 0;
1.86 + virtual void _notify(notifiable_t *object, notify_flags_t flags) = 0;
1.87
1.88 - virtual bool _transfer(FileNotificationState &state, file_t *file);
1.89 + virtual bool _transfer(ObjectNotificationState &state, notifiable_t *object);
1.90
1.91 public:
1.92 - virtual ~FileNotifier();
1.93 + virtual ~ObjectNotifier();
1.94
1.95 /* Local operations. */
1.96
1.97 virtual long start();
1.98
1.99 - virtual long subscribe(file_t *file, notify_flags_t flags);
1.100 + virtual long subscribe(notifiable_t *object, notify_flags_t flags);
1.101
1.102 - virtual long unsubscribe(file_t *file);
1.103 + virtual long unsubscribe(notifiable_t *object);
1.104
1.105 /* Event handling support. */
1.106
1.107 @@ -111,9 +111,9 @@
1.108
1.109
1.110
1.111 -/* An object monitoring notifications for a collection of different files. */
1.112 +/* An object monitoring notifications for a collection of different objects. */
1.113
1.114 -class GeneralFileNotifier : public FileNotifier
1.115 +class GeneralObjectNotifier : public ObjectNotifier
1.116 {
1.117 protected:
1.118 /* Locking to protect pending notification members and to coordinate access
1.119 @@ -125,43 +125,43 @@
1.120
1.121 std::condition_variable _general_condition;
1.122
1.123 - /* Files affected by notifications. */
1.124 + /* Objects affected by notifications. */
1.125
1.126 - std::list<file_t *> _affected;
1.127 + std::list<notifiable_t *> _affected;
1.128
1.129 /* Helper methods. */
1.130
1.131 - virtual void _notify(file_t *file, notify_flags_t flags);
1.132 + virtual void _notify(notifiable_t *object, notify_flags_t flags);
1.133
1.134 - virtual bool _retrieve(file_t **file);
1.135 + virtual bool _retrieve(notifiable_t **object);
1.136
1.137 - virtual bool _retrieve_for_file(file_t *file);
1.138 + virtual bool _retrieve_for_object(notifiable_t *object);
1.139
1.140 public:
1.141 - virtual long wait(file_t **file);
1.142 + virtual long wait(notifiable_t **object);
1.143 };
1.144
1.145
1.146
1.147 -/* An object monitoring notifications for specific files. */
1.148 +/* An object monitoring notifications for specific objects. */
1.149
1.150 -class SpecificFileNotifier : public FileNotifier
1.151 +class SpecificObjectNotifier : public ObjectNotifier
1.152 {
1.153 protected:
1.154 /* Helper methods. */
1.155
1.156 - virtual void _notify(file_t *file, notify_flags_t flags);
1.157 + virtual void _notify(notifiable_t *object, notify_flags_t flags);
1.158
1.159 public:
1.160 - virtual long wait_file(file_t *file);
1.161 + virtual long wait_object(notifiable_t *object);
1.162 };
1.163
1.164
1.165
1.166 /* Helper functions. */
1.167
1.168 -SpecificFileNotifier *notifier_get_task_notifier();
1.169 +SpecificObjectNotifier *notifier_get_task_notifier();
1.170
1.171 -GeneralFileNotifier *notifier_get_local_notifier();
1.172 +GeneralObjectNotifier *notifier_get_local_notifier();
1.173
1.174 // vim: tabstop=4 expandtab shiftwidth=4