mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-05-24 16:47:00 -04:00
Multicast message from DBService. Added GetNext method to Alarms DB.
This commit is contained in:
@@ -145,3 +145,16 @@ AlarmsRecord AlarmsRecordInterface::GetByID(uint32_t id) {
|
||||
}
|
||||
|
||||
|
||||
AlarmsRecord AlarmsRecordInterface::GetNext(time_t time) {
|
||||
auto alarm = alarmsDB->alarms.GetNext(time);
|
||||
|
||||
return AlarmsRecord{
|
||||
.ID = alarm.ID,
|
||||
.time = alarm.time,
|
||||
.snooze = alarm.snooze,
|
||||
.status = alarm.status,
|
||||
.path = alarm.path
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
|
||||
std::unique_ptr<std::vector<AlarmsRecord>> GetLimitOffsetByField(uint32_t offset,uint32_t limit,AlarmsRecordField field, const char* str) override final;
|
||||
|
||||
AlarmsRecord GetNext(time_t time);
|
||||
private:
|
||||
const uint32_t snippetLength = 45;
|
||||
AlarmsDB* alarmsDB;
|
||||
|
||||
@@ -176,5 +176,20 @@ uint32_t AlarmsTable::GetCountByFieldID(const char *field, uint32_t id) {
|
||||
return uint32_t{(*queryRet)[0].GetUInt32()};
|
||||
}
|
||||
|
||||
AlarmsTableRow AlarmsTable::GetNext(time_t time)
|
||||
{
|
||||
auto retQuery = db->Query("SELECT * from alarms WHERE status=1 AND time>%u ORDER BY time ASC LIMIT 1;", time % 86400);
|
||||
|
||||
if ((retQuery == nullptr) || (retQuery->GetRowCount() == 0)) {
|
||||
return AlarmsTableRow();
|
||||
}
|
||||
|
||||
return AlarmsTableRow{(*retQuery)[0].GetUInt32(), // ID
|
||||
(*retQuery)[1].GetUInt32(), // time
|
||||
(*retQuery)[2].GetUInt32(), // snooze
|
||||
(*retQuery)[3].GetUInt32(), // status
|
||||
(*retQuery)[4].GetString(), // path
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ public:
|
||||
uint32_t GetCount() override final;
|
||||
uint32_t GetCountByFieldID(const char* field,uint32_t id) override final;
|
||||
|
||||
AlarmsTableRow GetNext(time_t time);
|
||||
|
||||
private:
|
||||
|
||||
const char* createTableQuery =
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#include "messages/DBMessage.hpp"
|
||||
|
||||
#include"messages/DBNotificationMessage.hpp"
|
||||
|
||||
#include "MessageType.hpp"
|
||||
|
||||
#include "Database/Database.hpp"
|
||||
@@ -274,6 +276,13 @@ sys::Message_t ServiceDB::DataReceivedHandler(sys::DataMessage *msgl) {
|
||||
LOG_ERROR("DBAlarmAdd time: %lu",cpp_freertos::Ticks::GetTicks()-timestamp);
|
||||
#endif
|
||||
responseMsg = std::make_shared<DBAlarmResponseMessage>(nullptr, ret);
|
||||
|
||||
if(ret == true)
|
||||
{
|
||||
auto notificationMessage = std::make_shared<DBNotificationMessage>(MessageType::DBAlarmUpdateNotification);
|
||||
notificationMessage->notificationType = DBNotificatonType::Updated;
|
||||
sys::Bus::SendMulticast(notificationMessage, sys::BusChannels::ServiceDatabaseAlarmNotifications, this);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -327,6 +336,21 @@ sys::Message_t ServiceDB::DataReceivedHandler(sys::DataMessage *msgl) {
|
||||
responseMsg = std::make_shared<DBAlarmResponseMessage>(std::move(ret), true);
|
||||
}
|
||||
break;
|
||||
case MessageType::DBAlarmGetNext: {
|
||||
DBAlarmMessage *msg = reinterpret_cast<DBAlarmMessage *>(msgl);
|
||||
#if SHOW_DB_ACCESS_PERF == 1
|
||||
timestamp = cpp_freertos::Ticks::GetTicks();
|
||||
#endif
|
||||
auto ret = alarmsRecordInterface->GetNext(msg->time);
|
||||
#if SHOW_DB_ACCESS_PERF == 1
|
||||
LOG_ERROR("DBAlarmtGetNext time: %lu",cpp_freertos::Ticks::GetTicks()-timestamp);
|
||||
#endif
|
||||
auto records = std::make_unique<std::vector<AlarmsRecord>>();
|
||||
records->push_back(ret);
|
||||
responseMsg = std::make_shared<DBAlarmResponseMessage>(std::move(records), ret.ID == 0 ? false : true);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// ignore this message
|
||||
return std::make_shared<sys::ResponseMessage>();
|
||||
|
||||
@@ -34,6 +34,7 @@ private:
|
||||
std::unique_ptr<ThreadRecordInterface> threadRecordInterface;
|
||||
std::unique_ptr<ContactRecordInterface> contactRecordInterface;
|
||||
std::unique_ptr<AlarmsRecordInterface> alarmsRecordInterface;
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
|
||||
@@ -305,5 +305,17 @@ std::unique_ptr<std::vector<AlarmsRecord>> DBServiceAPI::AlarmGetLimitOffset(sys
|
||||
}
|
||||
}
|
||||
|
||||
AlarmsRecord DBServiceAPI::AlarmGetNext(sys::Service *serv, time_t time) {
|
||||
|
||||
std::shared_ptr<DBAlarmMessage> msg = std::make_shared<DBAlarmMessage>(MessageType::DBAlarmGetNext);
|
||||
msg->time = time;
|
||||
auto ret = sys::Bus::SendUnicast(msg,ServiceDB::serviceName,serv,5000);
|
||||
DBAlarmResponseMessage* alarmResponse = reinterpret_cast<DBAlarmResponseMessage*>(ret.second.get());
|
||||
if((ret.first == sys::ReturnCodes::Success) && (alarmResponse->retCode == true)){
|
||||
return std::move((*alarmResponse->records)[0]);
|
||||
}
|
||||
else{
|
||||
return AlarmsRecord{};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
static bool AlarmUpdate(sys::Service* serv,const AlarmsRecord& rec);
|
||||
static uint32_t AlarmGetCount(sys::Service* serv);
|
||||
static std::unique_ptr<std::vector<AlarmsRecord>> AlarmGetLimitOffset(sys::Service *serv,uint32_t offset,uint32_t limit);
|
||||
static AlarmsRecord AlarmGetNext(sys::Service *serv, time_t time);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -122,6 +122,7 @@ public:
|
||||
}
|
||||
virtual ~DBAlarmMessage() {};
|
||||
AlarmsRecord record;
|
||||
time_t time;
|
||||
};
|
||||
|
||||
class DBAlarmResponseMessage : public DBResponseMessage{
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* DBNotificationMessage.hpp
|
||||
*
|
||||
* Created on: 18 lip 2019
|
||||
* Author: kuba
|
||||
*/
|
||||
|
||||
#ifndef MODULE_SERVICES_SERVICE_DB_MESSAGES_DBNOTIFICATIONMESSAGE_HPP_
|
||||
#define MODULE_SERVICES_SERVICE_DB_MESSAGES_DBNOTIFICATIONMESSAGE_HPP_
|
||||
|
||||
#include <memory>
|
||||
#include "Service/Message.hpp"
|
||||
#include "MessageType.hpp"
|
||||
#include "DBMessage.hpp"
|
||||
|
||||
enum class DBNotificatonType{
|
||||
Updated
|
||||
};
|
||||
|
||||
class DBNotificationMessage : public sys::DataMessage
|
||||
{
|
||||
public:
|
||||
DBNotificationMessage( MessageType messageType ) : sys::DataMessage(static_cast<uint32_t>(messageType)) {};
|
||||
virtual ~DBNotificationMessage() {};
|
||||
|
||||
DBNotificatonType notificationType;
|
||||
};
|
||||
|
||||
class DBNotificationResponseMessage: public sys::ResponseMessage {
|
||||
public:
|
||||
DBNotificationResponseMessage(uint32_t retCode) : sys::ResponseMessage(),retCode(retCode) {};
|
||||
virtual ~DBNotificationResponseMessage() {};
|
||||
|
||||
uint32_t retCode;
|
||||
};
|
||||
|
||||
|
||||
#endif /* MODULE_SERVICES_SERVICE_DB_MESSAGES_DBNOTIFICATIONMESSAGE_HPP_ */
|
||||
@@ -21,6 +21,8 @@ EventManager::EventManager(const std::string& name)
|
||||
: sys::Service(name)
|
||||
{
|
||||
LOG_INFO("[EventManager] Initializing");
|
||||
|
||||
busChannels.push_back(sys::BusChannels::ServiceDatabaseAlarmNotifications);
|
||||
}
|
||||
|
||||
EventManager::~EventManager(){
|
||||
@@ -37,6 +39,13 @@ sys::Message_t EventManager::DataReceivedHandler(sys::DataMessage* msgl) {
|
||||
|
||||
bool handled = false;
|
||||
|
||||
if(msgl->messageType == static_cast<uint32_t>(MessageType::DBAlarmUpdateNotification))
|
||||
{
|
||||
LOG_INFO("DB updated");
|
||||
AlarmsRecord record = DBServiceAPI::AlarmGetNext(this, 0);
|
||||
LOG_INFO("Received alarm record ID: %d", record.ID);
|
||||
LOG_INFO("Path %s", record.path.c_str());
|
||||
}
|
||||
if(msgl->messageType == static_cast<uint32_t>(MessageType::KBDKeyEvent) &&
|
||||
msgl->sender == this->GetName()) {
|
||||
sevm::KbdMessage* msg = reinterpret_cast<sevm::KbdMessage*>(msgl);
|
||||
@@ -50,6 +59,16 @@ sys::Message_t EventManager::DataReceivedHandler(sys::DataMessage* msgl) {
|
||||
if( targetApplication.empty() == false ) {
|
||||
sys::Bus::SendUnicast(message, targetApplication, this);
|
||||
}
|
||||
if(msg->keyState == sevm::KeyboardEvents::keyPressed)
|
||||
{
|
||||
AlarmsRecord alarma;
|
||||
alarma.time=12;
|
||||
alarma.snooze=34;
|
||||
alarma.status=56;
|
||||
alarma.path = "78";
|
||||
|
||||
DBServiceAPI::AlarmAdd(this, alarma);
|
||||
}
|
||||
|
||||
handled = true;
|
||||
}
|
||||
@@ -85,7 +104,6 @@ sys::Message_t EventManager::DataReceivedHandler(sys::DataMessage* msgl) {
|
||||
}
|
||||
handled = true;
|
||||
}
|
||||
|
||||
else if(msgl->messageType == static_cast<uint32_t>(MessageType::EVMMinuteUpdated) &&
|
||||
msgl->sender == this->GetName() ){
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "common.hpp"
|
||||
|
||||
class EventManager: public sys::Service {
|
||||
private:
|
||||
uint32_t getDBAlarmCount(void);
|
||||
protected:
|
||||
sys::Worker* EventWorker = nullptr;
|
||||
//application where key events are sent. This is also only application that is allowed to change keyboard long press settings.
|
||||
|
||||
27
module-services/service-evtmgr/alarm/EventManagerAlarm.cpp
Normal file
27
module-services/service-evtmgr/alarm/EventManagerAlarm.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* EventManagerAlarm.cpp
|
||||
*
|
||||
* Created on: 18 lip 2019
|
||||
* Author: kuba
|
||||
*/
|
||||
|
||||
#include "EventManager.hpp"
|
||||
|
||||
#include "log/log.hpp"
|
||||
|
||||
#include "keyboard/keyboard.hpp"
|
||||
#include "WorkerEvent.hpp"
|
||||
#include "messages/EVMessages.hpp"
|
||||
|
||||
#include "vfs.hpp"
|
||||
|
||||
#include "service-db/api/DBServiceAPI.hpp"
|
||||
|
||||
|
||||
uint32_t EventManager::getDBAlarmCount(void)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
// Custom Bus channels
|
||||
ServiceCellularNotifications,
|
||||
Test2CustomBusChannel
|
||||
Test2CustomBusChannel,
|
||||
ServiceDatabaseAlarmNotifications
|
||||
|
||||
|
||||
#endif //MODULE_CORE_BUSCHANNELSCUSTOM_HPP
|
||||
|
||||
@@ -51,7 +51,8 @@ enum class MessageType {
|
||||
DBAlarmUpdate, // Update alarm remove
|
||||
DBAlarmGetLimitOffset, // Get alarm records by limit,offset
|
||||
DBAlarmGetCount, // Get alarm count
|
||||
|
||||
DBAlarmGetNext, // Get next alarm record
|
||||
DBAlarmUpdateNotification,
|
||||
|
||||
//Cellular messages
|
||||
CellularNotification, // Async notification message
|
||||
|
||||
Reference in New Issue
Block a user