diff options
| author | JF <jf@codingfield.com> | 2020-04-05 18:59:15 +0200 |
|---|---|---|
| committer | Gitea <gitea@fake.local> | 2020-04-05 18:59:15 +0200 |
| commit | 6e1bd118c5ecc53016548072501591b329500870 (patch) | |
| tree | 8447f6b7bbff0f423e9cf5d15ed709c630bed25e /src/Components/Ble/NotificationManager.cpp | |
| parent | 7e9a7e4d5fa0f55b43180600d499f1d0ce6aded1 (diff) | |
| parent | d5c2a58914fdeac4ef69382269b81d529e6d7c90 (diff) | |
Merge branch 'ble-notifications' of JF/PineTime into develop
Diffstat (limited to 'src/Components/Ble/NotificationManager.cpp')
| -rw-r--r-- | src/Components/Ble/NotificationManager.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/Components/Ble/NotificationManager.cpp b/src/Components/Ble/NotificationManager.cpp new file mode 100644 index 00000000..2e02cb15 --- /dev/null +++ b/src/Components/Ble/NotificationManager.cpp @@ -0,0 +1,29 @@ +#include <cstring> +#include "NotificationManager.h" + +using namespace Pinetime::Controllers; + +void NotificationManager::Push(Pinetime::Controllers::NotificationManager::Categories category, + const char *message, uint8_t messageSize) { + // TODO handle edge cases on read/write index + auto& notif = notifications[writeIndex]; + std::memcpy(notif.message.data(), message, messageSize); + notif.message[messageSize] = '\0'; + notif.category = category; + + writeIndex = (writeIndex + 1 < TotalNbNotifications) ? writeIndex + 1 : 0; + if(!empty && writeIndex == readIndex) + readIndex = writeIndex + 1; +} + +NotificationManager::Notification Pinetime::Controllers::NotificationManager::Pop() { +// TODO handle edge cases on read/write index + NotificationManager::Notification notification = notifications[readIndex]; + + if(readIndex != writeIndex) { + readIndex = (readIndex + 1 < TotalNbNotifications) ? readIndex + 1 : 0; + } + + // TODO Check move optimization on return + return notification; +} |
