ThreadList.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, 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 2012
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #pragma once
26 
27 #include <ArmarXCore/interface/core/ThreadingIceBase.h>
29 
30 #include <IceUtil/Thread.h>
31 #include <IceUtil/Time.h>
32 
33 #include <iosfwd>
34 #include <memory>
35 
36 namespace armarx
37 {
38 
39  class ThreadList;
41 
42  class ProcessWatcher;
43 
44  class ThreadList :
45  virtual public ThreadListInterface,
46  virtual public ManagedIceObject
47  {
48  public:
49  ThreadList();
50  ~ThreadList();
51 
52  Ice::StringSeq getRunningTaskNames(const Ice::Current& c = Ice::emptyCurrent) override;
53  Ice::StringSeq getPeriodicTaskNames(const Ice::Current& c = Ice::emptyCurrent) override;
54 
55  double getCpuUsage(const Ice::Current& c = Ice::emptyCurrent) override;
56 
57  RunningTaskList getRunningTasks(const Ice::Current& c = Ice::emptyCurrent) override;
58  PeriodicTaskList getPeriodicTasks(const Ice::Current& c = Ice::emptyCurrent) override;
59 
60  /**
61  * @brief add RunningTask instance to this thread list
62  * @param threadPtr pointer to the RunningTask instance to add
63  */
64  void addRunningTask(RunningTaskIceBase* threadPtr);
65 
66  /**
67  * @brief remove RunningTask instance from this thread list
68  * @param threadPtr pointer to the RunningTask instance to remove
69  */
70  bool removeRunningTask(RunningTaskIceBase* threadPtr);
71 
72  /**
73  * @brief add PeriodicTask instance to this thread list
74  * @param threadPtr pointer to the PeriodicTask instance to add
75  */
76  void addPeriodicTask(PeriodicTaskIceBase* threadPtr);
77 
78  /**
79  * @brief remove PeriodicTask instance from this thread list
80  * @param threadPtr pointer to the PeriodicTask instance to remove
81  */
82  bool removePeriodicTask(PeriodicTaskIceBase* threadPtr);
83 
84  /**
85  * @brief getApplicationThreadList retrieves the ThreadList, that
86  * contains all TimerTasks and PeriodicTasks in this Application.
87  *
88  * @return
89  */
90 
92  static int GetThreadJiffies(int threadId);
93  static int GetHertz();
94  protected:
95  void setApplicationThreadListName(const std::string& threadListName);
96  friend class ArmarXManager;
97  //inherited from ManagedIceObject
98  void onInitComponent() override;
99  void onConnectComponent() override;
100  void onDisconnectComponent() override;
101  std::string getDefaultName() const override
102  {
103  return "ThreadList";
104  }
105 
106  void updateCPUUsage();
107 
108  private:
109  struct Impl;
110  std::unique_ptr<Impl> impl;
111  };
112 }
113 
114 namespace std
115 {
116  ARMARXCORE_IMPORT_EXPORT ostream& operator<< (ostream& stream, const armarx::RunningTaskIceBase& task);
117 }
118 
119 
armarx::ThreadList::GetThreadJiffies
static int GetThreadJiffies(int threadId)
armarx::ThreadList::addRunningTask
void addRunningTask(RunningTaskIceBase *threadPtr)
add RunningTask instance to this thread list
Definition: ThreadList.cpp:137
armarx::ThreadList::updateCPUUsage
void updateCPUUsage()
Definition: ThreadList.cpp:70
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::ThreadList::getApplicationThreadList
static ThreadListPtr getApplicationThreadList()
getApplicationThreadList retrieves the ThreadList, that contains all TimerTasks and PeriodicTasks in ...
Definition: ThreadList.cpp:189
armarx::ThreadList::getRunningTasks
RunningTaskList getRunningTasks(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ThreadList.cpp:107
armarx::ThreadList::GetHertz
static int GetHertz()
IceInternal::Handle< ThreadList >
armarx::ThreadList::ThreadList
ThreadList()
Definition: ThreadList.cpp:45
armarx::ThreadList::getCpuUsage
double getCpuUsage(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ThreadList.cpp:101
ManagedIceObject.h
armarx::ThreadList::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ThreadList.cpp:65
armarx::ThreadList::getRunningTaskNames
Ice::StringSeq getRunningTaskNames(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ThreadList.cpp:74
armarx::ThreadList::removePeriodicTask
bool removePeriodicTask(PeriodicTaskIceBase *threadPtr)
remove PeriodicTask instance from this thread list
Definition: ThreadList.cpp:176
std::operator<<
ARMARXCORE_IMPORT_EXPORT ostream & operator<<(ostream &stream, const armarx::RunningTaskIceBase &task)
armarx::ThreadList::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ThreadList.h:101
armarx::ThreadList::setApplicationThreadListName
void setApplicationThreadListName(const std::string &threadListName)
Definition: ThreadList.cpp:195
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
std
Definition: Application.h:66
armarx::ThreadList::getPeriodicTasks
PeriodicTaskList getPeriodicTasks(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ThreadList.cpp:122
armarx::ThreadList::addPeriodicTask
void addPeriodicTask(PeriodicTaskIceBase *threadPtr)
add PeriodicTask instance to this thread list
Definition: ThreadList.cpp:164
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
armarx::ThreadList
Definition: ThreadList.h:44
armarx::ThreadList::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: ThreadList.cpp:56
armarx::ThreadList::getPeriodicTaskNames
Ice::StringSeq getPeriodicTaskNames(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ThreadList.cpp:87
armarx::ThreadList::~ThreadList
~ThreadList()
Definition: ThreadList.cpp:51
armarx::ArmarXManager
Main class of an ArmarX process.
Definition: ArmarXManager.h:97
armarx::ThreadList::removeRunningTask
bool removeRunningTask(RunningTaskIceBase *threadPtr)
remove RunningTask instance from this thread list
Definition: ThreadList.cpp:150
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ThreadList::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: ThreadList.cpp:60
armarx::ThreadListPtr
IceInternal::Handle< ThreadList > ThreadListPtr
Definition: RunningTask.h:39