forked from go-adsi/adsi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
computer.go
70 lines (61 loc) · 1.43 KB
/
computer.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package adsi
import (
"github.com/scjalliance/comshim"
"github.com/continuum-nilesh-akhade/adsi/api"
)
// Computer provides access to Active Directory computers.
type Computer struct {
object
iface *api.IADsComputer
}
// NewComputer returns a computer that manages the given COM interface.
func NewComputer(iface *api.IADsComputer) *Computer {
comshim.Add(1)
return &Computer{iface: iface, object: object{iface: &iface.IADs}}
}
func (c *Computer) closed() bool {
return (c.iface == nil)
}
// Close will release resources consumed by the computer. It should be
// called when the computer is no longer needed.
func (c *Computer) Close() {
c.m.Lock()
defer c.m.Unlock()
if c.closed() {
return
}
defer comshim.Done()
c.iface.Release()
c.object.iface = nil
c.iface = nil
}
// ID retrieves the ID of the computer.
func (c *Computer) ID() (id string, err error) {
c.m.Lock()
defer c.m.Unlock()
if c.closed() {
return "", ErrClosed
}
id, err = c.iface.ComputerID()
return
}
// Site retrieves the site of the computer.
func (c *Computer) Site() (site string, err error) {
c.m.Lock()
defer c.m.Unlock()
if c.closed() {
return "", ErrClosed
}
site, err = c.iface.Site()
return
}
// OperatingSystem retrieves the operating system of the computer.
func (c *Computer) OperatingSystem() (kind string, err error) {
c.m.Lock()
defer c.m.Unlock()
if c.closed() {
return "", ErrClosed
}
kind, err = c.iface.OperatingSystem()
return
}