From 40dfdeb41b7859b2eb9979eb8cb1a4dc45432906 Mon Sep 17 00:00:00 2001 From: John Brandt Date: Thu, 25 Jul 2024 16:09:05 -0600 Subject: [PATCH 1/2] feat: add stop service advertisement for windows --- adapter_windows.go | 3 +++ gatts_windows.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/adapter_windows.go b/adapter_windows.go index 726a45e..e26e3f5 100644 --- a/adapter_windows.go +++ b/adapter_windows.go @@ -7,6 +7,7 @@ import ( "github.com/go-ole/go-ole" "github.com/saltosystems/winrt-go" "github.com/saltosystems/winrt-go/windows/devices/bluetooth/advertisement" + "github.com/saltosystems/winrt-go/windows/devices/bluetooth/genericattributeprofile" "github.com/saltosystems/winrt-go/windows/foundation" ) @@ -16,6 +17,8 @@ type Adapter struct { connectHandler func(device Device, connected bool) defaultAdvertisement *Advertisement + + gattServiceProvider *genericattributeprofile.GattServiceProvider } // DefaultAdapter is the default adapter on the system. diff --git a/gatts_windows.go b/gatts_windows.go index 5bc3a0c..772e571 100644 --- a/gatts_windows.go +++ b/gatts_windows.go @@ -49,6 +49,8 @@ func (a *Adapter) AddService(s *Service) error { return err } + a.gattServiceProvider = serviceProvider + localService, err := serviceProvider.GetService() if err != nil { return err @@ -237,6 +239,10 @@ func (a *Adapter) AddService(s *Service) error { return serviceProvider.StartAdvertisingWithParameters(params) } +func (a *Adapter) StopServiceAdvertisement() error { + return a.gattServiceProvider.StopAdvertising() +} + // Write replaces the characteristic value with a new value. func (c *Characteristic) Write(p []byte) (n int, err error) { length := len(p) From 3d41e774de7219fbc1584e6d687ffb620db0e08f Mon Sep 17 00:00:00 2001 From: John Brandt Date: Tue, 30 Jul 2024 17:13:02 -0600 Subject: [PATCH 2/2] chore: add StopServiceAdvertisement stub for linux --- gatts_linux.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gatts_linux.go b/gatts_linux.go index dad88b1..d4cfd78 100644 --- a/gatts_linux.go +++ b/gatts_linux.go @@ -71,6 +71,12 @@ func (c *bluezChar) WriteValue(value []byte, options map[string]dbus.Variant) *d return nil } +func (a *Adapter) StopServiceAdvertisement() error { + // TODO: implement on linux + + return nil +} + // AddService creates a new service with the characteristics listed in the // Service struct. func (a *Adapter) AddService(s *Service) error {