From patchwork Thu Jan 30 00:09:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11357265 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B42361398 for ; Thu, 30 Jan 2020 00:11:47 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79BF2206F0 for ; Thu, 30 Jan 2020 00:11:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W7RPqZ1a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79BF2206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwxPG-0002HB-Qb; Thu, 30 Jan 2020 00:10:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwxPF-0002CJ-Qp for xen-devel@lists.xenproject.org; Thu, 30 Jan 2020 00:10:01 +0000 X-Inumbo-ID: da0e5a12-42f4-11ea-8396-bc764e2007e4 Received: from mail-yw1-xc30.google.com (unknown [2607:f8b0:4864:20::c30]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id da0e5a12-42f4-11ea-8396-bc764e2007e4; Thu, 30 Jan 2020 00:09:58 +0000 (UTC) Received: by mail-yw1-xc30.google.com with SMTP id 10so1057881ywv.5 for ; Wed, 29 Jan 2020 16:09:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=6hanIlAACZKCGtV6rO9p/hZ/dhbPIXlX4HbjWHdyFiw=; b=W7RPqZ1aL/4Dw1axFC15XcNoRhohJ4WFGtlZYaNLNd0jteTMfXc33WivaS1UY51GMH ZS4779WtKXfDghh0d11/fMyOlZOoLXB7al7ZVC1GJmVeWTEAXd/o90uQd7Q8A4opn16p X06JVCuYmrTlZymlK2wC6Maq1MmqCSrEzItxi7JHM8tWOhJspKEQNhbjtAWJHiFsg1Wl 92BYDsifQzcaTBN3tPYpP50B7ZGBjlvaBxpKENirD7NZhxiT7uBKQrVcXD7+hC98pxEI 1M6UeyMUmxT0apW3XliO2s/csTHBE5jEzoyX4xoZQ9AX8MstFqfi6qQqN66xKq3GNMvZ 03fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6hanIlAACZKCGtV6rO9p/hZ/dhbPIXlX4HbjWHdyFiw=; b=fJ3B7FJGTevTsrKhcg8XTmtLxcFfSMg8rZ4S3bpNhryqYB7W3jWH53yvn0gRBviJPV S0s2qAOn9VaYdsA5d+vJ98krO04W25DJeLmFWJnYxHbYIy61gqO8mMASK5X32w9U0kxo NagHcuHg1abciESdvuHH6OMiMJcMXCJp7+aJPr0PLO1UYIVJkppqWkbs8Q47aUXEgIFB eTfyc2Kfd2SGHPU9DGxh48n3+zMlXVyf0HEaJDCpqBZ5WjcUh2uPEalYuZZbbA+MEYgv /9kEP6DgeDXJDTZh7pVPPR8+I/XAzoIf2s1icfySSLJoClYu7UU5Xi0zQp2Nm0ziOxLq PMEg== X-Gm-Message-State: APjAAAXDampMRuhZZT6bhbf3+6ix5FKNInp3z/HJDAuQiSlZnFFkE7nt EQhHNrhI+y7i8vE8swxeefsIctIn X-Google-Smtp-Source: APXvYqyx0VNhaUEiFBRxuJoE1HTDRf54yGW2vW44dMz9owTagEDYvxoggLRjYVaA1IW0AvqcLzaPLQ== X-Received: by 2002:a25:ced4:: with SMTP id x203mr1759087ybe.419.1580342996145; Wed, 29 Jan 2020 16:09:56 -0800 (PST) Received: from four.lan (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id o69sm1767505ywd.38.2020.01.29.16.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 16:09:55 -0800 (PST) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Wed, 29 Jan 2020 19:09:50 -0500 Message-Id: X-Mailer: git-send-email 2.17.1 Subject: [Xen-devel] [PATCH] golang/xenlight: implement constructor generation X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Nick Rosbrook , Ian Jackson , George Dunlap , Wei Liu MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Generate constructors for generated Go types. Call libxl__init so the Go type can be properly initialized. If a type has a keyed union field, add a parameter to the function signature to set the key variable, and call the init function for the keyed union. Signed-off-by: Nick Rosbrook --- tools/golang/xenlight/gengotypes.py | 65 ++ tools/golang/xenlight/helpers.gen.go | 1002 +++++++++++++++++++++++++- 2 files changed, 1049 insertions(+), 18 deletions(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/gengotypes.py index b09cffb829..aec153098d 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -225,6 +225,9 @@ def xenlight_golang_generate_helpers(path = None, types = None, comment = None): if not isinstance(ty, idl.Struct): continue + f.write(xenlight_golang_define_constructor(ty)) + f.write('\n') + (fdef, extras) = xenlight_golang_define_from_C(ty) f.write(fdef) @@ -619,6 +622,68 @@ def xenlight_golang_array_to_C(ty = None): return s +def xenlight_golang_define_constructor(ty = None): + s = '' + + ctypename = ty.typename + gotypename = xenlight_golang_fmt_name(ctypename) + + # Since this func is exported, add a comment as per Go conventions. + s += '// New{} returns an instance of {}'.format(gotypename,gotypename) + s += ' initialized with defaults.\n' + + # If a struct has a keyed union, an extra argument is + # required in the function signature, and an extra _init + # call is needed. + params = [] + init_fns = [] + + # Add call to parent init_fn first. + init_fns.append('C.{}(&xc)'.format(ty.init_fn)) + + for f in ty.fields: + if not isinstance(f.type, idl.KeyedUnion): + continue + + param = f.type.keyvar + + param_ctype = param.type.typename + param_gotype = xenlight_golang_fmt_name(param_ctype) + param_goname = xenlight_golang_fmt_name(param.name,exported=False) + + # Serveral keyed unions use 'type' as the key variable name. In + # that case, prepend the first letter of the Go type name. + if param_goname == 'type': + param_goname = '{}type'.format(param_gotype.lower()[0]) + + # Add call to keyed union's init_fn. + init_fns.append('C.{}_{}(&xc, C.{}({}))'.format(ty.init_fn, + param.name, + param_ctype, + param_goname)) + + # Add to params list. + params.append('{} {}'.format(param_goname, param_gotype)) + + # Define function + s += 'func New{}({}) (*{}, error) {{\n'.format(gotypename, + ','.join(params), + gotypename) + + # Declare variables. + s += 'var (\nx {}\nxc C.{})\n\n'.format(gotypename, ctypename) + + # Write init_fn calls. + s += '\n'.join(init_fns) + s += '\n\n' + + # Call fromC to initialize Go type. + s += 'if err := x.fromC(&xc); err != nil {\n' + s += 'return nil, err }\n\n' + s += 'return &x, nil}\n' + + return s + def xenlight_golang_fmt_name(name, exported = True): """ Take a given type name and return an diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index 746d99b5ba..225ba6868e 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -30,6 +30,22 @@ typedef typeof(((struct libxl_psr_hw_info *)NULL)->u.mba)libxl_psr_hw_info_type_ */ import "C" +// NewIoportRange returns an instance of IoportRange initialized with defaults. +func NewIoportRange() (*IoportRange, error) { + var ( + x IoportRange + xc C.libxl_ioport_range + ) + + C.libxl_ioport_range_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *IoportRange) fromC(xc *C.libxl_ioport_range) error { x.First = uint32(xc.first) x.Number = uint32(xc.number) @@ -50,6 +66,22 @@ func (x *IoportRange) toC(xc *C.libxl_ioport_range) (err error) { return nil } +// NewIomemRange returns an instance of IomemRange initialized with defaults. +func NewIomemRange() (*IomemRange, error) { + var ( + x IomemRange + xc C.libxl_iomem_range + ) + + C.libxl_iomem_range_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *IomemRange) fromC(xc *C.libxl_iomem_range) error { x.Start = uint64(xc.start) x.Number = uint64(xc.number) @@ -72,6 +104,22 @@ func (x *IomemRange) toC(xc *C.libxl_iomem_range) (err error) { return nil } +// NewVgaInterfaceInfo returns an instance of VgaInterfaceInfo initialized with defaults. +func NewVgaInterfaceInfo() (*VgaInterfaceInfo, error) { + var ( + x VgaInterfaceInfo + xc C.libxl_vga_interface_info + ) + + C.libxl_vga_interface_info_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *VgaInterfaceInfo) fromC(xc *C.libxl_vga_interface_info) error { x.Kind = VgaInterfaceType(xc.kind) @@ -90,6 +138,22 @@ func (x *VgaInterfaceInfo) toC(xc *C.libxl_vga_interface_info) (err error) { return nil } +// NewVncInfo returns an instance of VncInfo initialized with defaults. +func NewVncInfo() (*VncInfo, error) { + var ( + x VncInfo + xc C.libxl_vnc_info + ) + + C.libxl_vnc_info_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *VncInfo) fromC(xc *C.libxl_vnc_info) error { if err := x.Enable.fromC(&xc.enable); err != nil { return fmt.Errorf("converting field Enable: %v", err) @@ -128,6 +192,22 @@ func (x *VncInfo) toC(xc *C.libxl_vnc_info) (err error) { return nil } +// NewSpiceInfo returns an instance of SpiceInfo initialized with defaults. +func NewSpiceInfo() (*SpiceInfo, error) { + var ( + x SpiceInfo + xc C.libxl_spice_info + ) + + C.libxl_spice_info_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *SpiceInfo) fromC(xc *C.libxl_spice_info) error { if err := x.Enable.fromC(&xc.enable); err != nil { return fmt.Errorf("converting field Enable: %v", err) @@ -196,6 +276,22 @@ func (x *SpiceInfo) toC(xc *C.libxl_spice_info) (err error) { return nil } +// NewSdlInfo returns an instance of SdlInfo initialized with defaults. +func NewSdlInfo() (*SdlInfo, error) { + var ( + x SdlInfo + xc C.libxl_sdl_info + ) + + C.libxl_sdl_info_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *SdlInfo) fromC(xc *C.libxl_sdl_info) error { if err := x.Enable.fromC(&xc.enable); err != nil { return fmt.Errorf("converting field Enable: %v", err) @@ -232,6 +328,22 @@ func (x *SdlInfo) toC(xc *C.libxl_sdl_info) (err error) { return nil } +// NewDominfo returns an instance of Dominfo initialized with defaults. +func NewDominfo() (*Dominfo, error) { + var ( + x Dominfo + xc C.libxl_dominfo + ) + + C.libxl_dominfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Dominfo) fromC(xc *C.libxl_dominfo) error { if err := x.Uuid.fromC(&xc.uuid); err != nil { return fmt.Errorf("converting field Uuid: %v", err) @@ -296,6 +408,22 @@ func (x *Dominfo) toC(xc *C.libxl_dominfo) (err error) { return nil } +// NewCpupoolinfo returns an instance of Cpupoolinfo initialized with defaults. +func NewCpupoolinfo() (*Cpupoolinfo, error) { + var ( + x Cpupoolinfo + xc C.libxl_cpupoolinfo + ) + + C.libxl_cpupoolinfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Cpupoolinfo) fromC(xc *C.libxl_cpupoolinfo) error { x.Poolid = uint32(xc.poolid) x.PoolName = C.GoString(xc.pool_name) @@ -328,6 +456,23 @@ func (x *Cpupoolinfo) toC(xc *C.libxl_cpupoolinfo) (err error) { return nil } +// NewChannelinfo returns an instance of Channelinfo initialized with defaults. +func NewChannelinfo(connection ChannelConnection) (*Channelinfo, error) { + var ( + x Channelinfo + xc C.libxl_channelinfo + ) + + C.libxl_channelinfo_init(&xc) + C.libxl_channelinfo_init_connection(&xc, C.libxl_channel_connection(connection)) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Channelinfo) fromC(xc *C.libxl_channelinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -401,6 +546,22 @@ func (x *Channelinfo) toC(xc *C.libxl_channelinfo) (err error) { return nil } +// NewVminfo returns an instance of Vminfo initialized with defaults. +func NewVminfo() (*Vminfo, error) { + var ( + x Vminfo + xc C.libxl_vminfo + ) + + C.libxl_vminfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Vminfo) fromC(xc *C.libxl_vminfo) error { if err := x.Uuid.fromC(&xc.uuid); err != nil { return fmt.Errorf("converting field Uuid: %v", err) @@ -425,6 +586,22 @@ func (x *Vminfo) toC(xc *C.libxl_vminfo) (err error) { return nil } +// NewVersionInfo returns an instance of VersionInfo initialized with defaults. +func NewVersionInfo() (*VersionInfo, error) { + var ( + x VersionInfo + xc C.libxl_version_info + ) + + C.libxl_version_info_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *VersionInfo) fromC(xc *C.libxl_version_info) error { x.XenVersionMajor = int(xc.xen_version_major) x.XenVersionMinor = int(xc.xen_version_minor) @@ -485,6 +662,22 @@ func (x *VersionInfo) toC(xc *C.libxl_version_info) (err error) { return nil } +// NewDomainCreateInfo returns an instance of DomainCreateInfo initialized with defaults. +func NewDomainCreateInfo() (*DomainCreateInfo, error) { + var ( + x DomainCreateInfo + xc C.libxl_domain_create_info + ) + + C.libxl_domain_create_info_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DomainCreateInfo) fromC(xc *C.libxl_domain_create_info) error { x.Type = DomainType(xc._type) if err := x.Hap.fromC(&xc.hap); err != nil { @@ -563,6 +756,22 @@ func (x *DomainCreateInfo) toC(xc *C.libxl_domain_create_info) (err error) { return nil } +// NewDomainRestoreParams returns an instance of DomainRestoreParams initialized with defaults. +func NewDomainRestoreParams() (*DomainRestoreParams, error) { + var ( + x DomainRestoreParams + xc C.libxl_domain_restore_params + ) + + C.libxl_domain_restore_params_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DomainRestoreParams) fromC(xc *C.libxl_domain_restore_params) error { x.CheckpointedStream = int(xc.checkpointed_stream) x.StreamVersion = uint32(xc.stream_version) @@ -593,6 +802,22 @@ func (x *DomainRestoreParams) toC(xc *C.libxl_domain_restore_params) (err error) return nil } +// NewSchedParams returns an instance of SchedParams initialized with defaults. +func NewSchedParams() (*SchedParams, error) { + var ( + x SchedParams + xc C.libxl_sched_params + ) + + C.libxl_sched_params_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *SchedParams) fromC(xc *C.libxl_sched_params) error { x.Vcpuid = int(xc.vcpuid) x.Weight = int(xc.weight) @@ -621,6 +846,22 @@ func (x *SchedParams) toC(xc *C.libxl_sched_params) (err error) { return nil } +// NewVcpuSchedParams returns an instance of VcpuSchedParams initialized with defaults. +func NewVcpuSchedParams() (*VcpuSchedParams, error) { + var ( + x VcpuSchedParams + xc C.libxl_vcpu_sched_params + ) + + C.libxl_vcpu_sched_params_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *VcpuSchedParams) fromC(xc *C.libxl_vcpu_sched_params) error { x.Sched = Scheduler(xc.sched) numVcpus := int(xc.num_vcpus) @@ -657,6 +898,22 @@ func (x *VcpuSchedParams) toC(xc *C.libxl_vcpu_sched_params) (err error) { return nil } +// NewDomainSchedParams returns an instance of DomainSchedParams initialized with defaults. +func NewDomainSchedParams() (*DomainSchedParams, error) { + var ( + x DomainSchedParams + xc C.libxl_domain_sched_params + ) + + C.libxl_domain_sched_params_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DomainSchedParams) fromC(xc *C.libxl_domain_sched_params) error { x.Sched = Scheduler(xc.sched) x.Weight = int(xc.weight) @@ -689,6 +946,22 @@ func (x *DomainSchedParams) toC(xc *C.libxl_domain_sched_params) (err error) { return nil } +// NewVnodeInfo returns an instance of VnodeInfo initialized with defaults. +func NewVnodeInfo() (*VnodeInfo, error) { + var ( + x VnodeInfo + xc C.libxl_vnode_info + ) + + C.libxl_vnode_info_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *VnodeInfo) fromC(xc *C.libxl_vnode_info) error { x.Memkb = uint64(xc.memkb) numDistances := int(xc.num_distances) @@ -729,6 +1002,22 @@ func (x *VnodeInfo) toC(xc *C.libxl_vnode_info) (err error) { return nil } +// NewRdmReserve returns an instance of RdmReserve initialized with defaults. +func NewRdmReserve() (*RdmReserve, error) { + var ( + x RdmReserve + xc C.libxl_rdm_reserve + ) + + C.libxl_rdm_reserve_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *RdmReserve) fromC(xc *C.libxl_rdm_reserve) error { x.Strategy = RdmReserveStrategy(xc.strategy) x.Policy = RdmReservePolicy(xc.policy) @@ -749,6 +1038,23 @@ func (x *RdmReserve) toC(xc *C.libxl_rdm_reserve) (err error) { return nil } +// NewDomainBuildInfo returns an instance of DomainBuildInfo initialized with defaults. +func NewDomainBuildInfo(dtype DomainType) (*DomainBuildInfo, error) { + var ( + x DomainBuildInfo + xc C.libxl_domain_build_info + ) + + C.libxl_domain_build_info_init(&xc) + C.libxl_domain_build_info_init_type(&xc, C.libxl_domain_type(dtype)) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.MaxVcpus = int(xc.max_vcpus) if err := x.AvailVcpus.fromC(&xc.avail_vcpus); err != nil { @@ -878,18 +1184,18 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_build_info) error { x.Tee = TeeType(xc.tee) x.Type = DomainType(xc._type) switch x.Type { - case DomainTypeHvm: - var typeHvm DomainBuildInfoTypeUnionHvm - if err := typeHvm.fromC(xc); err != nil { - return fmt.Errorf("converting field typeHvm: %v", err) - } - x.TypeUnion = typeHvm case DomainTypePv: var typePv DomainBuildInfoTypeUnionPv if err := typePv.fromC(xc); err != nil { return fmt.Errorf("converting field typePv: %v", err) } x.TypeUnion = typePv + case DomainTypeHvm: + var typeHvm DomainBuildInfoTypeUnionHvm + if err := typeHvm.fromC(xc); err != nil { + return fmt.Errorf("converting field typeHvm: %v", err) + } + x.TypeUnion = typeHvm case DomainTypePvh: var typePvh DomainBuildInfoTypeUnionPvh if err := typePvh.fromC(xc); err != nil { @@ -1406,6 +1712,22 @@ func (x *DomainBuildInfo) toC(xc *C.libxl_domain_build_info) (err error) { return nil } +// NewDeviceVfb returns an instance of DeviceVfb initialized with defaults. +func NewDeviceVfb() (*DeviceVfb, error) { + var ( + x DeviceVfb + xc C.libxl_device_vfb + ) + + C.libxl_device_vfb_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceVfb) fromC(xc *C.libxl_device_vfb) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -1446,6 +1768,22 @@ func (x *DeviceVfb) toC(xc *C.libxl_device_vfb) (err error) { return nil } +// NewDeviceVkb returns an instance of DeviceVkb initialized with defaults. +func NewDeviceVkb() (*DeviceVkb, error) { + var ( + x DeviceVkb + xc C.libxl_device_vkb + ) + + C.libxl_device_vkb_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceVkb) fromC(xc *C.libxl_device_vkb) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -1496,6 +1834,22 @@ func (x *DeviceVkb) toC(xc *C.libxl_device_vkb) (err error) { return nil } +// NewDeviceDisk returns an instance of DeviceDisk initialized with defaults. +func NewDeviceDisk() (*DeviceDisk, error) { + var ( + x DeviceDisk + xc C.libxl_device_disk + ) + + C.libxl_device_disk_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceDisk) fromC(xc *C.libxl_device_disk) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -1578,6 +1932,22 @@ func (x *DeviceDisk) toC(xc *C.libxl_device_disk) (err error) { return nil } +// NewDeviceNic returns an instance of DeviceNic initialized with defaults. +func NewDeviceNic() (*DeviceNic, error) { + var ( + x DeviceNic + xc C.libxl_device_nic + ) + + C.libxl_device_nic_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceNic) fromC(xc *C.libxl_device_nic) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -1836,6 +2206,22 @@ func (x *DeviceNic) toC(xc *C.libxl_device_nic) (err error) { return nil } +// NewDevicePci returns an instance of DevicePci initialized with defaults. +func NewDevicePci() (*DevicePci, error) { + var ( + x DevicePci + xc C.libxl_device_pci + ) + + C.libxl_device_pci_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DevicePci) fromC(xc *C.libxl_device_pci) error { x.Func = byte(xc._func) x.Dev = byte(xc.dev) @@ -1874,6 +2260,22 @@ func (x *DevicePci) toC(xc *C.libxl_device_pci) (err error) { return nil } +// NewDeviceRdm returns an instance of DeviceRdm initialized with defaults. +func NewDeviceRdm() (*DeviceRdm, error) { + var ( + x DeviceRdm + xc C.libxl_device_rdm + ) + + C.libxl_device_rdm_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceRdm) fromC(xc *C.libxl_device_rdm) error { x.Start = uint64(xc.start) x.Size = uint64(xc.size) @@ -1896,6 +2298,22 @@ func (x *DeviceRdm) toC(xc *C.libxl_device_rdm) (err error) { return nil } +// NewDeviceUsbctrl returns an instance of DeviceUsbctrl initialized with defaults. +func NewDeviceUsbctrl() (*DeviceUsbctrl, error) { + var ( + x DeviceUsbctrl + xc C.libxl_device_usbctrl + ) + + C.libxl_device_usbctrl_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceUsbctrl) fromC(xc *C.libxl_device_usbctrl) error { x.Type = UsbctrlType(xc._type) x.Devid = Devid(xc.devid) @@ -1926,6 +2344,23 @@ func (x *DeviceUsbctrl) toC(xc *C.libxl_device_usbctrl) (err error) { return nil } +// NewDeviceUsbdev returns an instance of DeviceUsbdev initialized with defaults. +func NewDeviceUsbdev(utype UsbdevType) (*DeviceUsbdev, error) { + var ( + x DeviceUsbdev + xc C.libxl_device_usbdev + ) + + C.libxl_device_usbdev_init(&xc) + C.libxl_device_usbdev_init_type(&xc, C.libxl_usbdev_type(utype)) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceUsbdev) fromC(xc *C.libxl_device_usbdev) error { x.Ctrl = Devid(xc.ctrl) x.Port = int(xc.port) @@ -1983,6 +2418,22 @@ func (x *DeviceUsbdev) toC(xc *C.libxl_device_usbdev) (err error) { return nil } +// NewDeviceDtdev returns an instance of DeviceDtdev initialized with defaults. +func NewDeviceDtdev() (*DeviceDtdev, error) { + var ( + x DeviceDtdev + xc C.libxl_device_dtdev + ) + + C.libxl_device_dtdev_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceDtdev) fromC(xc *C.libxl_device_dtdev) error { x.Path = C.GoString(xc.path) @@ -2003,6 +2454,22 @@ func (x *DeviceDtdev) toC(xc *C.libxl_device_dtdev) (err error) { return nil } +// NewDeviceVtpm returns an instance of DeviceVtpm initialized with defaults. +func NewDeviceVtpm() (*DeviceVtpm, error) { + var ( + x DeviceVtpm + xc C.libxl_device_vtpm + ) + + C.libxl_device_vtpm_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceVtpm) fromC(xc *C.libxl_device_vtpm) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -2033,6 +2500,22 @@ func (x *DeviceVtpm) toC(xc *C.libxl_device_vtpm) (err error) { return nil } +// NewDeviceP9 returns an instance of DeviceP9 initialized with defaults. +func NewDeviceP9() (*DeviceP9, error) { + var ( + x DeviceP9 + xc C.libxl_device_p9 + ) + + C.libxl_device_p9_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceP9) fromC(xc *C.libxl_device_p9) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -2069,6 +2552,22 @@ func (x *DeviceP9) toC(xc *C.libxl_device_p9) (err error) { return nil } +// NewDevicePvcallsif returns an instance of DevicePvcallsif initialized with defaults. +func NewDevicePvcallsif() (*DevicePvcallsif, error) { + var ( + x DevicePvcallsif + xc C.libxl_device_pvcallsif + ) + + C.libxl_device_pvcallsif_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DevicePvcallsif) fromC(xc *C.libxl_device_pvcallsif) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -2093,6 +2592,23 @@ func (x *DevicePvcallsif) toC(xc *C.libxl_device_pvcallsif) (err error) { return nil } +// NewDeviceChannel returns an instance of DeviceChannel initialized with defaults. +func NewDeviceChannel(connection ChannelConnection) (*DeviceChannel, error) { + var ( + x DeviceChannel + xc C.libxl_device_channel + ) + + C.libxl_device_channel_init(&xc) + C.libxl_device_channel_init_connection(&xc, C.libxl_channel_connection(connection)) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceChannel) fromC(xc *C.libxl_device_channel) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -2158,6 +2674,22 @@ func (x *DeviceChannel) toC(xc *C.libxl_device_channel) (err error) { return nil } +// NewConnectorParam returns an instance of ConnectorParam initialized with defaults. +func NewConnectorParam() (*ConnectorParam, error) { + var ( + x ConnectorParam + xc C.libxl_connector_param + ) + + C.libxl_connector_param_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *ConnectorParam) fromC(xc *C.libxl_connector_param) error { x.UniqueId = C.GoString(xc.unique_id) x.Width = uint32(xc.width) @@ -2182,6 +2714,22 @@ func (x *ConnectorParam) toC(xc *C.libxl_connector_param) (err error) { return nil } +// NewDeviceVdispl returns an instance of DeviceVdispl initialized with defaults. +func NewDeviceVdispl() (*DeviceVdispl, error) { + var ( + x DeviceVdispl + xc C.libxl_device_vdispl + ) + + C.libxl_device_vdispl_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceVdispl) fromC(xc *C.libxl_device_vdispl) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -2226,6 +2774,22 @@ func (x *DeviceVdispl) toC(xc *C.libxl_device_vdispl) (err error) { return nil } +// NewVsndParams returns an instance of VsndParams initialized with defaults. +func NewVsndParams() (*VsndParams, error) { + var ( + x VsndParams + xc C.libxl_vsnd_params + ) + + C.libxl_vsnd_params_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *VsndParams) fromC(xc *C.libxl_vsnd_params) error { numSampleRates := int(xc.num_sample_rates) cSampleRates := (*[1 << 28]C.uint32_t)(unsafe.Pointer(xc.sample_rates))[:numSampleRates:numSampleRates] @@ -2276,6 +2840,22 @@ func (x *VsndParams) toC(xc *C.libxl_vsnd_params) (err error) { return nil } +// NewVsndStream returns an instance of VsndStream initialized with defaults. +func NewVsndStream() (*VsndStream, error) { + var ( + x VsndStream + xc C.libxl_vsnd_stream + ) + + C.libxl_vsnd_stream_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *VsndStream) fromC(xc *C.libxl_vsnd_stream) error { x.UniqueId = C.GoString(xc.unique_id) x.Type = VsndStreamType(xc._type) @@ -2304,6 +2884,22 @@ func (x *VsndStream) toC(xc *C.libxl_vsnd_stream) (err error) { return nil } +// NewVsndPcm returns an instance of VsndPcm initialized with defaults. +func NewVsndPcm() (*VsndPcm, error) { + var ( + x VsndPcm + xc C.libxl_vsnd_pcm + ) + + C.libxl_vsnd_pcm_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *VsndPcm) fromC(xc *C.libxl_vsnd_pcm) error { x.Name = C.GoString(xc.name) if err := x.Params.fromC(&xc.params); err != nil { @@ -2348,6 +2944,22 @@ func (x *VsndPcm) toC(xc *C.libxl_vsnd_pcm) (err error) { return nil } +// NewDeviceVsnd returns an instance of DeviceVsnd initialized with defaults. +func NewDeviceVsnd() (*DeviceVsnd, error) { + var ( + x DeviceVsnd + xc C.libxl_device_vsnd + ) + + C.libxl_device_vsnd_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DeviceVsnd) fromC(xc *C.libxl_device_vsnd) error { x.BackendDomid = Domid(xc.backend_domid) x.BackendDomname = C.GoString(xc.backend_domname) @@ -2404,6 +3016,22 @@ func (x *DeviceVsnd) toC(xc *C.libxl_device_vsnd) (err error) { return nil } +// NewDomainConfig returns an instance of DomainConfig initialized with defaults. +func NewDomainConfig() (*DomainConfig, error) { + var ( + x DomainConfig + xc C.libxl_domain_config + ) + + C.libxl_domain_config_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DomainConfig) fromC(xc *C.libxl_domain_config) error { if err := x.CInfo.fromC(&xc.c_info); err != nil { return fmt.Errorf("converting field CInfo: %v", err) @@ -2712,6 +3340,22 @@ func (x *DomainConfig) toC(xc *C.libxl_domain_config) (err error) { return nil } +// NewDiskinfo returns an instance of Diskinfo initialized with defaults. +func NewDiskinfo() (*Diskinfo, error) { + var ( + x Diskinfo + xc C.libxl_diskinfo + ) + + C.libxl_diskinfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Diskinfo) fromC(xc *C.libxl_diskinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -2748,6 +3392,22 @@ func (x *Diskinfo) toC(xc *C.libxl_diskinfo) (err error) { return nil } +// NewNicinfo returns an instance of Nicinfo initialized with defaults. +func NewNicinfo() (*Nicinfo, error) { + var ( + x Nicinfo + xc C.libxl_nicinfo + ) + + C.libxl_nicinfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Nicinfo) fromC(xc *C.libxl_nicinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -2786,6 +3446,22 @@ func (x *Nicinfo) toC(xc *C.libxl_nicinfo) (err error) { return nil } +// NewVtpminfo returns an instance of Vtpminfo initialized with defaults. +func NewVtpminfo() (*Vtpminfo, error) { + var ( + x Vtpminfo + xc C.libxl_vtpminfo + ) + + C.libxl_vtpminfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Vtpminfo) fromC(xc *C.libxl_vtpminfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -2828,6 +3504,22 @@ func (x *Vtpminfo) toC(xc *C.libxl_vtpminfo) (err error) { return nil } +// NewUsbctrlinfo returns an instance of Usbctrlinfo initialized with defaults. +func NewUsbctrlinfo() (*Usbctrlinfo, error) { + var ( + x Usbctrlinfo + xc C.libxl_usbctrlinfo + ) + + C.libxl_usbctrlinfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Usbctrlinfo) fromC(xc *C.libxl_usbctrlinfo) error { x.Type = UsbctrlType(xc._type) x.Devid = Devid(xc.devid) @@ -2872,6 +3564,22 @@ func (x *Usbctrlinfo) toC(xc *C.libxl_usbctrlinfo) (err error) { return nil } +// NewVcpuinfo returns an instance of Vcpuinfo initialized with defaults. +func NewVcpuinfo() (*Vcpuinfo, error) { + var ( + x Vcpuinfo + xc C.libxl_vcpuinfo + ) + + C.libxl_vcpuinfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Vcpuinfo) fromC(xc *C.libxl_vcpuinfo) error { x.Vcpuid = uint32(xc.vcpuid) x.Cpu = uint32(xc.cpu) @@ -2912,6 +3620,22 @@ func (x *Vcpuinfo) toC(xc *C.libxl_vcpuinfo) (err error) { return nil } +// NewPhysinfo returns an instance of Physinfo initialized with defaults. +func NewPhysinfo() (*Physinfo, error) { + var ( + x Physinfo + xc C.libxl_physinfo + ) + + C.libxl_physinfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Physinfo) fromC(xc *C.libxl_physinfo) error { x.ThreadsPerCore = uint32(xc.threads_per_core) x.CoresPerSocket = uint32(xc.cores_per_socket) @@ -2972,6 +3696,22 @@ func (x *Physinfo) toC(xc *C.libxl_physinfo) (err error) { return nil } +// NewConnectorinfo returns an instance of Connectorinfo initialized with defaults. +func NewConnectorinfo() (*Connectorinfo, error) { + var ( + x Connectorinfo + xc C.libxl_connectorinfo + ) + + C.libxl_connectorinfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Connectorinfo) fromC(xc *C.libxl_connectorinfo) error { x.UniqueId = C.GoString(xc.unique_id) x.Width = uint32(xc.width) @@ -3004,6 +3744,22 @@ func (x *Connectorinfo) toC(xc *C.libxl_connectorinfo) (err error) { return nil } +// NewVdisplinfo returns an instance of Vdisplinfo initialized with defaults. +func NewVdisplinfo() (*Vdisplinfo, error) { + var ( + x Vdisplinfo + xc C.libxl_vdisplinfo + ) + + C.libxl_vdisplinfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Vdisplinfo) fromC(xc *C.libxl_vdisplinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -3056,6 +3812,22 @@ func (x *Vdisplinfo) toC(xc *C.libxl_vdisplinfo) (err error) { return nil } +// NewStreaminfo returns an instance of Streaminfo initialized with defaults. +func NewStreaminfo() (*Streaminfo, error) { + var ( + x Streaminfo + xc C.libxl_streaminfo + ) + + C.libxl_streaminfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Streaminfo) fromC(xc *C.libxl_streaminfo) error { x.ReqEvtch = int(xc.req_evtch) x.ReqRref = int(xc.req_rref) @@ -3076,6 +3848,22 @@ func (x *Streaminfo) toC(xc *C.libxl_streaminfo) (err error) { return nil } +// NewPcminfo returns an instance of Pcminfo initialized with defaults. +func NewPcminfo() (*Pcminfo, error) { + var ( + x Pcminfo + xc C.libxl_pcminfo + ) + + C.libxl_pcminfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Pcminfo) fromC(xc *C.libxl_pcminfo) error { numVsndStreams := int(xc.num_vsnd_streams) cStreams := (*[1 << 28]C.libxl_streaminfo)(unsafe.Pointer(xc.streams))[:numVsndStreams:numVsndStreams] @@ -3110,6 +3898,22 @@ func (x *Pcminfo) toC(xc *C.libxl_pcminfo) (err error) { return nil } +// NewVsndinfo returns an instance of Vsndinfo initialized with defaults. +func NewVsndinfo() (*Vsndinfo, error) { + var ( + x Vsndinfo + xc C.libxl_vsndinfo + ) + + C.libxl_vsndinfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Vsndinfo) fromC(xc *C.libxl_vsndinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -3160,6 +3964,22 @@ func (x *Vsndinfo) toC(xc *C.libxl_vsndinfo) (err error) { return nil } +// NewVkbinfo returns an instance of Vkbinfo initialized with defaults. +func NewVkbinfo() (*Vkbinfo, error) { + var ( + x Vkbinfo + xc C.libxl_vkbinfo + ) + + C.libxl_vkbinfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Vkbinfo) fromC(xc *C.libxl_vkbinfo) error { x.Backend = C.GoString(xc.backend) x.BackendId = uint32(xc.backend_id) @@ -3196,6 +4016,22 @@ func (x *Vkbinfo) toC(xc *C.libxl_vkbinfo) (err error) { return nil } +// NewNumainfo returns an instance of Numainfo initialized with defaults. +func NewNumainfo() (*Numainfo, error) { + var ( + x Numainfo + xc C.libxl_numainfo + ) + + C.libxl_numainfo_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Numainfo) fromC(xc *C.libxl_numainfo) error { x.Size = uint64(xc.size) x.Free = uint64(xc.free) @@ -3230,6 +4066,22 @@ func (x *Numainfo) toC(xc *C.libxl_numainfo) (err error) { return nil } +// NewCputopology returns an instance of Cputopology initialized with defaults. +func NewCputopology() (*Cputopology, error) { + var ( + x Cputopology + xc C.libxl_cputopology + ) + + C.libxl_cputopology_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Cputopology) fromC(xc *C.libxl_cputopology) error { x.Core = uint32(xc.core) x.Socket = uint32(xc.socket) @@ -3252,6 +4104,22 @@ func (x *Cputopology) toC(xc *C.libxl_cputopology) (err error) { return nil } +// NewPcitopology returns an instance of Pcitopology initialized with defaults. +func NewPcitopology() (*Pcitopology, error) { + var ( + x Pcitopology + xc C.libxl_pcitopology + ) + + C.libxl_pcitopology_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Pcitopology) fromC(xc *C.libxl_pcitopology) error { x.Seg = uint16(xc.seg) x.Bus = byte(xc.bus) @@ -3276,6 +4144,22 @@ func (x *Pcitopology) toC(xc *C.libxl_pcitopology) (err error) { return nil } +// NewSchedCreditParams returns an instance of SchedCreditParams initialized with defaults. +func NewSchedCreditParams() (*SchedCreditParams, error) { + var ( + x SchedCreditParams + xc C.libxl_sched_credit_params + ) + + C.libxl_sched_credit_params_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *SchedCreditParams) fromC(xc *C.libxl_sched_credit_params) error { x.TsliceMs = int(xc.tslice_ms) x.RatelimitUs = int(xc.ratelimit_us) @@ -3292,6 +4176,22 @@ func (x *SchedCreditParams) toC(xc *C.libxl_sched_credit_params) (err error) { return nil } +// NewSchedCredit2Params returns an instance of SchedCredit2Params initialized with defaults. +func NewSchedCredit2Params() (*SchedCredit2Params, error) { + var ( + x SchedCredit2Params + xc C.libxl_sched_credit2_params + ) + + C.libxl_sched_credit2_params_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *SchedCredit2Params) fromC(xc *C.libxl_sched_credit2_params) error { x.RatelimitUs = int(xc.ratelimit_us) @@ -3304,6 +4204,22 @@ func (x *SchedCredit2Params) toC(xc *C.libxl_sched_credit2_params) (err error) { return nil } +// NewDomainRemusInfo returns an instance of DomainRemusInfo initialized with defaults. +func NewDomainRemusInfo() (*DomainRemusInfo, error) { + var ( + x DomainRemusInfo + xc C.libxl_domain_remus_info + ) + + C.libxl_domain_remus_info_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *DomainRemusInfo) fromC(xc *C.libxl_domain_remus_info) error { x.Interval = int(xc.interval) if err := x.AllowUnsafe.fromC(&xc.allow_unsafe); err != nil { @@ -3368,6 +4284,23 @@ func (x *DomainRemusInfo) toC(xc *C.libxl_domain_remus_info) (err error) { return nil } +// NewEvent returns an instance of Event initialized with defaults. +func NewEvent(etype EventType) (*Event, error) { + var ( + x Event + xc C.libxl_event + ) + + C.libxl_event_init(&xc) + C.libxl_event_init_type(&xc, C.libxl_event_type(etype)) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *Event) fromC(xc *C.libxl_event) error { if err := x.Link.fromC(&xc.link); err != nil { return fmt.Errorf("converting field Link: %v", err) @@ -3379,6 +4312,12 @@ func (x *Event) fromC(xc *C.libxl_event) error { x.ForUser = uint64(xc.for_user) x.Type = EventType(xc._type) switch x.Type { + case EventTypeOperationComplete: + var typeOperationComplete EventTypeUnionOperationComplete + if err := typeOperationComplete.fromC(xc); err != nil { + return fmt.Errorf("converting field typeOperationComplete: %v", err) + } + x.TypeUnion = typeOperationComplete case EventTypeDomainShutdown: var typeDomainShutdown EventTypeUnionDomainShutdown if err := typeDomainShutdown.fromC(xc); err != nil { @@ -3391,12 +4330,6 @@ func (x *Event) fromC(xc *C.libxl_event) error { return fmt.Errorf("converting field typeDiskEject: %v", err) } x.TypeUnion = typeDiskEject - case EventTypeOperationComplete: - var typeOperationComplete EventTypeUnionOperationComplete - if err := typeOperationComplete.fromC(xc); err != nil { - return fmt.Errorf("converting field typeOperationComplete: %v", err) - } - x.TypeUnion = typeOperationComplete default: return fmt.Errorf("invalid union key '%v'", x.Type) } @@ -3493,6 +4426,22 @@ func (x *Event) toC(xc *C.libxl_event) (err error) { return nil } +// NewPsrCatInfo returns an instance of PsrCatInfo initialized with defaults. +func NewPsrCatInfo() (*PsrCatInfo, error) { + var ( + x PsrCatInfo + xc C.libxl_psr_cat_info + ) + + C.libxl_psr_cat_info_init(&xc) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *PsrCatInfo) fromC(xc *C.libxl_psr_cat_info) error { x.Id = uint32(xc.id) x.CosMax = uint32(xc.cos_max) @@ -3517,22 +4466,39 @@ func (x *PsrCatInfo) toC(xc *C.libxl_psr_cat_info) (err error) { return nil } +// NewPsrHwInfo returns an instance of PsrHwInfo initialized with defaults. +func NewPsrHwInfo(ptype PsrFeatType) (*PsrHwInfo, error) { + var ( + x PsrHwInfo + xc C.libxl_psr_hw_info + ) + + C.libxl_psr_hw_info_init(&xc) + C.libxl_psr_hw_info_init_type(&xc, C.libxl_psr_feat_type(ptype)) + + if err := x.fromC(&xc); err != nil { + return nil, err + } + + return &x, nil +} + func (x *PsrHwInfo) fromC(xc *C.libxl_psr_hw_info) error { x.Id = uint32(xc.id) x.Type = PsrFeatType(xc._type) switch x.Type { - case PsrFeatTypeCat: - var typeCat PsrHwInfoTypeUnionCat - if err := typeCat.fromC(xc); err != nil { - return fmt.Errorf("converting field typeCat: %v", err) - } - x.TypeUnion = typeCat case PsrFeatTypeMba: var typeMba PsrHwInfoTypeUnionMba if err := typeMba.fromC(xc); err != nil { return fmt.Errorf("converting field typeMba: %v", err) } x.TypeUnion = typeMba + case PsrFeatTypeCat: + var typeCat PsrHwInfoTypeUnionCat + if err := typeCat.fromC(xc); err != nil { + return fmt.Errorf("converting field typeCat: %v", err) + } + x.TypeUnion = typeCat default: return fmt.Errorf("invalid union key '%v'", x.Type) }