Add Static Devices
This commit is contained in:
@@ -14,85 +14,6 @@ void print()
|
||||
std::cout << "Print" << std::endl;
|
||||
}
|
||||
|
||||
void TestTimerAbort()
|
||||
{
|
||||
Timer::Timer timer;
|
||||
std::function<void()> 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::milliseconds>(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::milliseconds>(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::milliseconds>(std::chrono::steady_clock::now() - start);
|
||||
std::cout << "Elapsed: " << elapsed.count() << std::endl;
|
||||
std::cout << "---" << std::endl << std::endl;
|
||||
}
|
||||
|
||||
typedef std::unique_ptr<Timer::Timer> Pointer;
|
||||
|
||||
template<typename T, typename... Args>
|
||||
std::unique_ptr<T> make_unique(Args&&... args) {
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
void OnTimerEnd(const std::string& type, int id)
|
||||
{
|
||||
std::cout << "OnTimerEnd() " << type << " " << id <<std::endl;
|
||||
}
|
||||
|
||||
void StartNewTimer(std::deque<Pointer>& timers)
|
||||
{
|
||||
int delay(2000);
|
||||
std::string identifier("Blabla");
|
||||
int id(10);
|
||||
|
||||
// Protect!
|
||||
auto timer = make_unique<Timer::Timer>();
|
||||
timer->StartSingle(delay, static_cast<std::function<void(const std::string&, int)>>(std::bind(&OnTimerEnd, std::placeholders::_1, std::placeholders::_2)), identifier, id);
|
||||
timers.push_back(std::move(timer));
|
||||
}
|
||||
|
||||
void Cleanup(std::deque<Pointer>& timers)
|
||||
{
|
||||
timers.erase(std::remove_if(timers.begin(), timers.end(), [](Pointer& t){return !t->IsRunning();}), timers.end());
|
||||
}
|
||||
|
||||
void TestTimerDeque()
|
||||
{
|
||||
std::deque<Pointer> 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");
|
||||
|
||||
Reference in New Issue
Block a user