1.1 --- a/client.c Wed Nov 13 01:35:02 2019 +0100
1.2 +++ b/client.c Wed Nov 13 17:23:17 2019 +0100
1.3 @@ -119,8 +119,7 @@
1.4
1.5 /* Send the request. */
1.6
1.7 - fprintf(fp, client_function_body_call, opcode,
1.8 - (output_language == CPP_LANGUAGE) ? "endpoint()" : "_endp");
1.9 + fprintf(fp, client_function_body_call, opcode, "_endp");
1.10
1.11 /* Retrieve output parameters from the message. */
1.12
2.1 --- a/common.c Wed Nov 13 01:35:02 2019 +0100
2.2 +++ b/common.c Wed Nov 13 17:23:17 2019 +0100
2.3 @@ -104,13 +104,39 @@
2.4 return get_attribute_value(attr, "protocol");
2.5 }
2.6
2.7 +/* Obtain a suitable interface class name depending on the component role. */
2.8 +
2.9 +char *get_interface_class_name(struct interface *iface,
2.10 + enum component_role component)
2.11 +{
2.12 + char *name;
2.13 +
2.14 + switch (component)
2.15 + {
2.16 + case CLIENT_ROLE:
2.17 + if (asprintf(&name, "%s_client", iface->name) == -1)
2.18 + name = NULL;
2.19 + break;
2.20 +
2.21 + case SERVER_ROLE:
2.22 + name = strdup(iface->name);
2.23 + break;
2.24 +
2.25 + default:
2.26 + name = NULL;
2.27 + }
2.28 +
2.29 + return name;
2.30 +}
2.31 +
2.32 /* Generate a qualified operation name for declarations and definitions. */
2.33
2.34 char *get_signature_operation_name(struct interface *iface,
2.35 struct signature *sig,
2.36 + enum component_role component,
2.37 enum signature_role role, enum language lang)
2.38 {
2.39 - char *opname;
2.40 + char *opname, *class_name;
2.41
2.42 switch (lang)
2.43 {
2.44 @@ -120,8 +146,12 @@
2.45 case CPP_LANGUAGE:
2.46 if (role == DEFINITION_ROLE)
2.47 {
2.48 - if (asprintf(&opname, "%s::%s", iface->name, sig->operation) == -1)
2.49 + class_name = get_interface_class_name(iface, component);
2.50 +
2.51 + if (asprintf(&opname, "%s::%s", class_name, sig->operation) == -1)
2.52 opname = NULL;
2.53 +
2.54 + free(class_name);
2.55 }
2.56 else
2.57 opname = strdup(sig->operation);
3.1 --- a/common.h Wed Nov 13 01:35:02 2019 +0100
3.2 +++ b/common.h Wed Nov 13 17:23:17 2019 +0100
3.3 @@ -43,10 +43,14 @@
3.4 char *get_opcode(struct attribute *attr);
3.5 char *get_protocol(struct attribute *attr);
3.6
3.7 -/* Interface structure access. */
3.8 +/* Interface and operation naming. */
3.9 +
3.10 +char *get_interface_class_name(struct interface *iface,
3.11 + enum component_role component);
3.12
3.13 char *get_signature_operation_name(struct interface *iface,
3.14 struct signature *sig,
3.15 + enum component_role component,
3.16 enum signature_role role,
3.17 enum language lang);
3.18
4.1 --- a/declaration.c Wed Nov 13 01:35:02 2019 +0100
4.2 +++ b/declaration.c Wed Nov 13 17:23:17 2019 +0100
4.3 @@ -48,7 +48,8 @@
4.4
4.5 /* Structure the function name appropriately. */
4.6
4.7 - char *opname = get_signature_operation_name(iface, sig, role, output_language);
4.8 + char *opname = get_signature_operation_name(iface, sig, component, role,
4.9 + output_language);
4.10
4.11 /* Determine a suitable initial parameter for the component. */
4.12
5.1 --- a/interface.c Wed Nov 13 01:35:02 2019 +0100
5.2 +++ b/interface.c Wed Nov 13 17:23:17 2019 +0100
5.3 @@ -19,6 +19,7 @@
5.4 * Boston, MA 02110-1301, USA
5.5 */
5.6
5.7 +#include <stdlib.h>
5.8 #include "client.h"
5.9 #include "common.h"
5.10 #include "declaration.h"
5.11 @@ -43,9 +44,10 @@
5.12 void write_interface_definition(struct interface *iface,
5.13 enum component_role component, FILE *fp)
5.14 {
5.15 - int input_items = get_max_input_items(iface->signatures);
5.16 int cpp = (output_language == CPP_LANGUAGE);
5.17 int client = (component == CLIENT_ROLE);
5.18 + int input_items = get_max_input_items(iface->signatures);
5.19 + char *class_name = get_interface_class_name(iface, component);
5.20
5.21 /* Emit include statements. */
5.22
5.23 @@ -55,7 +57,32 @@
5.24 /* Begin any namespace. */
5.25
5.26 if (cpp)
5.27 - fprintf(fp, interface_prologue_cpp, iface->name);
5.28 + {
5.29 + /* Define the class. */
5.30 +
5.31 + fprintf(fp, interface_prologue_cpp, class_name);
5.32 +
5.33 + /* Inherit from the actual interface in the client. */
5.34 +
5.35 + if (client)
5.36 + fprintf(fp, client_interface_prologue_cpp, iface->name);
5.37 +
5.38 + /* Start the class body. */
5.39 +
5.40 + fputs(BEGIN_CLASS, fp);
5.41 +
5.42 + /* Define any state. */
5.43 +
5.44 + if (client)
5.45 + fprintf(fp, client_interface_endpoint_declaration_cpp, L4_CAP_TYPE);
5.46 +
5.47 + fputs(interface_signatures_prologue_cpp, fp);
5.48 +
5.49 + /* Define a constructor. */
5.50 +
5.51 + if (client)
5.52 + fprintf(fp, client_interface_constructor_cpp, class_name, L4_CAP_TYPE);
5.53 + }
5.54
5.55 /* Emit signatures. */
5.56
5.57 @@ -63,15 +90,15 @@
5.58 client ? write_client_signature
5.59 : write_server_interface_signature);
5.60
5.61 - /* Client interfaces need an endpoint access method. */
5.62 -
5.63 - if (cpp && client)
5.64 - fprintf(fp, client_interface_endpoint_method, L4_CAP_TYPE);
5.65 -
5.66 /* Terminate any namespace. */
5.67
5.68 if (cpp)
5.69 fputs(interface_epilogue_cpp, fp);
5.70
5.71 - fprintf(fp, expected_items_definition, iface->name, input_items);
5.72 + /* Define the maximum number of expected items for the interface. */
5.73 +
5.74 + if (!client)
5.75 + fprintf(fp, expected_items_definition, iface->name, input_items);
5.76 +
5.77 + free(class_name);
5.78 }
6.1 --- a/program.c Wed Nov 13 01:35:02 2019 +0100
6.2 +++ b/program.c Wed Nov 13 17:23:17 2019 +0100
6.3 @@ -466,7 +466,15 @@
6.4 /* Emit the headers. */
6.5
6.6 if (client_header_fp != NULL)
6.7 + {
6.8 + /* Emit interface include where the type is employed by the client
6.9 + interface. */
6.10 +
6.11 + if (output_language == CPP_LANGUAGE)
6.12 + write_include(output_basename, "_interface.h", client_header_fp);
6.13 +
6.14 write_interface_definition(iface, CLIENT_ROLE, client_header_fp);
6.15 + }
6.16
6.17 if (server_header_fp != NULL)
6.18 {
7.1 --- a/server.c Wed Nov 13 01:35:02 2019 +0100
7.2 +++ b/server.c Wed Nov 13 17:23:17 2019 +0100
7.3 @@ -139,8 +139,8 @@
7.4 struct interface *iface, struct signature *sig)
7.5 {
7.6 char *name, *addr,
7.7 - *opname = get_signature_operation_name(iface, sig, ACCESS_ROLE,
7.8 - output_language);
7.9 + *opname = get_signature_operation_name(iface, sig, SERVER_ROLE,
7.10 + ACCESS_ROLE, output_language);
7.11
7.12 fputs("\n err = ", fp);
7.13
8.1 --- a/templates.h Wed Nov 13 01:35:02 2019 +0100
8.2 +++ b/templates.h Wed Nov 13 17:23:17 2019 +0100
8.3 @@ -56,9 +56,15 @@
8.4 #define client_function_signature_prologue_cpp \
8.5 "\n%slong %s("
8.6
8.7 -#define client_interface_endpoint_method \
8.8 -"\nprotected:\n" \
8.9 -" %s endpoint() = 0;\n"
8.10 +#define client_interface_prologue_cpp \
8.11 +" : public %s"
8.12 +
8.13 +#define client_interface_endpoint_declaration_cpp \
8.14 +"protected:\n" \
8.15 +" %s _endp;\n\n"
8.16 +
8.17 +#define client_interface_constructor_cpp \
8.18 +"\n %s(%s endp) : _endp(endp) { }\n"
8.19
8.20 /* Compound interface dispatcher templates. */
8.21
8.22 @@ -151,8 +157,9 @@
8.23
8.24 #define interface_prologue_cpp \
8.25 "\n#ifdef __cplusplus\n" \
8.26 -"\nclass %s\n" \
8.27 -"{\n" \
8.28 +"\nclass %s"
8.29 +
8.30 +#define interface_signatures_prologue_cpp \
8.31 "public:"
8.32
8.33 #define interface_epilogue_cpp \
8.34 @@ -178,5 +185,6 @@
8.35
8.36 #define COMPLETE_SIGNATURE ";\n"
8.37 #define END_SIGNATURE "\n"
8.38 +#define BEGIN_CLASS "\n{\n"
8.39 #define BEGIN_FUNCTION "\n{\n"
8.40 #define END_FUNCTION "}\n"