InfiniTime/src/components/ble/NotificationManager.h
Max Friedrich 39d5b5c3a2
NotificationManager.h: Reorder notification struct fields to allow easier creation. (#1774)
This commit changes the order for the notification struct fields to allow the creation of notifications using a string literal.
```cpp
NotificationManager::Notifiation notification {
  "String literal with notification text",
  42,
  NotificationManager::Categories::SimpleAlert
};
```

Co-authored-by: minacode <minamoto9@web.de>
2023-07-09 14:39:38 +02:00

78 lines
2.1 KiB
C++

#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};
};
}
}