#include #include #include #include #include #include #include #include "Util/Timer.h" #include "Util/INIh.h" void print() { std::cout << "Print" << std::endl; } void TestTimerAbort() { PresenceDetection::Util::Timer timer; std::function f_print = print; std::cout << "---" << std::endl; auto start = std::chrono::steady_clock::now(); std::clock_t begin = std::clock(); timer.StartContinuous(1000, f_print); timer.Stop(); timer.Wait(); auto elapsed = std::chrono::duration_cast(std::chrono::steady_clock::now() - start); std::cout << "Elapsed: " << elapsed.count() << std::endl; std::cout << "---" << std::endl << std::endl; std::cout << "---" << std::endl; start = std::chrono::steady_clock::now(); timer.StartContinuous(3000, f_print); timer.Abort(); timer.Wait(); elapsed = std::chrono::duration_cast(std::chrono::steady_clock::now() - start); std::cout << "Elapsed: " << elapsed.count() << std::endl; std::cout << "---" << std::endl << std::endl; std::cout << "---" << std::endl; start = std::chrono::steady_clock::now(); timer.StartContinuous(3000, f_print); sleep(1); timer.Abort(); timer.Wait(); elapsed = std::chrono::duration_cast(std::chrono::steady_clock::now() - start); std::cout << "Elapsed: " << elapsed.count() << std::endl; std::cout << "---" << std::endl << std::endl; } typedef std::unique_ptr Pointer; template std::unique_ptr make_unique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } void OnTimerEnd(const std::string& type, int id) { std::cout << "OnTimerEnd() " << type << " " << id <& timers) { int delay(2000); std::string identifier("Blabla"); int id(10); // Protect! auto timer = make_unique(); timer->StartSingle(delay, static_cast>(std::bind(&OnTimerEnd, std::placeholders::_1, std::placeholders::_2)), identifier, id); timers.push_back(std::move(timer)); } void Cleanup(std::deque& timers) { timers.erase(std::remove_if(timers.begin(), timers.end(), [](Pointer& t){return !t->IsRunning();}), timers.end()); } void TestTimerDeque() { std::deque timers; StartNewTimer(timers); std::cout << "Count: " << timers.size() << std::endl; StartNewTimer(timers); std::cout << "Count: " << timers.size() << std::endl; sleep(5); std::cout << "Count: " << timers.size() << std::endl; Cleanup(timers); std::cout << "Count: " << timers.size() << std::endl; } void TestINIReader() { PresenceDetection::Util::INIReader reader("PresenceDetection.ini"); std::string target = reader.Get("PresenceDetection", "Target", ""); if (!target.empty()) std::cout << "Error" << std::endl; std::cout << target.size() << " " << target << std::endl; bool unifi = reader.GetBoolean("PresenceDetection", "UniFi", false); if (unifi) std::cout << "UniFi On" << std::endl; else std::cout << "UniFi Off" << std::endl; bool test = reader.GetBoolean("PresenceDetection", "Test", false); if (test) std::cout << "Test On" << std::endl; else std::cout << "Test Off" << std::endl; } int main(int /*argc*/, char** /*argv[]*/) { TestINIReader(); return 0; }