paul@124 | 1 | /* |
paul@124 | 2 | * File event notification support. |
paul@124 | 3 | * |
paul@124 | 4 | * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> |
paul@124 | 5 | * |
paul@124 | 6 | * This program is free software; you can redistribute it and/or |
paul@124 | 7 | * modify it under the terms of the GNU General Public License as |
paul@124 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@124 | 9 | * the License, or (at your option) any later version. |
paul@124 | 10 | * |
paul@124 | 11 | * This program is distributed in the hope that it will be useful, |
paul@124 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@124 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@124 | 14 | * GNU General Public License for more details. |
paul@124 | 15 | * |
paul@124 | 16 | * You should have received a copy of the GNU General Public License |
paul@124 | 17 | * along with this program; if not, write to the Free Software |
paul@124 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@124 | 19 | * Boston, MA 02110-1301, USA |
paul@124 | 20 | */ |
paul@124 | 21 | |
paul@124 | 22 | #pragma once |
paul@124 | 23 | |
paul@124 | 24 | #include <condition_variable> |
paul@124 | 25 | #include <list> |
paul@124 | 26 | #include <mutex> |
paul@124 | 27 | |
paul@124 | 28 | #include <fsclient/file.h> |
paul@124 | 29 | #include <ipc/server.h> |
paul@124 | 30 | #include <systypes/base.h> |
paul@124 | 31 | |
paul@124 | 32 | |
paul@124 | 33 | |
paul@124 | 34 | /* An object for monitoring file event notifications. */ |
paul@124 | 35 | |
paul@124 | 36 | class FileNotifier |
paul@124 | 37 | { |
paul@124 | 38 | protected: |
paul@124 | 39 | std::list<file_t *> _affected; |
paul@124 | 40 | l4_cap_idx_t _thread = L4_INVALID_CAP; |
paul@124 | 41 | bool _started = false; |
paul@124 | 42 | |
paul@124 | 43 | std::mutex _lock; |
paul@124 | 44 | std::condition_variable _notified; |
paul@124 | 45 | |
paul@124 | 46 | /* Helper methods. */ |
paul@124 | 47 | |
paul@124 | 48 | virtual void _notify(file_t *file, notify_flags_t flags); |
paul@124 | 49 | |
paul@124 | 50 | public: |
paul@124 | 51 | /* Server details. */ |
paul@124 | 52 | |
paul@124 | 53 | int expected_items(); |
paul@124 | 54 | |
paul@124 | 55 | ipc_server_handler_type handler(); |
paul@124 | 56 | |
paul@124 | 57 | void *interface() |
paul@124 | 58 | { return static_cast<FileNotifier *>(this); } |
paul@124 | 59 | |
paul@124 | 60 | /* Local operations. */ |
paul@124 | 61 | |
paul@124 | 62 | virtual long subscribe(file_t *file, notify_flags_t flags); |
paul@124 | 63 | |
paul@124 | 64 | virtual long unsubscribe(file_t *file); |
paul@124 | 65 | |
paul@124 | 66 | virtual void mainloop(); |
paul@124 | 67 | |
paul@124 | 68 | virtual long start(); |
paul@124 | 69 | |
paul@124 | 70 | virtual long wait(file_t **file); |
paul@124 | 71 | }; |
paul@124 | 72 | |
paul@124 | 73 | |
paul@124 | 74 | |
paul@124 | 75 | /* Helper functions. */ |
paul@124 | 76 | |
paul@124 | 77 | FileNotifier *get_notifier(); |
paul@124 | 78 | |
paul@124 | 79 | // vim: tabstop=4 expandtab shiftwidth=4 |