b59e9d42f4
- Update libvirt.go so that all libvirt calls now go through the generated routines. - Remove some libvirt routines that had the same name as generated ones, leave the rest as convenience routines. - Fix the handling of Optional-values (the declarations of which in the .x file look like pointers)
146 lines
3.1 KiB
Cheetah
146 lines
3.1 KiB
Cheetah
/*
|
|
* This file generated by internal/lvgen/generate.go. DO NOT EDIT BY HAND!
|
|
*
|
|
* To regenerate, run 'go generate' in internal/lvgen.
|
|
*/
|
|
|
|
package libvirt
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/davecgh/go-xdr/xdr2"
|
|
"github.com/digitalocean/go-libvirt/internal/constants"
|
|
)
|
|
|
|
const (
|
|
VirUUIDBuflen = 16
|
|
)
|
|
|
|
// Typedefs:
|
|
{{range .Typedefs}}type {{.Name}} {{.Type}}
|
|
{{end}}
|
|
// Enums:
|
|
{{range .Enums}}type {{.Name}} {{.Type}}
|
|
{{end}}
|
|
// Structs:
|
|
{{range .Structs}}type {{.Name}} struct {
|
|
{{range .Members}} {{.Name}} {{.Type}}
|
|
{{end -}}
|
|
}
|
|
|
|
{{end}}
|
|
// Unions:
|
|
{{range .Unions}}type {{.Name}} interface {
|
|
Get() interface{}
|
|
{{end -}}
|
|
}
|
|
|
|
{{range .Unions}}{{$uname := .Name}}{{range .Cases}}{{$casetype := printf "%v%v" $uname .CaseName}}
|
|
type {{$casetype}} struct {
|
|
DVal uint32
|
|
{{.Name}} {{.Type}}
|
|
}
|
|
func New{{$casetype}}(v {{.Type}}) *{{$casetype}} {
|
|
return &{{$casetype}}{DVal: {{.DiscriminantVal}}, {{.Name}}: v}
|
|
}
|
|
func decode{{$casetype}}(dec *xdr.Decoder) (*{{$casetype}}, error) {
|
|
var v {{.Type}}
|
|
_, err := dec.Decode(&v)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return New{{$casetype}}(v), nil
|
|
}
|
|
func (c *{{$casetype}}) Get() interface{} { return c.{{.Name}} }
|
|
{{end}}
|
|
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
|
|
}
|
|
{{- end}}
|
|
|
|
// 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
|
|
}
|
|
|
|
func decodeTypedParams(dec *xdr.Decoder) ([]TypedParam, error) {
|
|
count, _, err := dec.DecodeInt()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
params := make([]TypedParam, count)
|
|
for ix := int32(0); ix < count; ix++ {
|
|
p, err := decodeTypedParam(dec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
params[ix] = *p
|
|
}
|
|
|
|
return params, nil
|
|
}
|
|
|
|
// Procedures:
|
|
{{range .Procs}}
|
|
func (l *Libvirt) {{.Name}}({{range $ix, $arg := .Args}}{{if $ix}}, {{end}}{{.Name}} {{.Type}}{{end}}) ({{range .Ret}}r{{.Name}} {{.Type}}, {{end}}err error) {
|
|
var buf bytes.Buffer
|
|
{{if .ArgsStruct}}
|
|
args := {{.ArgsStruct}} {
|
|
{{range .Args}} {{.Name}}: {{.Name}},
|
|
{{end}} }
|
|
|
|
buf, err = encode(&args)
|
|
if err != nil {
|
|
return
|
|
}
|
|
{{end}}
|
|
var resp <-chan response
|
|
resp, err = l.request({{.Num}}, constants.Program, &buf)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
r := <-resp
|
|
if r.Status != StatusOK {
|
|
err = decodeError(r.Payload)
|
|
return
|
|
}
|
|
{{if .RetStruct}}
|
|
// Return value unmarshaling
|
|
rdr := bytes.NewReader(r.Payload)
|
|
dec := xdr.NewDecoder(rdr)
|
|
{{range .Ret}} // {{.Name}}: {{.Type}}
|
|
{{if eq .Type "[]TypedParam"}} r{{.Name}}, err = decodeTypedParams(dec)
|
|
if err != nil {
|
|
fmt.Println("error decoding typedparams")
|
|
return
|
|
}
|
|
{{else}} _, err = dec.Decode(&r{{.Name}})
|
|
if err != nil {
|
|
return
|
|
}
|
|
{{end}}{{end}}{{end}}
|
|
return
|
|
}
|
|
{{end}}
|