|
17 | 17 | #ifndef MBED_BLE_SIGNING_EVENT_MONITOR
|
18 | 18 | #define MBED_BLE_SIGNING_EVENT_MONITOR
|
19 | 19 |
|
| 20 | +#include "ble/common/StaticInterface.h" |
20 | 21 | #include "ble/BLETypes.h"
|
21 | 22 |
|
22 | 23 | namespace ble {
|
23 | 24 | namespace pal {
|
24 | 25 |
|
25 | 26 | /**
|
26 |
| - * Implemented by classes that need to be notified of signing events. |
27 |
| - * Notification is done by calling functions in the passed in event handler |
| 27 | + * Implemented by classes that are reacting to signing events. |
28 | 28 | */
|
29 |
| -class SigningEventMonitor { |
| 29 | +template<class Impl> |
| 30 | +class SigningMonitorEventHandler : public StaticInterface<Impl, SigningMonitorEventHandler> { |
| 31 | + |
| 32 | + using StaticInterface<Impl, ble::pal::SigningMonitorEventHandler>::impl; |
| 33 | + |
30 | 34 | public:
|
31 | 35 | /**
|
32 |
| - * Implemented by classes that are reacting to signing events. |
| 36 | + * Set new signed write peer counter. |
| 37 | + * |
| 38 | + * @param[in] connection connection handle |
| 39 | + * @param[in] sign_coutner counter received from peer |
33 | 40 | */
|
34 |
| - class EventHandler { |
35 |
| - public: |
36 |
| - /** |
37 |
| - * Set new signed write peer counter. |
38 |
| - * |
39 |
| - * @param[in] connection connection handle |
40 |
| - * @param[in] sign_coutner counter received from peer |
41 |
| - */ |
42 |
| - virtual void on_signed_write_received( |
43 |
| - connection_handle_t connection, |
44 |
| - uint32_t sign_coutner |
45 |
| - ) = 0; |
| 41 | + void on_signed_write_received( |
| 42 | + connection_handle_t connection, |
| 43 | + uint32_t sign_coutner |
| 44 | + ) { |
| 45 | + impl()->on_signed_write_received_( |
| 46 | + connection, |
| 47 | + sign_coutner |
| 48 | + ); |
| 49 | + } |
46 | 50 |
|
47 |
| - /** |
48 |
| - * Indicate that signed data was rejected due to verification failure. This could |
49 |
| - * be due to an invalid CSRK key. |
50 |
| - * |
51 |
| - * @param[in] connection connection handle |
52 |
| - */ |
53 |
| - virtual void on_signed_write_verification_failure( |
54 |
| - connection_handle_t connection |
55 |
| - ) = 0; |
| 51 | + /** |
| 52 | + * Indicate that signed data was rejected due to verification failure. This could |
| 53 | + * be due to an invalid CSRK key. |
| 54 | + * |
| 55 | + * @param[in] connection connection handle |
| 56 | + */ |
| 57 | + void on_signed_write_verification_failure( |
| 58 | + connection_handle_t connection |
| 59 | + ) { |
| 60 | + impl()->on_signed_write_verification_failure(connection); |
| 61 | + } |
56 | 62 |
|
57 |
| - /** |
58 |
| - * Notify a new signed write cmd was executed. |
59 |
| - */ |
60 |
| - virtual void on_signed_write() = 0; |
61 |
| - }; |
| 63 | + /** |
| 64 | + * Notify a new signed write cmd was executed. |
| 65 | + */ |
| 66 | + void on_signed_write() { |
| 67 | + impl()->on_signed_write_(); |
| 68 | + } |
| 69 | +}; |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +/** |
| 74 | + * Implemented by classes that need to be notified of signing events. |
| 75 | + * Notification is done by calling functions in the passed in event handler |
| 76 | + */ |
| 77 | +template<class Impl, class EventHandler> |
| 78 | +class SigningEventMonitor { |
| 79 | + Impl* impl() { |
| 80 | + return static_cast<Impl*>(this); |
| 81 | + } |
62 | 82 |
|
| 83 | +public: |
63 | 84 | /**
|
64 | 85 | * Register a handler for singing events to be used internally and serviced first.
|
65 | 86 | *
|
66 | 87 | * @param[in] signing_event_handler Event handler being registered.
|
67 | 88 | */
|
68 |
| - virtual void set_signing_event_handler(EventHandler *signing_event_handler) = 0; |
| 89 | + void set_signing_event_handler(EventHandler *signing_event_handler) |
| 90 | + { |
| 91 | + impl()->set_signing_event_handler_(signing_event_handler); |
| 92 | + } |
69 | 93 | };
|
70 | 94 |
|
71 | 95 | } // namespace pal
|
|
0 commit comments