blob: 55e686e5660049b0c614a5ca9c00b867168809ed [file] [log] [blame]
{{/*
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
*/}}
{{- define "ProtocolDefinition" -}}
const (
{{- range .Methods }}
{{ .OrdinalName }} uint64 = {{ .Ordinal | printf "%#x" }}
{{- end }}
)
{{ if .Openness.IsClosed -}}
type {{ .ProxyName }} _bindings.{{ .ProxyType }}
{{ range .Methods }}
{{range .DocComments}}
//{{ . }}
{{- end}}
func (p *{{ $.ProxyName }}) {{ if .IsEvent -}}
{{ .EventExpectName }}
{{- else -}}
{{ .Name }}
{{- end -}}
{{- if .Request -}}
(ctx_ _bindings.Context, {{ .Request.NamesAndTypes }})
{{- else -}}
(ctx_ _bindings.Context)
{{- end -}}
{{- if .HasResponse -}}
{{- if .Response }} ({{ .Response.Types }}, error)
{{- else }} error{{ end -}}
{{- else }} error{{ end }} {
{{- if .HasRequest }}
{{- if .Request }}
req_ := &{{ .Request.Construct }}
{{- else }}
var req_ _bindings.Message
{{- end }}
{{- end }}
{{- if .HasResponse }}
{{- if .Response }}
resp_ := &{{ .Response.Name }}{}
{{- else }}
var resp_ _bindings.Message
{{- end }}
{{- end }}
{{- if .HasRequest }}
{{- if .HasResponse }}
err_ := ((*_bindings.{{ $.ProxyType }})(p)).Call({{ .OrdinalName }}, req_, resp_)
{{- else }}
err_ := ((*_bindings.{{ $.ProxyType }})(p)).Send({{ .OrdinalName }}, req_)
{{- end }}
{{- else }}
{{- if .HasResponse }}
err_ := ((*_bindings.{{ $.ProxyType }})(p)).Recv({{ .OrdinalName }}, resp_)
{{- else }}
err_ := nil
{{- end }}
{{- end }}
{{- if .HasResponse }}
{{- if .Response }}
return {{ call .Response.Destructure "(*resp_)" }}, err_
{{- else }}
return err_
{{- end }}
{{- else }}
return err_
{{- end }}
}
{{- end }}
{{range .DocComments}}
//{{ . }}
{{- end}}
type {{ .Name }} interface {
{{- range .Methods }}
{{- range .DocComments}}
//{{ . }}
{{- end}}
{{- if .HasRequest }}
{{- if .Request }}
{{ .Name }}(ctx_ _bindings.Context, {{ .Request.NamesAndTypes }})
{{- else }}
{{ .Name }}(ctx_ _bindings.Context)
{{- end }}
{{- if .HasResponse -}}
{{- if .Response }} ({{ .Response.Types }}, error)
{{- else }} error{{ end -}}
{{- else }} error{{ end }}
{{- end }}
{{- end }}
}
{{- if eq .ProxyType "ChannelProxy" }}
type {{ .RequestName }} _bindings.InterfaceRequest
func New{{ .RequestName }}() ({{ .RequestName }}, *{{ .ProxyName }}, error) {
req, cli, err := _bindings.NewInterfaceRequest()
return {{ .RequestName }}(req), (*{{ .ProxyName }})(cli), err
}
{{- if .ProtocolNameString }}
// Implements ServiceRequest.
func (_ {{ .RequestName }}) Name() string {
return {{ .ProtocolNameString }}
}
func (c {{ .RequestName }}) ToChannel() _zx.Channel {
return c.Channel
}
const {{ .ProtocolNameConstant }} = {{ .ProtocolNameString }}
{{- end }}
{{- end }}
type {{ .StubName }} struct {
Impl {{ .Name }}
}
func (s_ *{{ .StubName }}) Dispatch(args_ _bindings.DispatchArgs) (_bindings.Message, bool, error) {
switch args_.Ordinal {
{{- range .Methods }}
{{- if not .IsEvent }}
case {{ .OrdinalName }}:
{{- if .HasRequest }}
{{- if .Request }}
in_ := &{{ .Request.Name }}{}
marshalerCtx, ok := _bindings.GetMarshalerContext(args_.Ctx)
if !ok {
return nil, false, _bindings.ErrMissingMarshalerContext
}
if err_ := _bindings.Unmarshal(marshalerCtx, args_.Bytes, args_.HandleInfos, in_); err_ != nil {
return nil, false, err_
}
{{- end }}
{{- end }}
{{ if .Response }}{{- .Response.Names -}}, {{- end -}}
{{- if .Request -}}
err_ := s_.Impl.{{ .Name }}(args_.Ctx, {{ call .Request.Destructure "(*in_)" -}})
{{- else -}}
err_ := s_.Impl.{{ .Name }}(args_.Ctx)
{{- end -}}
{{- if .HasResponse }}
{{- if .Response }}
out_ := &{{ .Response.Construct }}
return out_, true, err_
{{- else }}
return nil, true, err_
{{- end }}
{{- else }}
return nil, false, err_
{{- end }}
{{- end }}
{{- end }}
}
return nil, false, _bindings.ErrUnknownOrdinal
}
type {{ .EventProxyName }} _bindings.{{ .ProxyType }}
{{ range .Methods }}
{{- if .IsEvent }}
func (p *{{ $.EventProxyName }}) {{ .Name }}(
{{- if .Response -}}
{{- .Response.NamesAndTypes -}}
{{- end -}}
) error {
{{- if .HasResponse }}
{{- if .Response }}
event_ := &{{ .Response.Construct }}
{{- else }}
var event_ _bindings.Message
{{- end }}
{{- end }}
return ((*_bindings.{{ $.ProxyType }})(p)).Send({{ .OrdinalName }}, event_)
}
{{- end }}
{{- end }}
{{- else }}{{/* end of if .Openness.IsClosed */}}
// Bindings for this protocol have not been generated because it is an
// {{ .Openness }} protocol. If bindings for {{ .Openness }} protocols are
// needed in Go, please contact the FIDL team: fidl-dev@fuchsia.dev.
type {{ .ProxyName }} _bindings.{{ .ProxyType }}
// Bindings for this protocol have not been generated because it is an
// {{ .Openness }} protocol. If bindings for {{ .Openness }} protocols are
// needed in Go, please contact the FIDL team: fidl-dev@fuchsia.dev.
type {{ .Name }} interface {}
{{- if eq .ProxyType "ChannelProxy" }}
type {{ .RequestName }} _bindings.InterfaceRequest
func New{{ .RequestName }}() ({{ .RequestName }}, *{{ .ProxyName }}, error) {
req, cli, err := _bindings.NewInterfaceRequest()
return {{ .RequestName }}(req), (*{{ .ProxyName }})(cli), err
}
{{- if .ProtocolNameString }}
// Implements ServiceRequest.
func (_ {{ .RequestName }}) Name() string {
return {{ .ProtocolNameString }}
}
func (c {{ .RequestName }}) ToChannel() _zx.Channel {
return c.Channel
}
const {{ .ProtocolNameConstant }} = {{ .ProtocolNameString }}
{{- end }}
{{- end }}
// Bindings for this protocol have not been generated because it is an
// {{ .Openness }} protocol. If bindings for {{ .Openness }} protocols are
// needed in Go, please contact the FIDL team: fidl-dev@fuchsia.dev.
type {{ .StubName }} struct {}
// Bindings for this protocol have not been generated because it is an
// {{ .Openness }} protocol. If bindings for {{ .Openness }} protocols are
// needed in Go, please contact the FIDL team: fidl-dev@fuchsia.dev.
type {{ .EventProxyName }} struct {}
{{- end }}{{/* end of else for if .Openness.IsClosed */}}
{{ end -}}