nidas  v1.2-1520
SyncServer.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 #ifndef NIDAS_DYNLD_RAF_SYNCSERVER_H
28 #define NIDAS_DYNLD_RAF_SYNCSERVER_H
29 
30 #include <nidas/core/Socket.h>
31 #include "SyncRecordGenerator.h"
35 #include <nidas/util/Thread.h>
36 #include <nidas/util/auto_ptr.h>
37 
38 namespace nidas { namespace dynld { namespace raf {
39 
40 struct StopSignal
41 {
43  {}
44 
45  virtual void stop() = 0;
46 
47  virtual ~StopSignal()
48  {};
49 
50 private:
51  StopSignal(const StopSignal&);
53 };
54 
55 
58 {
59 public:
60 
61  SyncServer();
62 
63  ~SyncServer();
64 
69  void
70  openStream();
71 
82  void
84 
89  int
90  run() throw(nidas::util::Exception);
91 
92  virtual void interrupt();
93 
94  void
95  read(bool once = false) throw(nidas::util::IOException);
96 
97  void
98  setSorterLengthSeconds(float sorter_secs)
99  {
100  _sorterLengthSecs = sorter_secs;
101  }
102 
103  void
104  setRawSorterLengthSeconds(float sorter_secs)
105  {
106  _rawSorterLengthSecs = sorter_secs;
107  }
108 
114  std::string
116  {
117  return _xmlFileName;
118  }
119 
120  void
121  setXMLFileName(const std::string& name)
122  {
123  _xmlFileName = name;
124  }
125 
126  void
128  {
129  _address.reset(addr);
130  }
131 
136  void
138  {
139  _sampleClient = client;
140  }
141 
142  void
143  setDataFileNames(const std::list<std::string>& dataFileNames)
144  {
145  _dataFileNames = dataFileNames;
146  }
147 
155  void
156  setStopSignal(StopSignal *stop_signal)
157  {
158  _stop_signal = stop_signal;
159  }
160 
161  void
163 
164  void
166 
167  static const int DEFAULT_PORT = 30001;
168 
169  static const float SORTER_LENGTH_SECS;
170 
171  static const float RAW_SORTER_LENGTH_SECS;
172 
177  void connect(SampleOutput* output) throw();
178 
184  void disconnect(SampleOutput* output) throw();
185 
186 private:
187 
188  void
189  initProject();
190 
191  void
193 
194  void
195  stop();
196 
197  void
198  signalStop();
199 
200  void
202 
205 
208 
209  std::string _xmlFileName;
210 
211  std::list<std::string> _dataFileNames;
212 
213  nidas::util::auto_ptr<nidas::util::SocketAddress> _address;
214 
216 
218 
220 
222 
224 
226 
227  // Skip samples outside the time window.
230 
231  SyncServer(const SyncServer&);
232 
233  SyncServer&
234  operator=(const SyncServer&);
235 
236 };
237 
238 }}} // namespace nidas namespace dynld namespace raf
239 
240 
241 #endif // NIDAS_DYNLD_RAF_SYNCSERVER_H
242 
243 
float _rawSorterLengthSecs
Definition: SyncServer.h:217
Interface for an object that requests connections SampleOutputs.
Definition: ConnectionRequester.h:42
void signalStop()
Definition: SyncServer.cc:171
float _sorterLengthSecs
Definition: SyncServer.h:215
void disconnect(SampleOutput *output)
Implementation of SampleConnectionRequester::disconnect().
Definition: SyncServer.cc:467
SyncServer & operator=(const SyncServer &)
Definition: SyncServer.h:56
A class for parsing, formatting and doing operations on time, based on Unix time conventions, where leap seconds are ignored, so that there are always 60 seconds in a minute, 3600 seconds in an hour and 86400 seconds in a day.
Definition: UTime.h:76
void setXMLFileName(const std::string &name)
Definition: SyncServer.h:121
An implementation of a SampleInput.
Definition: SampleInputStream.h:172
void read(bool once=false)
Definition: SyncServer.cc:411
An interface for a socket address.
Definition: SocketAddress.h:36
A class for serializing Samples on an OutputStream.
Definition: SampleOutputStream.h:40
StopSignal * _stop_signal
Definition: SyncServer.h:221
void initProject()
Definition: SyncServer.cc:99
virtual void interrupt()
Interrupt this thread.
Definition: SyncServer.cc:150
Interface of an output stream of samples.
Definition: SampleOutput.h:47
long long dsm_time_t
Posix time in microseconds, the number of non-leap microseconds since 1970 Jan 1 00:00 UTC...
Definition: Sample.h:61
Definition: SyncServer.h:40
static const int DEFAULT_PORT
Definition: SyncServer.h:167
static const float RAW_SORTER_LENGTH_SECS
Definition: SyncServer.h:171
StopSignal & operator=(const StopSignal &)
void resetAddress(nidas::util::SocketAddress *addr)
Definition: SyncServer.h:127
virtual void start()
Start the thread running, meaning execute the run method in a separate thread.
Definition: Thread.cc:406
nidas::util::auto_ptr< nidas::util::SocketAddress > _address
Definition: SyncServer.h:213
Pure virtual interface of a client of Samples.
Definition: SampleClient.h:38
Definition: RawSampleInputStream.h:41
void getTimeWindow(nidas::util::UTime *start, nidas::util::UTime *end)
Definition: SyncServer.cc:364
nidas::core::Sample * _firstSample
Definition: SyncServer.h:223
void setSorterLengthSeconds(float sorter_secs)
Definition: SyncServer.h:98
void initSensors(SampleInputStream &sis)
Definition: SyncServer.cc:112
Definition: Exception.h:35
~SyncServer()
Definition: SyncServer.cc:75
std::string _xmlFileName
Definition: SyncServer.h:209
Definition: SyncRecordGenerator.h:37
Definition: Thread.h:80
SampleOutputStream * _outputStream
Definition: SyncServer.h:207
dsm_time_t _startTime
Definition: SyncServer.h:225
std::list< std::string > _dataFileNames
Definition: SyncServer.h:211
void setRawSorterLengthSeconds(float sorter_secs)
Definition: SyncServer.h:104
Interface to a data sample.
Definition: Sample.h:189
void handleSample(nidas::core::Sample *sample)
Definition: SyncServer.cc:392
dsm_time_t _startWindow
Definition: SyncServer.h:228
dsm_time_t _endWindow
Definition: SyncServer.h:229
std::string getXMLFileName()
Return the current XML filename setting.
Definition: SyncServer.h:115
Definition: IOException.h:37
void openStream()
Open the data file input stream and read the nidas header, but do not parse the project.
Definition: SyncServer.cc:254
int run()
This method implements the Runnable interface for Threads, but it can also be called synchronously wh...
Definition: SyncServer.cc:130
RawSampleInputStream * _inputStream
Definition: SyncServer.h:206
SyncServer()
Definition: SyncServer.cc:57
void setTimeWindow(nidas::util::UTime start, nidas::util::UTime end)
Definition: SyncServer.cc:379
void addSampleClient(SampleClient *client)
Specify a SampleClient instance to receive the sync samples instead of writing the sync samples to an...
Definition: SyncServer.h:137
void stop()
Definition: SyncServer.cc:190
SyncRecordGenerator _syncGen
Definition: SyncServer.h:204
SampleClient * _sampleClient
Definition: SyncServer.h:219
static const float SORTER_LENGTH_SECS
Definition: SyncServer.h:169
SamplePipeline sorts samples that are coming from one or more inputs.
Definition: SamplePipeline.h:79
void init()
Call this method to parse the project, setup sample tags, preload calibrations using the time of the ...
Definition: SyncServer.cc:293
virtual ~StopSignal()
Definition: SyncServer.h:47
void setStopSignal(StopSignal *stop_signal)
Set a callback function which will be called when the SyncServer reaches EOF on its input stream or s...
Definition: SyncServer.h:156
SamplePipeline _pipeline
Definition: SyncServer.h:203
void setDataFileNames(const std::list< std::string > &dataFileNames)
Definition: SyncServer.h:143
void connect(SampleOutput *output)
Implementation of SampleConnectionRequester::connect().
Definition: SyncServer.cc:463
StopSignal()
Definition: SyncServer.h:42