LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
LogCabin::Event::File::Monitor Class Reference

Registers a File handler to be monitored by the Event::Loop. More...

#include <File.h>

Inheritance diagram for LogCabin::Event::File::Monitor:
LogCabin::Event::Signal::Monitor LogCabin::Event::Timer::Monitor

List of all members.

Public Member Functions

 Monitor (Event::Loop &eventLoop, File &file, uint32_t fileEvents)
 Constructor; begins monitoring events on a file.
virtual ~Monitor ()
 Destructor; disables monitoring the file.
void disableForever ()
 Stop monitoring this file.
void setEvents (uint32_t events)
 Specify the events of interest for the file.

Public Attributes

Event::LoopeventLoop
 Event::Loop that will monitor the file.

Private Member Functions

 Monitor (const Monitor &)
Monitoroperator= (const Monitor &)

Private Attributes

std::mutex mutex
 Protects file from concurrent access/modification.
Filefile
 Pointer to file being monitored, or NULL if disableForever() has been called.

Detailed Description

Registers a File handler to be monitored by the Event::Loop.

Once this is constructed, the Event::Loop will call the File's event handler appropriately.

This object must be destroyed or disableForever() called BEFORE the File object can be destroyed safely.

Details: That Monitor objects have distinct lifetimes from File objects is the key reason why they exist. The registration functionality used to be integrated in File itself, but that posed a problem on destruction. Suppose class MyFile derives from File. ~File() is called after MyFile::handleFileEvent() is no longer safe to call (since MyFile members are already destroyed). So ~File() is too late to block the Event::Loop; it needs to happen before all this. See also https://github.com/logcabin/logcabin/issues/82

Definition at line 56 of file File.h.


Constructor & Destructor Documentation

LogCabin::Event::File::Monitor::Monitor ( Event::Loop eventLoop,
File file,
uint32_t  fileEvents 
)

Constructor; begins monitoring events on a file.

Parameters:
eventLoopEvent::Loop that will monitor the File object.
fileThe file to monitor for events.
fileEventsThe files handler will be invoked when any of the events specified by this parameter occur (OR-ed combination of EPOLL_EVENTS values). If this is 0 then the file handler starts off inactive; it will not trigger until setEvents() has been called (except possibly for errors such as EPOLLHUP; these events are always active).

Definition at line 30 of file File.cc.

Destructor; disables monitoring the file.

See disableForever().

Reimplemented in LogCabin::Event::Signal::Monitor, and LogCabin::Event::Timer::Monitor.

Definition at line 47 of file File.cc.


Member Function Documentation

Stop monitoring this file.

To guarantee that the event loop thread is no longer operating on the File, this method takes an Event::Loop::Lock internally. Once this returns, it is safe to destroy the File object, and it is guaranteed that the event loop thread is no longer operating on the File (unless the caller is running in the context of the File's event handler).

Definition at line 53 of file File.cc.

void LogCabin::Event::File::Monitor::setEvents ( uint32_t  events)

Specify the events of interest for the file.

This method is safe to call concurrently with file events triggering and disableForever. If called outside an event handler and no Event::Loop::Lock is taken, this may have a short delay while active handlers continue to be called.

Parameters:
eventsIndicates the conditions under which this object should be invoked (OR-ed combination of EPOLL_EVENTS values). If this is 0 then the file handler is set to inactive; it will not trigger until setEvents() has been called (except possibly for errors such as EPOLLHUP; these events are always active).

Definition at line 68 of file File.cc.

Monitor& LogCabin::Event::File::Monitor::operator= ( const Monitor ) [private]

Member Data Documentation

Event::Loop that will monitor the file.

Definition at line 107 of file File.h.

Protects file from concurrent access/modification.

Definition at line 113 of file File.h.

Pointer to file being monitored, or NULL if disableForever() has been called.

Definition at line 119 of file File.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines