1.1 --- a/common.c Tue Jul 07 23:07:30 2020 +0200
1.2 +++ b/common.c Wed Jul 08 00:42:34 2020 +0200
1.3 @@ -171,6 +171,21 @@
1.4 : GENERAL_FUNCTION_ROLE;
1.5 }
1.6
1.7 +enum specifier get_server_function_direction(enum function_role function)
1.8 +{
1.9 + switch (function)
1.10 + {
1.11 + case COMPLETION_ROLE:
1.12 + return IN_PARAMETER;
1.13 +
1.14 + case COMPLETION_REPLY_ROLE:
1.15 + return OUT_PARAMETER;
1.16 +
1.17 + default:
1.18 + return ANY_PARAMETER;
1.19 + }
1.20 +}
1.21 +
1.22 /* Obtain a suitable interface class name depending on the component role. */
1.23
1.24 char *get_interface_class_name(struct interface *iface,
1.25 @@ -276,7 +291,8 @@
1.26 enum parameter_role role,
1.27 enum function_role function)
1.28 {
1.29 - if ((param->specifier & OUT_PARAMETER) && (function != COMPLETION_ROLE))
1.30 + if ((param->specifier & OUT_PARAMETER) && (function != COMPLETION_ROLE) &&
1.31 + (function != COMPLETION_REPLY_ROLE))
1.32 {
1.33 switch (role)
1.34 {
2.1 --- a/common.h Tue Jul 07 23:07:30 2020 +0200
2.2 +++ b/common.h Wed Jul 08 00:42:34 2020 +0200
2.3 @@ -51,6 +51,8 @@
2.4
2.5 enum function_role get_server_function_role(struct signature *sig);
2.6
2.7 +enum specifier get_server_function_direction(enum function_role function);
2.8 +
2.9 /* Dispatcher object conversion (from compound to individual interfaces). */
2.10
2.11 char *get_object_conversion(struct interface *iface, int compound);
3.1 --- a/declaration.c Tue Jul 07 23:07:30 2020 +0200
3.2 +++ b/declaration.c Wed Jul 08 00:42:34 2020 +0200
3.3 @@ -39,11 +39,7 @@
3.4 int declaration = (role & DECLARATION_ROLE);
3.5 int member = (role & MEMBER_ROLE);
3.6 int server = (component == SERVER_ROLE);
3.7 -
3.8 - /* Explicit completion functions only employ input/inout parameters. */
3.9 -
3.10 - int completion = (function == COMPLETION_ROLE);
3.11 - enum specifier direction = completion ? IN_PARAMETER : ANY_PARAMETER;
3.12 + enum specifier direction = get_server_function_direction(function);
3.13
3.14 /* Indent and provide a qualifier for C++ class declarations. */
3.15
3.16 @@ -54,12 +50,18 @@
3.17 char *opname = get_signature_operation_name(iface, sig, component, role,
3.18 conf.language);
3.19
3.20 + /* Prefix any function name appropriately. */
3.21 +
3.22 + char *prefix = (function == COMPLETION_REPLY_ROLE) ? "complete_" : "";
3.23 +
3.24 /* Introduce an initial parameter for the component state. */
3.25
3.26 if (!cpp && member)
3.27 - fprintf(fp, interface_struct_member_function_signature_prologue, opname);
3.28 + fprintf(fp, interface_struct_member_function_signature_prologue, prefix,
3.29 + opname);
3.30 else
3.31 - fprintf(fp, interface_function_signature_prologue, qualifier, opname);
3.32 + fprintf(fp, interface_function_signature_prologue, qualifier, prefix,
3.33 + opname);
3.34
3.35 if (have_init_param)
3.36 write_initial_parameter(iface->name, fp);
3.37 @@ -72,17 +74,44 @@
3.38 fputs(")", fp);
3.39
3.40 /* Add a body for the function, this being used to define unimplemented
3.41 - methods in C++. The client has method definitions and therefore normal
3.42 - virtual methods. */
3.43 + methods or ahead-of-time reply completion functions in C++. The client
3.44 + has method definitions and therefore normal virtual methods. */
3.45
3.46 if (cpp && declaration && server)
3.47 - write_interface_unimplemented_method(sig, direction, fp);
3.48 + {
3.49 + if (function == COMPLETION_REPLY_ROLE)
3.50 + write_interface_completion_reply_method(sig, fp, iface);
3.51 + else
3.52 + write_interface_unimplemented_method(sig, direction, fp);
3.53 + }
3.54 else
3.55 fputs(get_signature_terminator(role), fp);
3.56
3.57 free(opname);
3.58 }
3.59
3.60 +/* Write a completion reply member function body for a C++ interface. */
3.61 +
3.62 +void write_interface_completion_reply_method(struct signature *sig,
3.63 + FILE *fp, struct interface *iface)
3.64 +{
3.65 + int have_init_param = (conf.language == C_LANGUAGE);
3.66 + char *opname = get_operation_name(iface, sig);
3.67 +
3.68 + fprintf(fp, interface_completion_reply_method_prologue_cpp, opname);
3.69 +
3.70 + if (have_init_param)
3.71 + write_initial_parameter(iface->name, fp);
3.72 +
3.73 + /* Write the parameters for an invocation of the server function completing an
3.74 + operation by sending a reply. */
3.75 +
3.76 + write_parameters(sig->parameters, fp, INVOCATION_ROLE, COMPLETION_ROLE,
3.77 + OUT_PARAMETER, have_init_param);
3.78 +
3.79 + fputs(interface_completion_reply_method_epilogue_cpp, fp);
3.80 +}
3.81 +
3.82 /* Write an unimplemented member function body for a C++ interface. */
3.83
3.84 void write_interface_unimplemented_method(struct signature *sig,
4.1 --- a/declaration.h Tue Jul 07 23:07:30 2020 +0200
4.2 +++ b/declaration.h Wed Jul 08 00:42:34 2020 +0200
4.3 @@ -31,6 +31,9 @@
4.4 enum function_role function, FILE *fp,
4.5 struct interface *iface);
4.6
4.7 +void write_interface_completion_reply_method(struct signature *sig,
4.8 + FILE *fp, struct interface *iface);
4.9 +
4.10 void write_interface_unimplemented_method(struct signature *sig,
4.11 enum specifier direction, FILE *fp);
4.12
5.1 --- a/server.c Tue Jul 07 23:07:30 2020 +0200
5.2 +++ b/server.c Wed Jul 08 00:42:34 2020 +0200
5.3 @@ -37,6 +37,11 @@
5.4 {
5.5 write_interface_signature(sig, role, SERVER_ROLE,
5.6 get_server_function_role(sig), fp, iface);
5.7 +
5.8 + /* Generate a signature for an ahead-of-time reply completion function. */
5.9 +
5.10 + write_interface_signature(sig, role, SERVER_ROLE, COMPLETION_REPLY_ROLE, fp,
5.11 + iface);
5.12 }
5.13
5.14 /* Generate signature declarations for each operation. */
5.15 @@ -98,7 +103,7 @@
5.16
5.17 char *prologue = completion ?
5.18 server_completion_function_signature_prologue :
5.19 - server_completion_optional_function_signature_prologue;
5.20 + server_completion_reply_function_signature_prologue;
5.21
5.22 fprintf(fp, prologue, opname, iface->name);
5.23
5.24 @@ -270,10 +275,10 @@
5.25 if (have_attribute(sig->attributes, "completion"))
5.26 fprintf(fp, server_completion_function_body_epilogue, "0", "_endp");
5.27
5.28 - /* Send a plain reply for optional/coupled completions. */
5.29 + /* Send a plain reply for reply/coupled completions. */
5.30
5.31 else
5.32 - fputs(server_completion_optional_function_body_epilogue, fp);
5.33 + fputs(server_completion_reply_function_body_epilogue, fp);
5.34
5.35 /* Free allocated strings. */
5.36
6.1 --- a/templates.h Tue Jul 07 23:07:30 2020 +0200
6.2 +++ b/templates.h Wed Jul 08 00:42:34 2020 +0200
6.3 @@ -195,7 +195,7 @@
6.4 #define server_completion_function_signature_prologue \
6.5 "\nlong complete_%s(l4_cap_idx_t _endp"
6.6
6.7 -#define server_completion_optional_function_signature_prologue \
6.8 +#define server_completion_reply_function_signature_prologue \
6.9 "\nlong complete_%s("
6.10
6.11 #define server_completion_function_body_prologue \
6.12 @@ -205,7 +205,7 @@
6.13 "\n ipc_message_send(&msg, %s, %s);\n\n" \
6.14 " return l4_error(msg.tag);\n"
6.15
6.16 -#define server_completion_optional_function_body_epilogue \
6.17 +#define server_completion_reply_function_body_epilogue \
6.18 "\n ipc_message_reply(&msg);\n\n" \
6.19 " return l4_error(msg.tag);\n"
6.20
6.21 @@ -245,10 +245,10 @@
6.22 "\n} iface_%s;\n"
6.23
6.24 #define interface_function_signature_prologue \
6.25 -"\n%slong %s("
6.26 +"\n%slong %s%s("
6.27
6.28 #define interface_struct_member_function_signature_prologue \
6.29 -"\n long (*%s)("
6.30 +"\n long (*%s%s)("
6.31
6.32 #define interface_unimplemented_method_prologue_cpp \
6.33 "\n {"
6.34 @@ -259,6 +259,15 @@
6.35 #define interface_unused_parameter \
6.36 " (void) %s;"
6.37
6.38 +#define interface_completion_reply_method_prologue_cpp \
6.39 +"\n" \
6.40 +" {\n" \
6.41 +" return complete_%s("
6.42 +
6.43 +#define interface_completion_reply_method_epilogue_cpp \
6.44 + ");\n" \
6.45 +" }\n"
6.46 +
6.47 /* Reference and object type definitions for interfaces. */
6.48
6.49 #define ref_type_definition_c \
7.1 --- a/types.h Tue Jul 07 23:07:30 2020 +0200
7.2 +++ b/types.h Wed Jul 08 00:42:34 2020 +0200
7.3 @@ -66,8 +66,9 @@
7.4
7.5 enum function_role
7.6 {
7.7 - COMPLETION_ROLE,
7.8 + COMPLETION_ROLE, /* decoupled input and output functions */
7.9 GENERAL_FUNCTION_ROLE,
7.10 + COMPLETION_REPLY_ROLE, /* completion for ahead-of-time reply */
7.11 };
7.12
7.13 /* Role of a parameter in output. */