paul@10 | 1 | /* |
paul@10 | 2 | * Common resource server functions. |
paul@10 | 3 | * |
paul@10 | 4 | * Copyright (C) 2018, 2019, 2020 Paul Boddie <paul@boddie.org.uk> |
paul@10 | 5 | * |
paul@10 | 6 | * This program is free software; you can redistribute it and/or |
paul@10 | 7 | * modify it under the terms of the GNU General Public License as |
paul@10 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@10 | 9 | * the License, or (at your option) any later version. |
paul@10 | 10 | * |
paul@10 | 11 | * This program is distributed in the hope that it will be useful, |
paul@10 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@10 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@10 | 14 | * GNU General Public License for more details. |
paul@10 | 15 | * |
paul@10 | 16 | * You should have received a copy of the GNU General Public License |
paul@10 | 17 | * along with this program; if not, write to the Free Software |
paul@10 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@10 | 19 | * Boston, MA 02110-1301, USA |
paul@10 | 20 | */ |
paul@10 | 21 | |
paul@10 | 22 | #pragma once |
paul@10 | 23 | |
paul@94 | 24 | #include <fsserver/resource.h> |
paul@10 | 25 | #include <ipc/server.h> |
paul@10 | 26 | |
paul@10 | 27 | |
paul@10 | 28 | |
paul@10 | 29 | /* Convenience abstraction for blocking servers. */ |
paul@10 | 30 | |
paul@10 | 31 | class ResourceServer |
paul@10 | 32 | { |
paul@10 | 33 | protected: |
paul@10 | 34 | Resource *_resource; |
paul@10 | 35 | ipc_server_config_type *_config; |
paul@10 | 36 | |
paul@10 | 37 | public: |
paul@10 | 38 | explicit ResourceServer(Resource *resource) |
paul@10 | 39 | : _resource(resource) |
paul@10 | 40 | { |
paul@10 | 41 | _config = new ipc_server_config_type; |
paul@10 | 42 | ipc_server_init_config(_config); |
paul@10 | 43 | } |
paul@10 | 44 | |
paul@10 | 45 | /* Access to configuration. */ |
paul@10 | 46 | |
paul@10 | 47 | ipc_server_config_type *config() |
paul@10 | 48 | { return _config; } |
paul@10 | 49 | |
paul@10 | 50 | /* Server IPC gate allocation. */ |
paul@10 | 51 | |
paul@10 | 52 | long bind(const char *name); |
paul@10 | 53 | |
paul@10 | 54 | /* Server initiation. */ |
paul@10 | 55 | |
paul@10 | 56 | long start(); |
paul@10 | 57 | |
paul@10 | 58 | long start_thread(); |
paul@10 | 59 | }; |
paul@10 | 60 | |
paul@10 | 61 | |
paul@10 | 62 | |
paul@10 | 63 | /* Server initialisation. */ |
paul@10 | 64 | |
paul@10 | 65 | void resource_init_config(ipc_server_config_type *config, Resource *resource); |
paul@10 | 66 | |
paul@10 | 67 | void resource_set_config_threaded(ipc_server_config_type *config, |
paul@10 | 68 | l4_cap_idx_t thread, int new_thread); |
paul@10 | 69 | |
paul@10 | 70 | /* Server initiation. */ |
paul@10 | 71 | |
paul@10 | 72 | long resource_start_config(ipc_server_config_type *config, Resource *resource); |
paul@10 | 73 | |
paul@10 | 74 | /* Server finalisation. */ |
paul@10 | 75 | |
paul@10 | 76 | void resource_thread_finaliser(ipc_server_config_type *config); |