TaskUtil.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarX
19  * @author Mirko Waechter( mirko.waechter at kit dot edu)
20  * @date 2017
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include "PeriodicTask.h"
27 #include "RunningTask.h"
28 #include <functional>
29 
30 namespace armarx
31 {
32 
33  /**
34  * Usage:
35  \verbatim
36  SimplePeriodicTask<>::pointer_type task = new SimplePeriodicTask<>([&]
37  {
38  ARMARX_INFO << "Hello world from another thread";
39  }, 100);
40  task->start();
41  \endverbatim
42  */
43  template<class Functor = std::function<void(void)> >
44  class SimplePeriodicTask : public PeriodicTask<SimplePeriodicTask<Functor> >
45  {
46  public:
47  SimplePeriodicTask(Functor f, int periodMs, bool assureMeanInterval = false, std::string name = "", bool forceSystemTime = true):
48  PeriodicTask<SimplePeriodicTask<Functor> >(this, &SimplePeriodicTask::runningFn, periodMs, assureMeanInterval, name, forceSystemTime),
49  f(f)
50  {}
51  void runningFn()
52  {
53  f();
54  }
55  Functor f;
56  };
57  template<class...Ts> SimplePeriodicTask(Ts...) -> SimplePeriodicTask<std::function<void(void)>>;
58 
59  /**
60  * Usage:
61  \verbatim
62  SimpleRunningTask<>::pointer_type task = new SimpleRunningTask<>([&]
63  {
64  ARMARX_INFO << "Hello world from another thread";
65  });
66  task->start();
67  \endverbatim
68  */
69  template<class Functor = std::function<void(void)>>
70  class SimpleRunningTask : public RunningTask<SimpleRunningTask<Functor> >
71  {
72  public:
73  SimpleRunningTask(Functor f, std::string name = ""):
74  RunningTask<SimpleRunningTask<Functor> >(this, &SimpleRunningTask::runningFn, name = ""),
75  f(f)
76  {}
77  void runningFn()
78  {
79  f();
80  }
81  Functor f;
82  };
83  template<class...Ts> SimpleRunningTask(Ts...) -> SimpleRunningTask<std::function<void(void)>>;
84 
85 }
86 
armarx::SimpleRunningTask
Usage:
Definition: TaskUtil.h:70
armarx::SimplePeriodicTask::runningFn
void runningFn()
Definition: TaskUtil.h:51
armarx::SimpleRunningTask
SimpleRunningTask(Ts...) -> SimpleRunningTask< std::function< void(void)>>
PeriodicTask.h
RunningTask.h
armarx::SimpleRunningTask::SimpleRunningTask
SimpleRunningTask(Functor f, std::string name="")
Definition: TaskUtil.h:73
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
armarx::SimplePeriodicTask::SimplePeriodicTask
SimplePeriodicTask(Functor f, int periodMs, bool assureMeanInterval=false, std::string name="", bool forceSystemTime=true)
Definition: TaskUtil.h:47
armarx::SimpleRunningTask::f
Functor f
Definition: TaskUtil.h:81
armarx::SimpleRunningTask::runningFn
void runningFn()
Definition: TaskUtil.h:77
armarx::SimplePeriodicTask
SimplePeriodicTask(Ts...) -> SimplePeriodicTask< std::function< void(void)>>
armarx::SimplePeriodicTask::f
Functor f
Definition: TaskUtil.h:55
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::SimplePeriodicTask
Usage:
Definition: ApplicationNetworkStats.h:32