2017-11-17 02:44:11 +03:00
|
|
|
// Copyright 2017 The go-libvirt Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-11-17 03:14:34 +03:00
|
|
|
//
|
|
|
|
// Code generated by internal/lvgen/generate.go. DO NOT EDIT.
|
|
|
|
//
|
|
|
|
// To regenerate, run 'go generate' in internal/lvgen.
|
|
|
|
//
|
2017-11-08 00:05:12 +03:00
|
|
|
|
|
|
|
package libvirt
|
|
|
|
|
2017-11-13 23:18:18 +03:00
|
|
|
import (
|
|
|
|
"bytes"
|
2017-11-15 02:59:55 +03:00
|
|
|
"fmt"
|
2017-11-13 23:18:18 +03:00
|
|
|
|
|
|
|
"github.com/davecgh/go-xdr/xdr2"
|
|
|
|
"github.com/digitalocean/go-libvirt/internal/constants"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
VirUUIDBuflen = 16
|
|
|
|
)
|
|
|
|
|
2017-11-17 01:14:05 +03:00
|
|
|
//
|
2017-11-08 00:05:12 +03:00
|
|
|
// Typedefs:
|
2017-11-17 01:14:05 +03:00
|
|
|
//
|
|
|
|
{{range .Typedefs}}// {{.Name}} is libvirt's {{.LVName}}
|
|
|
|
type {{.Name}} {{.Type}}
|
2017-11-08 00:05:12 +03:00
|
|
|
{{end}}
|
2017-11-17 01:14:05 +03:00
|
|
|
//
|
2017-11-08 00:05:12 +03:00
|
|
|
// Enums:
|
2017-11-17 01:14:05 +03:00
|
|
|
//
|
|
|
|
{{range .Enums}}// {{.Name}} is libvirt's {{.LVName}}
|
|
|
|
type {{.Name}} {{.Type}}
|
2017-11-08 00:05:12 +03:00
|
|
|
{{end}}
|
2017-11-17 01:14:05 +03:00
|
|
|
//
|
2017-11-08 00:05:12 +03:00
|
|
|
// Structs:
|
2017-11-17 01:14:05 +03:00
|
|
|
//
|
|
|
|
{{range .Structs}}// {{.Name}} is libvirt's {{.LVName}}
|
|
|
|
type {{.Name}} struct {
|
2017-11-08 00:05:12 +03:00
|
|
|
{{range .Members}} {{.Name}} {{.Type}}
|
|
|
|
{{end -}}
|
|
|
|
}
|
2017-11-13 23:18:18 +03:00
|
|
|
|
2017-11-08 00:05:12 +03:00
|
|
|
{{end}}
|
2017-11-17 01:14:05 +03:00
|
|
|
{{range .Unions}}// {{.Name}} is a discriminated union.
|
|
|
|
type {{.Name}} interface {
|
2017-11-13 23:18:18 +03:00
|
|
|
Get() interface{}
|
2017-11-08 00:05:12 +03:00
|
|
|
{{end -}}
|
|
|
|
}
|
2017-11-13 23:18:18 +03:00
|
|
|
{{range .Unions}}{{$uname := .Name}}{{range .Cases}}{{$casetype := printf "%v%v" $uname .CaseName}}
|
2017-11-17 01:14:05 +03:00
|
|
|
// {{$casetype}} is one of the possible values of the {{$uname}} union.
|
2017-11-13 23:18:18 +03:00
|
|
|
type {{$casetype}} struct {
|
|
|
|
DVal uint32
|
|
|
|
{{.Name}} {{.Type}}
|
|
|
|
}
|
2017-11-17 01:14:05 +03:00
|
|
|
// New{{$casetype}} creates a discriminated union value satisfying
|
|
|
|
// the {{$uname}} interface.
|
2017-11-16 22:17:46 +03:00
|
|
|
func New{{$casetype}}(v {{.Type}}) *{{$casetype}} {
|
|
|
|
return &{{$casetype}}{DVal: {{.DiscriminantVal}}, {{.Name}}: v}
|
|
|
|
}
|
|
|
|
func decode{{$casetype}}(dec *xdr.Decoder) (*{{$casetype}}, error) {
|
2017-11-15 02:59:55 +03:00
|
|
|
var v {{.Type}}
|
|
|
|
_, err := dec.Decode(&v)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return New{{$casetype}}(v), nil
|
|
|
|
}
|
2017-11-17 01:14:05 +03:00
|
|
|
// Get satisfies the {{$uname}} interface.
|
2017-11-13 23:18:18 +03:00
|
|
|
func (c *{{$casetype}}) Get() interface{} { return c.{{.Name}} }
|
|
|
|
{{end}}
|
2017-11-16 22:17:46 +03:00
|
|
|
func decode{{.Name}}(dec *xdr.Decoder) ({{.Name}}, error) {
|
|
|
|
discriminant, _, err := dec.DecodeInt()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var caseval {{.Name}}
|
|
|
|
switch discriminant {
|
|
|
|
{{range .Cases}}{{$casetype := printf "%v%v" $uname .CaseName}} case {{.DiscriminantVal}}:
|
|
|
|
caseval, err = decode{{$casetype}}(dec)
|
|
|
|
{{end}}
|
|
|
|
default:
|
|
|
|
err = fmt.Errorf("invalid parameter type %v", discriminant)
|
|
|
|
}
|
|
|
|
|
|
|
|
return caseval, err
|
|
|
|
}
|
2017-11-13 23:18:18 +03:00
|
|
|
{{- end}}
|
|
|
|
|
2017-11-16 22:17:46 +03:00
|
|
|
// TODO: Generate these.
|
|
|
|
func decodeTypedParam(dec *xdr.Decoder) (*TypedParam, error) {
|
|
|
|
name, _, err := dec.DecodeString()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
val, err := decodeTypedParamValue(dec)
|
|
|
|
return &TypedParam{name, val}, nil
|
|
|
|
}
|
|
|
|
|
2017-11-15 02:59:55 +03:00
|
|
|
func decodeTypedParams(dec *xdr.Decoder) ([]TypedParam, error) {
|
|
|
|
count, _, err := dec.DecodeInt()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-11-16 22:17:46 +03:00
|
|
|
params := make([]TypedParam, count)
|
2017-11-15 02:59:55 +03:00
|
|
|
for ix := int32(0); ix < count; ix++ {
|
2017-11-16 22:17:46 +03:00
|
|
|
p, err := decodeTypedParam(dec)
|
2017-11-15 02:59:55 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-11-16 22:17:46 +03:00
|
|
|
params[ix] = *p
|
2017-11-15 02:59:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return params, nil
|
|
|
|
}
|
|
|
|
|
2017-11-13 23:18:18 +03:00
|
|
|
{{range .Procs}}
|
2017-11-17 01:14:05 +03:00
|
|
|
// {{.Name}} is the go wrapper for {{.LVName}}.
|
2017-11-13 23:18:18 +03:00
|
|
|
func (l *Libvirt) {{.Name}}({{range $ix, $arg := .Args}}{{if $ix}}, {{end}}{{.Name}} {{.Type}}{{end}}) ({{range .Ret}}r{{.Name}} {{.Type}}, {{end}}err error) {
|
2018-02-05 01:35:27 +03:00
|
|
|
var buf []byte
|
2017-11-13 23:18:18 +03:00
|
|
|
{{if .ArgsStruct}}
|
|
|
|
args := {{.ArgsStruct}} {
|
|
|
|
{{range .Args}} {{.Name}}: {{.Name}},
|
|
|
|
{{end}} }
|
|
|
|
|
|
|
|
buf, err = encode(&args)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
{{end}}
|
2018-01-28 23:33:02 +03:00
|
|
|
{{if .RetStruct}} var r response{{end}}
|
2018-02-05 01:35:27 +03:00
|
|
|
{{if .RetStruct}}r{{else}}_{{end}}, err = l.request({{.Num}}, constants.Program, buf)
|
2017-11-13 23:18:18 +03:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
{{if .RetStruct}}
|
2017-11-15 02:59:55 +03:00
|
|
|
// Return value unmarshaling
|
2017-11-13 23:18:18 +03:00
|
|
|
rdr := bytes.NewReader(r.Payload)
|
|
|
|
dec := xdr.NewDecoder(rdr)
|
2017-11-15 02:59:55 +03:00
|
|
|
{{range .Ret}} // {{.Name}}: {{.Type}}
|
2017-11-16 22:17:46 +03:00
|
|
|
{{if eq .Type "[]TypedParam"}} r{{.Name}}, err = decodeTypedParams(dec)
|
2017-11-15 02:59:55 +03:00
|
|
|
if err != nil {
|
2017-11-16 22:17:46 +03:00
|
|
|
fmt.Println("error decoding typedparams")
|
2017-11-15 02:59:55 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
{{else}} _, err = dec.Decode(&r{{.Name}})
|
2017-11-13 23:18:18 +03:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2017-11-16 22:17:46 +03:00
|
|
|
{{end}}{{end}}{{end}}
|
2017-11-13 23:18:18 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
{{end}}
|