1 /* 2 * Generation of server dispatch and handle functions. 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 #include <stdlib.h> 23 #include "common.h" 24 #include "dispatch.h" 25 #include "templates.h" 26 27 28 29 /* Generate dispatch function signatures. */ 30 31 void write_dispatcher_signature(const char *name, enum signature_role role, 32 FILE *fp) 33 { 34 fprintf(fp, dispatch_function_signature, name, name); 35 fputs(get_signature_terminator(role), fp); 36 } 37 38 /* Generate handler function signatures. */ 39 40 void write_handler_signature(const char *name, enum signature_role role, 41 FILE *fp) 42 { 43 fprintf(fp, handle_function_signature, name, name); 44 fputs(get_signature_terminator(role), fp); 45 } 46 47 /* Generate a dispatch function for the different operations. */ 48 49 void write_dispatcher(struct signature *sig, FILE *fp, struct interface *iface) 50 { 51 write_dispatcher_signature(iface->name, DEFINITION_ROLE, fp); 52 53 /* Declare an error variable to support testing for already-sent messages. */ 54 55 fputs(" long err;\n\n", fp); 56 57 /* Interpret an operation indicator in the word data if a protocol applies to 58 the entire interface. */ 59 60 if (get_protocol(iface->attributes)) 61 fputs(" switch (ipc_message_get_word(msg, 0))\n {\n", fp); 62 else 63 fputs(" switch (l4_msgtag_label(msg->tag))\n {\n", fp); 64 65 write_dispatcher_cases(sig, fp, iface, 0); 66 fputs(server_function_dispatcher_body_epilogue, fp); 67 68 fputs("}\n", fp); 69 } 70 71 /* Generate each dispatch possibility within an interface. */ 72 73 void write_dispatcher_cases(struct signature *sig, FILE *fp, 74 struct interface *iface, int compound) 75 { 76 char *opcode, *opname, *protocol, *prefix, *ref, *s; 77 78 if (sig == NULL) 79 return; 80 81 opname = get_operation_name(iface, sig); 82 opcode = get_opcode_identifier(NULL, opname); 83 prefix = get_operation_wrapper_prefix(sig->attributes); 84 ref = get_object_conversion(iface, compound); 85 86 /* Generate a reply if appropriate. */ 87 88 if (have_attribute(sig->attributes, "completion")) 89 s = dispatch_function_wrapper_case; 90 else 91 s = dispatch_function_reply_wrapper_case; 92 93 /* Generate the case and invocation. */ 94 95 fprintf(fp, s, opcode, prefix, opname, ref); 96 97 /* Generate the other cases. */ 98 99 write_dispatcher_cases(sig->tail, fp, iface, compound); 100 101 /* Free allocated strings. */ 102 103 free(opcode); 104 free(opname); 105 free(ref); 106 }