Ejemplo n.º 1
0
        private void CleanupInternal()
        {
            if (mStatus == Status.Advertise)
            {
                mServiceProvider.StopAdvertising();
            }

            SetStatus(Status.Invalid);

            if (mInitializationCancelTokenSource != null)
            {
                mInitializationCancelTokenSource.Dispose();
                mInitializationCancelTokenSource = null;
            }

            mUploadCharacteristic   = null;
            mDownloadCharacteristic = null;
            mServiceProvider        = null;

            mSubscribedCentrals.Clear();


            // TODO


            mCallback = null;
            mFinished = true;
        }
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     if (serviceProvider != null)
     {
         if (serviceProvider.AdvertisementStatus != GattServiceProviderAdvertisementStatus.Stopped)
         {
             serviceProvider.StopAdvertising();
         }
         serviceProvider = null;
     }
 }
 public void Dispose()
 {
     // Windows BLE seems to get unreliable if services etc aren't disposed correctly.
     if (continueButtonCharacteristic != null)
     {
         continueButtonCharacteristic.ReadRequested            -= readContinueButtonValue;
         continueButtonCharacteristic.SubscribedClientsChanged -= subscribedClientsChanged;
         continueButtonCharacteristic = null;
     }
     if (stopButtonCharacteristic != null)
     {
         stopButtonCharacteristic.ReadRequested -= readStopButtonValue;
         stopButtonCharacteristic = null;
     }
     if (remoteCanContinueCharacteristic != null)
     {
         remoteCanContinueCharacteristic.WriteRequested -= writeRemoteCanContinue;
         remoteCanContinueCharacteristic = null;
     }
     if (remoteCanStopCharacteristic != null)
     {
         remoteCanStopCharacteristic.WriteRequested -= writeRemoteCanStop;
         remoteCanStopCharacteristic = null;
     }
     if (userMessageCharacteristic != null)
     {
         userMessageCharacteristic.WriteRequested -= writeUserMessage;
         userMessageCharacteristic = null;
     }
     if (cascableService != null)
     {
         cascableService.StopAdvertising();
         cascableService = null;
     }
 }
Ejemplo n.º 4
0
 private void UnpublishService(GattServiceProvider provider)
 {
     try
     {
         if ((provider.AdvertisementStatus == GattServiceProviderAdvertisementStatus.Started) ||
             (provider.AdvertisementStatus == GattServiceProviderAdvertisementStatus.Aborted))
         {
             provider.StopAdvertising();
             SubscribedHidClientsChanged?.Invoke(null);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Failed to stop advertising due to: " + e.Message);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Start up the bl;uetooth listeners, set UUIDs/ble-specific information.
        /// </summary>
        /// <returns></returns>
        private async Task MainAsync()
        {
            // Check if adapter supports peripheral and bluetooth low energy
            peripheralSupported = await CheckPeripheralRoleSupportAsync();

            if (!peripheralSupported)
            {
                Environment.Exit(1);
            }


            if (serviceProvider == null)
            {
                ServiceProviderInitAsync().Wait();
                if (serviceStarted)
                {
                    // Advertising server as connectable and discoverable.
                    advParameters = new GattServiceProviderAdvertisingParameters
                    {
                        // IsConnectable determines whether a call to publish will attempt to start advertising and
                        // put the service UUID in the ADV packet (best effort)
                        IsConnectable  = peripheralSupported,
                        IsDiscoverable = true
                    };

                    // Start server
                    serviceProvider.StartAdvertising(advParameters);


                    this.hasStarted = true;
                    if (this.setIndicate == true)
                    {
                        this.setIndicate = false;
                        Indicate();
                    }
                }
            }
            else
            {
                // Stops advertising support
                serviceProvider.StopAdvertising();
                serviceProvider = null;
            }
        }
Ejemplo n.º 6
0
        ApplicationCtx()
        {
            var exit = new ToolStripMenuItem("&Exit");

            notifyIcon.ContextMenuStrip.Items.Add(exit);

            exit.Click += (sender, args) =>
            {
                if (serviceProvider != null &&
                    serviceProvider.AdvertisementStatus == GattServiceProviderAdvertisementStatus.Started)
                {
                    serviceProvider.StopAdvertising();
                }

                notifyIcon.Visible = false;
                Application.Exit();
            };

            SetupGatt();
        }
 internal void Stop()
 {
     _gattServiceProvider.StopAdvertising();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Stop GATT Server
 /// </summary>
 public void Stop()
 {
     _gattServiceProvider.StopAdvertising(); // Warning: This does not change AdvertisementStatus status, fails on second click...
 }
Ejemplo n.º 9
0
 public async Task StopAsync(CancellationToken cancellationToken)
 {
     _gattServiceProviderFitnessMachine.StopAdvertising();
     await Task.Delay(100, cancellationToken);
 }