Skip to content

Commit 6871cd0

Browse files
committed
gap/linux: update implementation for GAP to allow for calling adv.Configure()
followed by adv.Start() followed by adv.Stop() multiple times. This is required in order to update advertising ServiceData. Signed-off-by: deadprogram <[email protected]>
1 parent 484dda9 commit 6871cd0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

gap_linux.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Advertisement struct {
2828
adapter *Adapter
2929
properties *prop.Properties
3030
path dbus.ObjectPath
31+
started bool
3132
}
3233

3334
// DefaultAdvertisement returns the default advertisement instance but does not
@@ -45,8 +46,8 @@ func (a *Adapter) DefaultAdvertisement() *Advertisement {
4546
//
4647
// On Linux with BlueZ, it is not possible to set the advertisement interval.
4748
func (a *Advertisement) Configure(options AdvertisementOptions) error {
48-
if a.properties != nil {
49-
panic("todo: configure advertisement a second time")
49+
if a.started {
50+
panic("cannot configure advertisement that is already started")
5051
}
5152

5253
var serviceUUIDs []string
@@ -110,6 +111,7 @@ func (a *Advertisement) Start() error {
110111
if err != nil {
111112
return fmt.Errorf("bluetooth: could not start advertisement: %w", err)
112113
}
114+
a.started = true
113115
return nil
114116
}
115117

@@ -122,6 +124,7 @@ func (a *Advertisement) Stop() error {
122124
}
123125
return fmt.Errorf("bluetooth: could not stop advertisement: %w", err)
124126
}
127+
a.started = false
125128
return nil
126129
}
127130

0 commit comments

Comments
 (0)