forked from muka/go-bluetooth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_ProfileManager1.go
162 lines (112 loc) · 3.22 KB
/
gen_ProfileManager1.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package profile
import (
"sync"
"github.com/muka/go-bluetooth/bluez"
"github.com/godbus/dbus"
)
var ProfileManager1Interface = "org.bluez.ProfileManager1"
// NewProfileManager1 create a new instance of ProfileManager1
//
// Args:
func NewProfileManager1() (*ProfileManager1, error) {
a := new(ProfileManager1)
a.client = bluez.NewClient(
&bluez.Config{
Name: "org.bluez",
Iface: ProfileManager1Interface,
Path: dbus.ObjectPath("/org/bluez"),
Bus: bluez.SystemBus,
},
)
return a, nil
}
/*
ProfileManager1 Profile Manager hierarchy
*/
type ProfileManager1 struct {
client *bluez.Client
propertiesSignal chan *dbus.Signal
objectManagerSignal chan *dbus.Signal
objectManager *bluez.ObjectManager
Properties *ProfileManager1Properties
}
// ProfileManager1Properties contains the exposed properties of an interface
type ProfileManager1Properties struct {
lock sync.RWMutex `dbus:"ignore"`
}
//Lock access to properties
func (p *ProfileManager1Properties) Lock() {
p.lock.Lock()
}
//Unlock access to properties
func (p *ProfileManager1Properties) Unlock() {
p.lock.Unlock()
}
// Close the connection
func (a *ProfileManager1) Close() {
a.client.Disconnect()
}
// Path return ProfileManager1 object path
func (a *ProfileManager1) Path() dbus.ObjectPath {
return a.client.Config.Path
}
// Client return ProfileManager1 dbus client
func (a *ProfileManager1) Client() *bluez.Client {
return a.client
}
// Interface return ProfileManager1 interface
func (a *ProfileManager1) Interface() string {
return a.client.Config.Iface
}
// GetObjectManagerSignal return a channel for receiving updates from the ObjectManager
func (a *ProfileManager1) GetObjectManagerSignal() (chan *dbus.Signal, func(), error) {
if a.objectManagerSignal == nil {
if a.objectManager == nil {
om, err := bluez.GetObjectManager()
if err != nil {
return nil, nil, err
}
a.objectManager = om
}
s, err := a.objectManager.Register()
if err != nil {
return nil, nil, err
}
a.objectManagerSignal = s
}
cancel := func() {
if a.objectManagerSignal == nil {
return
}
a.objectManagerSignal <- nil
a.objectManager.Unregister(a.objectManagerSignal)
a.objectManagerSignal = nil
}
return a.objectManagerSignal, cancel, nil
}
/*
RegisterProfile
This registers a profile implementation.
If an application disconnects from the bus all
its registered profiles will be removed.
HFP HS UUID: 0000111e-0000-1000-8000-00805f9b34fb
Default RFCOMM channel is 6. And this requires
authentication.
Available options:
string Name
Human readable name for the profile
string Service
*/
func (a *ProfileManager1) RegisterProfile(profile dbus.ObjectPath, uuid string, options map[string]interface{}) error {
return a.client.Call("RegisterProfile", 0, profile, uuid, options).Store()
}
/*
UnregisterProfile
This unregisters the profile that has been previously
registered. The object path parameter must match the
same value that has been used on registration.
Possible errors: org.bluez.Error.DoesNotExist
*/
func (a *ProfileManager1) UnregisterProfile(profile dbus.ObjectPath) error {
return a.client.Call("UnregisterProfile", 0, profile).Store()
}