forked from muka/go-bluetooth
/
Session1.go
53 lines (46 loc) · 1.33 KB
/
Session1.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
package obex
import (
"github.com/godbus/dbus"
"github.com/muka/go-bluetooth/bluez"
)
// NewObexSession1 create a new ObexSession1 client
func NewObexSession1(path string) *ObexSession1 {
a := new(ObexSession1)
a.client = bluez.NewClient(
&bluez.Config{
Name: "org.bluez.obex",
Iface: "org.bluez.obex.Session1",
Path: dbus.ObjectPath(path),
Bus: bluez.SessionBus,
},
)
a.Properties = new(ObexSession1Properties)
a.GetProperties()
return a
}
// ObexSession1 client
type ObexSession1 struct {
client *bluez.Client
Properties *ObexSession1Properties
}
// ObexSession1Properties exposed properties for ObexSession1
type ObexSession1Properties struct {
Source string // [readonly] Bluetooth adapter address
Destination string // [readonly] Bluetooth device address
Channel byte // [readonly] Bluetooth channel
Target string // [readonly] Target UUID
Root string // [readonly] Root path
}
// Close the connection
func (d *ObexSession1) Close() {
d.client.Disconnect()
}
//GetProperties load all available properties
func (d *ObexSession1) GetProperties() (*ObexSession1Properties, error) {
err := d.client.GetProperties(d.Properties)
return d.Properties, err
}
//GetProperty get a property
func (d *ObexSession1) GetProperty(name string) (dbus.Variant, error) {
return d.client.GetProperty(name)
}