AvahiGLibPoll *avahi_glib_poll_new(GMainContext *context, gint priority) { AvahiGLibPoll *g; static GSourceFuncs source_funcs = { prepare_func, check_func, dispatch_func, NULL, NULL, NULL }; g = (AvahiGLibPoll*) g_source_new(&source_funcs, sizeof(AvahiGLibPoll)); g_main_context_ref(g->context = context ? context : g_main_context_default()); g->api.userdata = g; g->api.watch_new = watch_new; g->api.watch_free = watch_free; g->api.watch_update = watch_update; g->api.watch_get_events = watch_get_events; g->api.timeout_new = timeout_new; g->api.timeout_free = timeout_free; g->api.timeout_update = timeout_update; g->watch_req_cleanup = FALSE; g->timeout_req_cleanup = FALSE; AVAHI_LLIST_HEAD_INIT(AvahiWatch, g->watches); AVAHI_LLIST_HEAD_INIT(AvahiTimeout, g->timeouts); g_source_attach(&g->source, g->context); g_source_set_priority(&g->source, priority); g_source_set_can_recurse(&g->source, FALSE); return g; }
static void connection_setup_add_watch (ConnectionSetup *cs, DBusWatch *watch) { guint flags; GIOCondition condition; GIOChannel *channel; IOHandler *handler; if (!dbus_watch_get_enabled (watch)) return; g_assert (dbus_watch_get_data (watch) == NULL); flags = dbus_watch_get_flags (watch); condition = G_IO_ERR | G_IO_HUP; if (flags & DBUS_WATCH_READABLE) condition |= G_IO_IN; if (flags & DBUS_WATCH_WRITABLE) condition |= G_IO_OUT; handler = g_slice_new (IOHandler); handler->cs = cs; handler->watch = watch; channel = g_io_channel_unix_new (dbus_watch_get_unix_fd (watch)); handler->source = g_io_create_watch (channel, condition); g_source_set_callback (handler->source, (GSourceFunc) io_handler_dispatch, handler, io_handler_source_finalized); g_source_attach (handler->source, cs->context); cs->ios = g_slist_prepend (cs->ios, handler); dbus_watch_set_data (watch, handler, io_handler_watch_freed); g_io_channel_unref (channel); }
static void update_rate_limiter_timeout (GFileMonitor *monitor, guint new_time) { ForEachData data; GSource *source; if (monitor->priv->timeout_fires_at != 0 && new_time != 0 && time_difference (new_time, monitor->priv->timeout_fires_at) == 0) return; /* Nothing to do, we already fire earlier than that */ data.min_time = G_MAXUINT32; data.monitor = monitor; data.time_now = get_time_msecs (); g_hash_table_foreach_remove (monitor->priv->rate_limiter, foreach_rate_limiter_update, &data); /* Remove old timeout */ if (monitor->priv->timeout) { g_source_destroy (monitor->priv->timeout); g_source_unref (monitor->priv->timeout); monitor->priv->timeout_fires_at = 0; monitor->priv->timeout = NULL; } /* Set up new timeout */ if (data.min_time != G_MAXUINT32) { source = g_timeout_source_new (data.min_time + 1); /* + 1 to make sure we've really passed the time */ g_source_set_callback (source, rate_limiter_timeout, monitor, NULL); g_source_attach (source, monitor->priv->context); monitor->priv->timeout = source; monitor->priv->timeout_fires_at = data.time_now + data.min_time; } }
static void create_child (void) { int pid; GIOChannel *in_channels[2]; GIOChannel *out_channels[2]; GSource *source; io_pipe (in_channels); io_pipe (out_channels); pid = fork (); if (pid > 0) /* Parent */ { g_io_channel_close (in_channels[0]); g_io_channel_close (out_channels[1]); source = g_io_create_watch (out_channels[0], G_IO_IN | G_IO_HUP); g_source_set_closure (source, g_cclosure_new (G_CALLBACK (input_callback), in_channels[1], NULL)); g_source_attach (source, NULL); } else if (pid == 0) /* Child */ { g_io_channel_close (in_channels[1]); g_io_channel_close (out_channels[0]); setsid (); run_child (in_channels[0], out_channels[1]); } else /* Error */ { fprintf (stderr, "Cannot fork: %s\n", g_strerror (errno)); exit (1); } }
/* Run loop for location provider thread. */ static void * run_geoclue2_loop(void *state_) { location_geoclue2_state_t *state = state_; GMainContext *context = g_main_context_new(); g_main_context_push_thread_default(context); state->loop = g_main_loop_new(context, FALSE); guint watcher_id = g_bus_watch_name( G_BUS_TYPE_SYSTEM, "org.freedesktop.GeoClue2", G_BUS_NAME_WATCHER_FLAGS_AUTO_START, on_name_appeared, on_name_vanished, state, NULL); /* Listen for closure of pipe */ GIOChannel *pipe_channel = g_io_channel_unix_new(state->pipe_fd_write); GSource *pipe_source = g_io_create_watch( pipe_channel, G_IO_IN | G_IO_HUP | G_IO_ERR); g_source_set_callback( pipe_source, (GSourceFunc)on_pipe_closed, state, NULL); g_source_attach(pipe_source, context); g_main_loop_run(state->loop); g_source_unref(pipe_source); g_io_channel_unref(pipe_channel); close(state->pipe_fd_write); g_bus_unwatch_name(watcher_id); g_main_loop_unref(state->loop); g_main_context_unref(context); return NULL; }
/** * g_io_scheduler_job_send_to_mainloop: * @job: a #GIOSchedulerJob * @func: a #GSourceFunc callback that will be called in the original thread * @user_data: data to pass to @func * @notify: (allow-none): a #GDestroyNotify for @user_data, or %NULL * * Used from an I/O job to send a callback to be run in the thread * that the job was started from, waiting for the result (and thus * blocking the I/O job). * * Returns: The return value of @func * * Deprecated: Use g_main_context_invoke(). **/ gboolean g_io_scheduler_job_send_to_mainloop (GIOSchedulerJob *job, GSourceFunc func, gpointer user_data, GDestroyNotify notify) { GSource *source; MainLoopProxy *proxy; gboolean ret_val; g_return_val_if_fail (job != NULL, FALSE); g_return_val_if_fail (func != NULL, FALSE); proxy = g_new0 (MainLoopProxy, 1); proxy->func = func; proxy->data = user_data; proxy->notify = notify; g_mutex_init (&proxy->ack_lock); g_cond_init (&proxy->ack_condition); g_mutex_lock (&proxy->ack_lock); source = g_idle_source_new (); g_source_set_priority (source, G_PRIORITY_DEFAULT); g_source_set_callback (source, mainloop_proxy_func, proxy, NULL); g_source_attach (source, job->context); g_source_unref (source); while (!proxy->ack) g_cond_wait (&proxy->ack_condition, &proxy->ack_lock); g_mutex_unlock (&proxy->ack_lock); ret_val = proxy->ret_val; mainloop_proxy_free (proxy); return ret_val; }
static LRESULT CALLBACK gui_unique_win32_message_handler (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_COPYDATA: if (unique_gimp) { COPYDATASTRUCT *copydata = (COPYDATASTRUCT *) lParam; GSource *source; GClosure *closure; IdleOpenData *data; data = idle_open_data_new (copydata->lpData, copydata->cbData, copydata->dwData != 0); closure = g_cclosure_new (G_CALLBACK (gui_unique_win32_idle_open), data, (GClosureNotify) idle_open_data_free); g_object_watch_closure (unique_gimp, closure); source = g_idle_source_new (); g_source_set_priority (source, G_PRIORITY_LOW); g_source_set_closure (source, closure); g_source_attach (source, NULL); g_source_unref (source); } return TRUE; default: return DefWindowProcW (hWnd, uMsg, wParam, lParam); } }
/* Must *not* take the agent lock, since it’s called from within * nice_component_set_io_context(), which holds the Component’s I/O lock. */ static void socket_source_attach (SocketSource *socket_source, GMainContext *context) { GSource *source; if (socket_source->socket->fileno == NULL) return; /* Create a source. */ source = g_socket_create_source (socket_source->socket->fileno, G_IO_IN, NULL); g_source_set_callback (source, (GSourceFunc) component_io_cb, socket_source, NULL); /* Add the source. */ nice_debug ("Attaching source %p (socket %p, FD %d) to context %p", source, socket_source->socket, g_socket_get_fd (socket_source->socket->fileno), context); g_assert (socket_source->source == NULL); socket_source->source = source; g_source_attach (source, context); }
static void gum_script_task_return (GumScriptTask * self) { GumScriptTaskPrivate * priv = self->priv; if (priv->synchronous) { g_mutex_lock (&priv->mutex); priv->completed = TRUE; g_cond_signal (&priv->cond); g_mutex_unlock (&priv->mutex); } else { GSource * source; source = g_idle_source_new (); g_source_set_callback (source, (GSourceFunc) gum_script_task_complete, g_object_ref (self), g_object_unref); g_source_attach (source, priv->context); g_source_unref (source); } }
static ConnectionSetup* connection_setup_new (GMainContext *context, DBusConnection *connection) { ConnectionSetup *cs; cs = g_slice_new0 (ConnectionSetup); g_assert (context != NULL); cs->context = context; g_main_context_ref (cs->context); if (connection) { cs->connection = connection; cs->message_queue_source = g_source_new ((GSourceFuncs *) &message_queue_funcs, sizeof (IBusMessageQueue)); ((IBusMessageQueue*)cs->message_queue_source)->connection = connection; g_source_attach (cs->message_queue_source, cs->context); } return cs; }
static void session_setup_g_source(Session *s) { if (!s->ggs) return; if (s->g_source && s->g_pollfd.fd != s->ggs->fd) { g_source_remove_poll(s->g_source, &s->g_pollfd); } if (!s->g_source) { s->g_source = g_source_new(&source_funcs, sizeof(Source)); ((Source *)(gpointer)s->g_source)->session=s; g_source_attach(s->g_source,g_main_loop_get_context(main_loop)); } s->g_pollfd.events=G_IO_ERR|G_IO_HUP|G_IO_NVAL; if (s->ggs->check&GG_CHECK_READ) s->g_pollfd.events|=G_IO_IN; if (s->ggs->check&GG_CHECK_WRITE) s->g_pollfd.events|=G_IO_OUT; if (s->g_pollfd.fd != s->ggs->fd) { s->g_pollfd.fd=s->ggs->fd; if (s->g_pollfd.fd!=-1) g_source_add_poll(s->g_source, &s->g_pollfd); } }
/** * gst_vulkan_display_xcb_new: * @name: (allow-none): a display name * * Create a new #GstVulkanDisplayXCB from the xcb display name. See XOpenDisplay() * for details on what is a valid name. * * Returns: (transfer full): a new #GstVulkanDisplayXCB or %NULL */ GstVulkanDisplayXCB * gst_vulkan_display_xcb_new (const gchar * name) { xcb_connection_t *connection; GstVulkanDisplayXCB *ret; int screen_no = 0; GST_DEBUG_CATEGORY_GET (gst_vulkan_display_debug, "gldisplay"); connection = xcb_connect (NULL, &screen_no); if (connection == NULL || xcb_connection_has_error (connection)) { GST_ERROR ("Failed to open XCB display connection with name, \'%s\'", name); return NULL; } ret = gst_vulkan_display_xcb_new_with_connection (connection, screen_no); GST_VULKAN_DISPLAY (ret)->event_source = xcb_event_source_new (ret); g_source_attach (GST_VULKAN_DISPLAY (ret)->event_source, GST_VULKAN_DISPLAY (ret)->main_context); ret->foreign_display = FALSE; return ret; }
guint g_timeout2_add_full (gint priority, guint interval, GSourceFunc function, gpointer data, GDestroyNotify notify) { GSource *source; guint id; g_return_val_if_fail (function != NULL, 0); source = g_timeout2_source_new (interval); if (priority != G_PRIORITY_DEFAULT) g_source_set_priority (source, priority); g_source_set_callback (source, function, data, notify); id = g_source_attach (source, NULL); g_source_unref (source); return id; }
/* * malloc PSource and port_create, start thread at pnode_ref. * if psource_new succeeded, the PSource will never * be freed. So PSource can be freed only in psource_new. * Note pnode_monitor_remove_all can also free PSource, but currently no one * invork it. */ static GSource* psource_new() { GSource *source = NULL; int fd; if ((fd = port_create()) >= 0) { source = g_source_new(&fen_source_func, sizeof(PSource)); PGPFD(source)->fd = fd; PGPFD(source)->events = G_IO_IN | G_IO_HUP | G_IO_ERR; g_source_set_callback(source, port_events_read_cb, NULL, NULL); g_source_attach(source, NULL); g_source_unref(source); g_source_add_poll(source, PGPFD(source)); FK_W ("%s 0x%p fd %d\n", __func__, source, PGPFD(source)->fd); } else { FK_W ("PORT_CREATE %s\n", g_strerror(errno)); g_return_val_if_reached(NULL); } return source; }
void * sol_mainloop_impl_source_add(const struct sol_mainloop_source_type *type, const void *data) { struct source_wrap_data *wrap_data; guint id; wrap_data = (struct source_wrap_data *)g_source_new(&source_funcs, sizeof(struct source_wrap_data)); SOL_NULL_CHECK(wrap_data, NULL); wrap_data->type = type; wrap_data->data = data; id = g_source_attach(&wrap_data->base, NULL); SOL_INT_CHECK_GOTO(id, == 0, error); return wrap_data; error: g_source_destroy(&wrap_data->base); g_source_unref(&wrap_data->base); return NULL; }
GSource * _gdk_broadway_event_source_new (GdkDisplay *display) { GSource *source; GdkEventSource *event_source; char *name; source = g_source_new (&event_funcs, sizeof (GdkEventSource)); name = g_strdup_printf ("GDK Broadway 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; 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; }
static void request_cancelled (GCancellable *cancellable, gpointer user_data) { GWin32ResolverRequest *req = user_data; if (req->cancellable) { g_signal_handlers_disconnect_by_func (req->cancellable, request_cancelled, req); g_object_unref (req->cancellable); req->cancellable = NULL; } /* We need to wait until main-loop-time to actually complete the * result; we don't use _complete_in_idle() here because we need to * keep track of the source so we can potentially cancel it before * it runs. */ req->cancelled_idle = g_idle_source_new (); g_source_set_callback (req->cancelled_idle, (GSourceFunc)request_cancelled_idle, req, NULL); g_source_attach (req->cancelled_idle, g_main_context_get_thread_default ()); }
static gboolean gst_gl_window_wayland_egl_open (GstGLWindow * window, GError ** error) { GstGLWindowWaylandEGL *window_egl = GST_GL_WINDOW_WAYLAND_EGL (window); window_egl->display.display = wl_display_connect (NULL); if (!window_egl->display.display) { g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE, "Failed to connect to Wayland display server"); goto error; } window_egl->display.registry = wl_display_get_registry (window_egl->display.display); wl_registry_add_listener (window_egl->display.registry, ®istry_listener, window_egl); wl_display_dispatch (window_egl->display.display); create_surface (window_egl); window_egl->display.cursor_surface = wl_compositor_create_surface (window_egl->display.compositor); window_egl->wl_source = wayland_event_source_new (window_egl->display.display); window_egl->main_context = g_main_context_new (); window_egl->loop = g_main_loop_new (window_egl->main_context, FALSE); g_source_attach (window_egl->wl_source, window_egl->main_context); return TRUE; error: return FALSE; }
gboolean ot_admin_sysroot_lock (OstreeSysroot *sysroot, GError **error) { gboolean ret = FALSE; gboolean acquired; struct ContextState state = { .mainctx = g_main_context_new (), .running = TRUE, }; g_main_context_push_thread_default (state.mainctx); if (!ostree_sysroot_try_lock (sysroot, &acquired, error)) goto out; if (!acquired) { GSource *timeout_src = g_timeout_source_new_seconds (3); g_source_set_callback (timeout_src, (GSourceFunc)on_sysroot_lock_timeout, &state, NULL); g_source_attach (timeout_src, state.mainctx); g_source_unref (timeout_src); on_sysroot_lock_timeout (&state); ostree_sysroot_lock_async (sysroot, NULL, (GAsyncReadyCallback)on_sysroot_lock_acquired, &state); while (state.running) g_main_context_iteration (state.mainctx, TRUE); } ret = TRUE; out: g_main_context_pop_thread_default (state.mainctx); g_main_context_unref (state.mainctx); return ret; }
static gboolean net_createUDPSocket(struct node *n, guint classid) { GError * err = NULL; GInetAddress *addr = n->netadr; guint port = 2300+n->classes[classid]; syslog(LOG_DEBUG,"net_createSockets: Creating udp socket on port %u\n", port); GSocketAddress * sa = g_inet_socket_address_new(addr,port); n->udpsockets[classid].n = n; GSocket *socket = g_socket_new(G_SOCKET_FAMILY_IPV6, G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, NULL); ub_assert(socket != NULL); if( g_socket_bind(socket, sa, TRUE, &err) == FALSE ){ syslog(LOG_WARNING, "net_createSockets: Error while binding udp socket: %s\n", err->message); g_error_free(err); return FALSE; } GSource *source = g_socket_create_source(socket, G_IO_IN, NULL); ub_assert(source != NULL); g_source_set_callback(source, (GSourceFunc)udp_read, &(n->udpsockets[classid]) , NULL); g_source_attach(source, g_main_context_default()); n->udpsockets[classid].socket = socket; n->udpsockets[classid].source = source; n->udpsockets[classid].socketaddress = sa; n->udpsockets[classid].classid = classid; //broadcast_addService(n->classes[classid]); return TRUE; }
QPAHiddTpHandler::QPAHiddTpHandler(QEglFSScreen* m_screen) : m_mousePressTime(0) , m_nyxPenHandle(0) , m_penFd(0) , m_metaActiveTouchesCount(0) , m_sendPenCancel (false) , m_penCancelPoint (0,0) , m_isSuspended (false) { m_deviceWidth = m_screen->geometry().width(); m_deviceHeight = m_screen->geometry().height(); flickGesture = new FlickGesture; m_screenEdgeFlickGesture = new ScreenEdgeFlickGesture; m_touchTimer.start(); InputControl* ic = new NyxInputControl(NYX_DEVICE_TOUCHPANEL, "Main"); m_tpInput = ic; if (ic) { m_nyxPenHandle = ic->getHandle(); if (m_nyxPenHandle) { nyx_error_t error = NYX_ERROR_NONE; error = nyx_device_get_event_source(m_nyxPenHandle, &m_penFd); if (error != NYX_ERROR_NONE) { g_critical("Unable to obtain touchpanel event_source"); return; } GIOChannel* ioChannel = g_io_channel_unix_new(m_penFd); GSource* ioSource = g_io_create_watch(ioChannel, (GIOCondition) G_IO_IN); g_source_set_callback(ioSource, (GSourceFunc) ioCallback, this, NULL); g_source_attach(ioSource, g_main_context_default()); } } }
static void owr_media_renderer_init(OwrMediaRenderer *renderer) { OwrMediaRendererPrivate *priv; GstBus *bus; GSource *bus_source; gchar *bin_name; renderer->priv = priv = OWR_MEDIA_RENDERER_GET_PRIVATE(renderer); priv->media_type = DEFAULT_MEDIA_TYPE; priv->source = DEFAULT_SOURCE; priv->disabled = DEFAULT_DISABLED; priv->message_origin_bus_set = owr_message_origin_bus_set_new(); bin_name = g_strdup_printf("media-renderer-%u", g_atomic_int_add(&unique_bin_id, 1)); priv->pipeline = gst_pipeline_new(bin_name); gst_pipeline_use_clock(GST_PIPELINE(priv->pipeline), gst_system_clock_obtain()); gst_element_set_base_time(priv->pipeline, _owr_get_base_time()); gst_element_set_start_time(priv->pipeline, GST_CLOCK_TIME_NONE); g_free(bin_name); #ifdef OWR_DEBUG g_signal_connect(priv->pipeline, "deep-notify", G_CALLBACK(_owr_deep_notify), NULL); #endif priv->sink = NULL; priv->src = NULL; bus = gst_pipeline_get_bus(GST_PIPELINE(priv->pipeline)); bus_source = gst_bus_create_watch(bus); g_source_set_callback(bus_source, (GSourceFunc) bus_call, priv->pipeline, NULL); g_source_attach(bus_source, _owr_get_main_context()); g_source_unref(bus_source); g_mutex_init(&priv->media_renderer_lock); }
static void test_timer_source_set_interval_seconds() { // 2s interval GTimerSource *source = g_timer_source_new_seconds(2); // 1s interval g_timer_source_set_interval_seconds(source, 1, true); g_assert_cmpint(g_timer_source_get_interval_ms(source), ==, 1000); // no main loop, no main context, cannot wakeup context, expect warning if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR)) { g_timer_source_set_interval_seconds(source, 2, false); exit(0); } g_test_trap_assert_stderr("*Cannot get context for timer_source*"); // valid main loop/context, source attached, expect no warning if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR)) { GMainLoop *main_loop = g_main_loop_new(NULL, false); g_source_attach ((GSource*)source, NULL); g_timer_source_set_interval_seconds(source, 1, false); g_main_loop_unref(main_loop); g_source_unref((GSource*)source); exit(0); } g_test_trap_assert_stderr_unmatched("*Cannot get context for timer_source*"); g_source_unref((GSource*)source); }
static __inline__ void hm_net_scheduler_init(HmNetSched *sched, guint n_loops, gboolean gather) { gint index; GSource *tsource; sched->nr_loops = n_loops; sched->last_loop = 0; for (index = 0; index < n_loops; ++index) { HmSchedLoop *l = &sched->loops[index]; l->context = g_main_context_new(); l->loop = g_main_loop_new( l->context, FALSE ); l->loop_thread = g_thread_create( hm_net_scheduler_loop_thread, l, FALSE, NULL ); if (gather) { tsource = g_timeout_source_new(GATHER_INTERVAL_MSEC); if (tsource) { g_source_set_callback(tsource, hm_net_loop_gather, NULL, NULL); g_source_attach(tsource, l->context); g_source_unref(tsource); } } } }
int qemu_init_main_loop(Error **errp) { int ret; GSource *src; Error *local_error = NULL; init_clocks(); ret = qemu_signal_init(); if (ret) { return ret; } qemu_aio_context = aio_context_new(&local_error); if (!qemu_aio_context) { error_propagate(errp, local_error); return -EMFILE; } gpollfds = g_array_new(FALSE, FALSE, sizeof(GPollFD)); src = aio_get_g_source(qemu_aio_context); g_source_attach(src, NULL); g_source_unref(src); return 0; }
static void initialize_io (CockpitStream *self) { GInputStream *is; GOutputStream *os; g_return_if_fail (self->priv->in_source == NULL); is = g_io_stream_get_input_stream (self->priv->io); os = g_io_stream_get_output_stream (self->priv->io); if (!G_IS_POLLABLE_INPUT_STREAM (is) || !g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (is)) || !G_IS_POLLABLE_OUTPUT_STREAM (os) || !g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (os))) { g_warning ("%s: stream is not pollable", self->priv->name); close_immediately (self, "internal-error"); return; } if (self->priv->connecting) { cockpit_connectable_unref (self->priv->connecting); self->priv->connecting = NULL; } self->priv->in_source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (is), NULL); g_source_set_name (self->priv->in_source, "stream-input"); g_source_set_callback (self->priv->in_source, (GSourceFunc)dispatch_input, self, NULL); g_source_attach (self->priv->in_source, self->priv->context); start_output (self); g_signal_emit (self, cockpit_stream_sig_open, 0); }
/** * g_unix_fd_add_full: * @priority: the priority of the source * @fd: a file descriptor * @condition: IO conditions to watch for on @fd * @function: a #GUnixFDSourceFunc * @user_data: data to pass to @function * @notify: function to call when the idle is removed, or %NULL * * Sets a function to be called when the IO condition, as specified by * @condition becomes true for @fd. * * This is the same as g_unix_fd_add(), except that it allows you to * specify a non-default priority and a provide a #GDestroyNotify for * @user_data. * * Returns: the ID (greater than 0) of the event source * * Since: 2.36 **/ guint g_unix_fd_add_full (gint priority, gint fd, GIOCondition condition, GUnixFDSourceFunc function, gpointer user_data, GDestroyNotify notify) { GSource *source; guint id; g_return_val_if_fail (function != NULL, 0); source = g_unix_fd_source_new (fd, condition); if (priority != G_PRIORITY_DEFAULT) g_source_set_priority (source, priority); g_source_set_callback (source, (GSourceFunc) function, user_data, notify); id = g_source_attach (source, NULL); g_source_unref (source); return id; }
static GSource * soup_socket_create_watch (SoupSocketPrivate *priv, GIOCondition cond, GPollableSourceFunc callback, gpointer user_data, GCancellable *cancellable) { GSource *watch; GMainContext *async_context; if (cond == G_IO_IN) watch = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (priv->istream), cancellable); else watch = g_pollable_output_stream_create_source (G_POLLABLE_OUTPUT_STREAM (priv->ostream), cancellable); g_source_set_callback (watch, (GSourceFunc)callback, user_data, NULL); if (priv->use_thread_context) async_context = g_main_context_get_thread_default (); else async_context = priv->async_context; g_source_attach (watch, async_context); g_source_unref (watch); return watch; }
/* must be called with the bus OBJECT LOCK */ static guint gst_bus_add_watch_full_unlocked (GstBus * bus, gint priority, GstBusFunc func, gpointer user_data, GDestroyNotify notify) { GMainContext *ctx; guint id; GSource *source; if (bus->priv->signal_watch) { GST_ERROR_OBJECT (bus, "Tried to add new watch while one was already there"); return 0; } source = gst_bus_create_watch (bus); if (!source) { g_critical ("Creating bus watch failed"); return 0; } if (priority != G_PRIORITY_DEFAULT) g_source_set_priority (source, priority); g_source_set_callback (source, (GSourceFunc) func, user_data, notify); ctx = g_main_context_get_thread_default (); id = g_source_attach (source, ctx); g_source_unref (source); if (id) { bus->priv->signal_watch = source; } GST_DEBUG_OBJECT (bus, "New source %p with id %u", source, id); return id; }
static gpointer test_thread (gpointer data) { GMainLoop *new_main_loop; GSource *source; GPid pid; gint ttl = GPOINTER_TO_INT (data); new_main_loop = g_main_loop_new (NULL, FALSE); pid = get_a_child (ttl); source = g_child_watch_source_new (pid); g_source_set_callback (source, (GSourceFunc) child_watch_callback, data, NULL); g_source_attach (source, g_main_loop_get_context (new_main_loop)); g_source_unref (source); #ifdef VERBOSE g_print ("whee! created pid: " GPID_FORMAT " (ttl %d)\n", pid, ttl); #endif g_main_loop_run (new_main_loop); return NULL; }