blob: 0b5b45a5f4cfd63ddf432ee3708bd6b42cf3bee6 [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" -}}
{{- $protocol := . }}
const (
{{- range $method := $protocol.Methods }}
{{ $method.OrdinalName }} uint64 = {{ $method.Ordinal | printf "%#x" }}
{{- end }}
)
{{ if $protocol.Openness.IsClosed -}}
type {{ $protocol.ProxyName }} _bindings.{{ $protocol.ProxyType }}
{{ range $method := $protocol.Methods }}
{{ range $comment := $method.DocComments }}
//{{ $comment }}
{{- end }}
func (p *{{ $.ProxyName }}) {{ if $method.IsEvent -}}
{{ $method.EventExpectName }}
{{- else -}}
{{ $method.Name }}
{{- end -}}
{{- if $method.Request -}}
(ctx_ _bindings.Context, {{ $method.Request.NamesAndTypes }})
{{- else -}}
(ctx_ _bindings.Context)
{{- end -}}
{{- if $method.HasResponse -}}
{{- if $method.Response }} ({{ $method.Response.Types }}, error)
{{- else }} error{{ end -}}
{{- else }} error{{ end }} {
{{- if $method.HasRequest }}
{{- if $method.Request }}
req_ := &{{ $method.Request.Construct }}
{{- else }}
var req_ _bindings.Message
{{- end }}
{{- end }}
{{- if $method.HasResponse }}
{{- if $method.Response }}
resp_ := &{{ $method.Response.Name }}{}
{{- else }}
var resp_ _bindings.Message
{{- end }}
{{- end }}
{{- if $method.HasRequest }}
{{- if $method.HasResponse }}
err_ := ((*_bindings.{{ $protocol.ProxyType }})(p)).Call({{ $method.OrdinalName }}, req_, resp_)
{{- else }}
err_ := ((*_bindings.{{ $protocol.ProxyType }})(p)).Send({{ $method.OrdinalName }}, req_)
{{- end }}
{{- else }}
{{- if $method.HasResponse }}
err_ := ((*_bindings.{{ $protocol.ProxyType }})(p)).Recv({{ $method.OrdinalName }}, resp_)
{{- else }}
err_ := nil
{{- end }}
{{- end }}
{{- if $method.HasResponse }}
{{- if $method.Response }}
return {{ call $method.Response.Destructure "(*resp_)" }}, err_
{{- else }}
return err_
{{- end }}
{{- else }}
return err_
{{- end }}
}
{{- end }}
{{ range $comment := .DocComments }}
//{{ $comment }}
{{- end }}
type {{ $protocol.Name }} interface {
{{- range $method := $protocol.Methods }}
{{- range $comment := $method.DocComments }}
//{{ $comment }}
{{- end }}
{{- if $method.HasRequest }}
{{- if $method.Request }}
{{ $method.Name }}(ctx_ _bindings.Context, {{ $method.Request.NamesAndTypes }})
{{- else }}
{{ $method.Name }}(ctx_ _bindings.Context)
{{- end }}
{{- if $method.HasResponse -}}
{{- if $method.Response }} ({{ $method.Response.Types }}, error)
{{- else }} error{{ end -}}
{{- else }} error{{ end }}
{{- end }}
{{- end }}
}
{{- if eq $protocol.ProxyType "ChannelProxy" }}
type {{ $protocol.RequestName }} _bindings.InterfaceRequest
func New{{ $protocol.RequestName }}() ({{ $protocol.RequestName }}, *{{ $protocol.ProxyName }}, error) {
req, cli, err := _bindings.NewInterfaceRequest()
return {{ $protocol.RequestName }}(req), (*{{ $protocol.ProxyName }})(cli), err
}
{{- if $protocol.ProtocolNameString }}
// Implements ServiceRequest.
func (_ {{ $protocol.RequestName }}) Name() string {
return {{ $protocol.ProtocolNameString }}
}
func (c {{ $protocol.RequestName }}) ToChannel() _zx.Channel {
return c.Channel
}
const {{ $protocol.ProtocolNameConstant }} = {{ $protocol.ProtocolNameString }}
{{- end }}
{{- end }}
type {{ $protocol.StubName }} struct {
Impl {{ $protocol.Name }}
}
func (s_ *{{ $protocol.StubName }}) Dispatch(args_ _bindings.DispatchArgs) (_bindings.Message, bool, error) {
switch args_.Ordinal {
{{- range $method := $protocol.Methods }}
{{- if not $method.IsEvent }}
case {{ $method.OrdinalName }}:
{{- if $method.HasRequest }}
{{- if $method.Request }}
in_ := &{{ $method.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 $method.Response }}{{- $method.Response.Names -}}, {{- end -}}
{{- if $method.Request -}}
err_ := s_.Impl.{{ $method.Name }}(args_.Ctx, {{ call $method.Request.Destructure "(*in_)" -}})
{{- else -}}
err_ := s_.Impl.{{ $method.Name }}(args_.Ctx)
{{- end -}}
{{- if $method.HasResponse }}
{{- if $method.Response }}
out_ := &{{ $method.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 {{ $protocol.EventProxyName }} _bindings.{{ $protocol.ProxyType }}
{{ range $method := $protocol.Methods }}
{{- if $method.IsEvent }}
func (p *{{ $protocol.EventProxyName }}) {{ $method.Name }}(
{{- if $method.Response -}}
{{- $method.Response.NamesAndTypes -}}
{{- end -}}
) error {
{{- if $method.HasResponse }}
{{- if $method.Response }}
event_ := &{{ $method.Response.Construct }}
{{- else }}
var event_ _bindings.Message
{{- end }}
{{- end }}
return ((*_bindings.{{ $protocol.ProxyType }})(p)).Send({{ $method.OrdinalName }}, event_)
}
{{- end }}
{{- end }}
{{- else }}{{/* end of if $protocol.Openness.IsClosed */}}
// Bindings for this protocol have not been generated because it is an
// {{ $protocol.Openness }} protocol. If bindings for {{ $protocol.Openness }} protocols are
// needed in Go, please contact the FIDL team: fidl-dev@fuchsia.dev.
type {{ $protocol.ProxyName }} _bindings.{{ $protocol.ProxyType }}
// Bindings for this protocol have not been generated because it is an
// {{ $protocol.Openness }} protocol. If bindings for {{ $protocol.Openness }} protocols are
// needed in Go, please contact the FIDL team: fidl-dev@fuchsia.dev.
type {{ $protocol.Name }} interface {}
{{- if eq $protocol.ProxyType "ChannelProxy" }}
type {{ $protocol.RequestName }} _bindings.InterfaceRequest
func New{{ $protocol.RequestName }}() ({{ $protocol.RequestName }}, *{{ $protocol.ProxyName }}, error) {
req, cli, err := _bindings.NewInterfaceRequest()
return {{ $protocol.RequestName }}(req), (*{{ $protocol.ProxyName }})(cli), err
}
{{- if $protocol.ProtocolNameString }}
// Implements ServiceRequest.
func (_ {{ $protocol.RequestName }}) Name() string {
return {{ $protocol.ProtocolNameString }}
}
func (c {{ $protocol.RequestName }}) ToChannel() _zx.Channel {
return c.Channel
}
const {{ $protocol.ProtocolNameConstant }} = {{ $protocol.ProtocolNameString }}
{{- end }}
{{- end }}
// Bindings for this protocol have not been generated because it is an
// {{ $protocol.Openness }} protocol. If bindings for {{ $protocol.Openness }} protocols are
// needed in Go, please contact the FIDL team: fidl-dev@fuchsia.dev.
type {{ $protocol.StubName }} struct {}
// Bindings for this protocol have not been generated because it is an
// {{ $protocol.Openness }} protocol. If bindings for {{ $protocol.Openness }} protocols are
// needed in Go, please contact the FIDL team: fidl-dev@fuchsia.dev.
type {{ $protocol.EventProxyName }} struct {}
{{- end }}{{/* end of else for if $protocol.Openness.IsClosed */}}
{{ end -}}