1.1 --- a/dispatch.c Mon Nov 11 21:30:31 2019 +0100
1.2 +++ b/dispatch.c Mon Nov 11 23:18:28 2019 +0100
1.3 @@ -1,5 +1,5 @@
1.4 /*
1.5 - * Generation of server dispatch functions.
1.6 + * Generation of server dispatch and handle functions.
1.7 *
1.8 * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 @@ -32,23 +32,31 @@
1.11
1.12
1.13
1.14 -/* Generate a dispatch function signature for the interface. */
1.15 +/* Generate dispatch function signatures. */
1.16
1.17 -void write_dispatcher_signature(FILE *fp, struct interface *iface)
1.18 +void write_dispatcher_signature(const char *name, const char *following, FILE *fp)
1.19 {
1.20 - char *type = (output_language == CPP_LANGUAGE) ? iface->name : "void";
1.21 + const char *type = (output_language == CPP_LANGUAGE) ? name : "void";
1.22 +
1.23 + fprintf(fp, dispatch_function_signature, name, type);
1.24 + fputs(following, fp);
1.25 +}
1.26
1.27 - fprintf(fp, "\nvoid dispatch_%s(ipc_message_t *msg, %s *_self);\n", iface->name, type);
1.28 +/* Generate handler function signatures. */
1.29 +
1.30 +void write_handler_signature(const char *name, const char *following, FILE *fp)
1.31 +{
1.32 + const char *type = (output_language == CPP_LANGUAGE) ? name : "void";
1.33 +
1.34 + fprintf(fp, handle_function_signature, name, type);
1.35 + fputs(following, fp);
1.36 }
1.37
1.38 /* Generate a dispatch function for the different operations. */
1.39
1.40 void write_dispatcher(struct signature *sig, FILE *fp, struct interface *iface)
1.41 {
1.42 - char *type = (output_language == CPP_LANGUAGE) ? iface->name : "void";
1.43 -
1.44 - fprintf(fp, "\nvoid dispatch_%s(ipc_message_t *msg, %s *_self)\n{\n",
1.45 - iface->name, type);
1.46 + write_dispatcher_signature(iface->name, BEGIN_FUNCTION, fp);
1.47
1.48 /* Interpret an operation indicator in the word data if a protocol applies to
1.49 the entire interface. */
2.1 --- a/dispatch.h Mon Nov 11 21:30:31 2019 +0100
2.2 +++ b/dispatch.h Mon Nov 11 23:18:28 2019 +0100
2.3 @@ -1,5 +1,5 @@
2.4 /*
2.5 - * Generation of server dispatch functions.
2.6 + * Generation of server dispatch and handle functions.
2.7 *
2.8 * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
2.9 *
2.10 @@ -26,4 +26,5 @@
2.11
2.12 void write_dispatcher(struct signature *sig, FILE *fp, struct interface *iface);
2.13 void write_dispatcher_cases(struct signature *sig, FILE *fp, struct interface *iface);
2.14 -void write_dispatcher_signature(FILE *fp, struct interface *iface);
2.15 +void write_dispatcher_signature(const char *name, const char *following, FILE *fp);
2.16 +void write_handler_signature(const char *name, const char *following, FILE *fp);
3.1 --- a/program.c Mon Nov 11 21:30:31 2019 +0100
3.2 +++ b/program.c Mon Nov 11 23:18:28 2019 +0100
3.3 @@ -176,16 +176,14 @@
3.4 {
3.5 fprintf(compound_dispatch_fp, compound_dispatch_prologue, output_compound);
3.6
3.7 - /* Write the handler function. */
3.8 + /* Write the handle function and dispatch function prologue. */
3.9
3.10 - write_compound_handler_signature(compound_dispatch_fp);
3.11 - fputs("\n", compound_dispatch_fp);
3.12 - fprintf(compound_dispatch_fp, compound_handle_function, output_compound_name);
3.13 + write_handler_signature(output_compound_name, END_SIGNATURE,
3.14 + compound_dispatch_fp);
3.15 + fprintf(compound_dispatch_fp, handle_function, output_compound_name);
3.16
3.17 - /* Write the dispatch function. */
3.18 -
3.19 - write_compound_dispatch_signature(compound_dispatch_fp);
3.20 - fputs("\n", compound_dispatch_fp);
3.21 + write_dispatcher_signature(output_compound_name, END_SIGNATURE,
3.22 + compound_dispatch_fp);
3.23 fputs(compound_dispatch_function_prologue, compound_dispatch_fp);
3.24 }
3.25
3.26 @@ -194,15 +192,13 @@
3.27 fprintf(compound_dispatch_header_fp, compound_dispatch_header_prologue,
3.28 output_compound);
3.29
3.30 - /* Write the handler signature. */
3.31 -
3.32 - write_compound_handler_signature(compound_dispatch_header_fp);
3.33 - fputs(";\n", compound_dispatch_header_fp);
3.34 + /* Write the handler and dispatch signatures. */
3.35
3.36 - /* Write the dispatch signature. */
3.37 + write_handler_signature(output_compound_name, COMPLETE_SIGNATURE,
3.38 + compound_dispatch_header_fp);
3.39
3.40 - write_compound_dispatch_signature(compound_dispatch_header_fp);
3.41 - fputs(";\n\n", compound_dispatch_header_fp);
3.42 + write_dispatcher_signature(output_compound_name, COMPLETE_SIGNATURE "\n",
3.43 + compound_dispatch_header_fp);
3.44 }
3.45
3.46 if (compound_interface_fp != NULL)
3.47 @@ -278,24 +274,6 @@
3.48 }
3.49 }
3.50
3.51 -void write_compound_dispatch_signature(FILE *fp)
3.52 -{
3.53 - char *s = (output_language == CPP_LANGUAGE) ?
3.54 - compound_dispatch_function_signature_cpp :
3.55 - compound_dispatch_function_signature_c;
3.56 -
3.57 - fprintf(fp, s, output_compound_name, output_compound_name);
3.58 -}
3.59 -
3.60 -void write_compound_handler_signature(FILE *fp)
3.61 -{
3.62 - char *s = (output_language == CPP_LANGUAGE) ?
3.63 - compound_handle_function_signature_cpp :
3.64 - compound_handle_function_signature_c;
3.65 -
3.66 - fprintf(fp, s, output_compound_name, output_compound_name);
3.67 -}
3.68 -
3.69 /* Augment a compound interface class declaration. */
3.70
3.71 void write_compound_interface(struct interface *iface)
3.72 @@ -484,6 +462,11 @@
3.73 write_functions(iface->signatures, server_fp, iface,
3.74 write_server_function);
3.75
3.76 + /* Emit handle and dispatch functions. */
3.77 +
3.78 + write_handler_signature(iface->name, END_SIGNATURE, server_fp);
3.79 + fprintf(server_fp, handle_function, iface->name);
3.80 +
3.81 write_dispatcher(iface->signatures, server_fp, iface);
3.82 }
3.83
3.84 @@ -514,7 +497,10 @@
3.85 write_signatures(iface->signatures, server_header_fp, iface,
3.86 write_server_signature);
3.87
3.88 - write_dispatcher_signature(server_header_fp, iface);
3.89 + /* Emit dispatch and handle function signatures. */
3.90 +
3.91 + write_dispatcher_signature(iface->name, COMPLETE_SIGNATURE, server_header_fp);
3.92 + write_handler_signature(iface->name, COMPLETE_SIGNATURE, server_header_fp);
3.93 }
3.94
3.95 if (server_interface_fp != NULL)
4.1 --- a/program.h Mon Nov 11 21:30:31 2019 +0100
4.2 +++ b/program.h Mon Nov 11 23:18:28 2019 +0100
4.3 @@ -29,8 +29,6 @@
4.4 void begin_compound_output(void);
4.5 void write_compound_output(struct interface *iface);
4.6 void write_compound_dispatch_include(void);
4.7 -void write_compound_dispatch_signature(FILE *fp);
4.8 -void write_compound_handler_signature(FILE *fp);
4.9 void write_compound_interface(struct interface *iface);
4.10 void end_compound_output(void);
4.11
5.1 --- a/templates.h Mon Nov 11 21:30:31 2019 +0100
5.2 +++ b/templates.h Mon Nov 11 23:18:28 2019 +0100
5.3 @@ -54,26 +54,6 @@
5.4 #define compound_dispatch_prologue \
5.5 "#include \"%s_server.h\"\n"
5.6
5.7 -#define compound_handle_function_signature_c \
5.8 -"\nvoid %s_handle(ipc_message_t *msg, void *_self)"
5.9 -
5.10 -#define compound_handle_function_signature_cpp \
5.11 -"\nvoid %s_handle(ipc_message_t *msg, %s *_self)"
5.12 -
5.13 -#define compound_handle_function \
5.14 -"{\n" \
5.15 -" ipc_message_open(msg);\n" \
5.16 -" %s_dispatch(msg, _self);\n" \
5.17 -" ipc_message_reply(msg);\n" \
5.18 -" ipc_message_discard(msg);\n" \
5.19 -"}\n"
5.20 -
5.21 -#define compound_dispatch_function_signature_c \
5.22 -"\nvoid %s_dispatch(ipc_message_t *msg, void *_self)"
5.23 -
5.24 -#define compound_dispatch_function_signature_cpp \
5.25 -"\nvoid %s_dispatch(ipc_message_t *msg, %s *_self)"
5.26 -
5.27 #define compound_dispatch_function_prologue \
5.28 "{\n" \
5.29 " switch (l4_msgtag_label(msg->tag))\n" \
5.30 @@ -109,6 +89,24 @@
5.31 #define compound_interfaces_prologue \
5.32 "#pragma once\n\n"
5.33
5.34 +/* Dispatch functions. */
5.35 +
5.36 +#define dispatch_function_signature \
5.37 +"\nvoid dispatch_%s(ipc_message_t *msg, %s *_self)"
5.38 +
5.39 +/* Message handling functions. */
5.40 +
5.41 +#define handle_function_signature \
5.42 +"\nvoid handle_%s(ipc_message_t *msg, %s *_self)"
5.43 +
5.44 +#define handle_function \
5.45 +"{\n" \
5.46 +" ipc_message_open(msg);\n" \
5.47 +" dispatch_%s(msg, _self);\n" \
5.48 +" ipc_message_reply(msg);\n" \
5.49 +" ipc_message_discard(msg);\n" \
5.50 +"}\n"
5.51 +
5.52 /* General header template. */
5.53
5.54 #define header_prologue \
5.55 @@ -159,3 +157,10 @@
5.56 " case %s:\n" \
5.57 " ipc_message_send_error(msg, wrap_%s(msg, _self));\n" \
5.58 " break;\n\n"
5.59 +
5.60 +/* Tokens. */
5.61 +
5.62 +#define COMPLETE_SIGNATURE ";\n"
5.63 +#define END_SIGNATURE "\n"
5.64 +#define BEGIN_FUNCTION "\n{\n"
5.65 +#define END_FUNCTION "}\n"