9#include <zypp-core/zyppng/base/UnixSignalSource>
66 (
void)
new (&src->
pollfds) std::vector<GUnixPollFD>();
81 src->
pollfds.std::vector< GUnixPollFD >::~vector();
104 if (
fdIt->tag ==
nullptr ) {
147 if ( pollfd.tag !=
nullptr ) {
150 if ( (
pendEvents & pollfd.reqEvents ) != 0 ) {
206 if (
source->_t ==
nullptr )
235 if(
dPtr->runIdleTasks() ) {
240 dPtr->_idleSource =
nullptr;
252 , source( other.source )
253 , callback( std::move( other.callback ) )
255 other.source =
nullptr;
269 source = other.source;
270 callback = std::move( other.callback );
271 other.source =
nullptr;
294 GLibTimerSource::destruct( src );
297 GAbstractEventSource::destruct( src );
351 auto data = std::move(
that->_waitPIDs.at(pid) );
352 that->_waitPIDs.erase( pid );
355 data.callback( pid, status );
361 }
catch (
const std::out_of_range &
e ) {
380 if (
notifier.eventDispatcher().lock().get() !=
this )
397 evSrc = (*itToEvSrc);
401 return currPollFd.pollfd == fd;
404 if (
it !=
evSrc->pollfds.end() ) {
406 it->reqEvents =
static_cast<GIOCondition
>(
cond );
409 evSrc->pollfds.push_back(
411 static_cast<GIOCondition
>(
cond),
425 if (
notifier.eventDispatcher().lock().get() !=
this )
428 auto &
evList =
d->_eventSources;
429 auto it = std::find_if(
evList.begin(),
evList.end(), [
ptr ](
const auto elem ){ return elem->eventSource == ptr; } );
434 auto &
fdList = (*it)->pollfds;
447 auto fdIt = std::find_if(
fdList.begin(),
fdList.end(), [
fd ](
const auto &
pFd ){ return pFd.pollfd == fd; } );
469 d->_runningTimers.push_back(
newSrc );
477 auto it = std::find_if(
d->_runningTimers.begin(),
d->_runningTimers.end(), [ &
timer ](
const GLibTimerSource *src ){
478 return src->_t == &timer;
481 if (
it !=
d->_runningTimers.end() ) {
483 d->_runningTimers.erase(
it );
514 if ( timeout < 0 ) timeout = 0;
518 ERR <<
"g_poll error: " << strerror(
errno) << std::endl;
535 data.
callback = std::move(callback);
539 d->_waitPIDs.insert( std::make_pair( pid, std::move(data) ) );
546 d->_waitPIDs.erase( pid );
547 }
catch (
const std::out_of_range &
e ) {
558 if (
d->_signalSource.expired ()) {
561 r =
d->_signalSource.lock ();
574 d->_idleFuncs.push( std::move(callback) );
575 d->enableIdleSource();
581 d->_unrefLater.push_back( std::move(
ptr) );
582 d->enableIdleSource();
587 d_func()->_unrefLater.clear();
592 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)
auto eintrSafeCall(Fun &&function, Args &&... args)
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 ZYPP_API ThreadData & current()
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
#define ZYPP_IMPL_PRIVATE(Class)