cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsTaskPeriodic.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Ankur Kapoor, Peter Kazanzides, Anton Deguet
7  Created on: 2004-04-30
8 
9  (C) Copyright 2004-2011 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 
27 #ifndef _mtsTaskPeriodic_h
28 #define _mtsTaskPeriodic_h
29 
30 #include <cisstCommon/cmnUnits.h>
34 
35 // Always include last
37 
39 {
41 public:
42  enum { STATE_TABLE_DEFAULT_SIZE = 256 };
43  std::string Name;
44  double Period;
46  unsigned int StateTableSize;
47 
49  mtsTaskPeriodicConstructorArg(const std::string &name, double period, bool isHardRealTime = false,
50  unsigned int sizeStateTable = STATE_TABLE_DEFAULT_SIZE) :
51  mtsGenericObject(), Name(name), Period(period), IsHardRealTime(isHardRealTime), StateTableSize(sizeStateTable) {}
53  Name(other.Name), Period(other.Period), IsHardRealTime(other.IsHardRealTime), StateTableSize(other.StateTableSize) {}
55 
56  void SerializeRaw(std::ostream & outputStream) const;
57  void DeSerializeRaw(std::istream & inputStream);
58 
59  void ToStream(std::ostream & outputStream) const;
60 
62  virtual void ToStreamRaw(std::ostream & outputStream, const char delimiter = ' ',
63  bool headerOnly = false, const std::string & headerPrefix = "") const;
64 
67  virtual bool FromStreamRaw(std::istream & inputStream, const char delimiter = ' ');
68 };
69 
71 
81 {
83 
84  friend class mtsTaskManager;
85 
86  public:
88 
89  protected:
90  /************************ Protected task data *********************/
91 
95 
97  double Period;
99 
103 
104  /********************* Methods that call user methods *****************/
105 
108  virtual void *RunInternal(void* argument);
109 
113  void StartupInternal(void);
114 
117  void CleanupInternal(void);
118 
120  void StartInternal(void);
121 
122  public:
123  /********************* Task constructor and destructor *****************/
124 
138  mtsTaskPeriodic(const std::string & name,
139  double periodicityInSeconds,
140  bool isHardRealTime = false,
141  unsigned int sizeStateTable = 256,
142  bool newThread = true);
143 
144  mtsTaskPeriodic(const std::string & name,
145  const osaAbsoluteTime& periodicity,
146  bool isHardRealTime = false,
147  unsigned int sizeStateTable = 256,
148  bool newThread = true);
149 
151 
153  virtual ~mtsTaskPeriodic();
154 
155  /********************* Methods to change task status *****************/
156  /* (use Start, Create and Kill methods from base classes) */
157 
159  void Suspend(void);
160 
161  /********************* Methods for task period and overrun ************/
162 
164  double GetPeriodicity(void) const;
165 
168  bool IsPeriodic(void) const;
169 
170 };
171 
172 
174 
175 
176 #endif // _mtsTaskPeriodic_h
177 
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
mtsTaskPeriodicConstructorArg(const std::string &name, double period, bool isHardRealTime=false, unsigned int sizeStateTable=STATE_TABLE_DEFAULT_SIZE)
Definition: mtsTaskPeriodic.h:49
#define mtsTaskManager
Definition: mtsTaskManager.h:34
void Suspend(void)
mtsTaskPeriodicConstructorArg()
Definition: mtsTaskPeriodic.h:48
virtual void StartInternal(void)
virtual void SerializeRaw(std::ostream &outputStream) const
virtual void DeSerializeRaw(std::istream &inputStream)
Declaration of osaTimeServer class.
virtual void ToStream(std::ostream &outputStream) const
Definition: mtsTaskPeriodic.h:38
Base class for data object in cisstMultiTask.
Definition: mtsGenericObject.h:56
Declaration of units and unit conversion methodsThis file include the definition and implementation o...
virtual bool FromStreamRaw(std::istream &inputStream, const char delimiter= ' ')
Defines a continuously executing task.
std::string Name
Definition: mtsTaskPeriodic.h:43
~mtsTaskPeriodicConstructorArg()
Definition: mtsTaskPeriodic.h:54
CMN_DECLARE_SERVICES_INSTANTIATION(mtsTaskPeriodicConstructorArg)
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
virtual void CleanupInternal(void)
Declaration of osaThreadBuddy.
mtsTaskContinuous BaseType
Definition: mtsTaskPeriodic.h:87
virtual void * RunInternal(void *argument)
osaAbsoluteTime AbsoluteTimePeriod
Definition: mtsTaskPeriodic.h:98
mtsTaskPeriodicConstructorArg(const mtsTaskPeriodicConstructorArg &other)
Definition: mtsTaskPeriodic.h:52
double Period
Definition: mtsTaskPeriodic.h:97
Rules of exporting.
unsigned int StateTableSize
Definition: mtsTaskPeriodic.h:46
virtual bool IsPeriodic(void) const
Definition: mtsTask.h:292
Definition: mtsTaskContinuous.h:77
Definition: mtsTaskPeriodic.h:80
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
const int CMN_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:331
virtual void StartupInternal(void)
virtual void ToStreamRaw(std::ostream &outputStream, const char delimiter= ' ', bool headerOnly=false, const std::string &headerPrefix="") const
Implementation of the Thread Proxy object in an OS independent manner.
Definition: osaThreadBuddy.h:63
double Period
Definition: mtsTaskPeriodic.h:44
Definition: osaTimeServer.h:36
bool IsHardRealTime
Definition: mtsTaskPeriodic.h:45
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76
bool IsHardRealTime
Definition: mtsTaskPeriodic.h:102
osaThreadBuddy ThreadBuddy
Definition: mtsTaskPeriodic.h:94