nidas
v1.2-1520
|
SensorHandler implements a DSMSensor event loop. More...
#include <SensorHandler.h>
Classes | |
class | NotifyPipe |
class | PolledDSMSensor |
Public Types | |
enum | runStatus { RUN_CANCELED = -1, RUN_OK = 0, NOT_RUNNING = 1, RUN_EXCEPTION = 2 } |
Values that can be returned by run method. More... | |
enum | SchedPolicy { NU_THREAD_OTHER =SCHED_OTHER, NU_THREAD_FIFO =SCHED_FIFO, NU_THREAD_RR =SCHED_RR } |
Public Member Functions | |
SensorHandler (unsigned short rserialPort=0) | |
Constructor. More... | |
~SensorHandler () | |
Close any remaining sensors. More... | |
void | signalHandler (int sig, siginfo_t *) |
Override default implementation of Thread::signalHandler(). More... | |
void | addSensor (DSMSensor *sensor) |
Add an unopened sensor to the SensorHandler. More... | |
void | closeSensor (DSMSensor *sensor) |
Request that SensorHandler close the sensor. More... | |
void | sensorIsOpen (DSMSensor *sensor) throw () |
After SensorOpener has opened the sensor, it will notify SensorHandler via this method that the sensor is open. More... | |
void | checkSensors (dsm_time_t) |
Check on each sensor. More... | |
void | setSensorStatsInterval (int val) |
Set the sensor statistics calculation period. More... | |
int | getSensorStatsInterval () const |
Get the sensor check period. More... | |
void | handleRemoteSerial (int fd, DSMSensor *sensor) throw (nidas::util::IOException) |
int | run () throw (nidas::util::Exception) |
Thread function. More... | |
std::list< DSMSensor * > | getAllSensors () const |
std::list< DSMSensor * > | getOpenedSensors () const |
void | interrupt () |
Interrupt polling. More... | |
int | join () throw (nidas::util::Exception) |
Join this thread and join the SensorOpener. More... | |
int | getEpollFd () const |
void | incrementFullBufferReads (const DSMSensor *sensor) |
Called by a DSMSensor to indicate that a read did not consume all available data. More... | |
void | updateTimeouts () |
Tell the SensorHandler that one or more sensor timeouts have changed. More... | |
virtual void | start () throw (Exception) |
Start the thread running, meaning execute the run method in a separate thread. More... | |
virtual void | kill (int sig) throw (Exception) |
Send a signal to this thread. More... | |
virtual void | cancel () throw (Exception) |
Cancel this thread. More... | |
virtual bool | isInterrupted () const |
Return true when this thread has been interrupted. More... | |
virtual bool | isRunning () const |
Is this thread running? More... | |
virtual bool | isJoined () const |
Has this thread been joined? More... | |
virtual bool | isDetached () const |
Is this a detached thread. More... | |
bool | isCancelEnabled () const |
Return true if the cancel state of this thread is PTHREAD_CANCEL_ENABLE. More... | |
bool | isCancelDeferred () const |
Return true if the cancel type of this thread is PTHREAD_CANCEL_DEFERRED. More... | |
const std::string & | getName () const throw () |
Return the name of this thread. More... | |
const std::string & | getFullName () throw () |
Return a name with a bunch of descriptive fields, specifying whether it is detached, the real-time priority, etc. More... | |
bool | setRealTimeRoundRobinPriority (int val) throw (Exception) |
bool | setRealTimeFIFOPriority (int val) throw (Exception) |
bool | setNonRealTimePriority () throw (Exception) |
void | setThreadScheduler (enum SchedPolicy policy, int priority) throw (Exception) |
void | blockSignal (int) |
Block a signal in this thread. More... | |
void | unblockSignal (int) |
Install a signal handler and unblock the signal. More... | |
Static Public Member Functions | |
static Thread * | currentThread () |
Return the thread object for the current thread. More... | |
static pthread_t | currentThreadId () |
static Thread * | lookupThread (pthread_t id) |
static const std::string & | currentName () |
Convenience routine to return the name for the current thread, or a string indicating that the name of the thread is unknown. More... | |
static std::string | getPolicyString (int policy) |
Convenience function to return a string for the given scheduler policy: "Non-RT", "RT:FIFO", "RT:RR" or "RT:Unknown". More... | |
static int | test (int argc, char **argv) |
a test method. More... | |
Protected Member Functions | |
void | setCancelEnabled (bool val) |
Set the cancel state for this thread - false means cancel requests are ignored. More... | |
void | setCancelDeferred (bool val) |
Set the cancel type for this thread. More... | |
pthread_t | getId () const |
void | testCancel () const |
Check if we have been cancelled. More... | |
virtual bool | amInterrupted () const |
Call testCancel, and return true when this thread has been interrupted. More... | |
Private Member Functions | |
void | add (DSMSensor *sensor) throw () |
Internal private method to create a PolledDSMSensor from a DSMSensor and add it to the list of currently active sensors. More... | |
void | remove (PolledDSMSensor *sensor) throw () |
Internal private method to close the PolledDSMSensor. More... | |
void | scheduleClose (PolledDSMSensor *) throw () |
Schedule this PolledDSMSensor to be closed when convenient. More... | |
void | scheduleReopen (PolledDSMSensor *) throw () |
Schedule this PolledDSMSensor to be closed and reopened. More... | |
void | add (RemoteSerialConnection *) throw () |
Internal private method to add a remote serial connection to a sensor. More... | |
void | remove (RemoteSerialConnection *) throw () |
void | scheduleAdd (RemoteSerialConnection *) throw () |
Schedule this remote serial connection to be closed when convenient. More... | |
void | scheduleClose (RemoteSerialConnection *) throw () |
void | handlePollingChange () |
Called when something has changed in our collection of sensors. More... | |
void | calcStatistics (dsm_time_t) |
void | setupTimeouts (int sensorCheckIntervalMsecs) |
void | checkTimeouts (dsm_time_t) |
SensorHandler (const SensorHandler &) | |
No copy. More... | |
SensorHandler & | operator= (const SensorHandler &) |
No assignment. More... | |
Private Attributes | |
std::list< DSMSensor * > | _allSensors |
The collection of DSMSensors to be handled. More... | |
nidas::util::Mutex | _pollingMutex |
bool | _pollingChanged |
A change in the polling file descriptors needs to be handled. More... | |
std::list< DSMSensor * > | _openedSensors |
Collection of DSMSensors which have been opened. More... | |
std::list< PolledDSMSensor * > | _polledSensors |
Those DSMSensors currently being polled. More... | |
std::list< DSMSensor * > | _newOpenedSensors |
Newly opened DSMSensors, which are to be added to the list of file descriptors to be polled. More... | |
std::set< PolledDSMSensor * > | _pendingSensorClosures |
Sensors to be closed, probably due to a read error or a timeout. More... | |
std::set< PolledDSMSensor * > | _pendingSensorReopens |
Sensors to be closed and then reopened. More... | |
unsigned short | _remoteSerialSocketPort |
RemoteSerialListener * | _rserial |
std::list < RemoteSerialConnection * > | _newRserials |
Newly opened RemoteSerialConnections, which are to be added to the list of file descriptors to be polled. More... | |
std::set < RemoteSerialConnection * > | _pendingRserialClosures |
RemoteSerialConnections to be closed, probably because the socket connection closed. More... | |
std::list < RemoteSerialConnection * > | _activeRserialConns |
int | _epollfd |
epoll file descriptor. More... | |
struct epoll_event * | _events |
int | _nevents |
NotifyPipe * | _notifyPipe |
dsm_time_t | _sensorCheckTime |
dsm_time_t | _sensorStatsTime |
int | _sensorCheckIntervalMsecs |
Interval for checking for timeouts on each sensor, in milliseconds. More... | |
unsigned int | _sensorCheckIntervalUsecs |
Same as _sensorCheckIntervalMsecs, but in microseconds. More... | |
unsigned int | _sensorStatsInterval |
Interval for calculcating through-put statistics on each sensor, in microseconds. More... | |
SensorOpener | _opener |
std::map< const DSMSensor *, unsigned int > | _fullBufferReads |
For each sensor, number of times that the input buffer was filled in a read, i.e. More... | |
bool | _acceptingOpens |
Friends | |
class | RemoteSerialConnection |
class | RemoteSerialListener |
SensorHandler implements a DSMSensor event loop.
It uses one of the available system calls, depending on the value of POLLING_METHOD, to check for events on the file descriptors of one or more PolledDSMSensors and RemoteSerial sockets.
The handlePollEvents() method is called on each active file descriptor. The polling loop is implemented in the Thread::run method of the SensorHandler.
This code has supported legacy systems which did not have the epoll() API, and used select/pselect or poll/ppoll instead. So, this code supports all the polling APIs, and one is selected using POLLING_METHOD. As of 2017 all known systems support epoll(), so the old select/poll code could be removed.
When an incoming socket connection is accepted on RemoteSerialListener, a RemoteSerialConnection is established, which first requests the name of a DSMSensor on the connected socket. If that sensor is found then data are then passed back and forth between the socket and the DSMSensor. This data path is separate from the normal Sample data path. It allows remote, direct control of serial sensors.
|
inherited |
Values that can be returned by run method.
User can define other values greater than RUN_EXCEPTION. These values are then returned by int join()
. Note that PTHREAD_CANCELLED is -1
Enumerator | |
---|---|
RUN_CANCELED | |
RUN_OK | |
NOT_RUNNING | |
RUN_EXCEPTION |
|
inherited |
SensorHandler::SensorHandler | ( | unsigned short | rserialPort = 0 | ) |
Constructor.
rserialPort | TCP socket port to listen for incoming requests to the rserial service. 0=don't listen. |
References _sensorStatsInterval, _sensorStatsTime, nidas::util::Thread::blockSignal(), nidas::util::getSystemTime(), MSECS_PER_SEC, N_POLLERR, N_POLLHUP, N_POLLIN, N_POLLRDHUP, setSensorStatsInterval(), and nidas::util::timeCeiling().
SensorHandler::~SensorHandler | ( | ) |
Close any remaining sensors.
Before this is called the run method should be finished.
References _allSensors, _epollfd, _events, _notifyPipe, _polledSensors, _rserial, nidas::core::SensorHandler::PolledDSMSensor::close(), and nidas::core::DSMSensor::setDSMConfig().
|
private |
No copy.
|
private |
Internal private method to create a PolledDSMSensor from a DSMSensor and add it to the list of currently active sensors.
References _openedSensors, _polledSensors, _pollingMutex, nidas::util::Mutex::lock(), PLOG, nidas::util::Mutex::unlock(), and nidas::util::Exception::what().
Referenced by handlePollingChange().
|
private |
Internal private method to add a remote serial connection to a sensor.
References _activeRserialConns, _allSensors, _pollingMutex, nidas::core::DSMSensor::getDeviceName(), nidas::core::DSMSensor::getName(), ILOG, nidas::util::Mutex::lock(), NLOG, PLOG, nidas::util::Mutex::unlock(), and nidas::util::Exception::what().
void SensorHandler::addSensor | ( | DSMSensor * | sensor | ) |
Add an unopened sensor to the SensorHandler.
SensorHandler will then own the DSMSensor.
References _allSensors, _opener, _pollingMutex, nidas::util::Mutex::lock(), nidas::core::SensorOpener::openSensor(), and nidas::util::Mutex::unlock().
Referenced by nidas::core::DSMConfig::openSensors().
|
protectedvirtualinherited |
Call testCancel, and return true when this thread has been interrupted.
This is protected because it should only called within the run method of the thread.
Referenced by nidas::core::SampleOutputRequestThread::run(), nidas::core::Looper::run(), nidas::dynld::isff::GOESOutput::run(), nidas::core::DSMServerStat::run(), and nidas::util::Thread::test().
|
inherited |
Block a signal in this thread.
This method is usually called before this Thread has started. If this Thread is currently running, then this method is only effective if called from this Thread, i.e. from its own run() method.
Because SIGINT, SIGTERM and SIGHUP are typically caught in the main thread, they are blocked by default in a Thread. Call unblockSignal(sig) if you want to catch them in a Thread.
References nidas::util::Thread::_blockedSignals, nidas::util::Thread::_unblockedSignals, nidas::util::Thread::currentThread(), nidas::util::Thread::isRunning(), and nidas::util::Thread::thr_add_sig().
Referenced by nidas::dynld::UDPSampleOutput::ConnectionMonitor::ConnectionMonitor(), nidas::core::ServerSocket::ConnectionThread::ConnectionThread(), nidas::core::DerivedDataReader::DerivedDataReader(), nidas::util::McSocketListener::McSocketListener(), nidas::util::McSocketMulticaster< SocketTT >::McSocketMulticaster(), SensorHandler(), nidas::core::SensorOpener::SensorOpener(), nidas::util::Thread::test(), nidas::dynld::RawSampleService::Worker::Worker(), nidas::core::XmlRpcThread::XmlRpcThread(), and nidas::dynld::UDPSampleOutput::XMLSocketListener::XMLSocketListener().
|
private |
References _sensorStatsInterval, _sensorStatsTime, nidas::core::DSMSensor::calcStatistics(), getAllSensors(), and nidas::util::timeCeiling().
Referenced by run().
|
virtualinherited |
Cancel this thread.
References nidas::util::Thread::_id, nidas::util::Thread::_mutex, nidas::util::Exception::errnoToString(), and nidas::util::Thread::getName().
Referenced by nidas::core::DSMService::cancel(), nidas::dynld::isff::GOESOutput::cancelThread(), nidas::core::DerivedDataReader::deleteInstance(), and nidas::core::DSMEngine::joinDataThreads().
void nidas::core::SensorHandler::checkSensors | ( | dsm_time_t | ) |
Check on each sensor.
Currently this means checking whether a timeout has occured and calculating statistics on the data received from the sensor.
|
private |
References _polledSensors, _sensorCheckIntervalUsecs, _sensorCheckTime, nidas::core::SensorHandler::PolledDSMSensor::checkTimeout(), scheduleReopen(), and nidas::util::timeCeiling().
Referenced by run().
void nidas::core::SensorHandler::closeSensor | ( | DSMSensor * | sensor | ) |
Request that SensorHandler close the sensor.
|
inlinestaticinherited |
Convenience routine to return the name for the current thread, or a string indicating that the name of the thread is unknown.
References nidas::util::Thread::currentThread(), nidas::util::Thread::getName(), and nidas::util::Thread::unknownName.
Referenced by nidas::util::Logger::msg_locked().
|
staticinherited |
Return the thread object for the current thread.
Returns null if not found.
Referenced by nidas::util::Thread::blockSignal(), nidas::util::Thread::currentName(), and nidas::util::Thread::unblockSignal().
|
staticinherited |
Referenced by nidas::core::Looper::removeClient().
list< DSMSensor * > SensorHandler::getAllSensors | ( | ) | const |
References _allSensors, and _pollingMutex.
Referenced by calcStatistics().
|
inline |
References _epollfd.
Referenced by nidas::core::RemoteSerialConnection::close(), and nidas::core::SensorHandler::PolledDSMSensor::close().
|
inherited |
Return a name with a bunch of descriptive fields, specifying whether it is detached, the real-time priority, etc.
References nidas::util::Thread::_fullname.
Referenced by nidas::util::Thread::pRun(), nidas::util::Thread::test(), nidas::util::Thread::thr_cleanup(), and nidas::util::Thread::thr_cleanup_delete().
|
inlineprotectedinherited |
References nidas::util::Thread::_id, and nidas::util::Thread::_mutex.
Referenced by nidas::util::Thread::isJoined(), nidas::util::Thread::join(), nidas::util::Thread::pRun(), and nidas::core::Looper::removeClient().
|
inherited |
Return the name of this thread.
References nidas::util::Thread::_name.
Referenced by nidas::core::DSMService::cancel(), nidas::util::Thread::cancel(), nidas::core::DSMService::checkSubThreads(), nidas::core::SensorHandler::PolledDSMSensor::checkTimeout(), nidas::util::Thread::currentName(), nidas::core::SensorHandler::PolledDSMSensor::handlePollEvents(), nidas::core::SampleSorter::heapDecrement(), nidas::core::DSMService::interrupt(), nidas::core::DSMService::join(), nidas::util::Thread::join(), nidas::core::SamplePipeline::join(), nidas::core::FsMountWorkerThread::run(), nidas::core::SampleSorter::run(), nidas::util::ThreadJoiner::run(), nidas::util::Thread::sigAction(), nidas::util::Thread::start(), nidas::util::Thread::test(), nidas::util::LogContext::threadName(), nidas::core::SampleSorter::~SampleSorter(), and nidas::util::Thread::~Thread().
list< DSMSensor * > SensorHandler::getOpenedSensors | ( | ) | const |
References _openedSensors, and _pollingMutex.
|
staticinherited |
Convenience function to return a string for the given scheduler policy: "Non-RT", "RT:FIFO", "RT:RR" or "RT:Unknown".
References nidas::util::Thread::NU_THREAD_FIFO, nidas::util::Thread::NU_THREAD_OTHER, and nidas::util::Thread::NU_THREAD_RR.
Referenced by nidas::core::DSMSensor::getLooper(), and nidas::util::Thread::makeFullName().
|
inline |
Get the sensor check period.
References _sensorStatsInterval, and USECS_PER_MSEC.
|
private |
Called when something has changed in our collection of sensors.
Mainly this maintains the set of file descriptors used by the epoll() system functions.
References _acceptingOpens, _activeRserialConns, _events, _nevents, _newOpenedSensors, _newRserials, _notifyPipe, _opener, _pendingRserialClosures, _pendingSensorClosures, _pendingSensorReopens, _polledSensors, _pollingChanged, _pollingMutex, _rserial, _sensorCheckIntervalMsecs, _sensorCheckIntervalUsecs, _sensorCheckTime, add(), fd, nidas::core::SensorHandler::PolledDSMSensor::getDSMSensor(), nidas::core::RemoteSerialListener::getFd(), nidas::core::RemoteSerialConnection::getFd(), nidas::core::SensorHandler::PolledDSMSensor::getFd(), nidas::core::SensorHandler::NotifyPipe::getFd(), nidas::util::getSystemTime(), nidas::core::SensorHandler::PolledDSMSensor::getTimeoutMsecs(), ILOG, nidas::util::Mutex::lock(), MSECS_PER_SEC, nidas::core::SensorOpener::reopenSensor(), setupTimeouts(), nidas::util::timeCeiling(), nidas::util::Mutex::unlock(), and USECS_PER_MSEC.
Referenced by run().
void nidas::core::SensorHandler::handleRemoteSerial | ( | int | fd, |
DSMSensor * | sensor | ||
) | |||
throw | ( | nidas::util::IOException | |
) |
void SensorHandler::incrementFullBufferReads | ( | const DSMSensor * | sensor | ) |
Called by a DSMSensor to indicate that a read did not consume all available data.
References _fullBufferReads, nidas::core::DSMSensor::getName(), and ILOG.
|
virtual |
Interrupt polling.
Reimplemented from nidas::util::Thread.
References _notifyPipe, nidas::util::Thread::kill(), and nidas::core::SensorHandler::NotifyPipe::notify().
Referenced by nidas::core::DSMEngine::interrupt().
|
inherited |
Return true if the cancel type of this thread is PTHREAD_CANCEL_DEFERRED.
References nidas::util::Thread::_cancel_deferred.
|
inherited |
Return true if the cancel state of this thread is PTHREAD_CANCEL_ENABLE.
References nidas::util::Thread::_cancel_enabled.
|
inlinevirtualinherited |
Is this a detached thread.
References nidas::util::Thread::_detached.
|
inlinevirtualinherited |
Return true when this thread has been interrupted.
Implements nidas::util::Runnable.
References nidas::util::Thread::_interrupted, and nidas::util::Thread::_mutex.
Referenced by nidas::core::SampleSorter::flush(), nidas::core::SampleOutputRequestThread::run(), nidas::core::StatusListener::run(), nidas::core::DerivedDataReader::run(), nidas::core::SensorOpener::run(), Sender::run(), nidas::core::DSMEngineStat::run(), run(), nidas::core::FsMountWorkerThread::run(), ModemLineSetter::run(), ModemLineMonitor::run(), nidas::core::SampleBuffer::run(), nidas::core::SampleSorter::run(), ServerThread::run(), nidas::util::McSocketListener::run(), and nidas::dynld::raf::SyncServer::stop().
|
inlinevirtualinherited |
Has this thread been joined?
References nidas::util::Thread::getId().
Referenced by nidas::core::FsMount::cancel(), nidas::core::DerivedDataReader::deleteInstance(), join(), nidas::dynld::isff::GOESOutput::joinThread(), nidas::util::Thread::test(), nidas::core::SampleBuffer::~SampleBuffer(), nidas::core::SampleSorter::~SampleSorter(), and nidas::util::Thread::~Thread().
|
inlinevirtualinherited |
Is this thread running?
References nidas::util::Thread::_mutex, and nidas::util::Thread::_running.
Referenced by nidas::util::Thread::blockSignal(), nidas::core::DSMService::cancel(), nidas::core::FsMount::cancel(), nidas::dynld::isff::GOESOutput::cancelThread(), nidas::core::DSMService::checkSubThreads(), nidas::dynld::UDPSampleOutput::XMLSocketListener::checkWorkers(), nidas::dynld::UDPSampleOutput::close(), nidas::util::McSocket< SocketT >::close(), nidas::core::DerivedDataReader::deleteInstance(), nidas::core::DSMService::interrupt(), nidas::core::SamplePipeline::join(), nidas::dynld::isff::GOESOutput::joinThread(), nidas::core::DSMServerApp::killStatusThread(), nidas::dynld::isff::GOESOutput::killThread(), nidas::core::Looper::removeClient(), run(), nidas::core::Looper::setupClientMaps(), nidas::util::Thread::test(), nidas::util::Thread::unblockSignal(), nidas::core::SampleBuffer::~SampleBuffer(), nidas::core::SampleSorter::~SampleSorter(), nidas::util::Thread::~Thread(), and nidas::dynld::UDPSampleOutput::~UDPSampleOutput().
|
virtual |
Join this thread and join the SensorOpener.
Reimplemented from nidas::util::Thread.
References _opener, nidas::util::Thread::isJoined(), and nidas::util::Thread::join().
Referenced by nidas::core::DSMEngine::joinDataThreads().
|
virtualinherited |
Send a signal to this thread.
References nidas::util::Exception::errnoToString().
Referenced by nidas::core::FsMount::cancel(), nidas::core::XmlRpcThread::interrupt(), nidas::core::SensorOpener::interrupt(), nidas::core::DerivedDataReader::interrupt(), interrupt(), nidas::util::McSocketListener::interrupt(), nidas::core::DSMServerApp::killStatusThread(), nidas::dynld::isff::GOESOutput::killThread(), main(), scheduleAdd(), scheduleClose(), scheduleReopen(), and sensorIsOpen().
|
staticinherited |
Referenced by nidas::util::LogContext::threadName().
|
private |
No assignment.
|
private |
Internal private method to close the PolledDSMSensor.
Remove it from the polling list, then delete it. The associated DSMSensor will be removed from _openedSensors.
References _openedSensors, _polledSensors, _pollingMutex, nidas::util::Mutex::lock(), PLOG, nidas::util::Mutex::unlock(), and nidas::util::Exception::what().
|
private |
|
virtual |
Thread function.
Thread function, epoll loop.
Implements nidas::util::Runnable.
References _acceptingOpens, _activeRserialConns, _epollfd, _events, _nevents, _newOpenedSensors, _notifyPipe, _opener, _pendingRserialClosures, _pendingSensorClosures, _polledSensors, _pollingChanged, _pollingMutex, _remoteSerialSocketPort, _rserial, _sensorCheckIntervalMsecs, _sensorCheckTime, _sensorStatsTime, calcStatistics(), checkTimeouts(), nidas::core::RemoteSerialListener::close(), nidas::core::SensorHandler::NotifyPipe::close(), nidas::core::DSMSensor::close(), fd, nidas::core::SamplePools::getInstance(), nidas::util::Logger::getInstance(), nidas::core::SamplePoolInterface::getNSamplesAlloc(), nidas::core::SamplePoolInterface::getNSamplesOut(), nidas::core::SamplePools::getPools(), nidas::util::getSystemTime(), nidas::core::Polled::handlePollEvents(), handlePollingChange(), if(), nidas::core::SensorOpener::interrupt(), nidas::util::Thread::isInterrupted(), nidas::util::Thread::isRunning(), nidas::util::Mutex::lock(), nidas::util::Logger::log(), LOG_INFO, LOG_WARNING, N_POLLERR, N_POLLIN, PLOG, POLL_EPOLL_ET, POLLING_METHOD, RemoteSerialListener, nidas::util::Thread::RUN_OK, nidas::util::Thread::start(), nidas::util::Mutex::unlock(), and nidas::util::Exception::what().
|
private |
Schedule this remote serial connection to be closed when convenient.
References _newRserials, _notifyPipe, _pollingChanged, _pollingMutex, nidas::util::Thread::kill(), nidas::util::Mutex::lock(), nidas::core::SensorHandler::NotifyPipe::notify(), and nidas::util::Mutex::unlock().
|
private |
Schedule this PolledDSMSensor to be closed when convenient.
References _notifyPipe, _pendingSensorClosures, _pollingChanged, _pollingMutex, nidas::util::Thread::kill(), nidas::util::Mutex::lock(), nidas::core::SensorHandler::NotifyPipe::notify(), and nidas::util::Mutex::unlock().
|
private |
|
private |
Schedule this PolledDSMSensor to be closed and reopened.
References _notifyPipe, _pendingSensorReopens, _pollingChanged, _pollingMutex, nidas::util::Thread::kill(), nidas::util::Mutex::lock(), nidas::core::SensorHandler::NotifyPipe::notify(), and nidas::util::Mutex::unlock().
Referenced by checkTimeouts().
void SensorHandler::sensorIsOpen | ( | DSMSensor * | sensor | ) | |
throw | ( | ||||
) |
After SensorOpener has opened the sensor, it will notify SensorHandler via this method that the sensor is open.
References _acceptingOpens, _newOpenedSensors, _notifyPipe, _pollingChanged, _pollingMutex, nidas::util::Thread::kill(), nidas::util::Mutex::lock(), nidas::core::SensorHandler::NotifyPipe::notify(), and nidas::util::Mutex::unlock().
Referenced by nidas::core::SensorOpener::run().
|
protectedinherited |
Set the cancel type for this thread.
true means cancel requests are deferred until the next cancellation point. false means they occur instantly. This is protected, it should be called only from a thread's own run method. See the pthreads(7) man page for a list of the cancellation points.
Note: non-deferred canceling is difficult to get right. It has not been tested with this class, and is not recommended.
References nidas::util::Thread::_cancel_deferred.
|
protectedinherited |
Set the cancel state for this thread - false means cancel requests are ignored.
See pthread_setcancelstate. This is protected, it should be called only from a thread's own run method.
References nidas::util::Thread::_cancel_enabled.
|
inherited |
|
inherited |
|
inherited |
|
inline |
Set the sensor statistics calculation period.
val | Period, in milliseconds. |
References _sensorStatsInterval, and USECS_PER_MSEC.
Referenced by SensorHandler().
|
inherited |
|
private |
References _polledSensors, MSECS_PER_SEC, NSECS_PER_MSEC, and nidas::core::SensorHandler::PolledDSMSensor::setupTimeouts().
Referenced by handlePollingChange().
|
virtual |
Override default implementation of Thread::signalHandler().
The default implementation sets the interrupted flag, which we don't want.
Reimplemented from nidas::util::Thread.
|
virtualinherited |
Start the thread running, meaning execute the run method in a separate thread.
References nidas::util::Thread::_id, nidas::util::Thread::_interrupted, nidas::util::Thread::_mutex, nidas::util::Thread::_running, nidas::util::Thread::_thread_attr, nidas::util::Exception::errnoToString(), nidas::util::Thread::getName(), nidas::util::Thread::makeFullName(), nidas::util::Thread::NU_THREAD_FIFO, nidas::util::Thread::NU_THREAD_OTHER, nidas::util::Thread::NU_THREAD_RR, nidas::util::Thread::registerThread(), nidas::util::Thread::setThreadSchedulerNolock(), nidas::util::Thread::thr_run(), nidas::util::Thread::thr_run_detached(), and WLOG.
Referenced by nidas::util::McSocketListener::accept(), nidas::dynld::RawSampleService::connect(), nidas::core::DerivedDataReader::createInstance(), nidas::util::McSocket< SocketT >::joinMulticaster(), main(), nidas::core::DSMEngine::openSensors(), nidas::core::SamplePipeline::procinit(), nidas::core::SamplePipeline::rawinit(), nidas::util::McSocket< SocketT >::request(), nidas::core::DSMServerApp::run(), nidas::core::DSMEngine::run(), PSI::run(), run(), nidas::core::FsMountWorkerThread::run(), nidas::dynld::UDPSampleOutput::XMLSocketListener::run(), nidas::core::Socket::ConnectionThread::run(), ServerThread::run(), nidas::core::Looper::setupClientMaps(), nidas::core::DSMServerApp::startXmlRpcThread(), and nidas::core::DSMEngine::startXmlRpcThread().
|
staticinherited |
a test method.
References nidas::util::Runnable::amInterrupted(), nidas::util::Thread::blockSignal(), nidas::util::Thread::getFullName(), nidas::util::Thread::getName(), nidas::util::Thread::isJoined(), nidas::util::Thread::isRunning(), nidas::util::Runnable::run(), nidas::util::Thread::Thread(), and nidas::util::Exception::what().
|
inlineprotectedinherited |
Check if we have been cancelled.
Calls pthread_testcancel. This is protected since it only checks the current thread - i.e. it must be called within the run method. Since it just calls pthread_testcancel, it is a cancellation point.
|
inherited |
Install a signal handler and unblock the signal.
The signal handler will log a message about the receipt of the signal at severity LOG_INFO using the nidas::util::Logger. Then, if the signal handler is being invoked from a registered Thread, the virtual method signalHandler() for that Thread will be called.
The signal handler is installed with the sigaction() system call, and will be the action for the given signal in all threads, including the main() thread. If other threads do not wish to take action on a given signal, they should call blockSignal(sig). Or they can define their own signalHandler() method.
After installing the signal handler, the signal is added to those that are unblocked for the thread, or if the Thread is not yet running, the signal will be unblocked in the thread once it runs.
As with blockSignal(), this method is typically called on this Thread before it has started. If this Thread has started, then the signal will only be unblocked if the method is called from this Thread, i.e. from its own run() method.
To install a signal handler, and then block the signal so that it is held as pending until it is later unblocked, typically with pselect(), or sigwaitinfo(), do:
References nidas::util::Thread::_blockedSignals, nidas::util::Thread::_unblockedSignals, nidas::util::Thread::currentThread(), nidas::util::Thread::isRunning(), and nidas::util::Thread::thr_add_sig().
Referenced by nidas::core::DerivedDataReader::DerivedDataReader(), nidas::core::FsMountWorkerThread::FsMountWorkerThread(), nidas::core::StatusListener::StatusListener(), nidas::core::StatusThread::StatusThread(), nidas::dynld::XMLConfigService::Worker::Worker(), nidas::core::XmlRpcThread::XmlRpcThread(), and nidas::dynld::UDPSampleOutput::XMLSocketListener::XMLSocketListener().
|
inline |
Tell the SensorHandler that one or more sensor timeouts have changed.
References _pollingChanged.
Referenced by nidas::core::RemoteSerialConnection::close().
|
friend |
|
friend |
Referenced by run().
|
private |
Referenced by handlePollingChange(), run(), and sensorIsOpen().
|
private |
Referenced by add(), handlePollingChange(), remove(), and run().
|
private |
The collection of DSMSensors to be handled.
Referenced by add(), addSensor(), getAllSensors(), and ~SensorHandler().
|
private |
epoll file descriptor.
Referenced by getEpollFd(), run(), and ~SensorHandler().
|
private |
Referenced by handlePollingChange(), run(), and ~SensorHandler().
|
private |
For each sensor, number of times that the input buffer was filled in a read, i.e.
the read did not consume all the data available.
Referenced by incrementFullBufferReads().
|
private |
Referenced by handlePollingChange(), and run().
|
private |
Newly opened DSMSensors, which are to be added to the list of file descriptors to be polled.
Referenced by handlePollingChange(), run(), and sensorIsOpen().
|
private |
Newly opened RemoteSerialConnections, which are to be added to the list of file descriptors to be polled.
Referenced by handlePollingChange(), and scheduleAdd().
|
private |
Referenced by handlePollingChange(), interrupt(), run(), scheduleAdd(), scheduleClose(), scheduleReopen(), sensorIsOpen(), and ~SensorHandler().
|
private |
Collection of DSMSensors which have been opened.
Referenced by add(), getOpenedSensors(), and remove().
|
private |
Referenced by addSensor(), handlePollingChange(), join(), and run().
|
private |
RemoteSerialConnections to be closed, probably because the socket connection closed.
Referenced by handlePollingChange(), run(), and scheduleClose().
|
private |
Sensors to be closed, probably due to a read error or a timeout.
Defined as a set to avoid bugs where a sensor might be added twice.
Referenced by handlePollingChange(), run(), and scheduleClose().
|
private |
Sensors to be closed and then reopened.
Also probably due to a read error or a timeout.
Referenced by handlePollingChange(), and scheduleReopen().
|
private |
Those DSMSensors currently being polled.
Referenced by add(), checkTimeouts(), handlePollingChange(), remove(), run(), setupTimeouts(), and ~SensorHandler().
|
private |
A change in the polling file descriptors needs to be handled.
Referenced by handlePollingChange(), run(), scheduleAdd(), scheduleClose(), scheduleReopen(), sensorIsOpen(), and updateTimeouts().
|
mutableprivate |
Referenced by add(), addSensor(), getAllSensors(), getOpenedSensors(), handlePollingChange(), remove(), run(), scheduleAdd(), scheduleClose(), scheduleReopen(), and sensorIsOpen().
|
private |
Referenced by run().
|
private |
Referenced by handlePollingChange(), run(), and ~SensorHandler().
|
private |
Interval for checking for timeouts on each sensor, in milliseconds.
Will be -1 if no sensors have a timeout.
Referenced by handlePollingChange(), and run().
|
private |
Same as _sensorCheckIntervalMsecs, but in microseconds.
Referenced by checkTimeouts(), and handlePollingChange().
|
private |
Referenced by checkTimeouts(), handlePollingChange(), and run().
|
private |
Interval for calculcating through-put statistics on each sensor, in microseconds.
Referenced by calcStatistics(), getSensorStatsInterval(), SensorHandler(), and setSensorStatsInterval().
|
private |
Referenced by calcStatistics(), run(), and SensorHandler().