1.1 --- a/libfsclient/lib/src/file.cc Sat Aug 21 19:28:08 2021 +0200
1.2 +++ b/libfsclient/lib/src/file.cc Sun Aug 22 22:37:55 2021 +0200
1.3 @@ -102,7 +102,7 @@
1.4 here. */
1.5
1.6 if (l4_is_valid_cap(file->ref))
1.7 - get_task_notifier()->unsubscribe(file);
1.8 + notifier_get_task_notifier()->unsubscribe(file);
1.9
1.10 if (file->memory != NULL)
1.11 ipc_detach_dataspace(file->memory);
1.12 @@ -386,50 +386,83 @@
1.13
1.14
1.15
1.16 +/* Opaque notifier type for file_notifier_t. */
1.17 +
1.18 +struct file_notifier
1.19 +{
1.20 + FileNotifier *obj;
1.21 +};
1.22 +
1.23 +
1.24 +
1.25 +/* Close a notifier object. */
1.26 +
1.27 +void file_notify_close(file_notifier_t *notifier)
1.28 +{
1.29 + delete notifier->obj;
1.30 + delete notifier;
1.31 +}
1.32 +
1.33 +/* Obtain a local notifier object. */
1.34 +
1.35 +file_notifier_t *file_notify_local()
1.36 +{
1.37 + file_notifier_t *notifier = new file_notifier_t;
1.38 +
1.39 + notifier->obj = notifier_get_local_notifier();
1.40 + return notifier;
1.41 +}
1.42 +
1.43 +/* Obtain the task-wide notifier object. */
1.44 +
1.45 +file_notifier_t *file_notify_task()
1.46 +{
1.47 + file_notifier_t *notifier = new file_notifier_t;
1.48 +
1.49 + notifier->obj = notifier_get_task_notifier();
1.50 + return notifier;
1.51 +}
1.52 +
1.53 /* Subscribe to notification events on a file. */
1.54
1.55 -long file_notify_subscribe(file_t *file, notify_flags_t flags, notifier_t notifier_type)
1.56 +long file_notify_subscribe(file_t *file, notify_flags_t flags, file_notifier_t *notifier)
1.57 {
1.58 - FileNotifier *notifier = get_notifier(notifier_type);
1.59 -
1.60 - return notifier->subscribe(file, flags);
1.61 + return notifier->obj->subscribe(file, flags);
1.62 }
1.63
1.64 /* Unsubscribe from notification events on a file. */
1.65
1.66 -long file_notify_unsubscribe(file_t *file, notifier_t notifier_type)
1.67 +long file_notify_unsubscribe(file_t *file, file_notifier_t *notifier)
1.68 {
1.69 - FileNotifier *notifier = get_notifier(notifier_type);
1.70 -
1.71 - return notifier->unsubscribe(file);
1.72 + return notifier->obj->unsubscribe(file);
1.73 }
1.74
1.75 /* Wait for a notification event on a file. */
1.76
1.77 -long file_notify_wait_file(file_t *file)
1.78 +long file_notify_wait_file(file_t *file, file_notifier_t *notifier)
1.79 {
1.80 - SpecificFileNotifier *notifier = get_task_notifier();
1.81 - long err = notifier->wait_file(file);
1.82 + SpecificFileNotifier *specific_notifier = dynamic_cast<SpecificFileNotifier *>(notifier->obj);
1.83 + long err = specific_notifier->wait_file(file);
1.84
1.85 /* Unsubscribe if a closure notification has been received. */
1.86
1.87 if (!err && (file->notifications & NOTIFY_PEER_CLOSED))
1.88 - file_notify_unsubscribe(file, NOTIFIER_TASK);
1.89 + file_notify_unsubscribe(file, notifier);
1.90
1.91 return err;
1.92 }
1.93
1.94 /* Wait for notification events on files. */
1.95
1.96 -long file_notify_wait_files(file_t **file)
1.97 +long file_notify_wait_files(file_t **file, file_notifier_t *notifier)
1.98 {
1.99 - GeneralFileNotifier *notifier = get_thread_notifier();
1.100 - long err = notifier->wait(file);
1.101 + GeneralFileNotifier *general_notifier = dynamic_cast<GeneralFileNotifier *>(notifier->obj);
1.102 + long err = general_notifier->wait(file);
1.103
1.104 /* Unsubscribe if a closure notification has been received. */
1.105
1.106 if (!err && ((*file)->notifications & NOTIFY_PEER_CLOSED))
1.107 - file_notify_unsubscribe(*file, NOTIFIER_THREAD);
1.108 + file_notify_unsubscribe(*file, notifier);
1.109
1.110 return err;
1.111 }