Skip to content

Commit

Permalink
gap/linux: update implementation for GAP to allow for calling adv.Con…
Browse files Browse the repository at this point in the history
…figure()

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]>
  • Loading branch information
deadprogram committed Jan 2, 2025
1 parent 863c1e3 commit 8ee03a0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gap_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Advertisement struct {
adapter *Adapter
properties *prop.Properties
path dbus.ObjectPath
started bool
}

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

var serviceUUIDs []string
Expand Down Expand Up @@ -110,6 +111,7 @@ func (a *Advertisement) Start() error {
if err != nil {
return fmt.Errorf("bluetooth: could not start advertisement: %w", err)
}
a.started = true
return nil
}

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

Expand Down

0 comments on commit 8ee03a0

Please sign in to comment.