diff --git a/module-audio/Audio/Operation/RouterOperation.cpp b/module-audio/Audio/Operation/RouterOperation.cpp index d639093fb..453fd49f6 100644 --- a/module-audio/Audio/Operation/RouterOperation.cpp +++ b/module-audio/Audio/Operation/RouterOperation.cpp @@ -27,6 +27,7 @@ namespace audio { if (framesPerBuffer > audioDeviceBuffer.capacity()) { audioDeviceBuffer.reserve(framesPerBuffer); + std::fill(std::begin(audioDeviceBuffer), std::end(audioDeviceBuffer), 0); } if (inputBuffer) { @@ -58,6 +59,7 @@ namespace audio { if (framesPerBuffer > audioDeviceCellularBuffer.capacity()) { audioDeviceCellularBuffer.reserve(framesPerBuffer); + std::fill(std::begin(audioDeviceCellularBuffer), std::end(audioDeviceCellularBuffer), 0); } if (inputBuffer) { @@ -78,7 +80,9 @@ namespace audio { }; audioDeviceBuffer.reserve(1024); + std::fill(std::begin(audioDeviceBuffer), std::end(audioDeviceBuffer), 0); audioDeviceCellularBuffer.reserve(1024); + std::fill(std::begin(audioDeviceCellularBuffer), std::end(audioDeviceCellularBuffer), 0); //TODO:M.P should be fetched from DB availableProfiles.push_back(std::make_unique(nullptr, 1, 2)); diff --git a/module-sys/SystemManager/SystemManager.cpp b/module-sys/SystemManager/SystemManager.cpp index 3070644c2..5b684bdb6 100644 --- a/module-sys/SystemManager/SystemManager.cpp +++ b/module-sys/SystemManager/SystemManager.cpp @@ -42,7 +42,7 @@ namespace sys InitHandler(); if(userInit){ - userInit(this); + userInit(); } while (enableRunLoop) { @@ -55,10 +55,12 @@ namespace sys EndScheduler(); } - void SystemManager::StartSystem() + void SystemManager::StartSystem(std::function init) { LogOutput::Output("Initializing system..."); + userInit = init; + // Start System manager StartService(); @@ -73,7 +75,7 @@ namespace sys return true; } - bool SystemManager::CreateService(std::shared_ptr service,Service* s,TickType_t timeout){ + bool SystemManager::CreateService(std::shared_ptr service,Service* caller,TickType_t timeout){ CriticalSection::Enter(); @@ -83,7 +85,7 @@ namespace sys service->StartService(); auto msg = std::make_shared(SystemMessageType::Start); - auto ret = Bus::SendUnicast(msg,service->GetName(),s,timeout); + auto ret = Bus::SendUnicast(msg,service->GetName(),caller,timeout); auto resp = std::static_pointer_cast(ret.second); if(ret.first == ReturnCodes::Success && (resp->retCode == ReturnCodes::Success)){ @@ -94,10 +96,10 @@ namespace sys } } - bool SystemManager::DestroyService(const std::string& name,Service* s,TickType_t timeout){ + bool SystemManager::DestroyService(const std::string& name,Service* caller,TickType_t timeout){ auto msg = std::make_shared(SystemMessageType::Exit); - auto ret = Bus::SendUnicast(msg,name,s,timeout); + auto ret = Bus::SendUnicast(msg,name,caller,timeout); auto resp = std::static_pointer_cast(ret.second); if(ret.first == ReturnCodes::Success && (resp->retCode == ReturnCodes::Success)){ @@ -119,10 +121,10 @@ namespace sys } } - bool SystemManager::SuspendService(const std::string& name,Service* s,TickType_t timeout){ + bool SystemManager::SuspendService(const std::string& name,Service* caller,TickType_t timeout){ auto msg = std::make_shared(SystemMessageType::GoSleep); - auto ret = Bus::SendUnicast(msg,name,s,timeout); + auto ret = Bus::SendUnicast(msg,name,caller,timeout); auto resp = std::static_pointer_cast(ret.second); if(ret.first == ReturnCodes::Success && (resp->retCode == ReturnCodes::Success)){ @@ -133,10 +135,10 @@ namespace sys } } - bool SystemManager::ResumeService(const std::string& name,Service* s,TickType_t timeout){ + bool SystemManager::ResumeService(const std::string& name,Service* caller,TickType_t timeout){ auto msg = std::make_shared(SystemMessageType::Wakeup); - auto ret = Bus::SendUnicast(msg,name,s,timeout); + auto ret = Bus::SendUnicast(msg,name,caller,timeout); auto resp = std::static_pointer_cast(ret.second); if(ret.first == ReturnCodes::Success && (resp->retCode == ReturnCodes::Success)){ @@ -147,11 +149,6 @@ namespace sys } } - void SystemManager::RegisterInitFunction(std::function init) - { - userInit = init; - } - ReturnCodes SystemManager::InitHandler(){ isReady = true; return ReturnCodes ::Success; diff --git a/module-sys/SystemManager/SystemManager.hpp b/module-sys/SystemManager/SystemManager.hpp index bf92be0e1..bb618d802 100644 --- a/module-sys/SystemManager/SystemManager.hpp +++ b/module-sys/SystemManager/SystemManager.hpp @@ -44,25 +44,22 @@ public: ~SystemManager(); - void StartSystem(); + void StartSystem(std::function init); // Invoke system close procedure static bool CloseSystem(Service* s); // Create new service - static bool CreateService(std::shared_ptr service,Service* s,TickType_t timeout=5000); + static bool CreateService(std::shared_ptr service,Service* caller,TickType_t timeout=5000); // Destroy existing service - static bool DestroyService(const std::string& name,Service* s,TickType_t timeout=5000); + static bool DestroyService(const std::string& name,Service* caller,TickType_t timeout=5000); // Suspend specified serivice - static bool SuspendService(const std::string& name,Service* s,TickType_t timeout=5000); + static bool SuspendService(const std::string& name,Service* caller,TickType_t timeout=5000); // Resume specified service - static bool ResumeService(const std::string& name,Service* s,TickType_t timeout=5000); - - // Register init procedure which will be invoked upon system start - void RegisterInitFunction(std::function init); + static bool ResumeService(const std::string& name,Service* caller,TickType_t timeout=5000); private: @@ -89,7 +86,7 @@ private: TickType_t pingInterval; uint32_t pingPongTimerID; - std::function userInit; + std::function userInit; static std::vector> servicesList; diff --git a/module-sys/tests/tests.cpp b/module-sys/tests/tests.cpp index 4e15c5350..e5b036b1f 100755 --- a/module-sys/tests/tests.cpp +++ b/module-sys/tests/tests.cpp @@ -14,21 +14,16 @@ #include "Test1/CommandsService.hpp" #include "Test1/TestService1.hpp" -int InitServices(sys::SystemManager* sysmgr) -{ - auto ret = sys::SystemManager::CreateService(std::make_shared("CommandsService"),sysmgr); - REQUIRE(ret); - - return 0; -} - TEST_CASE( "Test case 1" ) { - auto sysmgr = std::make_shared(5000); + auto sysmgr = std::make_shared(50000); - sysmgr->StartSystem(); + sysmgr->StartSystem([sysmgr]()->int{ + auto ret = sys::SystemManager::CreateService(std::make_shared("CommandsService"),sysmgr.get()); + REQUIRE(ret); - sysmgr->RegisterInitFunction(InitServices); + return 0; + }); cpp_freertos::Thread::StartScheduler(); diff --git a/source/main.cpp b/source/main.cpp index 2b233f21f..2930987eb 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -49,7 +49,7 @@ public: BlinkyService(const std::string &name) : sys::Service(name) { timer_id = CreateTimer(2000, true); - //ReloadTimer(timer_id); + ReloadTimer(timer_id); } ~BlinkyService() { @@ -58,7 +58,7 @@ public: // Invoked upon receiving data message sys::Message_t DataReceivedHandler(sys::DataMessage *msgl) override { -#if 0 // M.P: left here on purpose +#if 1 // M.P: left here on purpose //auto ret = AudioServiceAPI::PlaybackStart(this,"/home/mateusz/Music/limowreck.mp3"); //auto ret = AudioServiceAPI::PlaybackStart(this,"sys/audio/teee.flac"); //AudioServiceAPI::SetOutputVolume(this,0.6); @@ -80,7 +80,7 @@ public: // Invoked when timer ticked void TickHandler(uint32_t id) override { -#if 0 // M.P: left here on purpose +#if 1 // M.P: left here on purpose LOG_DEBUG("Blinky service tick!"); stopTimer(timer_id); @@ -113,53 +113,6 @@ public: uint32_t timer_id = 0; }; - -int SystemStart(sys::SystemManager *sysmgr) { - vfs.Init(); - - bool ret = false; - ret = sysmgr->CreateService(std::make_shared("ServiceGUI", 480, 600), sysmgr); - ret |= sysmgr->CreateService(std::make_shared("ServiceEink"), sysmgr); - ret |= sysmgr->CreateService(std::make_shared("EventManager"), sysmgr); - ret |= sysmgr->CreateService(std::make_shared(), sysmgr); - ret |= sysmgr->CreateService(std::make_shared("Blinky"), sysmgr); - ret |= sysmgr->CreateService(std::make_shared(), sysmgr); - ret |= sysmgr->CreateService(std::make_shared(), sysmgr); - - //vector with launchers to applications - std::vector > applications; - - //launcher for viewer - std::unique_ptr viewerLauncher = std::unique_ptr( - new app::ApplicationViewerLauncher()); - applications.push_back(std::move(viewerLauncher)); - - //launcher for desktop application - std::unique_ptr desktopLauncher = std::unique_ptr( - new app::ApplicationDesktopLauncher()); - applications.push_back(std::move(desktopLauncher)); - - //launcher for call application - std::unique_ptr callLauncher = std::unique_ptr( - new app::ApplicationCallLauncher()); - applications.push_back(std::move(callLauncher)); - - //launcher for settings application - std::unique_ptr settingsLauncher = std::unique_ptr( - new app::ApplicationSettingsLauncher()); - applications.push_back(std::move(settingsLauncher)); - - //start application manager - ret |= sysmgr->CreateService(std::make_shared("ApplicationManager", sysmgr, applications), - sysmgr); - - if (ret) { - return 0; - } - - return 0; -} - int main() { LOG_PRINTF("Launching PurePhone..\n "); @@ -168,9 +121,54 @@ int main() { auto sysmgr = std::make_shared(5000); - sysmgr->StartSystem(); + sysmgr->StartSystem([sysmgr]()->int{ - sysmgr->RegisterInitFunction(SystemStart); + vfs.Init(); + + bool ret = false; + ret = sys::SystemManager::CreateService(std::make_shared("ServiceGUI", 480, 600), sysmgr.get()); + ret |= sys::SystemManager::CreateService(std::make_shared("ServiceEink"), sysmgr.get()); + ret |= sys::SystemManager::CreateService(std::make_shared("EventManager"), sysmgr.get()); + ret |= sys::SystemManager::CreateService(std::make_shared(), sysmgr.get()); + ret |= sys::SystemManager::CreateService(std::make_shared("Blinky"), sysmgr.get()); + ret |= sys::SystemManager::CreateService(std::make_shared(), sysmgr.get()); + ret |= sys::SystemManager::CreateService(std::make_shared(), sysmgr.get()); + + //vector with launchers to applications + std::vector > applications; + + //launcher for viewer + std::unique_ptr viewerLauncher = std::unique_ptr( + new app::ApplicationViewerLauncher()); + applications.push_back(std::move(viewerLauncher)); + + //launcher for desktop application + std::unique_ptr desktopLauncher = std::unique_ptr( + new app::ApplicationDesktopLauncher()); + applications.push_back(std::move(desktopLauncher)); + + //launcher for call application + std::unique_ptr callLauncher = std::unique_ptr( + new app::ApplicationCallLauncher()); + applications.push_back(std::move(callLauncher)); + + //launcher for settings application + std::unique_ptr settingsLauncher = std::unique_ptr( + new app::ApplicationSettingsLauncher()); + applications.push_back(std::move(settingsLauncher)); + + //start application manager + ret |= sysmgr->CreateService(std::make_shared("ApplicationManager", sysmgr.get(), applications), + sysmgr.get()); + + if (ret) { + return 0; + } + + return 0; + + + }); cpp_freertos::Thread::StartScheduler();