Files
MuditaOS/module-sys/SystemManager/SystemManager.hpp
Radoslaw Wicik a8573a404c Apply new style
2020-03-17 10:03:16 +01:00

99 lines
2.4 KiB
C++

/*
* Service.hpp
*
* Created on: Mar 7, 2019
* Author: mati
*/
#ifndef SYSTEMMANAGER_SYSTEMMANAGER_HPP_
#define SYSTEMMANAGER_SYSTEMMANAGER_HPP_
#include <functional>
#include "thread.hpp"
#include "timer.hpp"
#include "condition_variable.hpp"
#include "mutex.hpp"
#include "Service/Mailbox.hpp"
#include "Service/Bus.hpp"
#include "Service/Service.hpp"
#include "Service/Message.hpp"
#include "PowerManager.hpp"
namespace sys
{
enum class SystemManagerMsgType
{
CloseSystem,
};
class SystemManagerMsg : public DataMessage
{
public:
SystemManagerMsg(SystemManagerMsgType type) : DataMessage(BusChannels::SystemManagerRequests), type(type)
{}
SystemManagerMsgType type;
};
class SystemManager : public Service
{
public:
SystemManager(TickType_t pingInterval);
~SystemManager();
void StartSystem(std::function<int()> init);
// Invoke system close procedure
static bool CloseSystem(Service *s);
static bool SuspendSystem(Service *caller);
static bool ResumeSystem(Service *caller);
static bool SuspendService(const std::string &name, Service *caller);
static bool ResumeService(const std::string &name, Service *caller);
// Create new service
static bool CreateService(std::shared_ptr<Service> service, Service *caller, TickType_t timeout = 5000);
// Destroy existing service
static bool DestroyService(const std::string &name, Service *caller, TickType_t timeout = 5000);
private:
void TickHandler(uint32_t id) override;
Message_t DataReceivedHandler(DataMessage *msg, ResponseMessage *resp) override;
ReturnCodes InitHandler() override;
ReturnCodes DeinitHandler() override
{
return ReturnCodes::Success;
}
ReturnCodes SwitchPowerModeHandler(const ServicePowerMode mode) override final
{
return ReturnCodes::Success;
}
void Run() override;
void CloseSystemHandler();
TickType_t pingInterval;
uint32_t pingPongTimerID;
std::function<int()> userInit;
static std::vector<std::shared_ptr<Service>> servicesList;
static cpp_freertos::MutexStandard destroyMutex;
static std::unique_ptr<PowerManager> powerManager;
};
} // namespace sys
#endif /* SYSTEMMANAGER_SYSTEMMANAGER_HPP_ */