Skip to content

Commit 39f30a5

Browse files
committed
windows: support removing service
1 parent 0c294a1 commit 39f30a5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

gatts_windows.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,32 @@ func (a *Adapter) AddService(s *Service) error {
240240
return serviceProvider.StartAdvertisingWithParameters(params)
241241
}
242242

243+
// RemoveService stops advertising the service and removes it.
244+
func (a *Adapter) RemoveService(s *Service) error {
245+
gattServiceOp, err := genericattributeprofile.GattServiceProviderCreateAsync(syscallUUIDFromUUID(s.UUID))
246+
247+
if err != nil {
248+
return err
249+
}
250+
251+
if err = awaitAsyncOperation(gattServiceOp, genericattributeprofile.SignatureGattServiceProviderResult); err != nil {
252+
return err
253+
}
254+
255+
res, err := gattServiceOp.GetResults()
256+
if err != nil {
257+
return err
258+
}
259+
260+
serviceProviderResult := (*genericattributeprofile.GattServiceProviderResult)(res)
261+
serviceProvider, err := serviceProviderResult.GetServiceProvider()
262+
if err != nil {
263+
return err
264+
}
265+
266+
return serviceProvider.StopAdvertising()
267+
}
268+
243269
// Write replaces the characteristic value with a new value.
244270
func (c *Characteristic) Write(p []byte) (n int, err error) {
245271
length := len(p)

0 commit comments

Comments
 (0)