Debian Codegraph @

internal/lvgen/procedures.tmpl

raw
1 // Copyright 2018 The go-libvirt Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 //
16 // Code generated by internal/lvgen/generate.go. DO NOT EDIT.
17 //
18 // To regenerate, run 'go generate' in internal/lvgen.
19 //
20
21 package libvirt
22
23 import (
24 "bytes"
25 "io"
26
27 "github.com/digitalocean/go-libvirt/internal/constants"
28 "github.com/digitalocean/go-libvirt/internal/go-xdr/xdr2"
29 )
30
31 // References to prevent "imported and not used" errors.
32 var (
33 _ = bytes.Buffer{}
34 _ = io.Copy
35 _ = constants.Program
36 _ = xdr.Unmarshal
37 )
38
39 //
40 // Typedefs:
41 //
42 {{range .Typedefs}}// {{.Name}} is libvirt's {{.LVName}}
43 type {{.Name}} {{.Type}}
44 {{end}}
45 //
46 // Enums:
47 //
48 {{range .Enums}}// {{.Name}} is libvirt's {{.LVName}}
49 type {{.Name}} {{.Type}}
50 {{end}}
51 //
52 // Structs:
53 //
54 {{range .Structs}}// {{.Name}} is libvirt's {{.LVName}}
55 type {{.Name}} struct {
56 {{range .Members}} {{.Name}} {{.Type}}
57 {{end -}}
58 }
59
60 {{end}}
61 {{range .Unions}}// {{.Name}} is a discriminated union.
62 type {{.Name}} struct {
63 D uint32
64 I interface{}
65 }
66 {{end -}}
67 {{range .Unions}}{{$uname := .Name}}{{range .Cases}}{{$casetype := printf "%v%v" $uname .CaseName}}
68 // New{{$casetype}} creates a discriminated union value satisfying
69 // the {{$uname}} interface.
70 func New{{$casetype}}(v {{.Type}}) *{{$uname}} {
71 return &{{$uname}}{D: {{.DiscriminantVal}}, I: v}
72 }
73 {{end}}
74 {{- end}}
75 {{range $proc := .Procs}}
76 // {{.Name}} is the go wrapper for {{.LVName}}.
77 func (l *Libvirt) {{.Name}}(
78 {{- range $ix, $arg := .Args}}
79 {{- if (eq $ix $proc.WriteStreamIdx)}}{{if $ix}}, {{end}}outStream io.Reader{{end}}
80 {{- if (eq $ix $proc.ReadStreamIdx)}}{{if $ix}}, {{end}}inStream io.Writer{{end}}
81 {{- if $ix}}, {{end}}{{.Name}} {{.Type}}
82 {{- end -}}
83 ) ({{range .Ret}}r{{.Name}} {{.Type}}, {{end}}err error) {
84 var buf []byte
85 {{if .ArgsStruct}}
86 args := {{.ArgsStruct}} {
87 {{range .Args}} {{.Name}}: {{.Name}},
88 {{end}} }
89
90 buf, err = encode(&args)
91 if err != nil {
92 return
93 }
94 {{end}}
95 {{if .RetStruct}} var r response{{end}}
96 {{if .RetStruct}}r{{else}}_{{end}}, err = l.requestStream({{.Num}}, constants.{{.Program}}Program, buf,
97 {{- if (ne .WriteStreamIdx -1)}} outStream,{{else}} nil,{{end}}
98 {{- if (ne .ReadStreamIdx -1)}} inStream{{else}} nil{{end -}}
99 )
100 if err != nil {
101 return
102 }
103 {{if .RetStruct}}
104 // Return value unmarshaling
105 tpd := typedParamDecoder{}
106 ct := map[string]xdr.TypeDecoder{"libvirt.TypedParam": tpd}
107 rdr := bytes.NewReader(r.Payload)
108 dec := xdr.NewDecoderCustomTypes(rdr, 0, ct)
109 {{range .Ret}} // {{.Name}}: {{.Type}}
110 _, err = dec.Decode(&r{{.Name}})
111 if err != nil {
112 return
113 }
114 {{end}}{{end}}
115 return
116 }
117 {{end}}