libcamera  v0.3.2+116-83c5ad0f
Supporting cameras in Linux since 2019
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | List of all members
libcamera::EventNotifier Class Reference

Notify of activity on a file descriptor. More...

Inheritance diagram for libcamera::EventNotifier:
Inheritance graph
[legend]
Collaboration diagram for libcamera::EventNotifier:
Collaboration graph
[legend]

Public Types

enum  Type { Read, Write, Exception }
 

Public Member Functions

 EventNotifier (int fd, Type type, Object *parent=nullptr)
 Construct an event notifier with a file descriptor and event type. More...
 
Type type () const
 Retrieve the type of the event being monitored. More...
 
int fd () const
 Retrieve the file descriptor being monitored. More...
 
bool enabled () const
 Retrieve the notifier state. More...
 
void setEnabled (bool enable)
 Enable or disable the notifier. More...
 
- Public Member Functions inherited from libcamera::Object
 Object (Object *parent=nullptr)
 Construct an Object instance. More...
 
virtual ~Object ()
 Destroy an Object instance. More...
 
void deleteLater ()
 Schedule deletion of the instance in the thread it belongs to. More...
 
void postMessage (std::unique_ptr< Message > msg)
 Post a message to the object's thread. More...
 
template<typename T , typename R , typename... FuncArgs, typename... Args, std::enable_if_t< std::is_base_of< Object, T >::value > * = nullptr>
invokeMethod (R(T::*func)(FuncArgs...), ConnectionType type, Args &&... args)
 Invoke a method asynchronously on an Object instance. More...
 
Threadthread () const
 Retrieve the thread the object is bound to. More...
 
void moveToThread (Thread *thread)
 Move the object and all its children to a different thread. More...
 
Objectparent () const
 Retrieve the object's parent. More...
 

Public Attributes

Signal activated
 Signal emitted when the event occurs. More...
 

Protected Member Functions

void message (Message *msg) override
 Message handler for the object. More...
 
- Protected Member Functions inherited from libcamera::Object
bool assertThreadBound (const char *message)
 Check if the caller complies with thread-bound constraints. More...
 

Detailed Description

Notify of activity on a file descriptor.

The EventNotifier models a file descriptor event source that can be monitored. It is created with the file descriptor to be monitored and the type of event, and is enabled by default. It will emit the activated signal whenever an event of the monitored type occurs on the file descriptor.

Supported type of events are EventNotifier::Read, EventNotifier::Write and EventNotifier::Exception. The type is specified when constructing the notifier, and can be retrieved using the type() function. To listen to multiple event types on the same file descriptor multiple notifiers must be created.

The notifier can be disabled with the setEnabled() function. When the notifier is disabled it ignores events and does not emit the activated signal. The notifier can then be re-enabled with the setEnabled() function.

Creating multiple notifiers of the same type for the same file descriptor is not allowed and results in undefined behaviour.

Notifier events are detected and dispatched from the EventDispatcher::processEvents() function.

Member Enumeration Documentation

◆ Type

Type of file descriptor event to listen for.

Enumerator
Read 

Data is available to be read from the file descriptor

Write 

Data can be written to the file descriptor

Exception 

An exception has occurred on the file descriptor

Constructor & Destructor Documentation

◆ EventNotifier()

libcamera::EventNotifier::EventNotifier ( int  fd,
Type  type,
Object parent = nullptr 
)

Construct an event notifier with a file descriptor and event type.

Parameters
[in]fdThe file descriptor to monitor
[in]typeThe event type to monitor
[in]parentThe parent Object

Member Function Documentation

◆ enabled()

libcamera::EventNotifier::enabled ( ) const
inline

Retrieve the notifier state.

Returns
True if the notifier is enabled, or false otherwise
See also
setEnabled()

◆ fd()

libcamera::EventNotifier::fd ( ) const
inline

Retrieve the file descriptor being monitored.

Returns
The file descriptor

◆ message()

void libcamera::EventNotifier::message ( Message msg)
overrideprotectedvirtual

Message handler for the object.

Parameters
[in]msgThe message

This virtual function receives messages for the object. It is called in the context of the object's thread, and can be overridden to process custom messages. The parent Object::message() function shall be called for any message not handled by the override function.

The message msg is valid only for the duration of the call, no reference to it shall be kept after this function returns.

Reimplemented from libcamera::Object.

◆ setEnabled()

void libcamera::EventNotifier::setEnabled ( bool  enable)

Enable or disable the notifier.

Parameters
[in]enableTrue to enable the notifier, false to disable it

This function enables or disables the notifier. A disabled notifier ignores events and does not emit the activated signal.

Thread Safety:
This function is thread-bound.

◆ type()

libcamera::EventNotifier::type ( ) const
inline

Retrieve the type of the event being monitored.

Returns
The type of the event

Member Data Documentation

◆ activated

libcamera::EventNotifier::activated

Signal emitted when the event occurs.

This signal is emitted when the event type() occurs on the file descriptor monitored by the notifier. The notifier pointer is passed as a parameter.


The documentation for this class was generated from the following files: