1.1 --- a/libfsclient/lib/src/file.cc Thu Feb 16 23:36:52 2023 +0100
1.2 +++ b/libfsclient/lib/src/file.cc Fri Feb 17 18:39:43 2023 +0100
1.3 @@ -89,9 +89,13 @@
1.4 file->data_current = 0;
1.5 file->object_flags = 0;
1.6 file->can_block = 0;
1.7 - file->notifications = 0;
1.8 file->flags = 0;
1.9 file->error = 0;
1.10 +
1.11 + /* Initialise the notifiable section of the structure. */
1.12 +
1.13 + file->notifiable.notifications = 0;
1.14 + file->notifiable.base = (notifiable_base_t *) file;
1.15 }
1.16
1.17
1.18 @@ -107,7 +111,7 @@
1.19 /* Only unsubscribe after actually closing the file and sending any
1.20 notifications. */
1.21
1.22 - notifier_get_task_notifier()->unsubscribe(file);
1.23 + notifier_get_task_notifier()->unsubscribe(file_notifiable(file));
1.24 }
1.25
1.26 if (file->memory != NULL)
1.27 @@ -607,10 +611,22 @@
1.28
1.29 struct file_notifier
1.30 {
1.31 - FileNotifier *obj;
1.32 + ObjectNotifier *obj;
1.33 };
1.34
1.35 +/* Conversion to the generic notification types. */
1.36
1.37 +notifiable_t *file_notifiable(file_t *file)
1.38 +{
1.39 + return &file->notifiable;
1.40 +}
1.41 +
1.42 +/* Return the notification flags for a file. */
1.43 +
1.44 +notify_flags_t file_notifications(file_t *file)
1.45 +{
1.46 + return file->notifiable.notifications;
1.47 +}
1.48
1.49 /* Close a notifier object. */
1.50
1.51 @@ -644,26 +660,26 @@
1.52
1.53 long file_notify_subscribe(file_t *file, notify_flags_t flags, file_notifier_t *notifier)
1.54 {
1.55 - return notifier->obj->subscribe(file, flags);
1.56 + return notifier->obj->subscribe(file_notifiable(file), flags);
1.57 }
1.58
1.59 /* Unsubscribe from notification events on a file. */
1.60
1.61 long file_notify_unsubscribe(file_t *file, file_notifier_t *notifier)
1.62 {
1.63 - return notifier->obj->unsubscribe(file);
1.64 + return notifier->obj->unsubscribe(file_notifiable(file));
1.65 }
1.66
1.67 /* Wait for a notification event on a file. */
1.68
1.69 long file_notify_wait_file(file_t *file, file_notifier_t *notifier)
1.70 {
1.71 - SpecificFileNotifier *specific_notifier = dynamic_cast<SpecificFileNotifier *>(notifier->obj);
1.72 - long err = specific_notifier->wait_file(file);
1.73 + SpecificObjectNotifier *specific_notifier = dynamic_cast<SpecificObjectNotifier *>(notifier->obj);
1.74 + long err = specific_notifier->wait_object(file_notifiable(file));
1.75
1.76 /* Unsubscribe if a closure notification has been received. */
1.77
1.78 - if (!err && (file->notifications & NOTIFY_PEER_CLOSED))
1.79 + if (!err && (file->notifiable.notifications & NOTIFY_PEER_CLOSED))
1.80 file_notify_unsubscribe(file, notifier);
1.81
1.82 return err;
1.83 @@ -673,12 +689,15 @@
1.84
1.85 long file_notify_wait_files(file_t **file, file_notifier_t *notifier)
1.86 {
1.87 - GeneralFileNotifier *general_notifier = dynamic_cast<GeneralFileNotifier *>(notifier->obj);
1.88 - long err = general_notifier->wait(file);
1.89 + GeneralObjectNotifier *general_notifier = dynamic_cast<GeneralObjectNotifier *>(notifier->obj);
1.90 + notifiable_t *notifiable;
1.91 + long err = general_notifier->wait(¬ifiable);
1.92 +
1.93 + *file = (file_t *) notifiable->base;
1.94
1.95 /* Unsubscribe if a closure notification has been received. */
1.96
1.97 - if (!err && ((*file)->notifications & NOTIFY_PEER_CLOSED))
1.98 + if (!err && ((*file)->notifiable.notifications & NOTIFY_PEER_CLOSED))
1.99 file_notify_unsubscribe(*file, notifier);
1.100
1.101 return err;