Fcitx
Public Member Functions | List of all members
fcitx::EventDispatcher Class Reference

A thread safe class to post event to a certain EventLoop. More...

#include <fcitx-utils/eventdispatcher.h>

Public Member Functions

 EventDispatcher ()
 Construct a new event dispatcher. More...
 
void attach (EventLoop *event)
 Attach EventDispatcher to an EventLoop. More...
 
void detach ()
 Detach event dispatcher from event loop, must be called from the same thread from event loop.
 
void schedule (std::function< void()> functor)
 A thread-safe function to schedule a functor to be call from event loop. More...
 
template<typename T >
void scheduleWithContext (TrackableObjectReference< T > context, std::function< void()> functor)
 A helper function that allows to only invoke certain function if the reference is still valid. More...
 
EventLoopeventLoop () const
 Return the currently attached event loop. More...
 

Detailed Description

A thread safe class to post event to a certain EventLoop.

Definition at line 26 of file eventdispatcher.h.

Constructor & Destructor Documentation

◆ EventDispatcher()

fcitx::EventDispatcher::EventDispatcher ( )

Construct a new event dispatcher.

May throw exception if it fails to create underlying file descriptor.

Definition at line 44 of file eventdispatcher.cpp.

Member Function Documentation

◆ attach()

void fcitx::EventDispatcher::attach ( EventLoop event)

Attach EventDispatcher to an EventLoop.

Must be called in the same thread of EventLoop.

Parameters
eventevent loop to attach to.

Definition at line 49 of file eventdispatcher.cpp.

◆ eventLoop()

EventLoop * fcitx::EventDispatcher::eventLoop ( ) const

Return the currently attached event loop.

Since
5.0.11

Definition at line 79 of file eventdispatcher.cpp.

◆ schedule()

void fcitx::EventDispatcher::schedule ( std::function< void()>  functor)

A thread-safe function to schedule a functor to be call from event loop.

If functor is null, it will simply wake up event loop. Passing null can be useful if you want to implement your own event loop and wake up event loop.

Parameters
functorfunctor to be called.

Definition at line 66 of file eventdispatcher.cpp.

◆ scheduleWithContext()

template<typename T >
void fcitx::EventDispatcher::scheduleWithContext ( TrackableObjectReference< T >  context,
std::function< void()>  functor 
)
inline

A helper function that allows to only invoke certain function if the reference is still valid.

If context object is not valid when calling scheduleWithContext, it won't be scheduled at all.

Parameters
contextthe context object.
functorfunction to be scheduled
Since
5.1.8

Definition at line 73 of file eventdispatcher.h.


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