8#include <zypp-core/zyppng/base/UnixSignalSource>
65 (
void)
new (&src->
pollfds) std::vector<GUnixPollFD>();
80 src->
pollfds.std::vector< GUnixPollFD >::~vector();
103 if (
fdIt->tag ==
nullptr ) {
146 if ( pollfd.tag !=
nullptr ) {
149 if ( (
pendEvents & pollfd.reqEvents ) != 0 ) {
205 if (
source->_t ==
nullptr )
234 if(
dPtr->runIdleTasks() ) {
239 dPtr->_idleSource =
nullptr;
251 , source( other.source )
252 , callback( std::move( other.callback ) )
254 other.source =
nullptr;
268 source = other.source;
269 callback = std::move( other.callback );
270 other.source =
nullptr;
293 GLibTimerSource::destruct( src );
296 GAbstractEventSource::destruct( src );
350 auto data = std::move(
that->_waitPIDs.at(pid) );
351 that->_waitPIDs.erase( pid );
354 data.callback( pid, status );
360 }
catch (
const std::out_of_range &
e ) {
379 if (
notifier.eventDispatcher().lock().get() !=
this )
396 evSrc = (*itToEvSrc);
400 return currPollFd.pollfd == fd;
403 if (
it !=
evSrc->pollfds.end() ) {
405 it->reqEvents =
static_cast<GIOCondition
>(
cond );
408 evSrc->pollfds.push_back(
410 static_cast<GIOCondition
>(
cond),
424 if (
notifier.eventDispatcher().lock().get() !=
this )
427 auto &
evList =
d->_eventSources;
428 auto it = std::find_if(
evList.begin(),
evList.end(), [
ptr ](
const auto elem ){ return elem->eventSource == ptr; } );
433 auto &
fdList = (*it)->pollfds;
446 auto fdIt = std::find_if(
fdList.begin(),
fdList.end(), [
fd ](
const auto &
pFd ){ return pFd.pollfd == fd; } );
468 d->_runningTimers.push_back(
newSrc );
476 auto it = std::find_if(
d->_runningTimers.begin(),
d->_runningTimers.end(), [ &
timer ](
const GLibTimerSource *src ){
477 return src->_t == &timer;
480 if (
it !=
d->_runningTimers.end() ) {
482 d->_runningTimers.erase(
it );
513 if ( timeout < 0 ) timeout = 0;
520 ERR <<
"g_poll error: " << strerror(
errno) << std::endl;
537 data.
callback = std::move(callback);
541 d->_waitPIDs.insert( std::make_pair( pid, std::move(data) ) );
548 d->_waitPIDs.erase( pid );
549 }
catch (
const std::out_of_range &
e ) {
560 if (
d->_signalSource.expired ()) {
563 r =
d->_signalSource.lock ();
576 d->_idleFuncs.push( std::move(callback) );
577 d->enableIdleSource();
583 d->_unrefLater.push_back( std::move(
ptr) );
584 d->enableIdleSource();
589 d_func()->_unrefLater.clear();
594 return d_func()->_runningTimers.size();
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void swap(AutoDispose &rhs) noexcept
Exchange the contents of two AutoDispose objects.
Base class for Exception.
std::shared_ptr< T > shared_this() const
std::unique_ptr< BasePrivate > d_ptr
~EventDispatcherPrivate() override
std::queue< EventDispatcher::IdleFunction > _idleFuncs
std::vector< std::shared_ptr< void > > _unrefLater
static void waitPidCallback(GPid pid, gint status, gpointer user_data)
std::thread::id _myThreadId
std::vector< GAbstractEventSource * > _eventSources
std::vector< GLibTimerSource * > _runningTimers
EventDispatcherPrivate(GMainContext *ctx, EventDispatcher &p)
static std::shared_ptr< EventDispatcher > create()
~EventDispatcher() override
UnixSignalSourceRef unixSignalSource()
virtual void registerTimer(Timer &timer)
void clearUnrefLaterList()
ulong runningTimers() const
void unrefLaterImpl(std::shared_ptr< void > &&ptr)
void * nativeDispatcherHandle() const
Returns the native dispatcher handle if the used implementation supports it.
std::function< bool()> IdleFunction
static bool waitForFdEvent(const int fd, int events, int &revents, int &timeout)
virtual void removeTimer(Timer &timer)
void trackChildProcess(int pid, std::function< void(int, int)> callback)
bool untrackChildProcess(int pid)
virtual void updateEventSource(AbstractEventSource ¬ifier, int fd, int mode)
virtual void removeEventSource(AbstractEventSource ¬ifier, int fd=-1)
static void setThreadDispatcher(const std::shared_ptr< EventDispatcher > &disp)
static std::shared_ptr< EventDispatcher > instance()
void invokeOnIdleImpl(IdleFunction &&callback)
The Timer class provides repetitive and single-shot timers.
static UnixSignalSourceRef create()
static gboolean eventLoopIdleFunc(gpointer user_data)
Called when the event loop is idle, here we run cleanup tasks and call later() callbacks of the user.
static GSourceFuncs glibTimerSourceFuncs
static int gioConditionToEventTypes(const GIOCondition rEvents, const int requestedEvs)
static int evModeToMask(int mode)
static GSourceFuncs abstractEventSourceFuncs
static gboolean check(GSource *source)
std::vector< GUnixPollFD > pollfds
AbstractEventSource * eventSource
static gboolean dispatch(GSource *source, GSourceFunc, gpointer)
static GAbstractEventSource * create(EventDispatcherPrivate *ev)
static void destruct(GAbstractEventSource *src)
static gboolean prepare(GSource *, gint *timeout)
EventDispatcherPrivate * _ev
static void destruct(GLibTimerSource *src)
static gboolean prepare(GSource *src, gint *timeout)
static gboolean check(GSource *source)
static GLibTimerSource * create()
static gboolean dispatch(GSource *source, GSourceFunc, gpointer)
GlibWaitPIDData & operator=(GlibWaitPIDData &&other) noexcept
EventDispatcher::WaitPidCallback callback
GlibWaitPIDData(GPid pid)
static ThreadData & current()
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
#define ZYPP_IMPL_PRIVATE(Class)