static GObject * gst_validate_monitor_constructor (GType type, guint n_construct_params, GObjectConstructParam * construct_params) { GstObject *target; GstValidateMonitor *monitor = GST_VALIDATE_MONITOR_CAST (G_OBJECT_CLASS (parent_class)->constructor (type, n_construct_params, construct_params)); if (monitor->parent) { GstPipeline *parent_pipeline = gst_validate_monitor_get_pipeline (monitor->parent); gst_validate_monitor_set_media_descriptor (monitor, monitor->parent->media_descriptor); if (parent_pipeline) { g_weak_ref_init (&monitor->pipeline, parent_pipeline); gst_object_unref (parent_pipeline); } } gst_validate_override_registry_attach_overrides (monitor); gst_validate_monitor_setup (monitor); target = gst_validate_monitor_get_target (monitor); g_object_set_data ((GObject *) target, "validate-monitor", monitor); gst_object_unref (target); return (GObject *) monitor; }
/** * nice_component_source_new: * @agent: a #NiceAgent * @stream_id: The stream's id * @component_id: The component's number * @pollable_stream: a #GPollableInputStream or #GPollableOutputStream to pass * to dispatched callbacks * @cancellable: (allow-none): a #GCancellable, or %NULL * * Create a new #ComponentSource, a type of #GSource which proxies poll events * from all sockets in the given @component. * * A callback function of type #GPollableSourceFunc must be connected to the * returned #GSource using g_source_set_callback(). @pollable_stream is passed * to all callbacks dispatched from the #GSource, and a reference is held on it * by the #GSource. * * The #GSource will automatically update to poll sockets as they’re added to * the @component (e.g. during peer discovery). * * Returns: (transfer full): a new #ComponentSource; unref with g_source_unref() */ GSource * nice_component_input_source_new (NiceAgent *agent, guint stream_id, guint component_id, GPollableInputStream *pollable_istream, GCancellable *cancellable) { ComponentSource *component_source; g_assert (G_IS_POLLABLE_INPUT_STREAM (pollable_istream)); component_source = (ComponentSource *) g_source_new (&component_source_funcs, sizeof (ComponentSource)); g_source_set_name ((GSource *) component_source, "ComponentSource"); component_source->component_socket_sources_age = 0; component_source->pollable_stream = g_object_ref (pollable_istream); g_weak_ref_init (&component_source->agent_ref, agent); component_source->stream_id = stream_id; component_source->component_id = component_id; /* Add a cancellable source. */ if (cancellable != NULL) { GSource *cancellable_source; cancellable_source = g_cancellable_source_new (cancellable); g_source_set_dummy_callback (cancellable_source); g_source_add_child_source ((GSource *) component_source, cancellable_source); g_source_unref (cancellable_source); } return (GSource *) component_source; }
/** * camel_object_bag_add: * @bag: a #CamelObjectBag * @key: a reserved key * @object: a #GObject * * Adds @object to @bag. The @key MUST have been previously reserved using * camel_object_bag_reserve(). **/ void camel_object_bag_add (CamelObjectBag *bag, gconstpointer key, gpointer object) { g_return_if_fail (bag != NULL); g_return_if_fail (key != NULL); g_return_if_fail (G_IS_OBJECT (object)); g_mutex_lock (&bag->mutex); /* Check it's the *same* object, not an old one at the same address */ if (!object_in_bag (bag, object)) { ObjRef *ref; gpointer copied_key; ref = g_slice_new (ObjRef); ref->bag = bag; /* We need to stash a 'raw' pointer since that's the key we use * in the key_table */ ref->obj = object; g_weak_ref_init (&ref->ref, object); copied_key = bag->key_copy_func (key); g_hash_table_insert (bag->key_table, object, copied_key); g_hash_table_insert (bag->object_table, copied_key, ref); object_bag_unreserve (bag, key); g_object_weak_ref ( G_OBJECT (object), (GWeakNotify) object_bag_notify, bag); } g_mutex_unlock (&bag->mutex); }
void gtk_gst_base_widget_init (GtkGstBaseWidget * widget) { int event_mask; widget->force_aspect_ratio = DEFAULT_FORCE_ASPECT_RATIO; widget->par_n = DEFAULT_PAR_N; widget->par_d = DEFAULT_PAR_D; widget->ignore_alpha = DEFAULT_IGNORE_ALPHA; gst_video_info_init (&widget->v_info); gst_video_info_init (&widget->pending_v_info); g_weak_ref_init (&widget->element, NULL); g_mutex_init (&widget->lock); gtk_widget_set_can_focus (GTK_WIDGET (widget), TRUE); event_mask = gtk_widget_get_events (GTK_WIDGET (widget)); event_mask |= GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK; gtk_widget_set_events (GTK_WIDGET (widget), event_mask); }
static void nice_input_stream_init (NiceInputStream *stream) { stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (stream, NICE_TYPE_INPUT_STREAM, NiceInputStreamPrivate); g_weak_ref_init (&stream->priv->agent_ref, NULL); }
static void gda_web_pstmt_init (GdaWebPStmt *pstmt) { g_return_if_fail (GDA_IS_PSTMT (pstmt)); GdaWebPStmtPrivate *priv = gda_web_pstmt_get_instance_private (pstmt); g_weak_ref_init (&priv->cnc, NULL); priv->pstmt_hash = NULL; }
static GWeakRef * weak_ref_new (gpointer obj) { GWeakRef *ref = g_slice_new (GWeakRef); g_weak_ref_init (ref, obj); return ref; }
GWeakRef * util_get_weak_ref(GObject *o) { g_return_val_if_fail(o != NULL, NULL); GWeakRef *ref = g_malloc(sizeof(GWeakRef)); g_weak_ref_init(ref, o); return ref; }
static void dconf_settings_backend_init (DConfSettingsBackend *dcsb) { GWeakRef *weak_ref; weak_ref = g_slice_new (GWeakRef); g_weak_ref_init (weak_ref, dcsb); dcsb->engine = dconf_engine_new (weak_ref, dconf_settings_backend_free_weak_ref); }
static void nice_output_stream_init (NiceOutputStream *stream) { stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (stream, NICE_TYPE_OUTPUT_STREAM, NiceOutputStreamPrivate); g_weak_ref_init (&stream->priv->agent_ref, NULL); stream->priv->closed_cancellable = g_cancellable_new (); }
GWeakRef* utils_create_weak_ref(gpointer obj) { GWeakRef* ref = g_malloc(sizeof(GWeakRef)); g_weak_ref_init(ref, obj); return ref; }
static void gda_sqlite_blob_op_init (GdaSqliteBlobOp *op) { g_return_if_fail (GDA_IS_SQLITE_BLOB_OP (op)); GdaSqliteBlobOpPrivate *priv = gda_sqlite_blob_op_get_instance_private (op); priv->sblob = NULL; g_weak_ref_init (&priv->provider, NULL); }
static void gst_gl_window_init (GstGLWindow * window) { window->priv = GST_GL_WINDOW_GET_PRIVATE (window); g_mutex_init (&window->lock); window->is_drawing = FALSE; g_weak_ref_init (&window->context_ref, NULL); }
/** * bt_notify_idle_dispatch: * @object: the object * @pspec: the arg * @user_data: the extra data * @func: the actual callback * * Save the parameters from a #GObject::notify callback, run it through * g_idle_add(), unpack the params and call @func. */ void bt_notify_idle_dispatch (GObject * object, GParamSpec * pspec, gpointer user_data, BtNotifyFunc func) { BtNotifyIdleData *data = g_slice_new (BtNotifyIdleData); data->object = object; data->pspec = pspec; data->func = func; g_weak_ref_init (&data->user_data, user_data); g_idle_add (on_idle_notify, data); }
static void gda_postgres_pstmt_init (GdaPostgresPStmt *pstmt) { g_return_if_fail (GDA_IS_PSTMT (pstmt)); GdaPostgresPStmtPrivate *priv = gda_postgres_pstmt_get_instance_private (pstmt); g_weak_ref_init (&priv->cnc, NULL); priv->pconn = NULL; priv->prep_name = NULL; priv->date_format_change = FALSE; priv->deallocated = FALSE; }
static void gda_pstmt_init (GdaPStmt *pstmt, G_GNUC_UNUSED GdaPStmtClass *klass) { g_return_if_fail (GDA_IS_PSTMT (pstmt)); pstmt->priv = g_new0 (GdaPStmtPrivate, 1); g_rec_mutex_init (& pstmt->priv->mutex); g_weak_ref_init (& pstmt->priv->gda_stmt_ref, NULL); pstmt->sql = NULL; pstmt->param_ids = NULL; pstmt->ncols = -1; pstmt->types = NULL; pstmt->tmpl_columns = NULL; }
static void gda_pstmt_init (GdaPStmt *pstmt) { g_return_if_fail (GDA_IS_PSTMT (pstmt)); GdaPStmtPrivate *priv = gda_pstmt_get_instance_private (pstmt); g_rec_mutex_init (& priv->mutex); g_weak_ref_init (&priv->gda_stmt_ref, NULL); priv->sql = NULL; priv->param_ids = NULL; priv->ncols = -1; priv->types = NULL; priv->tmpl_columns = NULL; }
static void mega_filesystem_init(MegaFilesystem *filesystem) { filesystem->priv = G_TYPE_INSTANCE_GET_PRIVATE(filesystem, MEGA_TYPE_FILESYSTEM, MegaFilesystemPrivate); filesystem->priv->pathmap = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref); filesystem->priv->handlemap = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref); filesystem->priv->share_keys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref); filesystem->priv->nodes = NULL; filesystem->priv->root_nodes = NULL; g_weak_ref_init(&filesystem->priv->session, NULL); }
static void gst_gl_context_init (GstGLContext * context) { context->priv = GST_GL_CONTEXT_GET_PRIVATE (context); context->window = NULL; context->gl_vtable = g_slice_alloc0 (sizeof (GstGLFuncs)); g_mutex_init (&context->priv->render_lock); g_cond_init (&context->priv->create_cond); g_cond_init (&context->priv->destroy_cond); context->priv->created = FALSE; g_weak_ref_init (&context->priv->other_context_ref, NULL); }
/** * gst_gl_display_add_context: * @display: a #GstGLDisplay * @context: (transfer none): a #GstGLContext * * Returns: whether @context was successfully added. %FALSE may be returned * if there already exists another context for @context's active thread. * * Must be called with the object lock held. * * Since: 1.6 */ gboolean gst_gl_display_add_context (GstGLDisplay * display, GstGLContext * context) { GstGLContext *collision = NULL; GstGLDisplay *context_display; gboolean ret = TRUE; GThread *thread; GWeakRef *ref; g_return_val_if_fail (GST_IS_GL_DISPLAY (display), FALSE); g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE); context_display = gst_gl_context_get_display (context); g_assert (context_display == display); gst_object_unref (context_display); thread = gst_gl_context_get_thread (context); if (thread) { collision = _get_gl_context_for_thread_unlocked (display, thread); g_thread_unref (thread); /* adding the same context is a no-op */ if (context == collision) { ret = TRUE; goto out; } if (_check_collision (context, collision)) { ret = FALSE; goto out; } } ref = g_new0 (GWeakRef, 1); g_weak_ref_init (ref, context); display->priv->contexts = g_list_prepend (display->priv->contexts, ref); out: if (collision) gst_object_unref (collision); GST_DEBUG_OBJECT (display, "%ssuccessfully inserted context %" GST_PTR_FORMAT, ret ? "" : "un", context); return ret; }
static void gst_gl_window_init (GstGLWindow * window) { GstGLWindowPrivate *priv = GST_GL_WINDOW_GET_PRIVATE (window); window->priv = priv; g_mutex_init (&window->lock); window->is_drawing = FALSE; g_weak_ref_init (&window->context_ref, NULL); g_mutex_init (&window->priv->sync_message_lock); g_cond_init (&window->priv->sync_message_cond); priv->main_context = g_main_context_new (); priv->loop = g_main_loop_new (priv->main_context, FALSE); }
static gboolean on_peer_certificate_received(ErDtlsConnection *connection, gchar *pem, GstErDtlsDec *self) { GWeakRef *ref; UNUSED(connection); g_return_val_if_fail(GST_IS_ER_DTLS_DEC(self), TRUE); GST_DEBUG_OBJECT(self, "Received peer certificate PEM: \n%s", pem); self->peer_pem = g_strdup(pem); ref = g_new(GWeakRef, 1); g_weak_ref_init(ref, self); g_idle_add((GSourceFunc) signal_peer_certificate_received, ref); return TRUE; }
/* * @stmt may be %NULL */ static void gda_stmt_reset_cb (GdaStatement *stmt, GdaPStmt *pstmt) { g_rec_mutex_lock (& pstmt->priv->mutex); if (stmt) g_signal_handlers_disconnect_by_func (G_OBJECT (stmt), G_CALLBACK (gda_stmt_reset_cb), pstmt); else { stmt = g_weak_ref_get (& pstmt->priv->gda_stmt_ref); if (stmt) { g_signal_handlers_disconnect_by_func (G_OBJECT (stmt), G_CALLBACK (gda_stmt_reset_cb), pstmt); g_object_unref (stmt); } } g_weak_ref_clear (& pstmt->priv->gda_stmt_ref); g_weak_ref_init (& pstmt->priv->gda_stmt_ref, NULL); g_rec_mutex_unlock (& pstmt->priv->mutex); }
static void test_refcounting() { OwrBus *bus; OwrMessageOrigin *origin; GWeakRef weak_ref; GAsyncQueue *queue; queue = g_async_queue_new(); bus = owr_bus_new(); owr_bus_set_message_callback(bus, on_message, queue, NULL); origin = mock_origin_new(); owr_bus_add_message_origin(bus, origin); g_weak_ref_init(&weak_ref, bus); OWR_POST_STATS(origin, TEST, NULL); g_object_unref(bus); /* this should finalize the bus, pending messages should not keep it alive */ assert_weak_ref(&weak_ref, FALSE, __LINE__); g_weak_ref_clear(&weak_ref); bus = owr_bus_new(); owr_bus_set_message_callback(bus, on_message, queue, NULL); owr_bus_add_message_origin(bus, origin); g_weak_ref_init(&weak_ref, origin); OWR_POST_STATS(origin, TEST, NULL); g_object_unref(origin); /* the origin should be kept alive though */ g_object_ref(origin); assert_weak_ref(&weak_ref, TRUE, __LINE__); g_object_unref(origin); g_assert(g_async_queue_timeout_pop(queue, G_USEC_PER_SEC)); g_usleep(1000); /* messages are cleaned up after all callbacks have happened, so wait a bit more */ assert_weak_ref(&weak_ref, FALSE, __LINE__); /* but be cleaned up after the message was handled */ g_weak_ref_clear(&weak_ref); /* same as previous tests, but with message filter */ origin = mock_origin_new(); owr_bus_add_message_origin(bus, origin); g_weak_ref_init(&weak_ref, origin); g_object_set(bus, "message-type-mask", OWR_MESSAGE_TYPE_STATS, NULL); OWR_POST_STATS(origin, TEST, NULL); OWR_POST_EVENT(origin, TEST, NULL); OWR_POST_ERROR(origin, TEST, NULL); g_object_unref(origin); g_object_ref(origin); assert_weak_ref(&weak_ref, TRUE, __LINE__); g_object_unref(origin); g_assert(g_async_queue_timeout_pop(queue, G_USEC_PER_SEC)); g_usleep(1000); assert_weak_ref(&weak_ref, FALSE, __LINE__); g_weak_ref_clear(&weak_ref); origin = mock_origin_new(); owr_bus_add_message_origin(bus, origin); g_weak_ref_init(&weak_ref, bus); OWR_POST_STATS(origin, TEST, NULL); OWR_POST_EVENT(origin, TEST, NULL); OWR_POST_ERROR(origin, TEST, NULL); g_object_unref(bus); assert_weak_ref(&weak_ref, FALSE, __LINE__); g_weak_ref_clear(&weak_ref); }