27#ifndef NIDAS_CORE_PORTSELECTOR_H
28#define NIDAS_CORE_PORTSELECTOR_H
30#include <nidas/Config.h>
55#if (((POLLING_METHOD == POLL_EPOLL_ET || POLLING_METHOD == POLL_EPOLL_LT) && !defined(HAVE_EPOLL_PWAIT)) || (POLLING_METHOD == POLL_POLL && !defined(HAVE_PPOLL)))
56#define USE_NOTIFY_PIPE
59namespace nidas {
namespace core {
182#if POLLING_METHOD == POLL_EPOLL_ET || POLLING_METHOD == POLL_EPOLL_LT
295#ifdef USE_NOTIFY_PIPE
454#if POLLING_METHOD == POLL_EPOLL_ET || POLLING_METHOD == POLL_EPOLL_LT
464#elif POLLING_METHOD == POLL_PSELECT
480#elif POLLING_METHOD == POLL_POLL
486#if POLLING_METHOD == POLL_PSELECT || POLLING_METHOD == POLL_POLL
492#if POLLING_METHOD == POLL_POLL
500 struct timespec _timeout;
504#ifdef USE_NOTIFY_PIPE
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition DSMSensor.h:88
virtual int getTimeoutMsecs() const
Definition DSMSensor.h:531
virtual int getReadFd() const
Definition DSMSensor.h:460
virtual std::string getName() const
Return a name that should fully identify this sensor.
Definition DSMSensor.h:183
Interface for objects with a file descriptor, providing a virtual method to be called when system cal...
Definition Polled.h:110
Definition RemoteSerialConnection.h:42
Definition RemoteSerialListener.h:42
Definition SensorHandler.h:297
void notify()
Used in public methods of SensorHandler which are called from other threads to notify the SensorHandl...
Definition SensorHandler.cc:413
NotifyPipe(const NotifyPipe &)
SensorHandler * _handler
Definition SensorHandler.h:318
bool handlePollEvents(uint32_t events)
Definition SensorHandler.cc:389
NotifyPipe & operator=(const NotifyPipe &)
NotifyPipe(SensorHandler *handler)
Definition SensorHandler.cc:328
int _fds[2]
Definition SensorHandler.h:317
~NotifyPipe()
Definition SensorHandler.cc:355
int getFd() const
Definition SensorHandler.h:314
void close()
Definition SensorHandler.cc:365
Definition SensorHandler.h:204
void close()
Remove this DSMSensor from those being polled, then call its close() method.
Definition SensorHandler.cc:211
PolledDSMSensor(DSMSensor *sensor, SensorHandler *handler)
Definition SensorHandler.cc:180
void setupTimeouts(int checkIntervalMsecs)
SensorHandler implements a fairly crude way to detect timeouts on data read from sensors.
Definition SensorHandler.cc:299
bool checkTimeout()
The SensorHandler will call this method of each opened sensor at the interval specified previously in...
Definition SensorHandler.cc:275
~PolledDSMSensor()
Destructor does not close().
Definition SensorHandler.h:214
SensorHandler * _handler
Definition SensorHandler.h:267
PolledDSMSensor & operator=(const PolledDSMSensor &)
DSMSensor * _sensor
Definition SensorHandler.h:265
DSMSensor * getDSMSensor()
Definition SensorHandler.h:221
PolledDSMSensor(const PolledDSMSensor &)
int _lastCheckInterval
What the previous timeout check interval was.
Definition SensorHandler.h:285
int getFd() const
Definition SensorHandler.h:223
int getTimeoutMsecs() const
Definition SensorHandler.h:227
bool handlePollEvents(uint32_t events)
Definition SensorHandler.cc:233
int _nTimeoutChecks
How many times this sensor has been checked for timeouts since the last time data was reads.
Definition SensorHandler.h:273
const std::string getName() const
Definition SensorHandler.h:225
int _nTimeoutChecksMax
How many timeout checks constitute an timeout on this sensor.
Definition SensorHandler.h:278
SensorHandler implements a DSMSensor event loop.
Definition SensorHandler.h:88
SensorHandler(const SensorHandler &)
No copy.
void addSensor(DSMSensor *sensor)
Add an unopened sensor to the SensorHandler.
Definition SensorHandler.cc:744
dsm_time_t _sensorStatsTime
Definition SensorHandler.h:510
RemoteSerialListener * _rserial
Definition SensorHandler.h:438
SensorOpener _opener
Definition SensorHandler.h:529
void interrupt()
Interrupt polling.
Definition SensorHandler.cc:720
dsm_time_t _sensorCheckTime
Definition SensorHandler.h:508
void scheduleAdd(RemoteSerialConnection *)
Schedule this remote serial connection to be closed when convenient.
Definition SensorHandler.cc:863
std::set< PolledDSMSensor * > _pendingSensorClosures
Sensors to be closed, probably due to a read error or a timeout.
Definition SensorHandler.h:428
void add(DSMSensor *sensor)
Internal private method to create a PolledDSMSensor from a DSMSensor and add it to the list of curren...
Definition SensorHandler.cc:815
std::list< DSMSensor * > getOpenedSensors() const
Definition SensorHandler.cc:174
std::list< DSMSensor * > _allSensors
The collection of DSMSensors to be handled.
Definition SensorHandler.h:385
void signalHandler(int sig, siginfo_t *)
Override default implementation of Thread::signalHandler().
Definition SensorHandler.cc:125
std::list< DSMSensor * > _openedSensors
Collection of DSMSensors which have been opened.
Definition SensorHandler.h:410
void handleRemoteSerial(int fd, DSMSensor *sensor)
struct epoll_event * _events
Definition SensorHandler.h:460
std::set< RemoteSerialConnection * > _pendingRserialClosures
RemoteSerialConnections to be closed, probably because the socket connection closed.
Definition SensorHandler.h:450
int _nevents
Definition SensorHandler.h:462
void setSensorStatsInterval(int val)
Set the sensor statistics calculation period.
Definition SensorHandler.h:141
~SensorHandler()
Close any remaining sensors.
Definition SensorHandler.cc:90
nidas::util::Mutex _pollingMutex
Definition SensorHandler.h:387
std::list< RemoteSerialConnection * > _newRserials
Newly opened RemoteSerialConnections, which are to be added to the list of file descriptors to be pol...
Definition SensorHandler.h:444
void scheduleClose(PolledDSMSensor *)
Schedule this PolledDSMSensor to be closed when convenient.
Definition SensorHandler.cc:786
bool _pollingChanged
A change in the polling file descriptors needs to be handled.
Definition SensorHandler.h:392
void checkSensors(dsm_time_t)
Check on each sensor.
SensorHandler(unsigned short rserialPort=0)
Constructor.
Definition SensorHandler.cc:44
std::map< const DSMSensor *, unsigned int > _fullBufferReads
For each sensor, number of times that the input buffer was filled in a read, i.e.
Definition SensorHandler.h:536
unsigned int _sensorCheckIntervalUsecs
Same as _sensorCheckIntervalMsecs, but in microseconds.
Definition SensorHandler.h:521
SensorHandler & operator=(const SensorHandler &)
No assignment.
std::list< PolledDSMSensor * > _polledSensors
Those DSMSensors currently being polled.
Definition SensorHandler.h:415
int run()
Thread function.
Definition SensorHandler.cc:426
void scheduleReopen(PolledDSMSensor *)
Schedule this PolledDSMSensor to be closed and reopened.
Definition SensorHandler.cc:802
unsigned short _remoteSerialSocketPort
Definition SensorHandler.h:436
int getEpollFd() const
Definition SensorHandler.h:183
int _sensorCheckIntervalMsecs
Interval for checking for timeouts on each sensor, in milliseconds.
Definition SensorHandler.h:516
void calcStatistics(dsm_time_t)
Definition SensorHandler.cc:130
int getSensorStatsInterval() const
Get the sensor check period.
Definition SensorHandler.h:149
std::list< RemoteSerialConnection * > _activeRserialConns
Definition SensorHandler.h:452
void updateTimeouts()
Tell the SensorHandler that one or more sensor timeouts have changed.
Definition SensorHandler.h:196
void handlePollingChange()
Called when something has changed in our collection of sensors.
Definition SensorHandler.cc:994
bool getPollingChanged()
Lock the polling mutex, read the state of the _pollingChanged flag, then return it.
Definition SensorHandler.cc:982
int _epollfd
epoll file descriptor.
Definition SensorHandler.h:458
void setupTimeouts(int sensorCheckIntervalMsecs)
Definition SensorHandler.cc:966
bool _acceptingOpens
Definition SensorHandler.h:538
unsigned int _sensorStatsInterval
Interval for calculcating through-put statistics on each sensor, in microseconds.
Definition SensorHandler.h:527
void checkTimeouts(dsm_time_t)
Definition SensorHandler.cc:150
void sensorIsOpen(DSMSensor *sensor)
After SensorOpener has opened the sensor, it will notify SensorHandler via this method that the senso...
Definition SensorHandler.cc:756
void incrementFullBufferReads(const DSMSensor *sensor)
Called by a DSMSensor to indicate that a read did not consume all available data.
Definition SensorHandler.cc:225
std::set< PolledDSMSensor * > _pendingSensorReopens
Sensors to be closed and then reopened.
Definition SensorHandler.h:434
std::list< DSMSensor * > _newOpenedSensors
Newly opened DSMSensors, which are to be added to the list of file descriptors to be polled.
Definition SensorHandler.h:421
int join()
Join this thread and join the SensorOpener.
Definition SensorHandler.cc:733
void closeSensor(DSMSensor *sensor)
Request that SensorHandler close the sensor.
void setPollingChanged()
Lock the polling mutex and set the _pollingChanged flag.
Definition SensorHandler.cc:988
void remove(PolledDSMSensor *sensor)
Internal private method to close the PolledDSMSensor.
Definition SensorHandler.cc:834
std::list< DSMSensor * > getAllSensors() const
Definition SensorHandler.cc:167
NotifyPipe * _notifyPipe
Definition SensorHandler.h:505
Thread which opens DSMSensors.
Definition SensorOpener.h:42
A C++ wrapper for a POSIX mutex.
Definition ThreadSupport.h:161
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
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:62
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
int fd
Definition twod.c:56
#define USECS_PER_MSEC
Definition types.h:115