// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include #include #include #include #include #include #include #include // for DBServiceAPI #include #include #include #include namespace sys { class DataMessage; } // namespace sys void EventManager::HandleAlarmTrigger(sys::DataMessage *msgl) { sevm::RtcMinuteAlarmMessage *msg = reinterpret_cast(msgl); // Send message to update time in application auto message = std::make_shared(MessageType::EVMMinuteUpdated); message->timestamp = msg->timestamp; if (targetApplication.empty() == false) { sys::Bus::SendUnicast(message, targetApplication, this); } time_t currentTime = message->timestamp; // it there is no valid alarm and DB is not empty if (alarmIsValid == false) { // check if its midnight if (currentTime % 86400 == 0) { alarmDBEmpty = false; } if (alarmDBEmpty == false) // get next alarm GetNextAlarmTimestamp(currentTime); } // there is valid alarm if (alarmIsValid == true) { // check if its time to trigger alarm // round time and compare to alaram timestamp if (alarmTimestamp == (currentTime % 86400)) { alarmIsValid = false; // Run "alarm" application. // std::unique_ptr switchMessage = std::make_unique(alarmID); // app::manager::Controller::sendAction(this, app::manager::actions::ShowAlarm, std::move(switchMessage)); } // check if alarm is not obsolete else if ((alarmTimestamp < (currentTime % 86400)) && ((currentTime + 60) % 86400) > (currentTime % 86400)) { alarmIsValid = false; } } } void EventManager::GetNextAlarmTimestamp(time_t timestamp) { AlarmsRecord record; record = DBServiceAPI::AlarmGetNext(this, ((timestamp) % 86400)); if (record.ID != 0) { alarmIsValid = true; alarmTimestamp = record.time; alarmID = record.ID; } else { alarmDBEmpty = true; } }