-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkuttilib-drivers.go
50 lines (43 loc) · 1.22 KB
/
kuttilib-drivers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package kuttilib
import (
"github.com/kuttiproject/drivercore"
)
// ValidDriverName checks if the specified name belongs to
// an available Driver.
func ValidDriverName(drivername string) bool {
return drivercore.IsRegisteredDriver(drivername)
}
// DriverNames returns the names of all available Drivers.
func DriverNames() []string {
return drivercore.RegisteredDrivers()
}
// Drivers returns all available Drivers.
func Drivers() []*Driver {
drivercount := drivercore.DriverCount()
result := make([]*Driver, 0, drivercount)
drivercore.ForEachDriver(func(vd drivercore.Driver) bool {
result = append(result, &Driver{vmdriver: vd})
return true
})
return result
}
// ForEachDriver iterates over Drivers.
//
// On each iteration, the callback function f is
// invoked with the Driver as a parameter. If the
// function returns false, iteration stops.
func ForEachDriver(f func(*Driver) bool) {
drivercore.ForEachDriver(func(vd drivercore.Driver) bool {
d := &Driver{vmdriver: vd}
return f(d)
})
}
// GetDriver gets the Driver with the specified name,
// or nil.
func GetDriver(drivername string) (*Driver, bool) {
vd, ok := drivercore.GetDriver(drivername)
if ok {
return &Driver{vmdriver: vd}, ok
}
return nil, ok
}