1 /*
2 ** Copyright 2011-2019 Centreon
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 **     http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 **
16 ** For more information : contact@centreon.com
17 */
18 
19 #include <iostream>
20 #include "com/centreon/exceptions/basic.hh"
21 #include "com/centreon/task_manager.hh"
22 
23 using namespace com::centreon;
24 
25 /**
26  *  @class task_test
27  *  @brief litle implementation of task to test task manager.
28  */
29 class task_test : public task {
30  public:
task_test()31   task_test() : task() {}
~task_test()32   ~task_test() noexcept {}
run()33   void run() {}
34 };
35 
36 /**
37  *  Check the task manager add.
38  *
39  *  @return 0 on success.
40  */
main()41 int main() {
42   try {
43     task_manager tm;
44 
45     task_test* t1 = new task_test;
46     tm.add(t1, timestamp::now(), true, true);
47     if (!tm.next_execution_time().to_useconds())
48       throw basic_error() << "add failed";
49 
50     task_test* t2 = new task_test;
51     tm.add(t2, timestamp::now(), false, false);
52     delete t2;
53   } catch (std::exception const& e) {
54     std::cerr << "error: " << e.what() << std::endl;
55     return 1;
56   }
57   return 0;
58 }
59