2020-03-28 18:05:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2020-10-20 18:57:39 +00:00
|
|
|
#include <atomic>
|
2020-03-28 18:05:28 +00:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Controllers {
|
|
|
|
class NotificationManager {
|
|
|
|
public:
|
|
|
|
enum class Categories {Unknown, SimpleAlert, Email, News, IncomingCall, MissedCall, Sms, VoiceMail, Schedule, HighProriotyAlert, InstantMessage };
|
2020-10-21 15:31:56 +00:00
|
|
|
static constexpr uint8_t MessageSize{100};
|
2020-03-28 18:05:28 +00:00
|
|
|
|
|
|
|
struct Notification {
|
2020-10-20 18:57:39 +00:00
|
|
|
using Id = uint8_t;
|
|
|
|
Id id;
|
|
|
|
bool valid = false;
|
|
|
|
uint8_t index;
|
2020-06-28 09:59:14 +00:00
|
|
|
std::array<char, MessageSize+1> message;
|
2020-03-28 18:05:28 +00:00
|
|
|
Categories category = Categories::Unknown;
|
|
|
|
};
|
2020-10-20 18:57:39 +00:00
|
|
|
Notification::Id nextId {0};
|
2020-03-28 18:05:28 +00:00
|
|
|
|
2020-10-22 08:43:42 +00:00
|
|
|
void Push(Notification&& notif);
|
2020-10-20 18:57:39 +00:00
|
|
|
Notification GetLastNotification();
|
|
|
|
Notification GetNext(Notification::Id id);
|
|
|
|
Notification GetPrevious(Notification::Id id);
|
|
|
|
bool ClearNewNotificationFlag();
|
|
|
|
bool AreNewNotificationsAvailable();
|
2020-03-28 18:05:28 +00:00
|
|
|
|
2020-10-21 15:31:56 +00:00
|
|
|
static constexpr uint8_t MaximumMessageSize() { return MessageSize; };
|
2020-10-21 20:15:02 +00:00
|
|
|
size_t NbNotifications() const;
|
2020-03-28 18:05:28 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-20 18:57:39 +00:00
|
|
|
Notification::Id GetNextId();
|
2020-03-28 18:05:28 +00:00
|
|
|
static constexpr uint8_t TotalNbNotifications = 5;
|
|
|
|
std::array<Notification, TotalNbNotifications> notifications;
|
|
|
|
uint8_t readIndex = 0;
|
|
|
|
uint8_t writeIndex = 0;
|
|
|
|
bool empty = true;
|
2020-10-20 18:57:39 +00:00
|
|
|
std::atomic<bool> newNotification{false};
|
2020-03-28 18:05:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|