QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context) : mainContext(context) { #if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 32 if (qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")) { static QBasicMutex mutex; QMutexLocker locker(&mutex); if (!g_thread_supported()) g_thread_init(NULL); } #endif if (mainContext) { g_main_context_ref(mainContext); } else { QCoreApplication *app = QCoreApplication::instance(); if (app && QThread::currentThread() == app->thread()) { mainContext = g_main_context_default(); g_main_context_ref(mainContext); } else { mainContext = g_main_context_new(); } } #if GLIB_CHECK_VERSION (2, 22, 0) g_main_context_push_thread_default (mainContext); #endif // setup post event source postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs, sizeof(GPostEventSource))); postEventSource->serialNumber.store(1); postEventSource->d = this; g_source_set_can_recurse(&postEventSource->source, true); g_source_attach(&postEventSource->source, mainContext); // setup socketNotifierSource socketNotifierSource = reinterpret_cast<GSocketNotifierSource *>(g_source_new(&socketNotifierSourceFuncs, sizeof(GSocketNotifierSource))); (void) new (&socketNotifierSource->pollfds) QList<GPollFDWithQSocketNotifier *>(); g_source_set_can_recurse(&socketNotifierSource->source, true); g_source_attach(&socketNotifierSource->source, mainContext); // setup normal and idle timer sources timerSource = reinterpret_cast<GTimerSource *>(g_source_new(&timerSourceFuncs, sizeof(GTimerSource))); (void) new (&timerSource->timerList) QTimerInfoList(); timerSource->processEventsFlags = QEventLoop::AllEvents; timerSource->runWithIdlePriority = false; g_source_set_can_recurse(&timerSource->source, true); g_source_attach(&timerSource->source, mainContext); idleTimerSource = reinterpret_cast<GIdleTimerSource *>(g_source_new(&idleTimerSourceFuncs, sizeof(GIdleTimerSource))); idleTimerSource->timerSource = timerSource; g_source_set_can_recurse(&idleTimerSource->source, true); g_source_set_priority(&idleTimerSource->source, G_PRIORITY_DEFAULT_IDLE); g_source_attach(&idleTimerSource->source, mainContext); }
QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context) : mainContext(context) { if (qgetenv("QT_NO_THREADED_GLIB").isEmpty()) { static int dummyValue = 0; // only used for its address QMutexLocker locker(QMutexPool::instance()->get(&dummyValue)); if (!g_thread_supported()) g_thread_init(NULL); } if (mainContext) { g_main_context_ref(mainContext); } else { QCoreApplication *app = QCoreApplication::instance(); if (app && QThread::currentThread() == app->thread()) { mainContext = g_main_context_default(); g_main_context_ref(mainContext); } else { mainContext = g_main_context_new(); } } // setup post event source postEventSource = reinterpret_cast<GPostEventSource *>(g_source_new(&postEventSourceFuncs, sizeof(GPostEventSource))); postEventSource->serialNumber = 1; g_source_set_can_recurse(&postEventSource->source, true); g_source_attach(&postEventSource->source, mainContext); // setup socketNotifierSource socketNotifierSource = reinterpret_cast<GSocketNotifierSource *>(g_source_new(&socketNotifierSourceFuncs, sizeof(GSocketNotifierSource))); (void) new (&socketNotifierSource->pollfds) QList<GPollFDWithQSocketNotifier *>(); g_source_set_can_recurse(&socketNotifierSource->source, true); g_source_attach(&socketNotifierSource->source, mainContext); // setup normal and idle timer sources timerSource = reinterpret_cast<GTimerSource *>(g_source_new(&timerSourceFuncs, sizeof(GTimerSource))); (void) new (&timerSource->timerList) QTimerInfoList(); timerSource->processEventsFlags = QEventLoop::AllEvents; timerSource->runWithIdlePriority = false; g_source_set_can_recurse(&timerSource->source, true); g_source_attach(&timerSource->source, mainContext); idleTimerSource = reinterpret_cast<GIdleTimerSource *>(g_source_new(&idleTimerSourceFuncs, sizeof(GIdleTimerSource))); idleTimerSource->timerSource = timerSource; g_source_set_can_recurse(&idleTimerSource->source, true); g_source_set_priority(&idleTimerSource->source, G_PRIORITY_DEFAULT_IDLE); g_source_attach(&idleTimerSource->source, mainContext); }
WaylandDisplay::WaylandDisplay() { m_display = wl_display_connect(nullptr); m_registry = wl_display_get_registry(m_display); wl_registry_add_listener(m_registry, &g_registryListener, &m_interfaces); wl_display_roundtrip(m_display); m_eventSource = g_source_new(&EventSource::sourceFuncs, sizeof(EventSource)); auto* source = reinterpret_cast<EventSource*>(m_eventSource); source->display = m_display; source->pfd.fd = wl_display_get_fd(m_display); source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; source->pfd.revents = 0; g_source_add_poll(m_eventSource, &source->pfd); g_source_set_name(m_eventSource, "[WPE] WaylandDisplay"); g_source_set_priority(m_eventSource, G_PRIORITY_HIGH + 30); g_source_set_can_recurse(m_eventSource, TRUE); g_source_attach(m_eventSource, g_main_context_get_thread_default()); if (m_interfaces.xdg) { xdg_shell_add_listener(m_interfaces.xdg, &g_xdgShellListener, nullptr); xdg_shell_use_unstable_version(m_interfaces.xdg, 5); } }
WaylandDisplay::WaylandDisplay() { m_display = wl_display_connect(nullptr); m_registry = wl_display_get_registry(m_display); wl_registry_add_listener(m_registry, &g_registryListener, &m_interfaces); wl_display_roundtrip(m_display); m_eventSource = g_source_new(&EventSource::sourceFuncs, sizeof(EventSource)); auto* source = reinterpret_cast<EventSource*>(m_eventSource); source->display = m_display; source->pfd.fd = wl_display_get_fd(m_display); source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; source->pfd.revents = 0; g_source_add_poll(m_eventSource, &source->pfd); g_source_set_name(m_eventSource, "[WPE] WaylandDisplay"); g_source_set_priority(m_eventSource, G_PRIORITY_HIGH + 30); g_source_set_can_recurse(m_eventSource, TRUE); g_source_attach(m_eventSource, g_main_context_get_thread_default()); if (m_interfaces.xdg) { xdg_shell_add_listener(m_interfaces.xdg, &g_xdgShellListener, nullptr); xdg_shell_use_unstable_version(m_interfaces.xdg, 5); } wl_seat_add_listener(m_interfaces.seat, &g_seatListener, &m_seatData); m_seatData.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); m_seatData.xkb.composeTable = xkb_compose_table_new_from_locale(m_seatData.xkb.context, setlocale(LC_CTYPE, nullptr), XKB_COMPOSE_COMPILE_NO_FLAGS); if (m_seatData.xkb.composeTable) m_seatData.xkb.composeState = xkb_compose_state_new(m_seatData.xkb.composeTable, XKB_COMPOSE_STATE_NO_FLAGS); }
void _clutter_backend_x11_events_init (ClutterBackend *backend) { ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend); GSource *source; ClutterEventSource *event_source; int connection_number; gchar *name; connection_number = ConnectionNumber (backend_x11->xdpy); CLUTTER_NOTE (EVENT, "Connection number: %d", connection_number); source = backend_x11->event_source = clutter_event_source_new (backend); event_source = (ClutterEventSource *) source; g_source_set_priority (source, CLUTTER_PRIORITY_EVENTS); name = g_strdup_printf ("Clutter X11 Event (connection: %d)", connection_number); g_source_set_name (source, name); g_free (name); event_source->event_poll_fd.fd = connection_number; event_source->event_poll_fd.events = G_IO_IN; event_sources = g_list_prepend (event_sources, event_source); g_source_add_poll (source, &event_source->event_poll_fd); g_source_set_can_recurse (source, TRUE); g_source_attach (source, NULL); }
GSource * _clutter_x11_event_source_new (ClutterBackendX11 *backend_x11) { ClutterEventSource *event_source; int connection_number; GSource *source; gchar *name; connection_number = ConnectionNumber (backend_x11->xdpy); CLUTTER_NOTE (EVENT, "Connection number: %d", connection_number); source = g_source_new (&event_funcs, sizeof (ClutterEventSource)); event_source = (ClutterEventSource *) source; name = g_strdup_printf ("Clutter X11 Event (connection: %d)", connection_number); g_source_set_name (source, name); g_free (name); event_source->backend = backend_x11; event_source->event_poll_fd.fd = connection_number; event_source->event_poll_fd.events = G_IO_IN; g_source_add_poll (source, &event_source->event_poll_fd); g_source_set_can_recurse (source, TRUE); return source; }
LOCAL_SYMBOL MetaEventQueue* meta_event_queue_new (Display *display, MetaEventQueueFunc func, gpointer data) { GSource *source; MetaEventQueue *eq; source = g_source_new (&eq_funcs, sizeof (MetaEventQueue)); eq = (MetaEventQueue*) source; eq->connection_fd = ConnectionNumber (display); eq->poll_fd.fd = eq->connection_fd; eq->poll_fd.events = G_IO_IN; eq->events = g_queue_new (); eq->display = display; g_source_set_priority (source, G_PRIORITY_DEFAULT); g_source_add_poll (source, &eq->poll_fd); g_source_set_can_recurse (source, TRUE); g_source_set_callback (source, (GSourceFunc) func, data, NULL); g_source_attach (source, NULL); g_source_unref (source); return eq; }
guint sock_add_watch(SockInfo *sock, GIOCondition condition, SockFunc func, gpointer data) { if (!sock) return FALSE; sock->callback = func; sock->condition = condition; sock->data = data; #ifdef USE_GNUTLS if (sock->ssl) { GSource *source = g_source_new(&ssl_watch_funcs, sizeof(SockSource)); ((SockSource *) source)->sock = sock; g_source_set_priority(source, G_PRIORITY_DEFAULT); g_source_set_can_recurse(source, FALSE); sock->g_source = g_source_attach(source, NULL); g_source_unref (source); /* Refcount back down to 1 */ return sock->g_source; } #endif return g_io_add_watch(sock->sock_ch, condition, sock_watch_cb, sock); }
GSource * gdk_x11_event_source_new (GdkDisplay *display) { GSource *source; GdkEventSource *event_source; GdkX11Display *display_x11; int connection_number; char *name; source = g_source_new (&event_funcs, sizeof (GdkEventSource)); name = g_strdup_printf ("GDK X11 Event source (%s)", gdk_display_get_name (display)); g_source_set_name (source, name); g_free (name); event_source = (GdkEventSource *) source; event_source->display = display; display_x11 = GDK_X11_DISPLAY (display); connection_number = ConnectionNumber (display_x11->xdisplay); event_source->event_poll_fd.fd = connection_number; event_source->event_poll_fd.events = G_IO_IN; g_source_add_poll (source, &event_source->event_poll_fd); g_source_set_priority (source, GDK_PRIORITY_EVENTS); g_source_set_can_recurse (source, TRUE); g_source_attach (source, NULL); event_sources = g_list_prepend (event_sources, source); return source; }
gboolean xevent_init() { X11Source* xsource; int fd; dpy = XOpenDisplay( g_getenv("DISPLAY") ); if( ! dpy ) return FALSE; /* according to the spec, private Atoms should prefix their names with _. */ CMD_ATOM = XInternAtom( dpy, "_LXSESSION", False ); fd = ConnectionNumber(dpy); /* fd of XDisplay connection */ if( G_UNLIKELY(fd == -1) ) return FALSE; /* set up main loop event source for XDisplay */ source = g_source_new (&event_funcs, sizeof(X11Source)); xsource = (X11Source*)source; xsource->poll_fd.fd = fd; xsource->poll_fd.events = G_IO_IN; g_source_add_poll(source, &xsource->poll_fd); g_source_set_can_recurse(source, TRUE); g_source_attach(source, NULL); return TRUE; }
std::unique_ptr<PlatformDisplayWayland> PlatformDisplayWayland::create() { struct wl_display* wlDisplay = wl_display_connect(nullptr); if (!wlDisplay) { WTFLogAlways("PlatformDisplayWayland initialization: failed to connect to the Wayland server socket. Check your WAYLAND_DISPLAY or WAYLAND_SOCKET environment variables."); return nullptr; } std::unique_ptr<PlatformDisplayWayland> display(new PlatformDisplayWayland(wlDisplay)); if (!display->isInitialized()) { WTFLogAlways("PlatformDisplayWayland initialization: failed to complete the initialization of the display."); return nullptr; } GSource* baseSource = g_source_new(&EventSource::sourceFuncs, sizeof(EventSource)); auto* source = reinterpret_cast<EventSource*>(baseSource); source->display = display->m_display; source->pfd.fd = wl_display_get_fd(display->m_display); source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; source->pfd.revents = 0; g_source_add_poll(baseSource, &source->pfd); g_source_set_name(baseSource, "[WebKit] WaylandDisplay"); g_source_set_priority(baseSource, G_PRIORITY_HIGH + 30); g_source_set_can_recurse(baseSource, TRUE); g_source_attach(baseSource, g_main_context_get_thread_default()); return display; }
pa_glib_mainloop *pa_glib_mainloop_new(GMainContext *c) { pa_glib_mainloop *g; static GSourceFuncs source_funcs = { prepare_func, check_func, dispatch_func, NULL, NULL, NULL }; g = (pa_glib_mainloop*) g_source_new(&source_funcs, sizeof(pa_glib_mainloop)); g_main_context_ref(g->context = c ? c : g_main_context_default()); g->api = vtable; g->api.userdata = g; PA_LLIST_HEAD_INIT(pa_io_event, g->io_events); PA_LLIST_HEAD_INIT(pa_time_event, g->time_events); PA_LLIST_HEAD_INIT(pa_defer_event, g->defer_events); g->n_enabled_defer_events = g->n_enabled_time_events = 0; g->io_events_please_scan = g->time_events_please_scan = g->defer_events_please_scan = 0; g->cached_next_time_event = NULL; g_source_attach(&g->source, g->context); g_source_set_can_recurse(&g->source, FALSE); return g; }
static crm_trigger_t * mainloop_setup_trigger(GSource * source, int priority, int (*dispatch) (gpointer user_data), gpointer userdata) { crm_trigger_t *trigger = NULL; trigger = (crm_trigger_t *) source; trigger->id = 0; trigger->trigger = FALSE; trigger->user_data = userdata; if (dispatch) { g_source_set_callback(source, dispatch, trigger, NULL); } g_source_set_priority(source, priority); g_source_set_can_recurse(source, FALSE); crm_trace("Setup %p with ref-count=%u", source, g_source_refcount(source)); trigger->id = g_source_attach(source, NULL); crm_trace("Attached %p with ref-count=%u", source, g_source_refcount(source)); return trigger; }
ViewBackend::ViewBackend(struct wpe_view_backend* backend) : backend(backend) { ipcHost.initialize(*this); bcm_host_init(); displayHandle = vc_dispmanx_display_open(0); graphics_get_display_size(DISPMANX_ID_HDMI, &width, &height); updateFd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (updateFd == -1) { fprintf(stderr, "ViewBackend: failed to create the update eventfd\n"); return; } updateSource = g_source_new(&UpdateSource::sourceFuncs, sizeof(UpdateSource)); auto& source = *reinterpret_cast<UpdateSource*>(updateSource); source.backend = this; source.pfd.fd = updateFd; source.pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; source.pfd.revents = 0; g_source_add_poll(updateSource, &source.pfd); g_source_set_name(updateSource, "[WPE] BCMRPi update"); g_source_set_priority(updateSource, G_PRIORITY_HIGH + 30); g_source_set_can_recurse(updateSource, TRUE); g_source_attach(updateSource, g_main_context_get_thread_default()); }
GSource * _gdk_wayland_display_event_source_new (GdkDisplay *display) { GSource *source; GdkWaylandEventSource *wl_source; GdkWaylandDisplay *display_wayland; char *name; source = g_source_new (&wl_glib_source_funcs, sizeof (GdkWaylandEventSource)); name = g_strdup_printf ("GDK Wayland Event source (%s)", "display name"); g_source_set_name (source, name); g_free (name); wl_source = (GdkWaylandEventSource *) source; display_wayland = GDK_WAYLAND_DISPLAY (display); wl_source->display = display; wl_source->pfd.fd = wl_display_get_fd(display_wayland->wl_display); wl_source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; g_source_add_poll(source, &wl_source->pfd); g_source_set_priority (source, GDK_PRIORITY_EVENTS); g_source_set_can_recurse (source, TRUE); g_source_attach (source, NULL); event_sources = g_list_prepend (event_sources, source); return source; }
nsresult nsAppShell::Init() { #ifdef PR_LOGGING if (!gWidgetLog) gWidgetLog = PR_NewLogModule("Widget"); if (!gWidgetFocusLog) gWidgetFocusLog = PR_NewLogModule("WidgetFocus"); if (!gWidgetDragLog) gWidgetDragLog = PR_NewLogModule("WidgetDrag"); if (!gWidgetDrawLog) gWidgetDrawLog = PR_NewLogModule("WidgetDraw"); #endif if (!sPollFunc) { sPollFunc = g_main_context_get_poll_func(NULL); g_main_context_set_poll_func(NULL, &PollWrapper); } if (PR_GetEnv("MOZ_DEBUG_PAINTS")) gdk_window_set_debug_updates(TRUE); int err = pipe(mPipeFDs); if (err) return NS_ERROR_OUT_OF_MEMORY; GIOChannel *ioc; GSource *source; // make the pipe nonblocking int flags = fcntl(mPipeFDs[0], F_GETFL, 0); if (flags == -1) goto failed; err = fcntl(mPipeFDs[0], F_SETFL, flags | O_NONBLOCK); if (err == -1) goto failed; flags = fcntl(mPipeFDs[1], F_GETFL, 0); if (flags == -1) goto failed; err = fcntl(mPipeFDs[1], F_SETFL, flags | O_NONBLOCK); if (err == -1) goto failed; ioc = g_io_channel_unix_new(mPipeFDs[0]); source = g_io_create_watch(ioc, G_IO_IN); g_io_channel_unref(ioc); g_source_set_callback(source, (GSourceFunc)EventProcessorCallback, this, nullptr); g_source_set_can_recurse(source, TRUE); mTag = g_source_attach(source, nullptr); g_source_unref(source); return nsBaseAppShell::Init(); failed: close(mPipeFDs[0]); close(mPipeFDs[1]); mPipeFDs[0] = mPipeFDs[1] = 0; return NS_ERROR_FAILURE; }
void mdm_wm_init (Window login_window) { XWindowAttributes attribs = { 0, }; GSource *source; gchar *display; wm_login_window = login_window; if (wm_disp != NULL) { return; } display = gdk_get_display (); wm_disp = XOpenDisplay (display); g_free (display); if (wm_disp == NULL) { /* EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEK! */ wm_disp = GDK_DISPLAY (); return; } trap_push (); XA_WM_PROTOCOLS = XInternAtom (wm_disp, "WM_PROTOCOLS", False); XA_WM_STATE = XInternAtom (wm_disp, "WM_STATE", False); XA_WM_TAKE_FOCUS = XInternAtom (wm_disp, "WM_TAKE_FOCUS", False); XA_COMPOUND_TEXT = XInternAtom (wm_disp, "COMPOUND_TEXT", False); XA_NET_WM_STRUT = XInternAtom (wm_disp, "_NET_WM_STRUT", False); wm_root = DefaultRootWindow (wm_disp); /* set event mask for events on root window */ XGetWindowAttributes (wm_disp, wm_root, &attribs); XSelectInput (wm_disp, wm_root, attribs.your_event_mask | SubstructureNotifyMask | SubstructureRedirectMask); if (trap_pop () != 0) return; trap_push (); add_all_current_windows (); source = g_source_new (&event_funcs, sizeof (GSource)); event_poll_fd.fd = ConnectionNumber (wm_disp); event_poll_fd.events = G_IO_IN; g_source_add_poll (source, &event_poll_fd); g_source_set_priority (source, GDK_PRIORITY_EVENTS); g_source_set_can_recurse (source, FALSE); g_source_attach (source, NULL); trap_pop (); }
void xt_client_xloop_create(void) { /* If this is the first running widget, hook this display into the mainloop */ if (0 == num_widgets) { int cnumber; GSource* gs; /* Set up xtdisplay in case we're missing one */ if (!xtdisplay) { (void)xt_client_get_display(); } /* * hook Xt event loop into the glib event loop. */ /* the assumption is that gtk_init has already been called */ gs = g_source_new(&xt_event_funcs, sizeof(GSource)); if (!gs) { return; } g_source_set_priority(gs, GDK_PRIORITY_EVENTS); g_source_set_can_recurse(gs, TRUE); tag = g_source_attach(gs, (GMainContext*)NULL); g_source_unref(gs); #ifdef VMS cnumber = XConnectionNumber(xtdisplay); #else cnumber = ConnectionNumber(xtdisplay); #endif xt_event_poll_fd.fd = cnumber; xt_event_poll_fd.events = G_IO_IN; xt_event_poll_fd.revents = 0; /* hmm... is this correct? */ g_main_context_add_poll ((GMainContext*)NULL, &xt_event_poll_fd, G_PRIORITY_LOW); /* add a timer so that we can poll and process Xt timers */ xt_polling_timer_id = g_timeout_add(25, (GtkFunction)xt_event_polling_timer_callback, xtdisplay); } /* Bump up our usage count */ num_widgets++; }
void gdk_android_events_init() { static GSourceFuncs event_funcs = { gdk_android_event_prepare, gdk_android_event_check, gdk_android_event_dispatch, NULL }; GSource *source = g_source_new(&event_funcs, sizeof(GSource)); g_source_set_name(source, "Android ALooper event source"); g_source_set_priority(source, GDK_PRIORITY_EVENTS); g_source_set_can_recurse(source, TRUE); g_source_attach(source, NULL); }
static void clutter_master_clock_init (ClutterMasterClock *self) { GSource *source; source = clutter_clock_source_new (self); self->source = source; self->idle = FALSE; self->ensure_next_iteration = FALSE; g_source_set_priority (source, CLUTTER_PRIORITY_REDRAW); g_source_set_can_recurse (source, FALSE); g_source_attach (source, NULL); }
void xdk_display_add_watch(XdkDisplay * self) { g_return_if_fail(self && self->priv->peer); XdkDisplayPrivate * priv = self->priv; if(priv->event_watch_id) { return; } GSource * source = xdk_display_watch_source_new(self); g_source_set_name(source, "XdkDisplayEventSource"); g_source_set_can_recurse(source, TRUE); priv->event_watch_id = g_source_attach(source, NULL); g_source_unref(source); }
/* * Add an Trigger to the gmainloop world... */ GTRIGSource* G_main_add_TriggerHandler(int priority, gboolean (*dispatch)(gpointer user_data), gpointer userdata, GDestroyNotify notify) { GTRIGSource* trig_src = NULL; GSource * source = g_source_new(&G_TRIG_SourceFuncs, sizeof(GTRIGSource)); gboolean failed = FALSE; trig_src = (GTRIGSource*)source; trig_src->magno = MAG_GTRIGSOURCE; trig_src->maxdispatchdelayms = DEFAULT_MAXDELAY; trig_src->maxdispatchms = DEFAULT_MAXDISPATCH; trig_src->dispatch = dispatch; trig_src->udata = userdata; trig_src->dnotify = notify; lc_store((trig_src->detecttime), zero_longclock); trig_src->manual_trigger = FALSE; g_source_set_priority(source, priority); g_source_set_can_recurse(source, FALSE); if(!failed) { trig_src->gsourceid = g_source_attach(source, NULL); trig_src->description = "trigger"; if (trig_src->gsourceid < 1) { cl_log(LOG_ERR, "G_main_add_TriggerHandler: Could not attach new source (%d)", trig_src->gsourceid); failed = TRUE; } } if(failed) { cl_log(LOG_ERR, "G_main_add_TriggerHandler: Trigger handler NOT added"); g_source_remove(trig_src->gsourceid); g_source_unref(source); source = NULL; trig_src = NULL; } else { if (debug_level > 1) { cl_log(LOG_DEBUG, "G_main_add_TriggerHandler: Added signal manual handler"); } } return trig_src; }
guint sock_add_watch_poll(SockInfo *sock, GIOCondition condition, SockFunc func, gpointer data) { GSource *source; sock->callback = func; sock->condition = condition; sock->data = data; source = g_source_new(&sock_watch_funcs, sizeof(SockSource)); ((SockSource *)source)->sock = sock; g_source_set_priority(source, G_PRIORITY_DEFAULT); g_source_set_can_recurse(source, FALSE); return g_source_attach(source, NULL); }
PIpcAsyncCallerBase::PIpcAsyncCallerBase(GMainLoop* loop) { int retval = ::pipe(m_pipeFd); if (retval) {} // setup an iochannel on the read end of the pipe m_ioChannel = g_io_channel_unix_new(m_pipeFd[0]); m_ioSource = g_io_create_watch(m_ioChannel, (GIOCondition) G_IO_IN); g_source_set_callback(m_ioSource, (GSourceFunc) callback, this, NULL); g_source_set_can_recurse(m_ioSource, true); GMainContext* ctxt = g_main_loop_get_context(loop); g_source_attach(m_ioSource, ctxt); pthread_mutex_init(&m_mutex, NULL); }
/* * Add an IPC_WaitConnection to the gmainloop world... */ GWCSource* G_main_add_IPC_WaitConnection(int priority , IPC_WaitConnection* wch , IPC_Auth* auth_info , gboolean can_recurse , gboolean (*dispatch)(IPC_Channel* wch , gpointer user_data) , gpointer userdata , GDestroyNotify notify) { GWCSource* wcp; GSource * source = g_source_new(&G_WC_SourceFuncs, sizeof(GWCSource)); wcp = (GWCSource*)source; wcp->magno = MAG_GWCSOURCE; wcp->maxdispatchdelayms = DEFAULT_MAXDELAY; wcp->maxdispatchms = DEFAULT_MAXDISPATCH; lc_store((wcp->detecttime), zero_longclock); wcp->udata = userdata; wcp->gpfd.fd = wch->ops->get_select_fd(wch); wcp->gpfd.events = DEF_EVENTS; wcp->gpfd.revents = 0; wcp->wch = wch; wcp->dnotify = notify; wcp->auth_info = auth_info; wcp->dispatch = dispatch; g_source_add_poll(source, &wcp->gpfd); g_source_set_priority(source, priority); g_source_set_can_recurse(source, can_recurse); wcp->gsourceid = g_source_attach(source, NULL); wcp->description = "IPC wait for connection"; if (wcp->gsourceid == 0) { g_source_remove_poll(source, &wcp->gpfd); g_source_unref(source); source = NULL; wcp = NULL; } return wcp; }
void CreateWatchWithCallback(PmSockIOChannel * const pOnChannel, GIOCondition ioCondition, PmSockWatch **pWatchToCreate, GSourceFunc CallbackForWatch, gpointer dataPassedToCallback, const char * myName) { GMainContext *pGMainContext = PmSockThreadCtxPeekGMainContext(PmSockPeekThreadContext(pOnChannel)); //this should be the same as gMainContext_ assert(pGMainContext); assert(*pWatchToCreate==NULL); PslError pslError = PmSockCreateWatch(pOnChannel, ioCondition, pWatchToCreate); UTIL_ASSERT_THROW_FATAL(!pslError, myName, Err("PmSockCreateWatch failed:", pslError).c_str() ); g_source_set_can_recurse((GSource *)*pWatchToCreate, false); g_source_set_callback((GSource *)*pWatchToCreate, CallbackForWatch, dataPassedToCallback, /*notify*/NULL); g_source_attach((GSource *)*pWatchToCreate, pGMainContext); PRINT_LINE("%s watch for ioCondition==%s created", myName, IOConditionToString(ioCondition)); }
static CoglGstSource * cogl_gst_source_new (CoglGstVideoSink *sink) { GSource *source; CoglGstSource *gst_source; source = g_source_new (&gst_source_funcs, sizeof (CoglGstSource)); gst_source = (CoglGstSource *) source; g_source_set_can_recurse (source, TRUE); g_source_set_priority (source, COGL_GST_DEFAULT_PRIORITY); gst_source->sink = sink; g_mutex_init (&gst_source->buffer_lock); gst_source->buffer = NULL; return gst_source; }
void _clutter_backend_win32_events_init (ClutterBackend *backend) { ClutterBackendWin32 *backend_win32 = CLUTTER_BACKEND_WIN32 (backend); GSource *source; ClutterEventSource *event_source; source = backend_win32->event_source = clutter_event_source_new (backend); event_source = (ClutterEventSource *) source; g_source_set_priority (source, CLUTTER_PRIORITY_EVENTS); event_source->event_poll_fd.fd = G_WIN32_MSG_HANDLE; event_source->event_poll_fd.events = G_IO_IN; g_source_add_poll (source, &event_source->event_poll_fd); g_source_set_can_recurse (source, TRUE); g_source_attach (source, NULL); }
static gboolean on_new_connection (GSocketService *service, GSocketConnection *socket_connection, GObject *source_object, DasomServer *server) { g_debug (G_STRLOC ": %s", G_STRFUNC); /* TODO: simple authentication using GCredentials */ GSocket *socket = g_socket_connection_get_socket (socket_connection); DasomMessage *message; message = dasom_recv_message (socket); if (message->header->type == DASOM_MESSAGE_CONNECT) dasom_send_message (socket, DASOM_MESSAGE_CONNECT_REPLY, NULL, 0, NULL); else { /* TODO: error handling */ dasom_send_message (socket, DASOM_MESSAGE_ERROR, NULL, 0, NULL); return TRUE; /* TODO: what happened if return value is FALSE */ } DasomConnection *connection; connection = dasom_connection_new (*(DasomConnectionType *) message->data, dasom_server_get_default_engine (server), NULL); dasom_message_unref (message); connection->socket = socket; dasom_server_add_connection (server, connection); if (connection->type == DASOM_CONNECTION_DASOM_AGENT) server->agents_list = g_list_prepend (server->agents_list, connection); connection->source = g_socket_create_source (socket, G_IO_IN, NULL); connection->socket_connection = g_object_ref (socket_connection); g_source_set_can_recurse (connection->source, TRUE); g_source_set_callback (connection->source, (GSourceFunc) on_incoming_message_dasom, connection, NULL); g_source_attach (connection->source, server->main_context); return TRUE; }
GSource* G_main_add_input(int priority, gboolean can_recurse, GSourceFuncs* funcs) { GSource * input_source = g_source_new(funcs, sizeof(GSource)); if (input_source == NULL){ cl_log(LOG_ERR, "create glib source for input failed!"); }else { g_source_set_priority(input_source, priority); g_source_set_can_recurse(input_source, can_recurse); if(g_source_attach(input_source, NULL) == 0){ cl_log(LOG_ERR, "attaching input_source to main context" " failed!! "); } } return input_source; }