nidas  v1.2-1520
DSMService.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2005, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 
28 #ifndef NIDAS_CORE_DSMSERVICE_H
29 #define NIDAS_CORE_DSMSERVICE_H
30 
31 #include <nidas/util/Thread.h>
32 #include "DOMable.h"
33 #include "NidsIterators.h"
34 
35 namespace nidas { namespace core {
36 
37 class Project;
38 class DSMServer;
39 class Site;
40 class SampleInput;
41 class SampleIOProcessor;
42 class IOChannel;
43 
47 class DSMService: public DOMable
48 {
49 public:
50 
54  DSMService(const std::string& name);
55 
56  virtual ~DSMService();
57 
58  const std::string& getName() const
59  {
60  return _name;
61  }
62 
63  virtual void setDSMServer(DSMServer* val);
64 
65  virtual DSMServer* getDSMServer() const { return _server; }
66 
67  virtual void connect(SampleInput*) throw() = 0;
68 
73  virtual void addProcessor(SampleIOProcessor* proc)
74  {
75  _processors.push_back(proc);
76  }
77 
78  virtual const std::list<SampleIOProcessor*>& getProcessors() const
79  {
80  return _processors;
81  }
82 
83  const std::list<SampleInput*>& getInputs() const
84  {
85  return _inputs;
86  }
87 
89 
93  virtual void schedule(bool optionalProcessing) throw(nidas::util::Exception) = 0;
94 
95  virtual int checkSubThreads() throw();
96 
97  virtual void cancel() throw();
98 
99  virtual void interrupt() throw();
100 
101  virtual int join() throw();
102 
103  static const std::string getClassName(const xercesc::DOMElement* node,
104  const Project*)
105  throw(nidas::util::InvalidParameterException);
106 
107  void fromDOMElement(const xercesc::DOMElement* node)
108  throw(nidas::util::InvalidParameterException);
109 
110  nidas::util::Thread::SchedPolicy getSchedPolicy() const
111  {
112  return _threadPolicy;
113  }
114 
115  int getSchedPriority() const
116  {
117  return _threadPriority;
118  }
119 
120  virtual void printClock(std::ostream&) throw() {}
121 
122  virtual void printStatus(std::ostream&,float) throw() {}
123 
124 protected:
125 
126  void addSubThread(nidas::util::Thread*) throw();
127 
128  std::string _name;
129 
131 
132  std::set<nidas::util::Thread*> _subThreads;
133 
134  nidas::util::Mutex _subThreadMutex;
135 
136  std::list<SampleInput*> _inputs;
137 
139 
140  std::list<IOChannel*> _ochans;
141 
142  nidas::util::Thread::SchedPolicy _threadPolicy;
143 
145 
146 private:
150  DSMService(const DSMService& x);
151 
155  DSMService& operator = (const DSMService& x);
156 
157 };
158 
159 }} // namespace nidas namespace core
160 
161 #endif
virtual void printClock(std::ostream &)
Definition: DSMService.h:120
const std::string & getName() const
Definition: DSMService.h:58
std::list< SampleInput * > _inputs
Definition: DSMService.h:136
virtual void interrupt()
Definition: DSMService.cc:92
virtual int join()
Definition: DSMService.cc:128
virtual const std::list< SampleIOProcessor * > & getProcessors() const
Definition: DSMService.h:78
virtual void setDSMServer(DSMServer *val)
Definition: DSMService.cc:81
nidas::util::Thread::SchedPolicy _threadPolicy
Definition: DSMService.h:142
nidas::util::Mutex _subThreadMutex
Definition: DSMService.h:134
int _threadPriority
Definition: DSMService.h:144
Interface of an object that can be instantiated from a DOM element, via the fromDOMElement method...
Definition: DOMable.h:51
virtual void cancel()
Definition: DSMService.cc:110
std::list< IOChannel * > _ochans
Definition: DSMService.h:140
virtual DSMServer * getDSMServer() const
Definition: DSMService.h:65
DSMService(const std::string &name)
Constructor.
Definition: DSMService.cc:43
std::set< nidas::util::Thread * > _subThreads
Definition: DSMService.h:132
nidas::util::Thread::SchedPolicy getSchedPolicy() const
Definition: DSMService.h:110
Class for iterating over the Processors of a DSMServer or DSMConfig.
Definition: NidsIterators.h:149
A channel for Input or Output of data.
Definition: IOChannel.h:64
void fromDOMElement(const xercesc::DOMElement *node)
Initialize myself from a xercesc::DOMElement.
Definition: DSMService.cc:205
Definition: Exception.h:35
virtual ~DSMService()
Definition: DSMService.cc:50
Definition: Thread.h:80
const std::list< SampleInput * > & getInputs() const
Definition: DSMService.h:83
ProcessorIterator getProcessorIterator() const
Definition: DSMService.cc:76
Interface of a processor of samples.
Definition: SampleIOProcessor.h:49
virtual int checkSubThreads()
Definition: DSMService.cc:149
virtual void schedule(bool optionalProcessing)=0
schedule this service to run.
Definition: Project.h:60
virtual void connect(SampleInput *)=0
A provider of services to a DSM.
Definition: DSMServer.h:50
int getSchedPriority() const
Definition: DSMService.h:115
static const std::string getClassName(const xercesc::DOMElement *node, const Project *)
Definition: DSMService.cc:179
Base class for a service, as built from a &lt;service&gt; XML tag.
Definition: DSMService.h:47
virtual void printStatus(std::ostream &, float)
Definition: DSMService.h:122
DSMServer * _server
Definition: DSMService.h:130
std::string _name
Definition: DSMService.h:128
std::list< SampleIOProcessor * > _processors
Definition: DSMService.h:138
void addSubThread(nidas::util::Thread *)
Definition: DSMService.cc:86
virtual void addProcessor(SampleIOProcessor *proc)
Add a processor to this RawSampleService.
Definition: DSMService.h:73
Interface of an input SampleSource.
Definition: SampleInput.h:47