src: Add DMA localagent
[barometer.git] / src / dma / vendor / github.com / libvirt / libvirt-go / interface.go
1 /*
2  * This file is part of the libvirt-go project
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  *
22  * Copyright (c) 2013 Alex Zorin
23  * Copyright (C) 2016 Red Hat, Inc.
24  *
25  */
26
27 package libvirt
28
29 /*
30 #cgo pkg-config: libvirt
31 #include <stdlib.h>
32 #include "interface_wrapper.h"
33 */
34 import "C"
35
36 import (
37         "unsafe"
38 )
39
40 type InterfaceXMLFlags int
41
42 const (
43         INTERFACE_XML_INACTIVE = InterfaceXMLFlags(C.VIR_INTERFACE_XML_INACTIVE)
44 )
45
46 type Interface struct {
47         ptr C.virInterfacePtr
48 }
49
50 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceCreate
51 func (n *Interface) Create(flags uint32) error {
52         var err C.virError
53         result := C.virInterfaceCreateWrapper(n.ptr, C.uint(flags), &err)
54         if result == -1 {
55                 return makeError(&err)
56         }
57         return nil
58 }
59
60 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDestroy
61 func (n *Interface) Destroy(flags uint32) error {
62         var err C.virError
63         result := C.virInterfaceDestroyWrapper(n.ptr, C.uint(flags), &err)
64         if result == -1 {
65                 return makeError(&err)
66         }
67         return nil
68 }
69
70 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceIsActive
71 func (n *Interface) IsActive() (bool, error) {
72         var err C.virError
73         result := C.virInterfaceIsActiveWrapper(n.ptr, &err)
74         if result == -1 {
75                 return false, makeError(&err)
76         }
77         if result == 1 {
78                 return true, nil
79         }
80         return false, nil
81 }
82
83 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetMACString
84 func (n *Interface) GetMACString() (string, error) {
85         var err C.virError
86         result := C.virInterfaceGetMACStringWrapper(n.ptr, &err)
87         if result == nil {
88                 return "", makeError(&err)
89         }
90         mac := C.GoString(result)
91         return mac, nil
92 }
93
94 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetName
95 func (n *Interface) GetName() (string, error) {
96         var err C.virError
97         result := C.virInterfaceGetNameWrapper(n.ptr, &err)
98         if result == nil {
99                 return "", makeError(&err)
100         }
101         name := C.GoString(result)
102         return name, nil
103 }
104
105 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetXMLDesc
106 func (n *Interface) GetXMLDesc(flags InterfaceXMLFlags) (string, error) {
107         var err C.virError
108         result := C.virInterfaceGetXMLDescWrapper(n.ptr, C.uint(flags), &err)
109         if result == nil {
110                 return "", makeError(&err)
111         }
112         xml := C.GoString(result)
113         C.free(unsafe.Pointer(result))
114         return xml, nil
115 }
116
117 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceUndefine
118 func (n *Interface) Undefine() error {
119         var err C.virError
120         result := C.virInterfaceUndefineWrapper(n.ptr, &err)
121         if result == -1 {
122                 return makeError(&err)
123         }
124         return nil
125 }
126
127 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceFree
128 func (n *Interface) Free() error {
129         var err C.virError
130         ret := C.virInterfaceFreeWrapper(n.ptr, &err)
131         if ret == -1 {
132                 return makeError(&err)
133         }
134         return nil
135 }
136
137 // See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceRef
138 func (c *Interface) Ref() error {
139         var err C.virError
140         ret := C.virInterfaceRefWrapper(c.ptr, &err)
141         if ret == -1 {
142                 return makeError(&err)
143         }
144         return nil
145 }