nidas  v1.2-1520
FileSet.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  ** 2009, 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_CORE_FILESET_H
28 #define NIDAS_CORE_FILESET_H
29 
30 #include "IOChannel.h"
31 #include "FsMount.h"
32 
33 #include <nidas/util/FileSet.h>
34 
35 #include <iostream>
36 
37 namespace nidas { namespace core {
38 
42 class FileSet: public IOChannel {
43 
44 public:
45 
46  FileSet();
47 
53 
54  ~FileSet();
55 
57  {
58  return 30;
59  }
60 
61  // virtual nidas::util::FileSet& getNUFileSet() { return *_fset; }
62 
63  bool isNewInput() const { return _fset->isNewFile(); }
64 
65  const std::string& getName() const;
66 
72  void setDir(const std::string& val);
73 
79  void setFileName(const std::string& val);
80 
81  void requestConnection(IOChannelRequester* requester)
83 
84  IOChannel* connect() throw(nidas::util::IOException);
85 
86  void setNonBlocking(bool val) throw(nidas::util::IOException)
87  {
88  if (val) PLOG(("%s: setNonBlocking(true) not implemented",
89  getName().c_str()));
90  }
91 
92  bool isNonBlocking() const throw(nidas::util::IOException)
93  {
94  return false;
95  }
96 
100  void setMount(FsMount* val) { _mount = val; }
101 
105  void mounted();
106 
110  FileSet* clone() const
111  {
112  return new FileSet(*this);
113  }
114 
115  dsm_time_t createFile(dsm_time_t t,bool exact)
117 
118  size_t read(void* buf, size_t len) throw(nidas::util::IOException)
119  {
120  return _fset->read(buf,len);
121  }
122 
123  size_t write(const void* buf, size_t len) throw(nidas::util::IOException)
124  {
125 #ifdef DEBUG
126  std::cerr << getName() << " write, len=" << len << std::endl;
127 #endif
128  return _fset->write(buf,len);
129  }
130 
131  size_t write(const struct iovec* iov, int iovcnt) throw(nidas::util::IOException)
132  {
133  return _fset->write(iov,iovcnt);
134  }
135 
136  void close() throw(nidas::util::IOException);
137 
138  int getFd() const { return _fset->getFd(); }
139 
140  void fromDOMElement(const xercesc::DOMElement* node)
142 
146  const std::string& getCurrentName() const
147  {
148  return _fset->getCurrentName();
149  }
150 
152  {
153  _fset->setStartTime(val);
154  }
155 
157  {
158  return _fset->getStartTime();
159  }
160 
162  {
163  _fset->setEndTime(val);
164  }
165 
167  {
168  return _fset->getStartTime();
169  }
170 
174  void setFileLengthSecs(int val)
175  {
176  _fset->setFileLengthSecs(val);
177  }
178 
179  int getFileLengthSecs() const
180  {
181  return _fset->getFileLengthSecs();
182  }
183 
184  void addFileName(const std::string& val)
185  {
186  _fset->addFileName(val);
187  }
188 
189  long long getFileSize() const throw(nidas::util::IOException)
190  {
191  return _fset->getFileSize();
192  }
193 
198  int getLastErrno() const
199  {
200  return _fset->getLastErrno();
201  }
202 
207  void
208  setKeepOpening(bool keepopening)
209  {
210  _fset->setKeepOpening(keepopening);
211  }
212 
213  bool
215  {
216  return _fset->keepOpening();
217  }
218 
226  static FileSet* getFileSet(const std::list<std::string>& filenames)
228 
229 protected:
230 
234  FileSet(const FileSet& x);
235 
237 
242  void setName(const std::string& val);
243 
244  std::string _name;
245 
247 
249 
250 private:
254  FileSet& operator=(const FileSet&);
255 };
256 
257 }} // namespace nidas namespace core
258 
259 #endif
FileSet & operator=(const FileSet &)
No assignment.
void setStartTime(const UTime &val)
Definition: FileSet.h:152
const std::string & getCurrentName() const
Get name of current file.
Definition: FileSet.h:146
Filesystem mounter/unmounter.
Definition: FsMount.h:51
void mounted()
This method is called by FsMount when it is done.
Definition: FileSet.cc:115
IOChannelRequester * _requester
Definition: FileSet.h:246
nidas::util::UTime getStartTime() const
Definition: FileSet.h:156
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
size_t write(const void *buf, size_t len)
Physical write method which must be implemented in derived classes.
Definition: FileSet.h:123
IOChannel * connect()
Establish a connection.
Definition: FileSet.cc:95
int getLastErrno() const
Get last error value.
Definition: FileSet.h:198
A description of a set of output files, consisting of a directory name and a file name format contain...
Definition: FileSet.h:66
Implementation of an IOChannel using an nidas::util::FileSet.
Definition: FileSet.h:42
void setStartTime(const nidas::util::UTime &val)
Definition: FileSet.h:151
void setFileLengthSecs(int val)
Set/get the file length in seconds.
Definition: FileSet.h:129
FileSet()
Definition: FileSet.cc:41
FsMount * _mount
Definition: FileSet.h:248
virtual void addFileName(const std::string &val)
Definition: FileSet.h:124
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
void setEndTime(const UTime &val)
Definition: FileSet.h:156
void setFileName(const std::string &val)
Set the file portion of the file search path.
Definition: FileSet.cc:75
static FileSet * getFileSet(const std::list< std::string > &filenames)
Convienence function to return a pointer to a nidas::core::FileSet, given a list of files...
Definition: FileSet.cc:186
void setName(const std::string &val)
Recognizeable name of this IOChannel - used for informative messages.
Definition: FileSet.cc:70
int getFileLengthSecs() const
Definition: FileSet.h:137
virtual size_t read(void *buf, size_t count)
Read from current file.
Definition: FileSet.cc:290
void fromDOMElement(const xercesc::DOMElement *node)
Initialize myself from a xercesc::DOMElement.
Definition: FileSet.cc:137
size_t write(const struct iovec *iov, int iovcnt)
Physical write method which must be implemented in derived classes.
Definition: FileSet.h:131
void requestConnection(IOChannelRequester *requester)
After the IOChannel is configured, a user of IOChannel calls requestConnection to get things started...
Definition: FileSet.cc:103
virtual size_t write(const void *buf, size_t count)
Write to current file.
Definition: FileSet.cc:305
void addFileName(const std::string &val)
Definition: FileSet.h:184
dsm_time_t createFile(dsm_time_t t, bool exact)
Request that an IOChannel open a new file, with a name based on a time.
Definition: FileSet.cc:129
nidas::util::UTime getEndTime() const
Definition: FileSet.h:166
void setMount(FsMount *val)
FileSet will own the FsMount.
Definition: FileSet.h:100
long long getFileSize() const
Definition: FileSet.h:189
size_t read(void *buf, size_t len)
Physical read method which must be implemented in derived classes.
Definition: FileSet.h:118
A channel for Input or Output of data.
Definition: IOChannel.h:64
FileSet * clone() const
Clone myself.
Definition: FileSet.h:110
bool isNewInput() const
Some IOChannels, namely FileSet, which opens successive files, need to indicate when a read is from t...
Definition: FileSet.h:63
UTime getStartTime() const
Definition: FileSet.h:154
void setKeepOpening(bool keepopening)
Set whether the FileSet should keep going to the next file when an error happens opening a file...
Definition: FileSet.h:253
int getFileLengthSecs() const
Definition: FileSet.h:179
void setEndTime(const nidas::util::UTime &val)
Definition: FileSet.h:161
int len
Definition: sing.cc:934
long long getFileSize() const
Definition: FileSet.cc:155
bool isNewFile() const
Definition: FileSet.h:106
bool isNonBlocking() const
Definition: FileSet.h:92
Definition: IOException.h:37
bool keepOpening()
Definition: FileSet.h:259
void setDir(const std::string &val)
Set the directory portion of the file search path.
Definition: FileSet.cc:85
const std::string & getName() const
Definition: FileSet.cc:64
void setNonBlocking(bool val)
Definition: FileSet.h:86
std::string _name
Definition: FileSet.h:244
~FileSet()
Definition: FileSet.cc:58
int getFd() const
Definition: FileSet.h:138
int getReconnectDelaySecs() const
Definition: FileSet.h:56
void setFileLengthSecs(int val)
Set/get the file length in seconds.
Definition: FileSet.h:174
int getLastErrno() const
Get last error value.
Definition: FileSet.h:243
bool keepOpening()
Definition: FileSet.h:214
int getFd() const
Definition: FileSet.h:104
void setKeepOpening(bool keepopening)
Set whether the FileSet should keep going to the next file when an error happens opening a file...
Definition: FileSet.h:208
void close()
Definition: FileSet.cc:120
#define PLOG(MSG)
Definition: Logger.h:302
Interface for an object that requests connections to Inputs or Outputs.
Definition: IOChannel.h:54
const std::string & getCurrentName() const
Get name of current file.
Definition: FileSet.h:163
Definition: InvalidParameterException.h:35
nidas::util::FileSet * _fset
Definition: FileSet.h:236