1 /* 2 * Template output. 3 * 4 * Copyright (C) 2019 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 /* Filename definitions. */ 25 26 #define client_filename "%s/%s_client.c" 27 #define client_header_filename "%s/%s_client.h" 28 #define common_filename "%s/%s_common.h" 29 #define compound_interfaces_filename "%s/%s_interfaces.h" 30 #define server_filename_c "%s/%s_server.c" 31 #define server_filename_cpp "%s/%s_server.cc" 32 #define server_header_filename "%s/%s_server.h" 33 #define server_interface_filename "%s/%s_interface.h" 34 35 /* Client templates. */ 36 37 #define client_prologue \ 38 "#include \"%s_client.h\"\n" \ 39 "#include \"%s_common.h\"\n" \ 40 "#include <ipc/message.h>\n" 41 42 #define client_function_body_prologue \ 43 " ipc_message_t msg;\n" \ 44 " long err;\n" 45 46 #define client_function_body_call \ 47 "\n ipc_message_request(&msg, %s, _endp);\n\n" \ 48 " err = l4_error(msg.tag);\n" \ 49 " if (err)\n" \ 50 " return err;\n" 51 52 /* Compound interface dispatcher templates. */ 53 54 #define compound_dispatch_prologue \ 55 "#include \"%s_server.h\"\n" 56 57 #define compound_handle_function_signature_c \ 58 "\nvoid %s_handle(ipc_message_t *msg, void *_self)" 59 60 #define compound_handle_function_signature_cpp \ 61 "\nvoid %s_handle(ipc_message_t *msg, %s *_self)" 62 63 #define compound_handle_function \ 64 "{\n" \ 65 " ipc_message_open(msg);\n" \ 66 " %s_dispatch(msg, _self);\n" \ 67 " ipc_message_reply(msg);\n" \ 68 " ipc_message_discard(msg);\n" \ 69 "}\n" 70 71 #define compound_dispatch_function_signature_c \ 72 "\nvoid %s_dispatch(ipc_message_t *msg, void *_self)" 73 74 #define compound_dispatch_function_signature_cpp \ 75 "\nvoid %s_dispatch(ipc_message_t *msg, %s *_self)" 76 77 #define compound_dispatch_function_prologue \ 78 "{\n" \ 79 " switch (l4_msgtag_label(msg->tag))\n" \ 80 " {\n" 81 82 #define compound_dispatch_epilogue \ 83 " default:\n" \ 84 " ipc_message_send_error(msg, -L4_EBADPROTO);\n" \ 85 " break;\n" \ 86 " }\n" \ 87 "}\n" 88 89 #define compound_dispatch_header_prologue \ 90 "#pragma once\n\n" \ 91 "#include <ipc/message.h>\n" \ 92 "#include \"%s_interface.h\"\n" 93 94 #define compound_dispatch_header_epilogue \ 95 "\n#define %s_expected_items %d\n" 96 97 /* Compound interface class definitions. */ 98 99 #define compound_interface_prologue \ 100 "#pragma once\n\n" \ 101 "#include \"%s_interfaces.h\"\n\n" \ 102 "#ifdef __cplusplus\n\n" \ 103 "class %s :" 104 105 #define compound_interface_epilogue \ 106 "\n{\n};\n\n" \ 107 "#endif /* __cplusplus */\n" 108 109 #define compound_interfaces_prologue \ 110 "#pragma once\n\n" 111 112 /* General header template. */ 113 114 #define header_prologue \ 115 "#pragma once\n\n" \ 116 "#include <l4/sys/types.h>\n" 117 118 /* Server templates. */ 119 120 #define server_header_prologue \ 121 "#pragma once\n\n" \ 122 "#include <ipc/message.h>\n" 123 124 #define server_prologue \ 125 "#include \"%s_server.h\"\n" \ 126 "#include \"%s_common.h\"\n" 127 128 #define server_function_body_prologue \ 129 " long err;\n" 130 131 #define server_function_body_call \ 132 " if (err)\n" \ 133 " return err;\n" 134 135 #define server_function_dispatcher_body_epilogue \ 136 " default:\n" \ 137 " ipc_message_send_error(msg, -L4_EBADPROTO);\n" \ 138 " break;\n" \ 139 " }\n" 140 141 /* Interface class definitions. */ 142 143 #define server_interface_prologue_cpp \ 144 "\nclass %s\n" \ 145 "{\n" \ 146 "public:" 147 148 #define server_interface_epilogue_cpp \ 149 "};\n" 150 151 /* Dispatch templates. */ 152 153 #define dispatch_function_interface_case \ 154 " case %s:\n" \ 155 " dispatch_%s(msg, _self);\n" \ 156 " break;\n\n" 157 158 #define dispatch_function_wrapper_case \ 159 " case %s:\n" \ 160 " ipc_message_send_error(msg, wrap_%s(msg, _self));\n" \ 161 " break;\n\n"