ref: 9196c18d376d4f18c686bcfec8550f9c8659d5ea
src/components/ble/NotificationManager.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
#pragma once #include <array> #include <atomic> #include <cstddef> #include <cstdint> namespace Pinetime { namespace Controllers { class NotificationManager { public: enum class Categories { Unknown, SimpleAlert, Email, News, IncomingCall, MissedCall, Sms, VoiceMail, Schedule, HighProriotyAlert, InstantMessage }; static constexpr uint8_t MessageSize {100}; struct Notification { using Id = uint8_t; using Idx = uint8_t; std::array<char, MessageSize + 1> message; uint8_t size; Categories category = Categories::Unknown; Id id = 0; bool valid = false; const char* Message() const; const char* Title() const; }; void Push(Notification&& notif); Notification GetLastNotification() const; Notification Get(Notification::Id id) const; Notification GetNext(Notification::Id id) const; Notification GetPrevious(Notification::Id id) const; // Return the index of the notification with the specified id, if not found return NbNotifications() Notification::Idx IndexOf(Notification::Id id) const; bool ClearNewNotificationFlag(); bool AreNewNotificationsAvailable() const; void Dismiss(Notification::Id id); static constexpr size_t MaximumMessageSize() { return MessageSize; }; bool IsEmpty() const { return size == 0; } size_t NbNotifications() const; private: Notification::Id nextId {0}; Notification::Id GetNextId(); const Notification& At(Notification::Idx idx) const; Notification& At(Notification::Idx idx); void DismissIdx(Notification::Idx idx); static constexpr uint8_t TotalNbNotifications = 5; std::array<Notification, TotalNbNotifications> notifications; size_t beginIdx = TotalNbNotifications - 1; // index of the newest notification size_t size = 0; // number of valid notifications in buffer std::atomic<bool> newNotification {false}; }; } } |