cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsTaskContinuous.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): Peter Kazanzides
7  Created on: 2008-09-23
8 
9  (C) Copyright 2008-2012 Johns Hopkins University (JHU), All Rights Reserved.
10 
11 --- begin cisst license - do not edit ---
12 
13 This software is provided "as is" under an open source license, with
14 no warranty. The complete license can be found in license.txt and
15 http://www.cisst.org/cisst/license.txt.
16 
17 --- end cisst license ---
18 */
19 
20 
26 #ifndef _mtsTaskContinuous_h
27 #define _mtsTaskContinuous_h
28 
29 #include <cisstMultiTask/mtsTask.h>
30 
31 // Always include last
33 
34 
36 {
38 public:
39  enum { STATE_TABLE_DEFAULT_SIZE = 256 };
40  std::string Name;
41  unsigned int StateTableSize;
42  bool NewThread;
43 
45  mtsTaskContinuousConstructorArg(const std::string &name,
46  unsigned int sizeStateTable = STATE_TABLE_DEFAULT_SIZE,
47  bool newThread = true) :
48  mtsGenericObject(), Name(name), StateTableSize(sizeStateTable), NewThread(newThread) {}
50  Name(other.Name), StateTableSize(other.StateTableSize), NewThread(other.NewThread) {}
52 
53  void SerializeRaw(std::ostream & outputStream) const;
54  void DeSerializeRaw(std::istream & inputStream);
55 
56  void ToStream(std::ostream & outputStream) const;
57 
59  virtual void ToStreamRaw(std::ostream & outputStream, const char delimiter = ' ',
60  bool headerOnly = false, const std::string & headerPrefix = "") const;
61 
64  virtual bool FromStreamRaw(std::istream & inputStream, const char delimiter = ' ');
65 };
66 
68 
78 {
80 
81  friend class mtsTaskManager;
82 
83 public:
84  typedef mtsTask BaseType;
85 
86 protected:
87  /************************ Protected task data *********************/
88 
90  bool NewThread;
91 
95 
96  /********************* Methods that call user methods *****************/
97 
100  virtual void *RunInternal(void* argument);
101 
103  virtual void StartInternal(void);
104 
105 public:
106  /********************* Task constructor and destructor *****************/
107 
139  mtsTaskContinuous(const std::string & name,
140  unsigned int sizeStateTable = 256,
141  bool newThread = true);
142 
144 
146  virtual ~mtsTaskContinuous();
147 
148  /********************* Methods to change task status *****************/
149 
150  /* Create a new thread (if needed). */
151  void Create(void *data = 0);
152 
154  void Start(void);
155 
157  void Suspend(void);
158 
160  void Kill(void);
161 };
162 
163 
165 
166 // Continuous task that doesn't create a thread (uses main thread).
167 
169 {
171 public:
172  mtsTaskMain(const std::string &name) : mtsTaskContinuous(name, 256, false) {}
174 };
175 
177 
178 #endif // _mtsTaskContinuous_h
179 
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
bool NewThread
Definition: mtsTaskContinuous.h:90
CMN_DECLARE_SERVICES_INSTANTIATION(mtsTaskContinuousConstructorArg)
#define mtsTaskManager
Definition: mtsTaskManager.h:34
virtual void SerializeRaw(std::ostream &outputStream) const
virtual void DeSerializeRaw(std::istream &inputStream)
virtual void ToStream(std::ostream &outputStream) const
mtsTaskContinuousConstructorArg(const std::string &name, unsigned int sizeStateTable=STATE_TABLE_DEFAULT_SIZE, bool newThread=true)
Definition: mtsTaskContinuous.h:45
Definition: mtsTaskContinuous.h:168
Base class for data object in cisstMultiTask.
Definition: mtsGenericObject.h:56
virtual bool FromStreamRaw(std::istream &inputStream, const char delimiter= ' ')
bool CaptureThread
Definition: mtsTaskContinuous.h:94
virtual void Suspend(void)
~mtsTaskContinuousConstructorArg()
Definition: mtsTaskContinuous.h:51
Definition: mtsTask.h:60
void Kill(void)
mtsTaskContinuousConstructorArg(const mtsTaskContinuousConstructorArg &other)
Definition: mtsTaskContinuous.h:49
void Create(void)
Definition: mtsTask.h:228
~mtsTaskMain()
Definition: mtsTaskContinuous.h:173
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
Definition: mtsTaskContinuous.h:35
Defines a periodic task.
mtsTaskMain(const std::string &name)
Definition: mtsTaskContinuous.h:172
Rules of exporting.
mtsTaskContinuousConstructorArg()
Definition: mtsTaskContinuous.h:44
Definition: mtsTaskContinuous.h:77
virtual void * RunInternal(void *argument)=0
unsigned int StateTableSize
Definition: mtsTaskContinuous.h:41
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
const int CMN_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:331
std::string Name
Definition: mtsTaskContinuous.h:40
virtual void ToStreamRaw(std::ostream &outputStream, const char delimiter= ' ', bool headerOnly=false, const std::string &headerPrefix="") const
mtsTask BaseType
Definition: mtsTaskContinuous.h:84
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76
virtual void Start(void)
bool NewThread
Definition: mtsTaskContinuous.h:42