paul@67 | 1 | /* |
paul@67 | 2 | * Template output. |
paul@67 | 3 | * |
paul@67 | 4 | * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk> |
paul@67 | 5 | * |
paul@67 | 6 | * This program is free software; you can redistribute it and/or |
paul@67 | 7 | * modify it under the terms of the GNU General Public License as |
paul@67 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@67 | 9 | * the License, or (at your option) any later version. |
paul@67 | 10 | * |
paul@67 | 11 | * This program is distributed in the hope that it will be useful, |
paul@67 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@67 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@67 | 14 | * GNU General Public License for more details. |
paul@67 | 15 | * |
paul@67 | 16 | * You should have received a copy of the GNU General Public License |
paul@67 | 17 | * along with this program; if not, write to the Free Software |
paul@67 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@67 | 19 | * Boston, MA 02110-1301, USA |
paul@67 | 20 | */ |
paul@67 | 21 | |
paul@67 | 22 | #pragma once |
paul@67 | 23 | |
paul@67 | 24 | /* Filename definitions. */ |
paul@67 | 25 | |
paul@91 | 26 | #define client_filename "%s/%s_client.c" |
paul@91 | 27 | #define client_header_filename "%s/%s_client.h" |
paul@91 | 28 | #define common_filename "%s/%s_common.h" |
paul@91 | 29 | #define compound_interfaces_filename "%s/%s_interfaces.h" |
paul@91 | 30 | #define server_filename_c "%s/%s_server.c" |
paul@91 | 31 | #define server_filename_cpp "%s/%s_server.cc" |
paul@91 | 32 | #define server_header_filename "%s/%s_server.h" |
paul@91 | 33 | #define server_interface_filename "%s/%s_interface.h" |
paul@67 | 34 | |
paul@90 | 35 | /* Client templates. */ |
paul@67 | 36 | |
paul@67 | 37 | #define client_prologue \ |
paul@67 | 38 | "#include \"%s_client.h\"\n" \ |
paul@67 | 39 | "#include \"%s_common.h\"\n" \ |
paul@67 | 40 | "#include <ipc/message.h>\n" |
paul@67 | 41 | |
paul@67 | 42 | #define client_function_body_prologue \ |
paul@67 | 43 | " ipc_message_t msg;\n" \ |
paul@67 | 44 | " long err;\n" |
paul@67 | 45 | |
paul@67 | 46 | #define client_function_body_call \ |
paul@67 | 47 | "\n ipc_message_request(&msg, %s, _endp);\n\n" \ |
paul@67 | 48 | " err = l4_error(msg.tag);\n" \ |
paul@67 | 49 | " if (err)\n" \ |
paul@67 | 50 | " return err;\n" |
paul@67 | 51 | |
paul@91 | 52 | /* Compound interface dispatcher templates. */ |
paul@90 | 53 | |
paul@91 | 54 | #define compound_dispatch_prologue \ |
paul@97 | 55 | "#include \"%s_server.h\"\n" |
paul@90 | 56 | |
paul@91 | 57 | #define compound_handle_function_signature_c \ |
paul@90 | 58 | "\nvoid %s_handle(ipc_message_t *msg, void *_self)" |
paul@90 | 59 | |
paul@91 | 60 | #define compound_handle_function_signature_cpp \ |
paul@90 | 61 | "\nvoid %s_handle(ipc_message_t *msg, %s *_self)" |
paul@90 | 62 | |
paul@91 | 63 | #define compound_handle_function \ |
paul@67 | 64 | "{\n" \ |
paul@67 | 65 | " ipc_message_open(msg);\n" \ |
paul@90 | 66 | " %s_dispatch(msg, _self);\n" \ |
paul@67 | 67 | " ipc_message_reply(msg);\n" \ |
paul@67 | 68 | " ipc_message_discard(msg);\n" \ |
paul@90 | 69 | "}\n" |
paul@90 | 70 | |
paul@91 | 71 | #define compound_dispatch_function_signature_c \ |
paul@90 | 72 | "\nvoid %s_dispatch(ipc_message_t *msg, void *_self)" |
paul@90 | 73 | |
paul@91 | 74 | #define compound_dispatch_function_signature_cpp \ |
paul@90 | 75 | "\nvoid %s_dispatch(ipc_message_t *msg, %s *_self)" |
paul@90 | 76 | |
paul@91 | 77 | #define compound_dispatch_function_prologue \ |
paul@67 | 78 | "{\n" \ |
paul@67 | 79 | " switch (l4_msgtag_label(msg->tag))\n" \ |
paul@67 | 80 | " {\n" |
paul@67 | 81 | |
paul@91 | 82 | #define compound_dispatch_epilogue \ |
paul@67 | 83 | " default:\n" \ |
paul@67 | 84 | " ipc_message_send_error(msg, -L4_EBADPROTO);\n" \ |
paul@67 | 85 | " break;\n" \ |
paul@67 | 86 | " }\n" \ |
paul@67 | 87 | "}\n" |
paul@67 | 88 | |
paul@91 | 89 | #define compound_dispatch_header_prologue \ |
paul@67 | 90 | "#pragma once\n\n" \ |
paul@90 | 91 | "#include <ipc/message.h>\n" \ |
paul@97 | 92 | "#include \"%s_interface.h\"\n" |
paul@67 | 93 | |
paul@91 | 94 | #define compound_dispatch_header_epilogue \ |
paul@84 | 95 | "\n#define %s_expected_items %d\n" |
paul@70 | 96 | |
paul@91 | 97 | /* Compound interface class definitions. */ |
paul@90 | 98 | |
paul@91 | 99 | #define compound_interface_prologue \ |
paul@90 | 100 | "#pragma once\n\n" \ |
paul@90 | 101 | "#include \"%s_interfaces.h\"\n\n" \ |
paul@94 | 102 | "#ifdef __cplusplus\n\n" \ |
paul@90 | 103 | "class %s :" |
paul@90 | 104 | |
paul@91 | 105 | #define compound_interface_epilogue \ |
paul@94 | 106 | "\n{\n};\n\n" \ |
paul@94 | 107 | "#endif /* __cplusplus */\n" |
paul@90 | 108 | |
paul@91 | 109 | #define compound_interfaces_prologue \ |
paul@90 | 110 | "#pragma once\n\n" |
paul@90 | 111 | |
paul@90 | 112 | /* General header template. */ |
paul@90 | 113 | |
paul@67 | 114 | #define header_prologue \ |
paul@67 | 115 | "#pragma once\n\n" \ |
paul@67 | 116 | "#include <l4/sys/types.h>\n" |
paul@67 | 117 | |
paul@90 | 118 | /* Server templates. */ |
paul@90 | 119 | |
paul@71 | 120 | #define server_header_prologue \ |
paul@71 | 121 | "#pragma once\n\n" \ |
paul@71 | 122 | "#include <ipc/message.h>\n" |
paul@71 | 123 | |
paul@67 | 124 | #define server_prologue \ |
paul@67 | 125 | "#include \"%s_server.h\"\n" \ |
paul@90 | 126 | "#include \"%s_common.h\"\n" |
paul@67 | 127 | |
paul@67 | 128 | #define server_function_body_prologue \ |
paul@67 | 129 | " long err;\n" |
paul@67 | 130 | |
paul@67 | 131 | #define server_function_body_call \ |
paul@67 | 132 | " if (err)\n" \ |
paul@67 | 133 | " return err;\n" |
paul@67 | 134 | |
paul@67 | 135 | #define server_function_dispatcher_body_epilogue \ |
paul@67 | 136 | " default:\n" \ |
paul@67 | 137 | " ipc_message_send_error(msg, -L4_EBADPROTO);\n" \ |
paul@67 | 138 | " break;\n" \ |
paul@67 | 139 | " }\n" |
paul@72 | 140 | |
paul@90 | 141 | /* Interface class definitions. */ |
paul@90 | 142 | |
paul@72 | 143 | #define server_interface_prologue_cpp \ |
paul@72 | 144 | "\nclass %s\n" \ |
paul@72 | 145 | "{\n" \ |
paul@72 | 146 | "public:" |
paul@72 | 147 | |
paul@72 | 148 | #define server_interface_epilogue_cpp \ |
paul@72 | 149 | "};\n" |
paul@91 | 150 | |
paul@91 | 151 | /* Dispatch templates. */ |
paul@91 | 152 | |
paul@91 | 153 | #define dispatch_function_interface_case \ |
paul@91 | 154 | " case %s:\n" \ |
paul@91 | 155 | " dispatch_%s(msg, _self);\n" \ |
paul@91 | 156 | " break;\n\n" |
paul@91 | 157 | |
paul@91 | 158 | #define dispatch_function_wrapper_case \ |
paul@91 | 159 | " case %s:\n" \ |
paul@91 | 160 | " ipc_message_send_error(msg, wrap_%s(msg, _self));\n" \ |
paul@91 | 161 | " break;\n\n" |