L4Re/departure

libipc/include/ipc/server.h

354:e54ba46787b6
2022-06-06 Paul Boddie Introduced another convenience macro for initialising servers plus a function for completing initialisation of servers in separate threads. mmap-region-flags
     1 /*     2  * Server binding/registration.     3  *     4  * Copyright (C) 2018, 2019, 2020, 2021, 2022 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 <l4/sys/types.h>    25     26 #include <ipc/message.h>    27     28 EXTERN_C_BEGIN    29     30 /* A convenience macro for invoking the server mainloop. */    31     32 #define ipc_server_loop_for(TYPE, POINTER, NAME) \    33   _ipc_server_loop_for(TYPE##_expected_items, (TYPE *) POINTER, \    34                        (ipc_server_handler_type) handle_##TYPE, \    35                        NAME)    36     37 /* A convenience macro for initialising a server. */    38     39 #define ipc_server_init_for(CONFIG, TYPE, POINTER) \    40   _ipc_server_init_for(CONFIG, TYPE##_expected_items, (TYPE *) POINTER, \    41                        (ipc_server_handler_type) handle_##TYPE)    42     43 /* A convenience macro for adding a configuration to an existing server. */    44     45 #define ipc_server_add_config(CONFIG, TYPE, POINTER, THREAD) \    46   _ipc_server_add_config(CONFIG, TYPE##_expected_items, (TYPE *) POINTER, \    47                        (ipc_server_handler_type) handle_##TYPE, \    48                        THREAD)    49     50 /* A handler function type. */    51     52 typedef void (*ipc_server_handler_type)(ipc_message_t *, void *);    53     54 /* A finaliser function type. */    55     56 struct ipc_server_config_type;    57     58 typedef void (*ipc_server_finaliser_type)(struct ipc_server_config_type *);    59     60 /* A server configuration type. */    61     62 typedef struct ipc_server_config_type    63 {    64   /* Component object references. C++ objects may provide different references    65      for the handler (providing access to the exposed interface) and the    66      finaliser (providing access to a distinct control interface). */    67     68   void *handler_obj;    69   void *finaliser_obj;    70     71   /* Expected capability item limit for incoming messages. */    72     73   int expected_items;    74     75   /* Handler for incoming messages and finaliser upon deletion. */    76     77   ipc_server_handler_type handler;    78   ipc_server_finaliser_type finaliser;    79     80   /* Configure a thread instead of using the current thread. */    81     82   int config_thread;    83     84   /* Thread and IPC capabilities. */    85     86   l4_cap_idx_t thread;    87   l4_cap_idx_t server;    88     89   /* Receive deletion notifications via an IRQ. */    90     91   int notifications;    92   l4_cap_idx_t irq;    93     94 } ipc_server_config_type;    95     96     97     98 /* Associate a notification IRQ with an IPC gate in the main thread. */    99    100 long ipc_server_apply_irq(l4_cap_idx_t cap, l4_cap_idx_t *irq);   101    102 /* Associate a notification IRQ with an IPC gate in the given thread. */   103    104 long ipc_server_apply_irq_for_thread(l4_cap_idx_t cap, l4_cap_idx_t *irq, l4_cap_idx_t thread);   105    106 /* Bind the main thread to a named IPC gate capability. */   107    108 long ipc_server_bind(const char *name, l4_umword_t id, l4_cap_idx_t *server);   109    110 /* Create a new IPC gate for the main thread. */   111    112 long ipc_server_new(l4_cap_idx_t *cap, void *obj);   113    114 /* Create a new IPC gate for the given thread. */   115    116 long ipc_server_new_for_thread(l4_cap_idx_t *cap, void *obj, l4_cap_idx_t thread);   117    118 /* Create an IPC gate for the main thread. */   119    120 long ipc_server_new_gate(l4_cap_idx_t *ref, l4_umword_t id);   121    122 /* Create an IPC gate for the indicated thread. */   123    124 long ipc_server_new_gate_for_thread(l4_cap_idx_t *ref, l4_cap_idx_t thread, l4_umword_t id);   125    126    127    128 /* Handle incoming messages for a server. */   129    130 long _ipc_server_loop_for(int expected_items, void *handler_obj,   131                           ipc_server_handler_type handler, const char *name);   132    133 /* Initialise a server. */   134    135 long _ipc_server_init_for(ipc_server_config_type *config, int expected_items,   136                           void *handler_obj, ipc_server_handler_type handler);   137    138 /* Add handling of incoming messages to an existing server. */   139    140 long _ipc_server_add_config(ipc_server_config_type *config, int expected_items,   141                             void *handler_obj, ipc_server_handler_type handler,   142                             l4_cap_idx_t thread);   143    144 /* Handle incoming messages and IRQ notifications for a server. */   145    146 long ipc_server_managed_loop(int expected_items, ipc_server_config_type *config);   147    148 /* A pthread-compatible mainloop initiation function. */   149    150 void *ipc_server_start_mainloop(void *data);   151    152 /* Wait for an incoming message via a dedicated IPC gate for a thread. */   153    154 l4_msgtag_t ipc_server_wait(l4_umword_t id);   155    156    157    158 /* Finalise a server configuration. */   159    160 void ipc_server_finalise_config(ipc_server_config_type *config);   161    162 /* Discard any thread created but not initiated. */   163    164 void ipc_server_discard_thread(ipc_server_config_type *config);   165    166 /* Initialise a server configuration. */   167    168 void ipc_server_init_config(ipc_server_config_type *config);   169    170 /* Initialise and start a server using the given configuration. */   171    172 long ipc_server_start_config(ipc_server_config_type *config);   173    174 /* Initialise and start a server using the given configuration and thread. */   175    176 long ipc_server_start_config_thread(ipc_server_config_type *config,   177                                     l4_cap_idx_t thread);   178    179 EXTERN_C_END   180    181 /* vim: tabstop=2 expandtab shiftwidth=2   182 */