Scheduling in c++

 

Daily timer

Introduction


In this example, I am trying to create a daily timer in C++.

Highlight

The interesting thing I learn from this example is how to use C++ forward and and wrapping it to a function container.

Gitlab example

Code

Gitlab project

Result

$ ./app/DailyTimer/DailyTimer
20230415_011838_175 [MSG]                DailyTimer::                     Main:    65,    76,Next alert time: 2023-04-15 01:18:38
Print from non-class 10
20230415_011843_176 [MSG]                DailyTimer::                     Main:    65,    77,Next alert time: 2023-04-15 01:18:43
Print from class 10


MSec timer

Introduction

This timer is similar to daily timer, user need to specify the next trigger time and the callback function to initial the timer. Timer will automatically callback continuously.

Code

Gitlab project

Result

$ ./app/MSecTimer/MSecTimer
20230415_042948_825 [MSG]                       Foo:    28,   293,Print from outside 10
20230415_042949_825 [MSG]                       Foo:    28,   293,Print from outside 10
20230415_042950_825 [MSG]                       Foo:    28,   293,Print from outside 10
20230415_042951_825 [MSG]                       Foo:    28,   293,Print from outside 10
20230415_042953_825 [MSG]                  FooClass::                    Print:    22,   294,Print from class 10
20230415_042954_826 [MSG]                  FooClass::                    Print:    22,   294,Print from class 10
20230415_042955_826 [MSG]                  FooClass::                    Print:    22,   294,Print from class 10
20230415_042956_826 [MSG]                  FooClass::                    Print:    22,   294,Print from class 10



Comments