1 /* 2 * File event notification support. 3 * 4 * Copyright (C) 2021 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 #pragma once 23 24 #include <condition_variable> 25 #include <list> 26 #include <mutex> 27 28 #include <fsclient/file.h> 29 #include <ipc/server.h> 30 #include <systypes/base.h> 31 32 33 34 /* An object for monitoring file event notifications. */ 35 36 class FileNotifier 37 { 38 protected: 39 std::list<file_t *> _affected; 40 l4_cap_idx_t _thread = L4_INVALID_CAP; 41 bool _started = false; 42 43 std::mutex _lock; 44 std::condition_variable _notified; 45 46 /* Helper methods. */ 47 48 virtual void _notify(file_t *file, notify_flags_t flags); 49 50 public: 51 /* Server details. */ 52 53 int expected_items(); 54 55 ipc_server_handler_type handler(); 56 57 void *interface() 58 { return static_cast<FileNotifier *>(this); } 59 60 /* Local operations. */ 61 62 virtual long subscribe(file_t *file, notify_flags_t flags); 63 64 virtual long unsubscribe(file_t *file); 65 66 virtual void mainloop(); 67 68 virtual long start(); 69 70 virtual long wait(file_t **file); 71 }; 72 73 74 75 /* Helper functions. */ 76 77 FileNotifier *get_notifier(); 78 79 // vim: tabstop=4 expandtab shiftwidth=4