Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Unified Diff: mojo/public/tools/bindings/generators/go_templates/interface.tmpl

Issue 1345263002: Generate Mojom Types in Go (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Use unexported functions instead of variables Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/go_templates/interface.tmpl
diff --git a/mojo/public/tools/bindings/generators/go_templates/interface.tmpl b/mojo/public/tools/bindings/generators/go_templates/interface.tmpl
index 1b9160f82d05f4b50017b523482c9f1ea3ba09f9..55a29760c6991e70fcebe3d35a0eb6ee4fa0bd4c 100644
--- a/mojo/public/tools/bindings/generators/go_templates/interface.tmpl
+++ b/mojo/public/tools/bindings/generators/go_templates/interface.tmpl
@@ -3,6 +3,7 @@
// found in the LICENSE file.
{% import "struct.tmpl" as struct_macros %}
+{% import "mojom_util_macros.tmpl" as util %}
{%- macro declare_params(struct) %}
{%- for field in struct.fields -%}
@@ -35,7 +36,7 @@
-{% macro define(interface) %}
+{% macro define(interface, descpkg, typepkg, pkg) %}
type {{interface|name}} interface {
{% for method in interface.methods %}
{{method|name}}{{declare_request_params(method)}}
@@ -101,9 +102,9 @@ func (p *{{interface|name}}_Proxy) Close_Proxy() {
}
{% for method in interface.methods %}
-{{struct_macros.define(method.param_struct, False)}}
+{{struct_macros.define(method.param_struct, typepkg, pkg, False)}}
{%- if method|has_response %}
-{{struct_macros.define(method.response_param_struct, False)}}
+{{struct_macros.define(method.response_param_struct, typepkg, pkg, False)}}
{%- endif %}
func (p *{{interface|name}}_Proxy) {{method|name}}{{declare_request_params(method)}} {
payload := &{{method.param_struct|name(False)}}{
@@ -170,6 +171,70 @@ func New{{interface|name}}Stub(r {{interface|name}}_Request, impl {{interface|na
return bindings.NewStub(connector, &{{interface|name(False)}}_Stub{connector, impl})
}
+var (
+ interfaceName_{{interface|name}} = "{{interface|name}}"
+{% for method in interface.methods %}
+ interfaceMethodName_{{interface|name}}_{{method|name}} = "{{method|name}}"
+{% endfor %}
+)
+
+func {{util.typeName(interface, typepkg, pkg)}}() {{typepkg}}MojomInterface {
+ responseParamsMap := make(map[string]*{{typepkg}}MojomStruct)
+ _ = responseParamsMap // To avoid the declared but unused compiler error
+{% for method in interface.methods %}
+ {% if method|has_response %}
+ mstruct_{{method|name}} := {{util.typeName(method.response_param_struct, typepkg, pkg)}}()
+ responseParamsMap[interfaceMethodName_{{interface|name}}_{{method|name}}] = &mstruct_{{method|name}}
+ {% endif %}
+{% endfor %}
+ return {{typepkg}}MojomInterface{
+ DeclData: &{{typepkg}}DeclarationData{
+ ShortName: &interfaceName_{{interface|name}},
+ },
+ Methods: map[uint32]{{typepkg}}MojomMethod{
+{%- for method in interface.methods -%}
+ {{interface|name(False)}}_{{method|name}}_Name: {{typepkg}}MojomMethod{
+ DeclData: &{{typepkg}}DeclarationData{
+ ShortName: &interfaceMethodName_{{interface|name}}_{{method|name}},
+ },
+ Parameters: {{util.typeName(method.param_struct, typepkg, pkg)}}(),
+ ResponseParams: responseParamsMap[interfaceMethodName_{{interface|name}}_{{method|name}}],
+ },
+{%- endfor -%}
+ },
+ }
+}
+func (r *{{interface|name}}_Request) Type() {{typepkg}}MojomInterface {
+ return {{util.typeName(interface, typepkg, pkg)}}()
+}
+
+func (r *{{interface|name}}_Request) Desc() map[string]{{typepkg}}UserDefinedType {
+ return Descriptor()
+}
+
+
+
+type {{interface|name}}_ServiceDescription struct{}
+
+func (sd *{{interface|name}}_ServiceDescription) GetTopLevelInterface() (outMojomInterface {{typepkg}}MojomInterface, err error) {
+ return {{util.typeName(interface, typepkg, pkg)}}(), nil
+}
+
+func (sd *{{interface|name}}_ServiceDescription) GetTypeDefinition(inTypeKey string) (outType mojom_types.UserDefinedType, err error) {
+ if udt, ok := Descriptor()[inTypeKey]; ok {
+ return udt, nil
+ }
+ return nil, fmt.Errorf("%s_ServiceDescription does not recognize %s", "{{interface|name}}", inTypeKey)
+}
+
+func (sd *{{interface|name}}_ServiceDescription) GetAllTypeDefinitions() (outDefinitions *map[string]mojom_types.UserDefinedType, err error) {
+ o := Descriptor()
+ return &o, nil
+}
+
+var _ {{descpkg}}ServiceDescription = (*{{interface|name}}_ServiceDescription)(nil)
+
+
func (s *{{interface|name(False)}}_Stub) Accept(message *bindings.Message) (err error) {
switch message.Header.Type {
{% for method in interface.methods %}

Powered by Google App Engine
This is Rietveld 408576698