forked from muka/go-bluetooth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_Profile1.go
179 lines (129 loc) · 3.69 KB
/
gen_Profile1.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package profile
import (
"sync"
"github.com/muka/go-bluetooth/bluez"
"github.com/godbus/dbus"
)
var Profile1Interface = "org.bluez.Profile1"
// NewProfile1 create a new instance of Profile1
//
// Args:
// - servicePath: unique name
// - objectPath: freely definable
func NewProfile1(servicePath string, objectPath dbus.ObjectPath) (*Profile1, error) {
a := new(Profile1)
a.client = bluez.NewClient(
&bluez.Config{
Name: servicePath,
Iface: Profile1Interface,
Path: dbus.ObjectPath(objectPath),
Bus: bluez.SystemBus,
},
)
return a, nil
}
/*
Profile1 Profile hierarchy
*/
type Profile1 struct {
client *bluez.Client
propertiesSignal chan *dbus.Signal
objectManagerSignal chan *dbus.Signal
objectManager *bluez.ObjectManager
Properties *Profile1Properties
}
// Profile1Properties contains the exposed properties of an interface
type Profile1Properties struct {
lock sync.RWMutex `dbus:"ignore"`
}
//Lock access to properties
func (p *Profile1Properties) Lock() {
p.lock.Lock()
}
//Unlock access to properties
func (p *Profile1Properties) Unlock() {
p.lock.Unlock()
}
// Close the connection
func (a *Profile1) Close() {
a.client.Disconnect()
}
// Path return Profile1 object path
func (a *Profile1) Path() dbus.ObjectPath {
return a.client.Config.Path
}
// Client return Profile1 dbus client
func (a *Profile1) Client() *bluez.Client {
return a.client
}
// Interface return Profile1 interface
func (a *Profile1) Interface() string {
return a.client.Config.Iface
}
// GetObjectManagerSignal return a channel for receiving updates from the ObjectManager
func (a *Profile1) 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
}
/*
Release
This method gets called when the service daemon
unregisters the profile. A profile can use it to do
cleanup tasks. There is no need to unregister the
profile, because when this method gets called it has
already been unregistered.
*/
func (a *Profile1) Release() error {
return a.client.Call("Release", 0, ).Store()
}
/*
NewConnection
This method gets called when a new service level
connection has been made and authorized.
Common fd_properties:
uint16 Version Profile version (optional)
uint16 Features Profile features (optional)
Possible errors: org.bluez.Error.Rejected
org.bluez.Error.Canceled
*/
func (a *Profile1) NewConnection(device dbus.ObjectPath, fd int32, fd_properties map[string]interface{}) error {
return a.client.Call("NewConnection", 0, device, fd, fd_properties).Store()
}
/*
RequestDisconnection
This method gets called when a profile gets
disconnected.
The file descriptor is no longer owned by the service
daemon and the profile implementation needs to take
care of cleaning up all connections.
If multiple file descriptors are indicated via
NewConnection, it is expected that all of them
are disconnected before returning from this
method call.
Possible errors: org.bluez.Error.Rejected
org.bluez.Error.Canceled
*/
func (a *Profile1) RequestDisconnection(device dbus.ObjectPath) error {
return a.client.Call("RequestDisconnection", 0, device).Store()
}