nidas  v1.2-1520
WatchedFileSensor.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  ** 2011, 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 #include <nidas/Config.h>
28 #ifdef HAVE_SYS_INOTIFY_H
29 
30 /* From inotify man page:
31  * Inotify was merged into the 2.6.13 Linux kernel. The required library inter‐
32  * faces were added to glibc in version 2.4. (IN_DONT_FOLLOW, IN_MASK_ADD, and
33  * IN_ONLYDIR were only added in version 2.5.)
34  * As of Aug 2011, we're using glibc 2.3.3 on the Vipers and Vulcans
35  * cat /opt/arcom/arm-linux/lib/libc.so
36  * ls -l /opt/arcom/arm-linux/lib/libc.so.6 -> libc-2.3.3.so
37  * So, there is no inotify on the Vipers/Vulcans until they are upgraded.
38  * HAVE_SYS_INOTIFY_H will be defined by Scons if sys/inotify.h is found.
39  */
40 
41 #ifndef NIDAS_DYNLD_WATCHEDFILESENSOR_H
42 #define NIDAS_DYNLD_WATCHEDFILESENSOR_H
43 
46 
47 namespace nidas { namespace dynld {
48 
49 using namespace nidas::core;
50 
75 class WatchedFileSensor : public CharacterSensor
76 {
77 
78 public:
79 
84  WatchedFileSensor();
85 
86  ~WatchedFileSensor();
87 
92  int getReadFd() const
93  {
94  return _inotifyfd;
95  }
96 
97  int getWriteFd() const
98  {
99  return -1;
100  }
101 
105  void open(int flags) throw(nidas::util::IOException,
107 
108  /*
109  * Stop monitoring the file.
110  */
111  void close() throw(nidas::util::IOException);
112 
118  bool readSamples() throw(nidas::util::IOException);
119 
120 private:
121 
125  void getFileStatus() throw(nidas::util::IOException);
126 
133  void getPathStatus(dev_t& dev, ino_t& inode) throw(nidas::util::IOException);
134 
139  bool differentInode() throw(nidas::util::IOException);
140 
150  void reopen() throw(nidas::util::IOException);
151 
155  int _inotifyfd;
156 
160  int _watchd;
161 
165  uint32_t _events;
166 
170  IODevice* _iodev;
171 
175  int _flags;
176 
181  dev_t _dev;
182 
187  ino_t _inode;
188 
192  bool _seekToEnd;
193 
197  off_t _size;
198 
202  off_t _curpos;
203 
205  WatchedFileSensor(const WatchedFileSensor&);
206 
208  WatchedFileSensor& operator=(const WatchedFileSensor&);
209 
210 };
211 
212 }} // namespace nidas namespace dynld
213 
214 #endif
215 #endif // HAVE_SYS_INOTIFY_H
Implementation of support for a sensor which generates character output.
Definition: CharacterSensor.h:46
An interface to an IO device.
Definition: IODevice.h:41
Definition: IOException.h:37
Definition: InvalidParameterException.h:35