Mistake on this page?
Report an issue in GitHub or email us
GattServer.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2013 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MBED_GATT_SERVER_H__
18 #define MBED_GATT_SERVER_H__
19 
20 #include "ble/common/StaticInterface.h"
21 #include "ble/GattService.h"
22 #include "ble/GattAttribute.h"
23 #include "ble/GattServerEvents.h"
24 #include "ble/GattCallbackParamTypes.h"
25 #include "ble/CallChainOfFunctionPointersWithContext.h"
26 #include "BleImplementationForward.h"
27 
28 #if !defined(DOXYGEN_ONLY)
29 namespace ble {
30 namespace interface {
31 #endif
32 
33 /**
34  * @addtogroup ble
35  * @{
36  * @addtogroup gatt
37  * @{
38  * @addtogroup server
39  * @{
40  */
41 
42 /**
43  * Construct and operates a GATT server.
44  *
45  * A Gatt server is a collection of GattService; these services contain
46  * characteristics that a peer connected to the device may read or write.
47  * These characteristics may also emit updates to subscribed clients when their
48  * values change.
49  *
50  * @p Server Layout
51  *
52  * Application code can add a GattService object to the server with the help of
53  * the function addService(). That function registers all the GattCharacteristic
54  * enclosed in the service, as well as all the characteristics descriptors (see
55  * GattAttribute) these characteristics contain. Service registration assigns
56  * a unique handle to the various attributes being part of the service; this
57  * handle should be used for subsequent read or write of these components.
58  *
59  * There are no primitives defined to remove a single service; however, a call to
60  * the function reset() removes all services previously registered in the
61  * GattServer.
62  *
63  * @p Characteristic and attributes access
64  *
65  * Values of the characteristic and the characteristic descriptor present in the
66  * GattServer must be accessed through the handle assigned to them when the service
67  * has been registered; the GattServer class offers several flavors of read()
68  * and write() functions that retrieve or mutate an attribute value.
69  *
70  * Application code can query if a client has subscribed to a given
71  * characteristic's value update by invoking the function areUpdatesEnabled().
72  *
73  * @p Events
74  *
75  * The GattServer allows application code to register several event handlers that
76  * can be used to monitor client and server activities:
77  * - onDataSent(): Register an event handler that is called when a
78  * characteristic value update has been sent to a client.
79  * - onDataWriten(): Register an event handler that is called when a
80  * client has written an attribute of the server.
81  * - onDataRead(): Register an event handler that is called when a
82  * client has read an attribute of the server.
83  * - onUpdatesEnabled: Register an event handler that is called when a
84  * client subscribes to updates of a characteristic.
85  * - onUpdatesDisabled: Register an event handler that is called when a
86  * client unsubscribes from updates of a characteristic.
87  * - onConfimationReceived: Register an event handler that is called
88  * when a client acknowledges a characteristic value notification.
89  *
90  * @note The term characteristic value update is used to represent
91  * Characteristic Value Notification and Characteristic Value Indication when
92  * the nature of the server initiated is not relevant.
93  */
94 #if !defined(DOXYGEN_ONLY)
95 template <class Impl>
96 class GattServer : public StaticInterface<Impl, GattServer> {
97 #else
98 class GattServer {
99 #endif
100 
102 
103 public:
104 
105  /**
106  * Definition of the general handler of GattServer related events.
107  */
108  struct EventHandler {
109  /**
110  * Function invoked when the connections changes the ATT_MTU which controls
111  * the maximum size of an attribute that can be read in a single L2CAP packet
112  * which might be fragmented across multiple packets.
113  *
114  * @param connectionHandle The handle of the connection that changed the size.
115  * @param attMtuSize
116  */
117  virtual void onAttMtuChange(
118  ble::connection_handle_t connectionHandle,
119  uint16_t attMtuSize
120  )
121  {
122  }
123  };
124 
125  /**
126  * Assign the event handler implementation that will be used by the
127  * module to signal events back to the application.
128  *
129  * @param handler Application implementation of an EventHandler.
130  */
132  {
133  eventHandler = handler;
134  }
135 
136  /**
137  * Event handler invoked when the server has sent data to a client.
138  *
139  * @see onDataSent().
140  */
142 
143  /**
144  * Callchain of DataSentCallback_t objects.
145  *
146  * @see onDataSent().
147  */
150 
151  /**
152  * Event handler invoked when the client has written an attribute of the
153  * server.
154  *
155  * @see onDataWritten().
156  */
159 
160  /**
161  * Callchain of DataWrittenCallback_t objects.
162  *
163  * @see onDataWritten().
164  */
167 
168  /**
169  * Event handler invoked when the client has read an attribute of the server.
170  *
171  * @see onDataRead().
172  */
175 
176  /**
177  * Callchain of DataReadCallback_t.
178  *
179  * @see onDataRead().
180  */
183 
184  /**
185  * Event handler invoked when the GattServer is reset.
186  *
187  * @see onShutdown() reset()
188  */
191 
192  /**
193  * Callchain of GattServerShutdownCallback_t.
194  *
195  * @see onShutdown() reset()
196  */
199 
200  /**
201  * Event handler that handles subscription to characteristic updates,
202  * unsubscription from characteristic updates and notification confirmation.
203  *
204  * @see onUpdatesEnabled() onUpdateDisabled() onConfirmationReceived()
205  */
207 
208 protected:
209  /**
210  * Construct a GattServer instance.
211  */
212  GattServer();
213 
214  /*
215  * The following functions are meant to be overridden in the platform
216  * specific subclass.
217  */
218 public:
219 
220  /**
221  * Add a service declaration to the local attribute server table.
222  *
223  * This functions inserts a service declaration in the attribute table
224  * followed by the characteristic declarations (including characteristic
225  * descriptors) present in @p service.
226  *
227  * The process assigns a unique attribute handle to all the elements added
228  * into the attribute table. This handle is an ID that must be used for
229  * subsequent interractions with the elements.
230  *
231  * @note There is no mirror function that removes a single service.
232  * Application code can remove all the registered services by calling
233  * reset().
234  *
235  * @attention Service, characteristics and descriptors objects registered
236  * within the GattServer must remain reachable until reset() is called.
237  *
238  * @param[in] service The service to be added; attribute handle of services,
239  * characteristic and characteristic descriptors are updated by the
240  * process.
241  *
242  * @return BLE_ERROR_NONE if the service was successfully added.
243  */
244  ble_error_t addService(GattService &service);
245 
246  /**
247  * Read the value of an attribute present in the local GATT server.
248  *
249  * @param[in] attributeHandle Handle of the attribute to read.
250  * @param[out] buffer A buffer to hold the value being read.
251  * @param[in,out] lengthP Length of the buffer being supplied. If the
252  * attribute value is longer than the size of the supplied buffer, this
253  * variable holds upon return the total attribute value length (excluding
254  * offset). The application may use this information to allocate a suitable
255  * buffer size.
256  *
257  * @return BLE_ERROR_NONE if a value was read successfully into the buffer.
258  *
259  * @attention read(ble::connection_handle_t, GattAttribute::Handle_t, uint8_t *, uint16_t *)
260  * must be used to read Client Characteristic Configuration Descriptor (CCCD)
261  * because the value of this type of attribute depends on the connection.
262  */
263  ble_error_t read(
264  GattAttribute::Handle_t attributeHandle,
265  uint8_t buffer[],
266  uint16_t *lengthP
267  );
268 
269  /**
270  * Read the value of an attribute present in the local GATT server.
271  *
272  * The connection handle allows application code to read the value of a
273  * Client Characteristic Configuration Descriptor for a given connection.
274  *
275  * @param[in] connectionHandle Connection handle.
276  * @param[in] attributeHandle Attribute handle for the value attribute of
277  * the characteristic.
278  * @param[out] buffer A buffer to hold the value being read.
279  * @param[in,out] lengthP Length of the buffer being supplied. If the
280  * attribute value is longer than the size of the supplied buffer, this
281  * variable holds upon return the total attribute value length (excluding
282  * offset). The application may use this information to allocate a suitable
283  * buffer size.
284  *
285  * @return BLE_ERROR_NONE if a value was read successfully into the buffer.
286  */
287  ble_error_t read(
288  ble::connection_handle_t connectionHandle,
289  GattAttribute::Handle_t attributeHandle,
290  uint8_t *buffer,
291  uint16_t *lengthP
292  );
293 
294  /**
295  * Update the value of an attribute present in the local GATT server.
296  *
297  * @param[in] attributeHandle Handle of the attribute to write.
298  * @param[in] value A pointer to a buffer holding the new value.
299  * @param[in] size Size in bytes of the new value (in bytes).
300  * @param[in] localOnly If this flag is false and the attribute handle
301  * written is a characteristic value, then the server sends an update
302  * containing the new value to all clients that have subscribed to the
303  * characteristic's notifications or indications. Otherwise, the update does
304  * not generate a single server initiated event.
305  *
306  * @return BLE_ERROR_NONE if the attribute value has been successfully
307  * updated.
308  */
309  ble_error_t write(
310  GattAttribute::Handle_t attributeHandle,
311  const uint8_t *value,
312  uint16_t size,
313  bool localOnly = false
314  );
315 
316  /**
317  * Update the value of an attribute present in the local GATT server.
318  *
319  * The connection handle parameter allows application code to direct
320  * notification or indication resulting from the update to a specific client.
321  *
322  * @param[in] connectionHandle Connection handle.
323  * @param[in] attributeHandle Handle for the value attribute of the
324  * characteristic.
325  * @param[in] value A pointer to a buffer holding the new value.
326  * @param[in] size Size of the new value (in bytes).
327  * @param[in] localOnly If this flag is false and the attribute handle
328  * written is a characteristic value, then the server sends an update
329  * containing the new value to the client identified by the parameter
330  * @p connectionHandle if it is subscribed to the characteristic's
331  * notifications or indications. Otherwise, the update does not generate a
332  * single server initiated event.
333  *
334  * @return BLE_ERROR_NONE if the attribute value has been successfully
335  * updated.
336  */
337  ble_error_t write(
338  ble::connection_handle_t connectionHandle,
339  GattAttribute::Handle_t attributeHandle,
340  const uint8_t *value,
341  uint16_t size,
342  bool localOnly = false
343  );
344 
345  /**
346  * Determine if one of the connected clients has subscribed to notifications
347  * or indications of the characteristic in input.
348  *
349  * @param[in] characteristic The characteristic.
350  * @param[out] enabledP Upon return, *enabledP is true if updates are
351  * enabled for a connected client; otherwise, *enabledP is false.
352  *
353  * @return BLE_ERROR_NONE if the connection and handle are found. False
354  * otherwise.
355  */
356  ble_error_t areUpdatesEnabled(
357  const GattCharacteristic &characteristic,
358  bool *enabledP
359  );
360 
361  /**
362  * Determine if an identified client has subscribed to notifications or
363  * indications of a given characteristic.
364  *
365  * @param[in] connectionHandle The connection handle.
366  * @param[in] characteristic The characteristic.
367  * @param[out] enabledP Upon return, *enabledP is true if the client
368  * identified by @p connectionHandle has subscribed to notifications or
369  * indications of @p characteristic; otherwise, *enabledP is false.
370  *
371  * @return BLE_ERROR_NONE if the connection and handle are found. False
372  * otherwise.
373  */
374  ble_error_t areUpdatesEnabled(
375  ble::connection_handle_t connectionHandle,
376  const GattCharacteristic &characteristic,
377  bool *enabledP
378  );
379 
380  /**
381  * Indicate if the underlying stack emit events when an attribute is read by
382  * a client.
383  *
384  * @attention This function should be overridden to return true if
385  * applicable.
386  *
387  * @return true if onDataRead is supported; false otherwise.
388  */
389  bool isOnDataReadAvailable() const;
390 
391  /*
392  * APIs with nonvirtual implementations.
393  */
394 public:
395  /**
396  * Add an event handler that monitors emission of characteristic value
397  * updates.
398  *
399  * @param[in] callback Event handler being registered.
400  *
401  * @note It is possible to chain together multiple onDataSent callbacks
402  * (potentially from different modules of an application).
403  */
404  void onDataSent(const DataSentCallback_t &callback)
405  {
406  dataSentCallChain.add(callback);
407  }
408 
409  /**
410  * Add an event handler that monitors emission of characteristic value
411  * updates.
412  *
413  * @param[in] objPtr Pointer to the instance that is used to invoke the
414  * event handler.
415  * @param[in] memberPtr Event handler being registered. It is a member
416  * function.
417  */
418  template <typename T>
419  void onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count))
420  {
421  dataSentCallChain.add(objPtr, memberPtr);
422  }
423 
424  /**
425  * Access the callchain of data sent event handlers.
426  *
427  * @return A reference to the DATA_SENT event callback chain.
428  */
430  {
431  return dataSentCallChain;
432  }
433 
434  /**
435  * Set an event handler that is called after
436  * a connected peer has written an attribute.
437  *
438  * @param[in] callback The event handler being registered.
439  *
440  * @attention It is possible to set multiple event handlers. Registered
441  * handlers may be removed with onDataWritten().detach(callback).
442  */
444  {
445  dataWrittenCallChain.add(callback);
446  }
447 
448  /**
449  * Set an event handler that is called after
450  * a connected peer has written an attribute.
451  *
452  * @param[in] objPtr Pointer to the instance that is used to invoke the
453  * event handler (@p memberPtr).
454  * @param[in] memberPtr Event handler being registered. It is a member
455  * function.
456  */
457  template <typename T>
459  T *objPtr,
460  void (T::*memberPtr)(const GattWriteCallbackParams *context)
461  ) {
462  dataWrittenCallChain.add(objPtr, memberPtr);
463  }
464 
465  /**
466  * Access the callchain of data written event handlers.
467  *
468  * @return A reference to the data written event callbacks chain.
469  *
470  * @note It is possible to register callbacks using
471  * onDataWritten().add(callback).
472  *
473  * @note It is possible to unregister callbacks using
474  * onDataWritten().detach(callback).
475  */
477  {
478  return dataWrittenCallChain;
479  }
480 
481  /**
482  * Set an event handler that monitors attribute reads from connected clients.
483  *
484  * @param[in] callback Event handler being registered.
485  *
486  * @return BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available;
487  * else BLE_ERROR_NONE.
488  *
489  * @note This functionality may not be available on all underlying stacks.
490  * Application code may work around that limitation by monitoring read
491  * requests instead of read events.
492  *
493  * @see GattCharacteristic::setReadAuthorizationCallback()
494  * @see isOnDataReadAvailable().
495  *
496  * @attention It is possible to set multiple event handlers. Registered
497  * handlers may be removed with onDataRead().detach(callback).
498  */
500  {
501  if (!isOnDataReadAvailable()) {
503  }
504 
505  dataReadCallChain.add(callback);
506  return BLE_ERROR_NONE;
507  }
508 
509  /**
510  * Set an event handler that monitors attribute reads from connected clients.
511  *
512  * @param[in] objPtr Pointer to the instance that is used to invoke the
513  * event handler (@p memberPtr).
514  * @param[in] memberPtr Event handler being registered. It is a member
515  * function.
516  */
517  template <typename T>
519  T *objPtr,
520  void (T::*memberPtr)(const GattReadCallbackParams *context)
521  ) {
522  if (!isOnDataReadAvailable()) {
524  }
525 
526  dataReadCallChain.add(objPtr, memberPtr);
527  return BLE_ERROR_NONE;
528  }
529 
530  /**
531  * Access the callchain of data read event handlers.
532  *
533  * @return A reference to the data read event callbacks chain.
534  *
535  * @note It is possible to register callbacks using
536  * onDataRead().add(callback).
537  *
538  * @note It is possible to unregister callbacks using
539  * onDataRead().detach(callback).
540  */
542  {
543  return dataReadCallChain;
544  }
545 
546  /**
547  * Set an event handler that monitors shutdown or reset of the GattServer.
548  *
549  * The event handler is invoked when the GattServer instance is about
550  * to be shut down. This can result in a call to reset() or BLE::reset().
551  *
552  * @param[in] callback Event handler being registered.
553  *
554  * @note It is possible to set up multiple shutdown event handlers.
555  *
556  * @note It is possible to unregister a callback using
557  * onShutdown().detach(callback)
558  */
560  {
561  shutdownCallChain.add(callback);
562  }
563 
564  /**
565  * Set an event handler that monitors shutdown or reset of the GattServer.
566  *
567  * The event handler is invoked when the GattServer instance is about
568  * to be shut down. This can result of a call to reset() or BLE::reset().
569  *
570  * @param[in] objPtr Pointer to the instance that is used to invoke the
571  * event handler (@p memberPtr).
572  * @param[in] memberPtr Event handler being registered. It is a member
573  * function.
574  */
575  template <typename T>
576  void onShutdown(T *objPtr, void (T::*memberPtr)(const GattServer *))
577  {
578  shutdownCallChain.add(objPtr, memberPtr);
579  }
580 
581  /**
582  * Access the callchain of shutdown event handlers.
583  *
584  * @return A reference to the shutdown event callbacks chain.
585  *
586  * @note It is possible to register callbacks using
587  * onShutdown().add(callback).
588  *
589  * @note It is possible to unregister callbacks using
590  * onShutdown().detach(callback).
591  */
593  {
594  return shutdownCallChain;
595  }
596 
597  /**
598  * Set up an event handler that monitors subscription to characteristic
599  * updates.
600  *
601  * @param[in] callback Event handler being registered.
602  */
603  void onUpdatesEnabled(EventCallback_t callback)
604  {
605  updatesEnabledCallback = callback;
606  }
607 
608  /**
609  * Set up an event handler that monitors unsubscription from characteristic
610  * updates.
611  *
612  * @param[in] callback Event handler being registered.
613  */
614  void onUpdatesDisabled(EventCallback_t callback)
615  {
616  updatesDisabledCallback = callback;
617  }
618 
619  /**
620  * Set up an event handler that monitors notification acknowledgment.
621  *
622  * The event handler is called when a client sends a confirmation that it has
623  * correctly received a notification from the server.
624  *
625  * @param[in] callback Event handler being registered.
626  */
627  void onConfirmationReceived(EventCallback_t callback)
628  {
629  confirmationReceivedCallback = callback;
630  }
631 
632  /* Entry points for the underlying stack to report events back to the user. */
633 protected:
634  /**
635  * Helper function that notifies all registered handlers of an occurrence
636  * of a data written event.
637  *
638  * @attention Vendor implementation must invoke this function after one of
639  * the GattServer attributes has been written.
640  *
641  * @param[in] params The data written parameters passed to the registered
642  * handlers.
643  */
645  {
646  dataWrittenCallChain.call(params);
647  }
648 
649  /**
650  * Helper function that notifies all registered handlers of an occurrence
651  * of a data read event.
652  *
653  * @attention Vendor implementation must invoke this function after one of
654  * the GattServer attributes has been read.
655  *
656  * @param[in] params The data read parameters passed to the registered
657  * handlers.
658  */
660  {
661  dataReadCallChain.call(params);
662  }
663 
664  /**
665  * Helper function that notifies the registered handler of an occurrence
666  * of updates enabled, updates disabled or confirmation received events.
667  *
668  * @attention Vendor implementation must invoke this function when a client
669  * subscribes to characteristic updates, unsubscribes from characteristic
670  * updates or a notification confirmation has been received.
671  *
672  * @param[in] type The type of event that occurred.
673  * @param[in] attributeHandle The handle of the attribute concerned by the
674  * event.
675  */
678  GattAttribute::Handle_t attributeHandle
679  ) {
680  switch (type) {
682  if (updatesEnabledCallback) {
683  updatesEnabledCallback(attributeHandle);
684  }
685  break;
687  if (updatesDisabledCallback) {
688  updatesDisabledCallback(attributeHandle);
689  }
690  break;
692  if (confirmationReceivedCallback) {
693  confirmationReceivedCallback(attributeHandle);
694  }
695  break;
696 
698  // Called every time a notification or indication has been sent
699  handleDataSentEvent(1);
700  break;
701 
702  default:
703  break;
704  }
705  }
706 
707  /**
708  * Helper function that notifies all registered handlers of an occurrence
709  * of a data sent event.
710  *
711  * @attention Vendor implementation must invoke this function after the
712  * emission of a notification or an indication.
713  *
714  * @param[in] count Number of packets sent.
715  */
716  void handleDataSentEvent(unsigned count)
717  {
718  dataSentCallChain.call(count);
719  }
720 
721 public:
722  /**
723  * Shut down the GattServer instance.
724  *
725  * This function notifies all event handlers listening for shutdown events
726  * that the GattServer is about to be shut down; then it clears all
727  * GattServer state.
728  *
729  * @note This function is meant to be overridden in the platform-specific
730  * subclass. Overides must call the parent function before any cleanup.
731  *
732  * @return BLE_ERROR_NONE on success.
733  */
734  ble_error_t reset(void);
735 
736 protected:
737  /* --- Abstract calls to override --- */
738 
739  /* Derived implementation must call the base reset_ */
740  ble_error_t reset_(void);
741 
742  ble_error_t addService_(GattService &service);
743 
744  ble_error_t read_(
745  GattAttribute::Handle_t attributeHandle,
746  uint8_t buffer[],
747  uint16_t *lengthP
748  );
749 
750  ble_error_t read_(
751  ble::connection_handle_t connectionHandle,
752  GattAttribute::Handle_t attributeHandle,
753  uint8_t *buffer,
754  uint16_t *lengthP
755  );
756 
757  ble_error_t write_(
758  GattAttribute::Handle_t attributeHandle,
759  const uint8_t *value,
760  uint16_t size,
761  bool localOnly
762  );
763 
764  ble_error_t write_(
765  ble::connection_handle_t connectionHandle,
766  GattAttribute::Handle_t attributeHandle,
767  const uint8_t *value,
768  uint16_t size,
769  bool localOnly
770  );
771 
772  ble_error_t areUpdatesEnabled_(
773  const GattCharacteristic &characteristic,
774  bool *enabledP
775  );
776 
777  ble_error_t areUpdatesEnabled_(
778  ble::connection_handle_t connectionHandle,
779  const GattCharacteristic &characteristic,
780  bool *enabledP
781  );
782 
783  bool isOnDataReadAvailable_() const;
784 
785 protected:
786  /**
787  * Event handler provided by the application.
788  */
790 
791  /**
792  * The total number of services added to the ATT table.
793  */
794  uint8_t serviceCount;
795 
796  /**
797  * The total number of characteristics added to the ATT table.
798  */
800 
801 private:
802  /**
803  * Callchain containing all registered callback handlers for data sent
804  * events.
805  */
806  DataSentCallbackChain_t dataSentCallChain;
807 
808  /**
809  * Callchain containing all registered callback handlers for data written
810  * events.
811  */
812  DataWrittenCallbackChain_t dataWrittenCallChain;
813 
814  /**
815  * Callchain containing all registered callback handlers for data read
816  * events.
817  */
818  DataReadCallbackChain_t dataReadCallChain;
819 
820  /**
821  * Callchain containing all registered callback handlers for shutdown
822  * events.
823  */
824  GattServerShutdownCallbackChain_t shutdownCallChain;
825 
826  /**
827  * The registered callback handler for updates enabled events.
828  */
829  EventCallback_t updatesEnabledCallback;
830 
831  /**
832  * The registered callback handler for updates disabled events.
833  */
834  EventCallback_t updatesDisabledCallback;
835 
836  /**
837  * The registered callback handler for confirmation received events.
838  */
839  EventCallback_t confirmationReceivedCallback;
840 
841 private:
842  /* Disallow copy and assignment. */
843  GattServer(const GattServer &);
844  GattServer& operator=(const GattServer &);
845 };
846 
847 /**
848  * @}
849  * @}
850  * @}
851  */
852 
853 #if !defined(DOXYGEN_ONLY)
854 } // interface
855 } // ble
856 
857 typedef ble::impl::GattServer GattServer;
858 
859 #endif
860 
861 
862 #endif /* ifndef MBED_GATT_SERVER_H__ */
ble_error_t onDataRead(T *objPtr, void(T::*memberPtr)(const GattReadCallbackParams *context))
Set an event handler that monitors attribute reads from connected clients.
Definition: GattServer.h:518
uint8_t serviceCount
The total number of services added to the ATT table.
Definition: GattServer.h:794
Definition of the general handler of GattServer related events.
Definition: GattServer.h:108
FunctionPointerWithContext< const GattServer * > GattServerShutdownCallback_t
Event handler invoked when the GattServer is reset.
Definition: GattServer.h:190
void handleDataWrittenEvent(const GattWriteCallbackParams *params)
Helper function that notifies all registered handlers of an occurrence of a data written event...
Definition: GattServer.h:644
void handleDataSentEvent(unsigned count)
Helper function that notifies all registered handlers of an occurrence of a data sent event...
Definition: GattServer.h:716
uintptr_t connection_handle_t
Opaque reference to a connection.
Definition: BLETypes.h:86
GattServerShutdownCallbackChain_t & onShutdown()
Access the callchain of shutdown event handlers.
Definition: GattServer.h:592
void setEventHandler(EventHandler *handler)
Assign the event handler implementation that will be used by the module to signal events back to the ...
Definition: GattServer.h:131
CallChainOfFunctionPointersWithContext< const GattWriteCallbackParams * > DataWrittenCallbackChain_t
Callchain of DataWrittenCallback_t objects.
Definition: GattServer.h:166
DataWrittenCallbackChain_t & onDataWritten()
Access the callchain of data written event handlers.
Definition: GattServer.h:476
void onShutdown(const GattServerShutdownCallback_t &callback)
Set an event handler that monitors shutdown or reset of the GattServer.
Definition: GattServer.h:559
ble_error_t onDataRead(const DataReadCallback_t &callback)
Set an event handler that monitors attribute reads from connected clients.
Definition: GattServer.h:499
void onDataWritten(T *objPtr, void(T::*memberPtr)(const GattWriteCallbackParams *context))
Set an event handler that is called after a connected peer has written an attribute.
Definition: GattServer.h:458
virtual void onAttMtuChange(ble::connection_handle_t connectionHandle, uint16_t attMtuSize)
Function invoked when the connections changes the ATT_MTU which controls the maximum size of an attri...
Definition: GattServer.h:117
CallChainOfFunctionPointersWithContext< unsigned > DataSentCallbackChain_t
Callchain of DataSentCallback_t objects.
Definition: GattServer.h:149
DataSentCallbackChain_t & onDataSent()
Access the callchain of data sent event handlers.
Definition: GattServer.h:429
void handleEvent(GattServerEvents::gattEvent_e type, GattAttribute::Handle_t attributeHandle)
Helper function that notifies the registered handler of an occurrence of updates enabled, updates disabled or confirmation received events.
Definition: GattServer.h:676
No error.
Definition: blecommon.h:151
void onDataSent(const DataSentCallback_t &callback)
Add an event handler that monitors emission of characteristic value updates.
Definition: GattServer.h:404
gattEvent_e
Enumeration of events, which a GattServer implementation can generate.
ble::attribute_handle_t Handle_t
Representation of an attribute handle.
Definition: GattAttribute.h:67
FunctionPointerWithContext< unsigned > DataSentCallback_t
Event handler invoked when the server has sent data to a client.
Definition: GattServer.h:141
Notification or indication enabled in CCCD.
Construct and operates a GATT server.
Definition: GattServer.h:98
GATT Write event definition.
CallChainOfFunctionPointersWithContext< const GattServer * > GattServerShutdownCallbackChain_t
Callchain of GattServerShutdownCallback_t.
Definition: GattServer.h:198
GATT Read event definition.
Representation of a GattServer characteristic.
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=0)
Create a callback class with type inferred from the arguments.
Definition: Callback.h:709
Fired when a server event was successfully sent.
void onShutdown(T *objPtr, void(T::*memberPtr)(const GattServer *))
Set an event handler that monitors shutdown or reset of the GattServer.
Definition: GattServer.h:576
EventHandler * eventHandler
Event handler provided by the application.
Definition: GattServer.h:789
FunctionPointerWithContext< const GattWriteCallbackParams * > DataWrittenCallback_t
Event handler invoked when the client has written an attribute of the server.
Definition: GattServer.h:158
void handleDataReadEvent(const GattReadCallbackParams *params)
Helper function that notifies all registered handlers of an occurrence of a data read event...
Definition: GattServer.h:659
DataReadCallbackChain_t & onDataRead()
Access the callchain of data read event handlers.
Definition: GattServer.h:541
void onConfirmationReceived(EventCallback_t callback)
Set up an event handler that monitors notification acknowledgment.
Definition: GattServer.h:627
Representation of a GattServer service.
Definition: GattService.h:38
void onUpdatesEnabled(EventCallback_t callback)
Set up an event handler that monitors subscription to characteristic updates.
Definition: GattServer.h:603
Requested a feature that isn&#39;t yet implemented or isn&#39;t supported by the target HW.
Definition: blecommon.h:162
FunctionPointerWithContext< GattAttribute::Handle_t > EventCallback_t
Event handler that handles subscription to characteristic updates, unsubscription from characteristic...
Definition: GattServer.h:206
void onUpdatesDisabled(EventCallback_t callback)
Set up an event handler that monitors unsubscription from characteristic updates. ...
Definition: GattServer.h:614
void onDataWritten(const DataWrittenCallback_t &callback)
Set an event handler that is called after a connected peer has written an attribute.
Definition: GattServer.h:443
FunctionPointerWithContext< const GattReadCallbackParams * > DataReadCallback_t
Event handler invoked when the client has read an attribute of the server.
Definition: GattServer.h:174
Notification or Indication disabled in CCCD.
Entry namespace for all BLE API definitions.
Response received from Characteristic Value Indication message.
CallChainOfFunctionPointersWithContext< const GattReadCallbackParams * > DataReadCallbackChain_t
Callchain of DataReadCallback_t.
Definition: GattServer.h:182
void onDataSent(T *objPtr, void(T::*memberPtr)(unsigned count))
Add an event handler that monitors emission of characteristic value updates.
Definition: GattServer.h:419
uint8_t characteristicCount
The total number of characteristics added to the ATT table.
Definition: GattServer.h:799
ble_error_t
Error codes for the BLE API.
Definition: blecommon.h:147
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.