Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose stop service advertisment on Windows #281

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions adapter_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions gatts_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions gatts_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (a *Adapter) AddService(s *Service) error {
return err
}

a.gattServiceProvider = serviceProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly each GATT service requires its own GattServiceProvider. So if someone adds two services this would only store the latest created.

Users should be able to add and stop the specific service they want.

I was thinking that a map with the UUID and the service provider could work, but the BLE spec allows UUIDs to be repeated (a problem already found on other ble libraries hbldh/bleak#362).

So maybe AddService() should return some handle to the created service to stop it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe AddService() should return some handle to the created service to stop it?

That sounds like a very reasonable suggestion!


localService, err := serviceProvider.GetService()
if err != nil {
return err
Expand Down Expand Up @@ -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)
Expand Down
Loading