nidas v1.2.3
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
47namespace nidas { namespace dynld {
48
49using namespace nidas::core;
50
75class WatchedFileSensor : public CharacterSensor
76{
77
78public:
79
85
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);
106
107 /*
108 * Stop monitoring the file.
109 */
110 void close();
111
117 bool readSamples();
118
119private:
120
124 void getFileStatus();
125
132 void getPathStatus(dev_t& dev, ino_t& inode);
133
138 bool differentInode();
139
149 void reopen();
150
154 int _inotifyfd;
155
159 int _watchd;
160
164 uint32_t _events;
165
169 IODevice* _iodev;
170
174 int _flags;
175
180 dev_t _dev;
181
186 ino_t _inode;
187
191 bool _seekToEnd;
192
196 off_t _size;
197
201 off_t _curpos;
202
204 WatchedFileSensor(const WatchedFileSensor&);
205
207 WatchedFileSensor& operator=(const WatchedFileSensor&);
208
209};
210
211}} // namespace nidas namespace dynld
212
213#endif
214#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:42
The essential core classes of nidas.
Definition A2DConverter.h:31
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31