| 1 | // | 
|---|---|
| 2 | // Timer.cpp | 
| 3 | // | 
| 4 | // This sample demonstrates the Timer and Stopwatch classes. | 
| 5 | // | 
| 6 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. | 
| 7 | // and Contributors. | 
| 8 | // | 
| 9 | // SPDX-License-Identifier: BSL-1.0 | 
| 10 | // | 
| 11 | |
| 12 | |
| 13 | #include "Poco/Timer.h" | 
| 14 | #include "Poco/Thread.h" | 
| 15 | #include "Poco/Stopwatch.h" | 
| 16 | #include <iostream> | 
| 17 | |
| 18 | |
| 19 | using Poco::Timer; | 
| 20 | using Poco::TimerCallback; | 
| 21 | using Poco::Thread; | 
| 22 | using Poco::Stopwatch; | 
| 23 | |
| 24 | |
| 25 | class TimerExample | 
| 26 | { | 
| 27 | public: | 
| 28 | TimerExample() | 
| 29 | { | 
| 30 | _sw.start(); | 
| 31 | } | 
| 32 | |
| 33 | void onTimer(Timer& timer) | 
| 34 | { | 
| 35 | std::cout << "Callback called after "<< _sw.elapsed()/1000 << " milliseconds."<< std::endl; | 
| 36 | } | 
| 37 | |
| 38 | private: | 
| 39 | Stopwatch _sw; | 
| 40 | }; | 
| 41 | |
| 42 | |
| 43 | int main(int argc, char** argv) | 
| 44 | { | 
| 45 | TimerExample example; | 
| 46 | |
| 47 | Timer timer(250, 500); | 
| 48 | timer.start(TimerCallback<TimerExample>(example, &TimerExample::onTimer)); | 
| 49 | |
| 50 | Thread::sleep(5000); | 
| 51 | |
| 52 | timer.stop(); | 
| 53 | |
| 54 | return 0; | 
| 55 | } | 
| 56 | 
