Beispiel #1
0
/**
 * camel_object_bag_get:
 * @bag: a #CamelObjectBag
 * @key: a key
 *
 * Lookup an object by @key.  If the key is currently reserved, the function
 * will block until another thread commits or aborts the reservation.  The
 * caller owns the reference to the returned object.  Use g_object_unref ()
 * to unreference it.
 *
 * Returns: the object corresponding to @key, or %NULL if not found
 **/
gpointer
camel_object_bag_get (CamelObjectBag *bag,
                      gconstpointer key)
{
	KeyReservation *reservation;
	ObjRef *ref;
	gpointer object = NULL;

	g_return_val_if_fail (bag != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);

	g_mutex_lock (&bag->mutex);

	/* Look for the key in the bag. */
	ref = g_hash_table_lookup (bag->object_table, key);
	if (ref != NULL) {
		object = g_weak_ref_get (&ref->ref);
		if (object != NULL) {
			g_mutex_unlock (&bag->mutex);
			return object;
		}

		/* Remove stale reference to dead object. */
		g_hash_table_remove (bag->key_table, ref->obj);
		g_hash_table_remove (bag->object_table, key);
	}

	/* Check if the key has been reserved. */
	reservation = key_reservation_lookup (bag, key);
	if (reservation == NULL) {
		/* No such key, so return NULL. */
		g_mutex_unlock (&bag->mutex);
		return NULL;
	}

	/* Wait for the key to be unreserved. */
	reservation->waiters++;
	while (reservation->owner != NULL)
		g_cond_wait (&reservation->cond, &bag->mutex);
	reservation->waiters--;

	/* Check if an object was added by another thread. */
	ref = g_hash_table_lookup (bag->object_table, key);
	if (ref != NULL) {
		object = g_weak_ref_get (&ref->ref);
		if (object == NULL) {
			/* Remove stale reference to dead object. */
			g_hash_table_remove (bag->key_table, ref->obj);
			g_hash_table_remove (bag->object_table, key);
		}
	}

	/* We're not reserving it. */
	reservation->owner = g_thread_self ();
	object_bag_unreserve (bag, key);

	g_mutex_unlock (&bag->mutex);

	return object;
}
Beispiel #2
0
/**
 * camel_object_bag_reserve:
 * @bag: a #CamelObjectBag
 * @key: the key to reserve
 *
 * Reserves @key in @bag.  If @key is already reserved in another thread,
 * then wait until the reservation has been committed.
 *
 * After reserving @key, you either get a reference to the object
 * corresponding to @key (similar to camel_object_bag_get()) or you get
 * %NULL, signifying that you MUST call either camel_object_bag_add() or
 * camel_object_bag_abort().
 *
 * Returns: the object for @key, or %NULL if @key is not found
 **/
gpointer
camel_object_bag_reserve (CamelObjectBag *bag,
                          gconstpointer key)
{
	KeyReservation *reservation;
	ObjRef *ref;
	gpointer object = NULL;

	g_return_val_if_fail (bag != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);

	g_mutex_lock (&bag->mutex);

	/* If object for key already exists, return it immediately. */
	ref = g_hash_table_lookup (bag->object_table, key);
	if (ref != NULL) {
		object = g_weak_ref_get (&ref->ref);
		if (object != NULL) {
			g_mutex_unlock (&bag->mutex);
			return object;
		}

		/* Remove stale reference to dead object. */
		g_hash_table_remove (bag->key_table, ref->obj);
		g_hash_table_remove (bag->object_table, key);
	}

	/* If no such key exists in the bag, create a reservation. */
	reservation = key_reservation_lookup (bag, key);
	if (reservation == NULL) {
		key_reservation_new (bag, key);
		g_mutex_unlock (&bag->mutex);
		return NULL;
	}

	/* Wait for the reservation to be committed or aborted. */
	reservation->waiters++;
	while (reservation->owner != NULL)
		g_cond_wait (&reservation->cond, &bag->mutex);
	reservation->owner = g_thread_self ();
	reservation->waiters--;

	/* Check if the object was added by another thread. */
	ref = g_hash_table_lookup (bag->object_table, key);
	if (ref != NULL) {
		object = g_weak_ref_get (&ref->ref);
		if (object != NULL) {
			/* We have an object; no need to reserve the key. */
			object_bag_unreserve (bag, key);
		} else {
			/* Remove stale reference to dead object. */
			g_hash_table_remove (bag->key_table, ref->obj);
			g_hash_table_remove (bag->object_table, key);
		}
	}

	g_mutex_unlock (&bag->mutex);

	return object;
}
Beispiel #3
0
static void
gimp_operation_tool_unlink_chains (GimpOperationTool *op_tool)
{
  GObject *options_gui = g_weak_ref_get (&op_tool->options_gui_ref);
  GList   *chains;

  g_return_if_fail (options_gui != NULL);

  chains = g_object_get_data (options_gui, "chains");

  while (chains)
    {
      GimpChainButton *chain = chains->data;
      gboolean         active;

      active = gimp_chain_button_get_active (chain);

      g_object_set_data (G_OBJECT (chain), "was-active",
                         GINT_TO_POINTER (active));

      if (active)
        {
          gimp_chain_button_set_active (chain, FALSE);

          g_signal_emit_by_name (chain, "toggled");
        }

      chains = chains->next;
    }

  g_object_unref (options_gui);
}
Beispiel #4
0
static gboolean
gimp_operation_tool_initialize (GimpTool     *tool,
                                GimpDisplay  *display,
                                GError      **error)
{
  if (GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
    {
      GimpFilterTool    *filter_tool = GIMP_FILTER_TOOL (tool);
      GimpOperationTool *op_tool     = GIMP_OPERATION_TOOL (tool);

      if (filter_tool->config)
        {
          GtkWidget *options_gui;

          gimp_operation_tool_sync_op (op_tool, TRUE);
          options_gui = g_weak_ref_get (&op_tool->options_gui_ref);
          if (! options_gui)
            {
              gimp_operation_tool_create_gui (op_tool);
              gimp_operation_tool_add_gui (op_tool);
            }
          else
            {
              g_object_unref (options_gui);
            }
        }

      return TRUE;
    }

  return FALSE;
}
Beispiel #5
0
static gssize
nice_input_stream_read_nonblocking (GPollableInputStream *stream, void *buffer,
    gsize count, GError **error)
{
  NiceInputStreamPrivate *priv = NICE_INPUT_STREAM (stream)->priv;
  NiceAgent *agent;  /* owned */
  gssize len;

  /* Closed streams are not readable. */
  if (g_input_stream_is_closed (G_INPUT_STREAM (stream))) {
    return 0;
  }

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&priv->agent_ref);
  if (agent == NULL) {
    g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CLOSED,
        "Stream is closed due to the NiceAgent being finalised.");
    return -1;
  }

  len = nice_agent_recv_nonblocking (agent, priv->stream_id,
      priv->component_id, (guint8 *) buffer, count, NULL, error);

  g_object_unref (agent);

  return len;
}
/**
 * owr_message_origin_post_message:
 * @origin: (transfer none): the origin that is posting the message
 * @type: the #OwrMessageType of the message
 * @sub_type: the #OwrMessageSubType of the message
 * @data: (element-type utf8 GValue) (nullable) (transfer full): extra data
 *
 * Post a new message to all buses that are subscribed to @origin
 */
void owr_message_origin_post_message(OwrMessageOrigin *origin, OwrMessageType type, OwrMessageSubType sub_type, GHashTable *data)
{
    OwrMessage *message;
    OwrMessageOriginBusSet *bus_set;
    GHashTableIter iter;
    GWeakRef *ref;
    OwrBus *bus;

    g_return_if_fail(OWR_IS_MESSAGE_ORIGIN(origin));

    message = _owr_message_new(origin, type, sub_type, data);
    GST_TRACE_OBJECT(origin, "posting message %p", message);

    bus_set = owr_message_origin_get_bus_set(origin);
    g_return_if_fail(bus_set);

    g_mutex_lock(&bus_set->mutex);

    g_hash_table_iter_init(&iter, bus_set->table);
    while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &ref)) {
        bus = g_weak_ref_get(ref);
        if (bus) {
            _owr_bus_post_message(bus, message);
            g_object_unref(bus);
        } else {
            GST_DEBUG_OBJECT(origin, "message bus finalized, removing weak ref: %p", ref);
            g_hash_table_iter_remove(&iter);
        }
    }

    _owr_message_unref(message);

    g_mutex_unlock(&bus_set->mutex);
}
Beispiel #7
0
/*
 * Blob read request
 */
static glong
gda_sqlite_blob_op_read (GdaBlobOp *op, GdaBlob *blob, glong offset, glong size)
{
	GdaSqliteBlobOp *bop;
	GdaBinary *bin;
	gpointer buffer = NULL;
	int rc;

	g_return_val_if_fail (GDA_IS_SQLITE_BLOB_OP (op), -1);
	bop = GDA_SQLITE_BLOB_OP (op);
  GdaSqliteBlobOpPrivate *priv = gda_sqlite_blob_op_get_instance_private (bop);
	g_return_val_if_fail (priv->sblob, -1);
	if (offset >= G_MAXINT)
		return -1;
	g_return_val_if_fail (blob, -1);

	if (offset > G_MAXINT)
		return -1;
	if (size > G_MAXINT)
		return -1;

	GdaSqliteProvider *prov = g_weak_ref_get (&priv->provider);
	g_return_val_if_fail (prov != NULL, -1);

	bin = gda_blob_get_binary (blob);
	gda_binary_set_data (bin, (guchar*) "", 0);

	/* fetch blob data using C API into bin->data, and set bin->binary_length */
	int rsize;
	int len;

	len = SQLITE3_CALL (prov, sqlite3_blob_bytes) (priv->sblob);
	if (len < 0){
		g_object_unref (prov);
		return -1;
	} else if (len == 0) {
		g_object_unref (prov);
		return 0;
	}
		
	rsize = (int) size;
	if (offset >= len) {
		g_object_unref (prov);
		return -1;
	}

	if (len - offset < rsize)
		rsize = len - offset;
  
	rc = SQLITE3_CALL (prov, sqlite3_blob_read) (priv->sblob, buffer, rsize, offset);
	if (rc != SQLITE_OK) {
		gda_binary_reset_data (bin);
		g_object_unref (prov);
		return -1;
	}
	gda_binary_set_data (bin, buffer, rsize);
	g_object_unref (prov);

	return gda_binary_get_size (bin);
}
Beispiel #8
0
/**
 * camel_object_bag_list:
 * @bag: a #CamelObjectBag
 *
 * Returns a #GPtrArray of all the objects in the bag.  The caller owns
 * both the array and the object references, so to free the array use:
 *
 * <informalexample>
 *   <programlisting>
 *     g_ptr_array_foreach (array, g_object_unref, NULL);
 *     g_ptr_array_free (array, TRUE);
 *   </programlisting>
 * </informalexample>
 *
 * Returns: an array of objects in @bag
 **/
GPtrArray *
camel_object_bag_list (CamelObjectBag *bag)
{
	GPtrArray *array;
	GList *values;

	g_return_val_if_fail (bag != NULL, NULL);

	/* XXX Too bad we're not returning a GList; this would be trivial. */

	array = g_ptr_array_new ();

	g_mutex_lock (&bag->mutex);

	values = g_hash_table_get_values (bag->object_table);
	while (values != NULL) {
		ObjRef *ref = values->data;
		GObject *obj = g_weak_ref_get (&ref->ref);
		if (obj)
			g_ptr_array_add (array, obj);
		values = g_list_delete_link (values, values);
	}

	g_mutex_unlock (&bag->mutex);

	return array;
}
Beispiel #9
0
static gboolean
nice_output_stream_close (GOutputStream *stream, GCancellable *cancellable,
    GError **error)
{
  NiceOutputStreamPrivate *priv = NICE_OUTPUT_STREAM (stream)->priv;
  NiceComponent *component = NULL;
  NiceStream *_stream = NULL;
  NiceAgent *agent;  /* owned */

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&priv->agent_ref);
  if (agent == NULL)
    return TRUE;

  agent_lock ();

  /* Shut down the write side of the pseudo-TCP stream. */
  if (agent_find_component (agent, priv->stream_id, priv->component_id,
          &_stream, &component) && agent->reliable &&
      !pseudo_tcp_socket_is_closed (component->tcp)) {
    pseudo_tcp_socket_shutdown (component->tcp, PSEUDO_TCP_SHUTDOWN_WR);
  }

  agent_unlock ();

  g_object_unref (agent);

  return TRUE;
}
Beispiel #10
0
/**
 * gda_pstmt_set_gda_statement:
 * @pstmt: a #GdaPStmt object
 * @stmt: (allow-none): a #GdaStatement object, or %NULL
 *
 * Informs @pstmt that it corresponds to the preparation of the @stmt statement
 */
void
gda_pstmt_set_gda_statement (GdaPStmt *pstmt, GdaStatement *stmt)
{
	g_return_if_fail (GDA_IS_PSTMT (pstmt));
	g_return_if_fail (!stmt || GDA_IS_STATEMENT (stmt));

	g_rec_mutex_lock (& pstmt->priv->mutex);

	GdaStatement *estmt;
	estmt = g_weak_ref_get (& pstmt->priv->gda_stmt_ref);
	if (estmt == stmt) {
		if (estmt)
			g_object_unref (estmt);
		g_rec_mutex_unlock (& pstmt->priv->mutex);
		return;
	}

	gda_stmt_reset_cb (NULL, pstmt);

	if (stmt) {
		g_object_ref (stmt);
		g_weak_ref_set (& pstmt->priv->gda_stmt_ref, stmt);
		g_signal_connect (G_OBJECT (stmt), "reset", G_CALLBACK (gda_stmt_reset_cb), pstmt);
	}
	g_rec_mutex_unlock (& pstmt->priv->mutex);
}
Beispiel #11
0
static void
gda_postgres_pstmt_dispose (GObject *object)
{
	GdaPostgresPStmt *pstmt = (GdaPostgresPStmt *) object;

	g_return_if_fail (GDA_IS_PSTMT (pstmt));
  GdaPostgresPStmtPrivate *priv = gda_postgres_pstmt_get_instance_private (pstmt);

  if (!priv->deallocated) {
    GdaConnection *cnc = NULL;

    cnc = g_weak_ref_get (&priv->cnc);
    if (cnc != NULL) {
      /* deallocate statement */
	    gchar *sql;
	    PGresult *pg_res;

	    sql = g_strdup_printf ("DEALLOCATE %s", priv->prep_name);
	    pg_res = _gda_postgres_PQexec_wrap (cnc, priv->pconn, sql);
	    g_free (sql);
	    if (pg_res)
		    PQclear (pg_res);
      g_object_unref (cnc);
    }
    priv->deallocated = TRUE;
  }
	/* free memory */
	g_clear_pointer (&priv->prep_name, g_free);

	/* chain to parent class */
	G_OBJECT_CLASS (gda_postgres_pstmt_parent_class)->dispose (object);
}
static GstGLContext *
_get_gl_context_for_thread_unlocked (GstGLDisplay * display, GThread * thread)
{
  GstGLContext *context = NULL;
  GList *prev = NULL, *l = display->priv->contexts;

  while (l) {
    GWeakRef *ref = l->data;
    GThread *context_thread;

    context = g_weak_ref_get (ref);
    if (!context) {
      /* remove dead contexts */
      g_weak_ref_clear (l->data);
      display->priv->contexts = g_list_delete_link (display->priv->contexts, l);
      l = prev ? prev->next : display->priv->contexts;
      continue;
    }

    context_thread = gst_gl_context_get_thread (context);
    if (thread != NULL && thread == context_thread) {
      g_thread_unref (context_thread);
      gst_object_unref (context);
      prev = l;
      l = l->next;
      continue;
    }

    if (context_thread)
      g_thread_unref (context_thread);
    return context;
  }

  return NULL;
}
Beispiel #13
0
/**
 * gst_gl_window_get_context:
 * @window: a #GstGLWindow
 *
 * Returns: (transfer full): the #GstGLContext associated with this @window
 *
 * Since: 1.4
 */
GstGLContext *
gst_gl_window_get_context (GstGLWindow * window)
{
  g_return_val_if_fail (GST_IS_GL_WINDOW (window), NULL);

  return (GstGLContext *) g_weak_ref_get (&window->context_ref);
}
Beispiel #14
0
static gboolean
object_in_bag (CamelObjectBag *bag,
               gpointer object)
{
	gconstpointer key;
	ObjRef *ref;
	GObject *obj2;

	key = g_hash_table_lookup (bag->key_table, object);
	if (key == NULL)
		return FALSE;

	ref = g_hash_table_lookup (bag->object_table, key);
	if (ref == NULL)
		return FALSE;

	obj2 = g_weak_ref_get (&ref->ref);
	if (obj2 == NULL) {
		/* Remove stale reference to dead object. */
		g_hash_table_remove (bag->key_table, object);
		g_hash_table_remove (bag->object_table, key);
	} else {
		g_object_unref (obj2);
	}

	return obj2 == object;
}
Beispiel #15
0
static GSource *
nice_output_stream_create_source (GPollableOutputStream *stream,
    GCancellable *cancellable)
{
  NiceOutputStreamPrivate *priv = NICE_OUTPUT_STREAM (stream)->priv;
  GSource *component_source = NULL;
  NiceComponent *component = NULL;
  NiceStream *_stream = NULL;
  NiceAgent *agent;  /* owned */

  component_source = g_pollable_source_new (G_OBJECT (stream));

  if (cancellable) {
    GSource *cancellable_source = g_cancellable_source_new (cancellable);

    g_source_set_dummy_callback (cancellable_source);
    g_source_add_child_source (component_source, cancellable_source);
    g_source_unref (cancellable_source);
  }

  /* Closed streams cannot have sources. */
  if (g_output_stream_is_closed (G_OUTPUT_STREAM (stream)))
    return component_source;

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&priv->agent_ref);
  if (agent == NULL)
    return component_source;

  agent_lock ();

  /* Grab the socket for this component. */
  if (!agent_find_component (agent, priv->stream_id, priv->component_id,
          &_stream, &component)) {
    g_warning ("Could not find component %u in stream %u", priv->component_id,
        priv->stream_id);
    goto done;
  }

   if (component->tcp_writable_cancellable) {
    GSource *cancellable_source =
        g_cancellable_source_new (component->tcp_writable_cancellable);

    g_source_set_dummy_callback (cancellable_source);
    g_source_add_child_source (component_source, cancellable_source);
    g_source_unref (cancellable_source);
  }

done:
  agent_unlock ();

  g_object_unref (agent);

  return component_source;
}
Beispiel #16
0
/**
 * gda_pstmt_get_gda_statement:
 * @pstmt: a #GdaPStmt object
 *
 * Get a pointer to the #GdaStatement which led to the creation of this prepared statement.
 * 
 * Note: if that statement has been modified since the creation of @pstmt, then this method
 * will return %NULL
 *
 * Returns: (transfer full): the #GdaStatement
 */
GdaStatement *
gda_pstmt_get_gda_statement (GdaPStmt *pstmt)
{
	g_return_val_if_fail (GDA_IS_PSTMT (pstmt), NULL);
	GdaPStmtPrivate *priv = gda_pstmt_get_instance_private (pstmt);
	g_rec_mutex_lock (& priv->mutex);
	GdaStatement *stmt;
	stmt = g_weak_ref_get (& priv->gda_stmt_ref);
	g_rec_mutex_unlock (& priv->mutex);
	return stmt;
}
Beispiel #17
0
static gboolean
nice_input_stream_is_readable (GPollableInputStream *stream)
{
  NiceInputStreamPrivate *priv = NICE_INPUT_STREAM (stream)->priv;
  Component *component = NULL;
  Stream *_stream = NULL;
  gboolean retval = FALSE;
  GSList *i;
  NiceAgent *agent;  /* owned */

  /* Closed streams are not readable. */
  if (g_input_stream_is_closed (G_INPUT_STREAM (stream)))
    return FALSE;

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&priv->agent_ref);
  if (agent == NULL)
    return FALSE;

  agent_lock (agent);

  if (!agent_find_component (agent, priv->stream_id, priv->component_id,
          &_stream, &component)) {
    g_warning ("Could not find component %u in stream %u", priv->component_id,
        priv->stream_id);
    goto done;
  }

  /* If it’s a reliable agent, see if there’s any pending data in the pseudo-TCP
   * buffer. */
  if (agent->reliable &&
      pseudo_tcp_socket_get_available_bytes (component->tcp) > 0) {
    retval = TRUE;
    goto done;
  }

  /* Check whether any of the component’s FDs are pollable. */
  for (i = component->socket_sources; i != NULL; i = i->next) {
    SocketSource *socket_source = i->data;
    NiceSocket *nicesock = socket_source->socket;

    if (g_socket_condition_check (nicesock->fileno, G_IO_IN) != 0) {
      retval = TRUE;
      break;
    }
  }

done:
  agent_unlock (agent);

  g_object_unref (agent);

  return retval;
}
Beispiel #18
0
/**
 * gda_pstmt_get_gda_statement:
 * @pstmt: a #GdaPStmt object
 *
 * Get a pointer to the #GdaStatement which led to the creation of this prepared statement.
 * 
 * Note: if that statement has been modified since the creation of @pstmt, then this method
 * will return %NULL
 *
 * Returns: (transfer none): the #GdaStatement
 */
GdaStatement *
gda_pstmt_get_gda_statement (GdaPStmt *pstmt)
{
	g_return_val_if_fail (GDA_IS_PSTMT (pstmt), NULL);
	g_rec_mutex_lock (& pstmt->priv->mutex);
	GdaStatement *stmt;
	stmt = g_weak_ref_get (& pstmt->priv->gda_stmt_ref);
	if (stmt)
		g_object_unref (stmt);
	g_rec_mutex_unlock (& pstmt->priv->mutex);
	return stmt;
}
Beispiel #19
0
static void
gimp_operation_tool_relink_chains (GimpOperationTool *op_tool)
{
  GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (op_tool);
  GObject        *options_gui = g_weak_ref_get (&op_tool->options_gui_ref);
  GList          *chains;

  g_return_if_fail (options_gui != NULL);

  chains = g_object_get_data (options_gui, "chains");

  while (chains)
    {
      GimpChainButton *chain = chains->data;

      if (g_object_get_data (G_OBJECT (chain), "was-active"))
        {
          const gchar *name_x    = g_object_get_data (chains->data, "x-property");
          const gchar *name_y    = g_object_get_data (chains->data, "y-property");
          const gchar *names[2]  = { name_x, name_y };
          GValue       values[2] = { G_VALUE_INIT, G_VALUE_INIT };
          GValue       double_x  = G_VALUE_INIT;
          GValue       double_y  = G_VALUE_INIT;

          g_object_getv (filter_tool->config, 2, names, values);

          g_value_init (&double_x, G_TYPE_DOUBLE);
          g_value_init (&double_y, G_TYPE_DOUBLE);

          if (g_value_transform (&values[0], &double_x) &&
              g_value_transform (&values[1], &double_y) &&
              g_value_get_double (&double_x) ==
              g_value_get_double (&double_y))
            {
              gimp_chain_button_set_active (chain, TRUE);

              g_signal_emit_by_name (chain, "toggled");
            }

          g_value_unset (&double_x);
          g_value_unset (&double_y);
          g_value_unset (&values[0]);
          g_value_unset (&values[1]);

          g_object_set_data (G_OBJECT (chain), "was-active", NULL);
        }

      chains = chains->next;
    }

  g_object_unref (options_gui);
}
Beispiel #20
0
static void
gda_web_pstmt_dispose (GObject *object)
{
	GdaWebPStmt *pstmt = (GdaWebPStmt *) object;

	g_return_if_fail (GDA_IS_PSTMT (pstmt));
  GdaWebPStmtPrivate *priv = gda_web_pstmt_get_instance_private (pstmt);

	if (priv->pstmt_hash) {
    GdaConnection *cnc = NULL;
		WebConnectionData *cdata;
    cnc = g_weak_ref_get (&priv->cnc);
    if (cnc != NULL) {
		  cdata = (WebConnectionData*) gda_connection_internal_get_provider_data_error (cnc, NULL);
		  if (!cdata)
			  goto next;

		  /* send command to deallocate prepared statement */
		  xmlDocPtr doc;
		  xmlNodePtr root, cmdnode;
		  gchar *token;
		  doc = xmlNewDoc (BAD_CAST "1.0");
		  root = xmlNewNode (NULL, BAD_CAST "request");
		  xmlDocSetRootElement (doc, root);
		  token = _gda_web_compute_token (cdata);
		  xmlNewChild (root, NULL, BAD_CAST "token", BAD_CAST token);
		  g_free (token);
		  cmdnode = xmlNewChild (root, NULL, BAD_CAST "cmd", BAD_CAST "UNPREPARE");
		  xmlNewChild (cmdnode, NULL, BAD_CAST "preparehash", BAD_CAST priv->pstmt_hash);

		  xmlChar *cmde;
		  xmlDocPtr replydoc;
		  int size;
		  gchar status;

		  xmlDocDumpMemory (doc, &cmde, &size);
		  xmlFreeDoc (doc);
		  replydoc = _gda_web_send_message_to_frontend (cnc, cdata, MESSAGE_UNPREPARE, (gchar*) cmde,
							        cdata->key, &status);
		  xmlFree (cmde);
		  if (replydoc)
			  xmlFreeDoc (replydoc);
    }
		
	next:
		/* free memory */
		g_free (priv->pstmt_hash);
	}

	/* chain to parent class */
	G_OBJECT_CLASS (gda_web_pstmt_parent_class)->finalize (object);
}
Beispiel #21
0
static gboolean
on_idle_notify (gpointer user_data)
{
  BtNotifyIdleData *data = (BtNotifyIdleData *) user_data;
  gpointer weak_data = g_weak_ref_get (&data->user_data);

  if (weak_data) {
    data->func (data->object, data->pspec, weak_data);
    g_object_unref (weak_data);
  }
  g_weak_ref_clear (&data->user_data);
  g_slice_free (BtNotifyIdleData, data);
  return FALSE;
}
Beispiel #22
0
static void mega_filesystem_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
  MegaFilesystem* filesystem = MEGA_FILESYSTEM(object);
  MegaFilesystemPrivate* priv = filesystem->priv;

  switch (property_id)
  {
    case PROP_SESSION:
      g_value_take_object(value, g_weak_ref_get(&priv->session));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
  }
}
Beispiel #23
0
/**
 * gda_pstmt_copy_contents:
 * @src: a #GdaPStmt object
 * @dest: a #GdaPStmt object
 *
 * Copies @src's data to @dest 
 */
void
gda_pstmt_copy_contents (GdaPStmt *src, GdaPStmt *dest)
{
	GSList *list;
	g_return_if_fail (GDA_IS_PSTMT (src));
	g_return_if_fail (GDA_IS_PSTMT (dest));
	GdaPStmtPrivate *priv = gda_pstmt_get_instance_private (src);
	GdaPStmtPrivate *dpriv = gda_pstmt_get_instance_private (dest);

	g_rec_mutex_lock (& priv->mutex);
	g_rec_mutex_lock (& dpriv->mutex);

	g_free (dpriv->sql);
	dpriv->sql = NULL;
	if (priv->sql)
		dpriv->sql = g_strdup (priv->sql);
	if (dpriv->param_ids) {
		g_slist_free_full (dpriv->param_ids, (GDestroyNotify) g_free);
		dpriv->param_ids = NULL;
	}
	for (list = priv->param_ids; list; list = list->next)
		dpriv->param_ids = g_slist_append (dpriv->param_ids, g_strdup ((gchar *) list->data));
	dpriv->ncols = priv->ncols;
	if (dpriv->types != NULL) {
		g_free (dpriv->types);
	}
	dpriv->types = NULL;
	if (priv->types) {
		dpriv->types = g_new (GType, dpriv->ncols);
		memcpy (dpriv->types, priv->types, sizeof (GType) * dpriv->ncols); /* Flawfinder: ignore */
	}
	if (priv->tmpl_columns) {
		GSList *list;
		for (list = priv->tmpl_columns; list; list = list->next)
			dpriv->tmpl_columns = g_slist_append (dpriv->tmpl_columns,
							     gda_column_copy (GDA_COLUMN (list->data)));
	}
	GdaStatement *stmt;
	stmt = g_weak_ref_get (& priv->gda_stmt_ref);
	if (stmt) {
		gda_pstmt_set_gda_statement (dest, stmt);
		g_object_unref (stmt);
	}

	g_rec_mutex_unlock (& priv->mutex);
	g_rec_mutex_unlock (& dpriv->mutex);

}
static gboolean signal_peer_certificate_received(GWeakRef *ref)
{
    GstErDtlsDec *self;

    self = g_weak_ref_get(ref);
    g_weak_ref_clear(ref);
    g_free(ref);
    ref = NULL;

    if (self) {
        g_object_notify_by_pspec(G_OBJECT(self), properties[PROP_PEER_PEM]);
        g_object_unref(self);
        self = NULL;
    }

    return FALSE;
}
Beispiel #25
0
/**
 * gda_pstmt_copy_contents:
 * @src: a #GdaPStmt object
 * @dest: a #GdaPStmt object
 *
 * Copies @src's data to @dest 
 */
void
gda_pstmt_copy_contents (GdaPStmt *src, GdaPStmt *dest)
{
	GSList *list;
	g_return_if_fail (GDA_IS_PSTMT (src));
	g_return_if_fail (GDA_IS_PSTMT (dest));

	g_rec_mutex_lock (& src->priv->mutex);
	g_rec_mutex_lock (& dest->priv->mutex);

	g_free (dest->sql);
	dest->sql = NULL;
	if (src->sql)
		dest->sql = g_strdup (src->sql);
	if (dest->param_ids) {
		g_slist_foreach (dest->param_ids, (GFunc) g_free, NULL);
		g_slist_free (dest->param_ids);
		dest->param_ids = NULL;
	}
	for (list = src->param_ids; list; list = list->next) 
		dest->param_ids = g_slist_append (dest->param_ids, g_strdup ((gchar *) list->data));
	dest->ncols = src->ncols;

	g_free (dest->types);
	dest->types = NULL;
	if (src->types) {
		dest->types = g_new (GType, dest->ncols);
		memcpy (dest->types, src->types, sizeof (GType) * dest->ncols); /* Flawfinder: ignore */
	}
	if (src->tmpl_columns) {
		GSList *list;
		for (list = src->tmpl_columns; list; list = list->next) 
			dest->tmpl_columns = g_slist_append (dest->tmpl_columns, 
							     gda_column_copy (GDA_COLUMN (list->data)));
	}
	GdaStatement *stmt;
	stmt = g_weak_ref_get (& src->priv->gda_stmt_ref);
	if (stmt) {
		gda_pstmt_set_gda_statement (dest, stmt);
		g_object_unref (stmt);
	}

	g_rec_mutex_unlock (& src->priv->mutex);
	g_rec_mutex_unlock (& dest->priv->mutex);

}
Beispiel #26
0
static void
pango_core_text_font_finalize (GObject *object)
{
  PangoCoreTextFont *ctfont = (PangoCoreTextFont *)object;
  PangoCoreTextFontPrivate *priv = ctfont->priv;
  PangoCoreTextFontMap* fontmap = g_weak_ref_get ((GWeakRef *)&priv->fontmap);
  if (fontmap)
    {
      g_weak_ref_clear ((GWeakRef *)&priv->fontmap);
      g_object_unref (fontmap);
    }

  if (priv->coverage)
    pango_coverage_unref (priv->coverage);

  G_OBJECT_CLASS (pango_core_text_font_parent_class)->finalize (object);
}
static void
media_unprepared (GstRTSPMedia * media, GWeakRef * ref)
{
  GstRTSPMediaFactory *factory = g_weak_ref_get (ref);
  GstRTSPMediaFactoryPrivate *priv;

  if (!factory)
    return;

  priv = factory->priv;

  g_mutex_lock (&priv->medias_lock);
  g_hash_table_foreach_remove (priv->medias, (GHRFunc) compare_media, media);
  g_mutex_unlock (&priv->medias_lock);

  g_object_unref (factory);
}
Beispiel #28
0
/*
 * Get length request
 */
static glong
gda_sqlite_blob_op_get_length (GdaBlobOp *op)
{
	GdaSqliteBlobOp *bop;
	int len;

	g_return_val_if_fail (GDA_IS_SQLITE_BLOB_OP (op), -1);
	bop = GDA_SQLITE_BLOB_OP (op);
  GdaSqliteBlobOpPrivate *priv = gda_sqlite_blob_op_get_instance_private (bop);
	g_return_val_if_fail (priv->sblob, -1);
	GdaSqliteProvider *prov = g_weak_ref_get (&priv->provider);
	g_return_val_if_fail (prov != NULL, -1);

	len = SQLITE3_CALL (prov, sqlite3_blob_bytes) (priv->sblob);
	g_object_unref (prov);
	return len >= 0 ? len : 0;
}
Beispiel #29
0
static gboolean
nice_output_stream_is_writable (GPollableOutputStream *stream)
{
  NiceOutputStreamPrivate *priv = NICE_OUTPUT_STREAM (stream)->priv;
  NiceComponent *component = NULL;
  NiceStream *_stream = NULL;
  gboolean retval = FALSE;
  NiceAgent *agent;  /* owned */

  /* Closed streams are not writeable. */
  if (g_output_stream_is_closed (G_OUTPUT_STREAM (stream)))
    return FALSE;

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&priv->agent_ref);
  if (agent == NULL)
    return FALSE;

  agent_lock ();

  if (!agent_find_component (agent, priv->stream_id, priv->component_id,
          &_stream, &component)) {
    g_warning ("Could not find component %u in stream %u", priv->component_id,
        priv->stream_id);
    goto done;
  }
  if (component->selected_pair.local != NULL) {
    NiceSocket *sockptr = component->selected_pair.local->sockptr;

    /* If it’s a reliable agent, see if there’s any space in the pseudo-TCP
     * output buffer. */
    if (!nice_socket_is_reliable (sockptr)) {
      retval = pseudo_tcp_socket_can_send (component->tcp);
    } else {
      retval = (g_socket_condition_check (sockptr->fileno, G_IO_OUT) != 0);
    }
  }

done:
  agent_unlock ();

  g_object_unref (agent);

  return retval;
}
Beispiel #30
0
/* Properly destroy an ObjRef as it's freed from the hash table */
static void
wref_free_func (gpointer p)
{
	ObjRef *ref = p;
	GObject *obj = g_weak_ref_get (&ref->ref);

	if (obj) {
		/* The object is being removed from the bag while it's
		 * still alive, e.g. by camel_object_bag_remove()
		 * or camel_object_bag_destroy(). Drop the weak_ref. */
		g_object_weak_unref (
			obj, (GWeakNotify) object_bag_notify,
			ref->bag);
		g_object_unref (obj);
	}
	g_weak_ref_clear (&ref->ref);
	g_slice_free (ObjRef, ref);
}