void
_ostree_static_delta_part_execute_async (OstreeRepo      *repo,
                                         GVariant        *header,
                                         GVariant        *part,
                                         GCancellable    *cancellable,
                                         GAsyncReadyCallback  callback,
                                         gpointer         user_data)
{
  StaticDeltaPartExecuteAsyncData *asyncdata;

  asyncdata = g_new0 (StaticDeltaPartExecuteAsyncData, 1);
  asyncdata->repo = g_object_ref (repo);
  asyncdata->header = g_variant_ref (header);
  asyncdata->part = g_variant_ref (part);
  asyncdata->cancellable = cancellable ? g_object_ref (cancellable) : NULL;

  asyncdata->result = g_simple_async_result_new ((GObject*) repo,
                                                 callback, user_data,
                                                 _ostree_static_delta_part_execute_async);

  g_simple_async_result_set_op_res_gpointer (asyncdata->result, asyncdata,
                                             static_delta_part_execute_async_data_free);
  g_simple_async_result_run_in_thread (asyncdata->result, static_delta_part_execute_thread, G_PRIORITY_DEFAULT, cancellable);
  g_object_unref (asyncdata->result);
}
Example #2
0
static gboolean
set_invocation (Realms *realms,
                GDBusMethodInvocation *invocation,
                const gchar *op,
                const gchar *name,
                GVariant *creds,
                GVariant *options)
{
  if (realms->op_invocation == NULL)
    {
      realms->op_invocation = invocation;
      realms->op = op;
      realms->op_name = g_strdup (name);
      realms->op_creds = g_variant_ref (creds);
      realms->op_options = g_variant_ref (options);
      realms->op_id = g_strdup_printf ("cockpitd-%u", realms->next_op_id++);
      realms->op_cancelled = FALSE;
      cockpit_realms_set_busy (COCKPIT_REALMS (realms),
                               g_variant_new ("(ss)", op, name));
      g_string_assign (realms->diagnostics, "");
      return TRUE;
    }
  else
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR,
                                             COCKPIT_ERROR_FAILED,
                                             "Busy");
      return FALSE;
    }
}
static gboolean
on_manager_handle_add_account (GoaManager             *manager,
                               GDBusMethodInvocation  *invocation,
                               const gchar            *provider_type,
                               const gchar            *identity,
                               const gchar            *presentation_identity,
                               GVariant               *credentials,
                               GVariant               *details,
                               gpointer                user_data)
{
  GoaDaemon *daemon = GOA_DAEMON (user_data);
  AddAccountData *data;

  data = g_slice_new0 (AddAccountData);
  data->daemon = g_object_ref (daemon);
  data->manager = g_object_ref (manager);
  data->invocation = g_object_ref (invocation);
  data->provider_type = g_strdup (provider_type);
  data->identity = g_strdup (identity);
  data->presentation_identity = g_strdup (presentation_identity);
  data->credentials = g_variant_ref (credentials);
  data->details = g_variant_ref (details);

  goa_provider_get_all (get_all_providers_cb, data);

  return TRUE; /* invocation was handled */
}
Example #4
0
static void
extract_accel_from_menu_item(GMenuModel    * model,
                             gint            item,
                             GActionMap    * action_map,
                             GtkAccelGroup * accel_group)
{
    GMenuAttributeIter *iter;
    const gchar *key;
    GVariant *value;
    const gchar *accel = NULL;
    const gchar *action = NULL;
    GVariant *target = NULL;

    iter = g_menu_model_iterate_item_attributes(model, item);
    while (g_menu_attribute_iter_get_next(iter, &key, &value)) {
        if (g_str_equal(key, "action")
            && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING))
            action = g_variant_get_string(value, NULL);
        else if (g_str_equal(key, "accel")
                 && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING))
            accel = g_variant_get_string(value, NULL);
        else if (g_str_equal(key, "target"))
            target = g_variant_ref(value);
        g_variant_unref(value);
    }
    g_object_unref(iter);

    if (accel && action) {
        guint accel_key;
        GdkModifierType accel_mods;
        AccelInfo *info;
        const gchar *basename;
        GClosure *closure;

        gtk_accelerator_parse(accel, &accel_key, &accel_mods);
        basename = strchr(action, '.');
        basename = basename ? basename + 1 : action;
        info = g_new(AccelInfo, 1);
        info->action = g_action_map_lookup_action(action_map, basename);
        info->parameter = target ? g_variant_ref(target) : NULL;
        closure = g_cclosure_new(G_CALLBACK(accel_activate), info,
                                 (GClosureNotify) accel_info_free);
        gtk_accel_group_connect(accel_group, accel_key, accel_mods, 0,
                                closure);
    }

    if (target)
        g_variant_unref(target);
}
Example #5
0
// Simple wrapper for a common D-Bus pattern.
GVariant * g_dbus_simple_send(GDBusConnection *bus, GDBusMessage *msg, const gchar *type)
{
    GDBusMessage *reply;
    GVariant *body;
    gchar *fmt;

    if (!(reply = g_dbus_send(bus, msg, 0, -1, 0, 0, 0))) {
        g_object_unref(msg);
        return NULL;
    }

    body  = g_dbus_message_get_body(reply);
    fmt   = g_dbus_message_print(reply, 0);

    g_variant_ref(body);

    if (g_strcmp0(g_variant_type_peek_string(g_variant_get_type(body)), type) != 0) {
        g_message("body type %s does not match expected type %s, message: %s",
                  g_variant_type_peek_string(g_variant_get_type(body)),
                  type,
                  fmt);
        g_variant_unref(body);

        // return error
        body = NULL;
    }

    g_free(fmt);
    g_object_unref(reply);
    g_object_unref(msg);
    return body;
}
static gboolean
emit_notifications_in_idle (gpointer user_data)
{
  GObject *object = G_OBJECT (user_data);
  GDBusConnection *connection;
  const gchar *path;
  GHashTable *notification_queue;
  GHashTableIter iter;
  const gchar *property_name;
  GVariant *value;
  GVariantBuilder *builder;
  GVariantBuilder *invalidated_builder;
  GHashTable *pvc;
  gboolean has_changes;

  notification_queue = g_object_get_data (object, "gdbus-codegen-notification-queue");
  path = g_object_get_data (object, "gdbus-codegen-path");
  connection = g_object_get_data (object, "gdbus-codegen-connection");
  pvc = g_object_get_data (object, "gdbus-codegen-pvc");
  g_assert (notification_queue != NULL && path != NULL && connection != NULL && pvc != NULL);

  builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
  invalidated_builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
  g_hash_table_iter_init (&iter, notification_queue);
  has_changes = FALSE;
  while (g_hash_table_iter_next (&iter, (gpointer) &property_name, (gpointer) &value))
    {
      GVariant *cached_value;
      cached_value = g_hash_table_lookup (pvc, property_name);
      if (cached_value == NULL || !g_variant_equal (cached_value, value))
	{
	  g_hash_table_insert (pvc, (gpointer) property_name, (gpointer) g_variant_ref (value));
          g_variant_builder_add (builder, "{sv}", property_name, value);
	  has_changes = TRUE;
	}
    }

  if (has_changes)
    {
      g_dbus_connection_emit_signal (connection,
				     NULL,
				     path,
                                     "org.freedesktop.DBus.Properties",
                                     "PropertiesChanged",
                                     g_variant_new ("(sa{sv}as)",
                                                    "org.gnome.evolution.dataserver.CalendarFactory",
						    builder,
						    invalidated_builder),
				     NULL);
    }
  else
    {
      g_variant_builder_unref (builder);
      g_variant_builder_unref (invalidated_builder);
    }

  g_hash_table_remove_all (notification_queue);
  g_object_set_data (object, "gdbus-codegen-notification-idle-id", GUINT_TO_POINTER (0));
  return FALSE;
}
Example #7
0
/**
 * workman_attribute_get_value:
 *
 * Returns: (transfer full): the attribute %G_VARIANT_TYPE_MAYBE value
 */
GVariant *workman_attribute_get_value(WorkmanAttribute *attr)
{
    if (!attr->priv->value)
        return NULL;

    return g_variant_ref(attr->priv->value);
}
static void
vpn_export_get_secrets_cb (GObject *object,
                           GAsyncResult *result,
                           gpointer user_data)
{
	NMConnection *tmp;
	GVariant *secrets;
	GError *error = NULL;

	secrets = nm_remote_connection_get_secrets_finish (NM_REMOTE_CONNECTION (object),
	                                                   result, &error);

	/* We don't really care about errors; if the user couldn't authenticate
	 * then just let them export everything except secrets.  Duplicate the
	 * connection so that we don't let secrets sit around in the original
	 * one.
	 */
	tmp = nm_simple_connection_new_clone (NM_CONNECTION (object));
	g_assert (tmp);
	if (secrets)
		nm_connection_update_secrets (tmp, NM_SETTING_VPN_SETTING_NAME, secrets, NULL);
	vpn_export (tmp);
	g_object_unref (tmp);
	if (secrets)
		g_variant_ref (secrets);
	g_clear_error (&error);
}
Example #9
0
static void
on_kerberos_proxy_ready (GObject *object,
                         GAsyncResult *res,
                         gpointer user_data)
{
  RealmData *data = (RealmData *)user_data;

  GError *error = NULL;
  GDBusProxy *proxy = g_dbus_proxy_new_for_bus_finish (res, &error);

  if (error)
    {
      g_warning ("Unable to create realmd KerberosMembership proxy: %s", error->message);
      g_error_free (error);
    }

  data->details = get_realm_details (data->realmd_object, proxy);
  g_variant_ref (data->details);
  g_clear_object (&proxy);

  update_realm_configured (data);

  data->valid = TRUE;
  mark_realm_ready (data);
}
Example #10
0
static void
add_accelerators_from_menu_item (GtkWindow      *window,
				 GtkAccelGroup  *accel_group,
				 GMenuModel     *model,
				 int             item)
{
	GMenuAttributeIter	*iter;
	const char		*key;
	GVariant		*value;
	const char		*accel = NULL;
	const char		*action = NULL;
	GVariant		*target = NULL;

	iter = g_menu_model_iterate_item_attributes (model, item);
	while (g_menu_attribute_iter_get_next (iter, &key, &value)) {
		if (g_str_equal (key, "action") && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
			action = g_variant_get_string (value, NULL);
		else if (g_str_equal (key, "accel") && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
			accel = g_variant_get_string (value, NULL);
		else if (g_str_equal (key, "target"))
			target = g_variant_ref (value);
		g_variant_unref (value);
	}
	g_object_unref (iter);

	_gtk_window_add_accelerator_for_action (window,
						accel_group,
						action,
						accel,
						target);

	if (target != NULL)
		g_variant_unref (target);
}
static void _presence_cb_response_error(OCDoHandle handle, int ret_val)
{
	FN_CALL;
	int ret;
	OCDoHandle handle2;
	GVariant *value, *value2;

	value = g_variant_new("(iusiis)", ret_val, 0, IC_STR_NULL, IOTCON_CONNECTIVITY_ALL,
			IOTCON_PRESENCE_RESOURCE_CREATED, IC_STR_NULL);
	value2 = g_variant_ref(value);

	ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_PRESENCE,
			ICD_POINTER_TO_INT64(handle), value);
	if (IOTCON_ERROR_NONE != ret)
		ERR("_ocprocess_response_signal() Fail(%d)", ret);

	handle2 = icd_ioty_presence_table_get_handle(ICD_MULTICAST_ADDRESS);
	if (handle2 && (handle2 != handle)) {
		ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_PRESENCE,
				ICD_POINTER_TO_INT64(handle), value2);
		if (IOTCON_ERROR_NONE != ret)
			ERR("_ocprocess_response_signal() Fail(%d)", ret);
	} else {
		g_variant_unref(value2);
	}
}
Example #12
0
void scp_tree_data_assign_pointer(ScpTreeData *data, GType type, gpointer ptr, gboolean copy)
{
	switch (scp_tree_data_get_fundamental_type(type))
	{
		case G_TYPE_STRING :
		{
			data->v_pointer = copy ? g_strdup((const char *) ptr) : ptr;
			break;
		}
		case G_TYPE_POINTER :
		{
			data->v_pointer = ptr;
			break;
		}
		case G_TYPE_OBJECT :
		{
			data->v_pointer = copy && ptr ? g_object_ref(ptr) : ptr;
			break;
		}
		case G_TYPE_BOXED :
		{
			data->v_pointer = copy && ptr ? g_boxed_copy(type, data->v_pointer) : ptr;
			break;
		}
	#if GLIB_CHECK_VERSION(2, 26, 0)
		case G_TYPE_VARIANT :
		{
			data->v_pointer = copy && ptr ? g_variant_ref(ptr) : ptr;
			break;
		}
	#endif
		default : scp_tree_data_warn_unsupported_type(G_STRFUNC, type);
	}
}
Example #13
0
static gboolean set_prop_handler(	GDBusConnection *connection,
					const gchar *sender,
					const gchar *object_path,
					const gchar *interface_name,
					const gchar *property_name,
					GVariant *value,
					GError **error,
					gpointer data )
{
	mpris *inst = data;

	if(g_strcmp0(property_name, "Fullscreen") == 0
	&& g_variant_get_boolean(value) != inst->gmpv_ctx->gui->fullscreen)
	{
		toggle_fullscreen(inst->gmpv_ctx);
	}
	else
	{
		g_hash_table_replace(	((mpris *) data)->base_prop_table,
					g_strdup(property_name),
					g_variant_ref(value) );
	}

	return TRUE; /* This function should always succeed */
}
Example #14
0
static GHashTable *
get_playing_song_info (GDBusProxy *mpris)
{
	GHashTable *properties;
	GVariant *prop;
	GVariant *metadata;
	GVariantIter iter;
	GVariant *value;
	char *key;
	GError *error = NULL;

	prop = g_dbus_proxy_call_sync (mpris,
				       "org.freedesktop.DBus.Properties.Get",
				       g_variant_new ("(ss)", "org.mpris.MediaPlayer2.Player", "Metadata"),
				       G_DBUS_CALL_FLAGS_NONE,
				       -1,
				       NULL,
				       &error);
	if (annoy (&error)) {
		return NULL;
	}

	g_variant_get (prop, "(v)", &metadata);

	properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);
	g_variant_iter_init (&iter, metadata);
	while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) {
		g_hash_table_insert (properties, g_strdup (key), g_variant_ref (value));
	}

	g_variant_unref (prop);
	return properties;
}
static void
_contact_lookup(GError *error, GHashTable *contact, gpointer data)
{
	char *tmp;
	GVariant *gtmp;
	struct _recipient_pack *pack = (struct _recipient_pack *)data;

	if (error) {
		g_warning("Error will trying to resolve number: (%d) %s",
			  error->code, error->message);
		ui_utils_error_message_from_gerror_show(VIEW_PTR(*pack->view),
			D_("Error will trying to resolve number."), error);
		return;
	}
	if (!contact ) {
		g_debug("No contact found");
		return;
	}

	tmp = phoneui_utils_contact_display_name_get(contact);
	if (tmp) {
		g_hash_table_insert(pack->recipient, "Name",
				    g_variant_ref_sink(g_variant_new_string(tmp)));
		free(tmp);
	}
	gtmp = g_hash_table_lookup(contact, "Photo");
	if (gtmp) {
		g_hash_table_insert(pack->recipient, "Photo", g_variant_ref(gtmp));
	}
	if (pack->view->layout_recipients) {
		elm_genlist_item_update(pack->glit);
	}
}
EosUpdateInfo *
eos_update_info_new (const gchar *checksum,
                     GVariant *commit,
                     const gchar *refspec,
                     const gchar *original_refspec,
                     const gchar * const *urls,
                     EosExtensions *extensions)
{
  EosUpdateInfo *info;

  g_return_val_if_fail (checksum != NULL, NULL);
  g_return_val_if_fail (commit != NULL, NULL);
  g_return_val_if_fail (refspec != NULL, NULL);
  g_return_val_if_fail (original_refspec != NULL, NULL);
  g_return_val_if_fail (EOS_IS_EXTENSIONS (extensions), NULL);

  info = g_object_new (EOS_TYPE_UPDATE_INFO, NULL);
  info->checksum = g_strdup (checksum);
  info->commit = g_variant_ref (commit);
  info->refspec = g_strdup (refspec);
  info->original_refspec = g_strdup (original_refspec);
  info->urls = g_strdupv ((gchar **) urls);
  info->extensions = g_object_ref (extensions);

  return info;
}
static void
save_file_done (GObject *source,
                GAsyncResult *result,
                gpointer data)
{
  g_autoptr(Request) request = data;
  guint response;
  GVariant *options;
  g_autoptr(GError) error = NULL;
  g_autoptr(GTask) task = NULL;

  if (!xdp_impl_file_chooser_call_save_file_finish (XDP_IMPL_FILE_CHOOSER (source),
                                                    &response,
                                                    &options,
                                                    result,
                                                    &error))
    {
      g_warning ("Backend call failed: %s", error->message);
    }

  g_object_set_data (G_OBJECT (request), "response", GINT_TO_POINTER (response));
  if (options)
    g_object_set_data_full (G_OBJECT (request), "options", g_variant_ref (options), (GDestroyNotify)g_variant_unref);

  task = g_task_new (NULL, NULL, NULL, NULL);
  g_task_set_task_data (task, g_object_ref (request), g_object_unref);
  g_task_run_in_thread (task, send_response_in_thread_func);
}
Example #18
0
/*
** DBus method call: "CrownChallenge"
*/
gboolean on_handle_crown_challenge ( Warfacebot *object,
									 GDBusMethodInvocation *invocation )
{
	if ( invalidated )
	{
		struct list *ml = session.wf.missions;

		GVariantBuilder *marr_builder;

		if ( marr != NULL )
			g_variant_unref ( marr );

		marr_builder = g_variant_builder_new ( G_VARIANT_TYPE ( "a(sssii)" ) );

		list_foreach ( ml, (f_list_callback) mlist_to_array, marr_builder );

		marr = g_variant_new ( "a(sssii)", marr_builder );

		g_variant_ref ( marr );

		g_variant_builder_unref ( marr_builder );

		invalidated = FALSE;
	}

	warfacebot_complete_crown_challenge ( object, invocation, marr );

	return TRUE;
}
Example #19
0
static gboolean
gum_store_module_address (const GumModuleDetails * details,
                          gpointer user_data)
{
  GumEnumerateExportsContext * ctx = user_data;
  GVariant * value;

  value = g_variant_new_uint64 (details->range->base_address);
  g_hash_table_insert (ctx->modules, g_strdup (details->name),
      g_variant_ref (value));
  g_hash_table_insert (ctx->modules, g_strdup (details->path),
      g_variant_ref (value));
  g_variant_unref (value);

  return TRUE;
}
/* < internal >
 * _g_dbus_method_invocation_new:
 * @sender: The bus name that invoked the method or %NULL if @connection is not a bus connection.
 * @object_path: The object path the method was invoked on.
 * @interface_name: The name of the D-Bus interface the method was invoked on.
 * @method_name: The name of the method that was invoked.
 * @method_info: Information about the method call or %NULL.
 * @connection: The #GDBusConnection the method was invoked on.
 * @message: The D-Bus message as a #GDBusMessage.
 * @parameters: The parameters as a #GVariant tuple.
 * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object().
 *
 * Creates a new #GDBusMethodInvocation object.
 *
 * Returns: A #GDBusMethodInvocation. Free with g_object_unref().
 *
 * Since: 2.26
 */
GDBusMethodInvocation *
_g_dbus_method_invocation_new (const gchar           *sender,
                               const gchar           *object_path,
                               const gchar           *interface_name,
                               const gchar           *method_name,
                               const GDBusMethodInfo *method_info,
                               GDBusConnection       *connection,
                               GDBusMessage          *message,
                               GVariant              *parameters,
                               gpointer               user_data)
{
  GDBusMethodInvocation *invocation;

  g_return_val_if_fail (sender == NULL || g_dbus_is_name (sender), NULL);
  g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
  g_return_val_if_fail (interface_name == NULL || g_dbus_is_interface_name (interface_name), NULL);
  g_return_val_if_fail (g_dbus_is_member_name (method_name), NULL);
  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
  g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
  g_return_val_if_fail (g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE), NULL);

  invocation = G_DBUS_METHOD_INVOCATION (g_object_new (G_TYPE_DBUS_METHOD_INVOCATION, NULL));
  invocation->sender = g_strdup (sender);
  invocation->object_path = g_strdup (object_path);
  invocation->interface_name = g_strdup (interface_name);
  invocation->method_name = g_strdup (method_name);
  invocation->method_info = g_dbus_method_info_ref ((GDBusMethodInfo *)method_info);
  invocation->connection = g_object_ref (connection);
  invocation->message = g_object_ref (message);
  invocation->parameters = g_variant_ref (parameters);
  invocation->user_data = user_data;

  return invocation;
}
Example #21
0
void abrt_p2_task_finish(AbrtP2Task *task,
            GVariant **result,
            gint32 *code,
            GError **error)
{
    if (   task->pv->p2t_status != ABRT_P2_TASK_STATUS_DONE
        && task->pv->p2t_status != ABRT_P2_TASK_STATUS_FAILED)
    {
        g_set_error(error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
                "Cannot finalize undone task");
        return;
    }

    ABRT_P2_TASK_VIRTUAL_FINISH(task, error);

    if (*error != NULL)
        return;

    if (task->pv->p2t_results)
        *result = g_variant_ref(task->pv->p2t_results);
    else
        *result = g_variant_new("a{sv}", NULL);

    *code = task->pv->p2t_code;
}
Example #22
0
/**
 * secret_prompt_perform_finish:
 * @self: a prompt
 * @result: the asynchronous result passed to the callback
 * @error: location to place an error on failure
 *
 * Complete asynchronous operation to run a prompt and perform the prompting.
 *
 * Returns a variant result if the prompt was completed and not dismissed. The
 * type of result depends on the action the prompt is completing, and is
 * defined in the Secret Service DBus API specification.
 *
 * Returns: (transfer full): %NULL if the prompt was dismissed or an error occurred,
 *          a variant result if the prompt was successful
 */
GVariant *
secret_prompt_perform_finish (SecretPrompt *self,
                              GAsyncResult *result,
                              GError **error)
{
	PerformClosure *closure;
	GSimpleAsyncResult *res;
	gchar *string;

	g_return_val_if_fail (SECRET_IS_PROMPT (self), NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);
	g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
	                                                      secret_prompt_perform), NULL);

	res = G_SIMPLE_ASYNC_RESULT (result);

	if (_secret_util_propagate_error (res, error))
		return NULL;

	closure = g_simple_async_result_get_op_res_gpointer (res);
	if (closure->result == NULL)
		return NULL;
	if (closure->return_type != NULL && !g_variant_is_of_type (closure->result, closure->return_type)) {
		string = g_variant_type_dup_string (closure->return_type);
		g_warning ("received unexpected result type %s from Completed signal instead of expected %s",
		           g_variant_get_type_string (closure->result), string);
		g_free (string);
		return NULL;
	}
	return g_variant_ref (closure->result);
}
Example #23
0
void Decoder::set_option(const char *id, GVariant *value)
{
	assert(value);
	g_variant_ref(value);
    _options_back[id] = value;
    _setted = true;
}
static GVariant *
g_simple_action_get_state (GAction *action)
{
  GSimpleAction *simple = G_SIMPLE_ACTION (action);

  return simple->priv->state ? g_variant_ref (simple->priv->state) : NULL;
}
static void
g_simple_action_set_state (GAction  *action,
                           GVariant *value)
{
  GSimpleAction *simple = G_SIMPLE_ACTION (action);

  g_return_if_fail (value != NULL);

  {
    const GVariantType *state_type;

    state_type = simple->priv->state ?
                   g_variant_get_type (simple->priv->state) : NULL;
    g_return_if_fail (state_type != NULL);
    g_return_if_fail (g_variant_is_of_type (value, state_type));
  }

  g_variant_ref_sink (value);

  if (!g_variant_equal (simple->priv->state, value))
    {
      if (simple->priv->state)
        g_variant_unref (simple->priv->state);

      simple->priv->state = g_variant_ref (value);

      g_object_notify (G_OBJECT (simple), "state");
    }

  g_variant_unref (value);
}
GVariant *
nm_dhcp4_config_get_options (NMDhcp4Config *self)
{
	g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL);

	return g_variant_ref (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options);
}
Example #27
0
static gboolean
gum_store_module_address (const gchar * name,
                          const GumMemoryRange * range,
                          const gchar * path,
                          gpointer user_data)
{
    GumEnumerateExportsContext * ctx = user_data;
    GVariant * value;

    value = g_variant_new_uint64 (range->base_address);
    g_hash_table_insert (ctx->modules, g_strdup (name), g_variant_ref (value));
    g_hash_table_insert (ctx->modules, g_strdup (path), g_variant_ref (value));
    g_variant_unref (value);

    return TRUE;
}
Example #28
0
static OlLyricSourceCandidate *
ol_lyric_source_candidate_new_with_variant (GVariant *dict)
{
  ol_log_func ();
  OlLyricSourceCandidate *candidate = NULL;
  GVariantIter *dictiter = NULL;
  gchar *key = NULL;
  gchar *title, *artist, *album, *comment, *sourceid;
  GVariant *downloadinfo = NULL;
  GVariant *value = NULL;
  title = artist = album = comment = sourceid = NULL;
  g_variant_get (dict, "a{sv}", &dictiter);
  while (g_variant_iter_loop (dictiter, "{sv}", &key, &value))
  {
    if (strcmp (key, "title") == 0 && title == NULL)
    {
      title = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "artist") == 0 && artist == NULL)
    {
      artist = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "album") == 0 && album == NULL)
    {
      album = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "comment") == 0 && comment == NULL)
    {
      comment = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "sourceid") == 0 && sourceid == NULL)
    {
      sourceid = g_variant_dup_string (value, NULL);
    }
    else if (strcmp (key, "downloadinfo") == 0 && downloadinfo == NULL)
    {
      downloadinfo = g_variant_ref (value);
    }
    else
    {
      ol_errorf ("Unknown candidate key: %s\n", key);
    }
  }
  g_variant_iter_free (dictiter);
  candidate = ol_lyric_source_candidate_new (title,
                                             artist,
                                             album,
                                             comment,
                                             sourceid,
                                             downloadinfo);
  g_free (title);
  g_free (artist);
  g_free (album);
  g_free (comment);
  g_free (sourceid);
  g_variant_unref (downloadinfo);
  return candidate;
}
Example #29
0
GtkTreeDataList *
_gtk_tree_data_list_node_copy (GtkTreeDataList *list,
                               GType            type)
{
  GtkTreeDataList *new_list;

  g_return_val_if_fail (list != NULL, NULL);
  
  new_list = _gtk_tree_data_list_alloc ();
  new_list->next = NULL;

  switch (get_fundamental_type (type))
    {
    case G_TYPE_BOOLEAN:
    case G_TYPE_CHAR:
    case G_TYPE_UCHAR:
    case G_TYPE_INT:
    case G_TYPE_UINT:
    case G_TYPE_LONG:
    case G_TYPE_ULONG:
    case G_TYPE_INT64:
    case G_TYPE_UINT64:
    case G_TYPE_ENUM:
    case G_TYPE_FLAGS:
    case G_TYPE_POINTER:
    case G_TYPE_FLOAT:
    case G_TYPE_DOUBLE:
      new_list->data = list->data;
      break;
    case G_TYPE_STRING:
      new_list->data.v_pointer = g_strdup (list->data.v_pointer);
      break;
    case G_TYPE_OBJECT:
    case G_TYPE_INTERFACE:
      new_list->data.v_pointer = list->data.v_pointer;
      if (new_list->data.v_pointer)
	g_object_ref (new_list->data.v_pointer);
      break;
    case G_TYPE_BOXED:
      if (list->data.v_pointer)
	new_list->data.v_pointer = g_boxed_copy (type, list->data.v_pointer);
      else
	new_list->data.v_pointer = NULL;
      break;
    case G_TYPE_VARIANT:
      if (list->data.v_pointer)
	new_list->data.v_pointer = g_variant_ref (list->data.v_pointer);
      else
	new_list->data.v_pointer = NULL;
      break;
    default:
      g_warning ("Unsupported node type (%s) copied.", g_type_name (type));
      break;
    }

  return new_list;
}
Example #30
0
/**
 * g_variant_get_child_value:
 * @value: a container #GVariant
 * @index_: the index of the child to fetch
 *
 * Reads a child item out of a container #GVariant instance.  This
 * includes variants, maybes, arrays, tuples and dictionary
 * entries.  It is an error to call this function on any other type of
 * #GVariant.
 *
 * It is an error if @index_ is greater than the number of child items
 * in the container.  See g_variant_n_children().
 *
 * The returned value is never floating.  You should free it with
 * g_variant_unref() when you're done with it.
 *
 * This function is O(1).
 *
 * Returns: (transfer full): the child at the specified index
 *
 * Since: 2.24
 **/
GVariant *
g_variant_get_child_value (GVariant *value,
                           gsize     index_)
{
  g_return_val_if_fail (index_ < g_variant_n_children (value), NULL);

  if (~g_atomic_int_get (&value->state) & STATE_SERIALISED)
    {
      g_variant_lock (value);

      if (~value->state & STATE_SERIALISED)
        {
          GVariant *child;

          child = g_variant_ref (value->contents.tree.children[index_]);
          g_variant_unlock (value);

          return child;
        }

      g_variant_unlock (value);
    }

  {
    GVariantSerialised serialised = {
      value->type_info,
      (gpointer) value->contents.serialised.data,
      value->size
    };
    GVariantSerialised s_child;
    GVariant *child;

    /* get the serialiser to extract the serialised data for the child
     * from the serialised data for the container
     */
    s_child = g_variant_serialised_get_child (serialised, index_);

    /* create a new serialised instance out of it */
    child = g_slice_new (GVariant);
#ifdef GSTREAMER_LITE
    if (child == NULL) {
      return NULL;
    }
#endif // GSTREAMER_LITE
    child->type_info = s_child.type_info;
    child->state = (value->state & STATE_TRUSTED) |
                   STATE_SERIALISED;
    child->size = s_child.size;
    child->ref_count = 1;
    child->contents.serialised.bytes =
      g_bytes_ref (value->contents.serialised.bytes);
    child->contents.serialised.data = s_child.data;

    return child;
  }
}