static void
packagekit_install_package_names_ready_cb (GObject      *source_object,
        GAsyncResult *res,
        gpointer      user_data)
{
    InstallerData   *idata = user_data;
    GDBusProxy      *proxy;
    GVariant        *values;
    GError          *error = NULL;
    FrErrorType  error_type = FR_ERROR_NONE;
    char            *error_message = NULL;

    proxy = G_DBUS_PROXY (source_object);
    values = g_dbus_proxy_call_finish (proxy, res, &error);
    if (values == NULL) {
        if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)
                || (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_DBUS_ERROR)
                    && (error->message != NULL)
                    && (strstr (error->message, "org.freedesktop.Packagekit.Modify.Cancelled") != NULL)))
        {
            error_type = FR_ERROR_STOPPED;
            error_message = NULL;
        }
        else {
            error_type = FR_ERROR_GENERIC;
            error_message = g_strdup_printf ("%s\n%s",
                                             _("There was an internal error trying to search for applications:"),
                                             error->message);
        }
        g_clear_error (&error);
    }

    package_installer_terminated (idata, error_type, error_message);

    g_free (error_message);
    if (values != NULL)
        g_variant_unref (values);
    g_object_unref (proxy);
}
Esempio n. 2
0
static guint
gtk_application_impl_dbus_inhibit (GtkApplicationImpl         *impl,
                                   GtkWindow                  *window,
                                   GtkApplicationInhibitFlags  flags,
                                   const gchar                *reason)
{
  GtkApplicationImplDBus *dbus = (GtkApplicationImplDBus *) impl;
  GVariant *res;
  GError *error = NULL;
  guint cookie;

  if (dbus->sm_proxy == NULL)
    return 0;

  res = g_dbus_proxy_call_sync (dbus->sm_proxy,
                                "Inhibit",
                                g_variant_new ("(s@usu)",
                                               dbus->app_id,
                                               window ? gtk_application_impl_dbus_get_window_system_id (dbus, window) : g_variant_new_uint32 (0),
                                               reason,
                                               flags),
                                G_DBUS_CALL_FLAGS_NONE,
                                G_MAXINT,
                                NULL,
                                &error);

 if (error)
    {
      g_warning ("Calling Inhibit failed: %s", error->message);
      g_error_free (error);
      return 0;
    }

  g_variant_get (res, "(u)", &cookie);
  g_variant_unref (res);

  return cookie;

}
gboolean
appendStringToVariantIfUnique (GVariant	  **variant,
			       const char *string)
{
    GVariantBuilder newVariantBuilder;
    FindItemInVariantData findItemData;

    memset (&findItemData, 0, sizeof (FindItemInVariantData));
    g_variant_builder_init (&newVariantBuilder, G_VARIANT_TYPE ("as"));

    findItemData.item = string;

    rebuildVariant  (&newVariantBuilder, *variant, findItemForVariantData, &findItemData);

    if (!findItemData.found)
	g_variant_builder_add (&newVariantBuilder, "s", string);

    g_variant_unref (*variant);
    *variant = g_variant_builder_end (&newVariantBuilder);

    return !findItemData.found;
}
Esempio n. 4
0
static GVariant *
go_conf_get (GOConfNode *node, gchar const *key, GVariantType const *t)
{
	GVariant *res = g_settings_get_value (node->settings, key);
	if (res == NULL) {
		d (g_warning ("Unable to load key '%s'", key));
		return NULL;
	}

	if (!g_variant_is_of_type (res, t)) {
		char *tstr = g_variant_type_dup_string (t);
		g_warning ("Expected `%s' got `%s' for key %s",
			   tstr,
			   g_variant_get_type_string (res),
			   key);
		g_free (tstr);
		g_variant_unref (res);
		return NULL;
	}

	return res;
}
static void hev_dbus_object_test_changed_handler(GObject *obj,
			const gchar *value, gpointer user_data)
{
	HevDBusInterfaceTest *self = HEV_DBUS_INTERFACE_TEST(user_data);
	HevDBusInterfaceTestPrivate *priv = HEV_DBUS_INTERFACE_TEST_GET_PRIVATE(self);
	GDBusConnection *connection = NULL;
	const gchar *object_path = NULL;
	GVariant *variant = NULL;

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	connection = g_dbus_interface_skeleton_get_connection(G_DBUS_INTERFACE_SKELETON(self));
	object_path = g_dbus_interface_skeleton_get_object_path(G_DBUS_INTERFACE_SKELETON(self));

	variant = g_variant_new("(s)", value);

	g_dbus_connection_emit_signal(connection, NULL, object_path,
				HEV_DBUS_INTERFACE_TEST_NAME, "Changed",
				variant, NULL);

	g_variant_unref(variant);
}
static void
request_password_session_process_cb (GObject *source,
    GAsyncResult *result,
    gpointer user_data)
{
  SignonAuthSession *session = (SignonAuthSession *) source;
  AuthContext *ctx = user_data;
  GVariant *variant;
  GError *error = NULL;

  variant = signon_auth_session_process_finish (session, result, &error);
  if (error != NULL)
    {
      DEBUG ("Error processing the session to request user's attention: %s",
          error->message);
      g_clear_error (&error);
    }

  g_variant_unref (variant);

  auth_context_done (ctx);
}
Esempio n. 7
0
/**
 * workman_attribute_set_value:
 * @attr: a #WorkmanAttribute
 * @value: (transfer floating): the attribute %G_VARIANT_TYPE_MAYBE value to set
 * @error: (allow-none): return location for a #GError, or %NULL
 *
 * Returns: %TRUE if the operation succeeded
 */
gboolean
workman_attribute_set_value(WorkmanAttribute *attr,
                            GVariant *value,
                            GError **error)
{
    g_return_val_if_fail(value != NULL, FALSE);

    if (attr->priv->value) {
        const GVariantType *old_type = g_variant_get_type(attr->priv->value);
        const GVariantType *new_type = g_variant_get_type(value);

        g_return_val_if_fail(g_variant_type_equal(old_type, new_type),
                             FALSE);

        g_variant_unref(attr->priv->value);
    }

    attr->priv->value = value;
    g_variant_ref_sink(attr->priv->value);

    return TRUE;
}
Esempio n. 8
0
static void
on_op_done (GObject *object,
            GAsyncResult *res,
            gpointer user_data)
{
  Realms *realms = REALMS (user_data);

  GError *error = NULL;
  GVariant *join_result = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), res, &error);

  if (error)
    end_invocation_take_gerror (realms, error);
  else
    {
      if (strcmp (realms->op, "Join") == 0)
        cockpit_realms_complete_join (COCKPIT_REALMS (realms), realms->op_invocation);
      else
        cockpit_realms_complete_leave (COCKPIT_REALMS (realms), realms->op_invocation);
      clear_invocation (realms);
      g_variant_unref (join_result);
    }
}
static void
delete_fingerprints (void)
{
        GDBusProxy *device;
        GVariant *result;

        if (manager == NULL) {
                create_manager ();
                if (manager == NULL)
                        return;
        }

        device = get_first_device ();
        if (device == NULL)
                return;

        result = g_dbus_proxy_call_sync (device, "DeleteEnrolledFingers", g_variant_new ("(s)", ""), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
        if (result)
                g_variant_unref (result);

        g_object_unref (device);
}
Esempio n. 10
0
static void
on_reload_cb (GObject      *source_object,
	      GAsyncResult *res,
	      gpointer      user_data)
{
	GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
	GVariant        *value;
	GError          *error = NULL;

	value = g_dbus_connection_call_finish (connection, res, &error);
	if (!value) {
		g_warning ("Failed to Reload: %s", error->message);
		g_error_free (error);
	}
	g_variant_unref (value);

	/* We did not open a window, so manually clear the startup
	 * notification. */
	gdk_notify_startup_complete ();

	ev_application_shutdown (EV_APP);
}
Esempio n. 11
0
static void
exred_addtoarchive_ready_cb (GObject      *source_object,
				  GAsyncResult *res,
				  gpointer      user_data)
{
	GDBusProxy *proxy;
	GVariant   *values;
	GError     *error = NULL;

	proxy = G_DBUS_PROXY (source_object);
	values = g_dbus_proxy_call_finish (proxy, res, &error);
	if (values == NULL) {
		g_error ("%s\n", error->message);
		g_clear_error (&error);
	}

	if (values != NULL)
		g_variant_unref (values);
	g_object_unref (proxy);

	g_main_loop_quit (loop);
}
Esempio n. 12
0
static gboolean
update_bus_environment (State        *state,
                        GCancellable *cancellable)
{
        GVariantBuilder      builder;
        GVariant            *reply = NULL;
        GError              *error = NULL;
        gboolean             environment_updated = FALSE;

        g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
        g_variant_builder_add (&builder, "{ss}", "DISPLAY", state->display_name);
        g_variant_builder_add (&builder, "{ss}", "XAUTHORITY", state->auth_file);

        reply = g_dbus_connection_call_sync (state->bus_connection,
                                             "org.freedesktop.DBus",
                                             "/org/freedesktop/DBus",
                                             "org.freedesktop.DBus",
                                             "UpdateActivationEnvironment",
                                             g_variant_new ("(@a{ss})",
                                                            g_variant_builder_end (&builder)),
                                             NULL,
                                             G_DBUS_CALL_FLAGS_NONE,
                                             -1, cancellable, &error);

        if (reply == NULL) {
                g_debug ("could not update activation environment: %s", error->message);
                goto out;
        }

        g_variant_unref (reply);

        environment_updated = TRUE;

out:
        g_clear_error (&error);

        return environment_updated;
}
Esempio n. 13
0
/**
 * gpm_manager_systemd_shutdown:
 *
 * Shutdown the system using systemd-logind.
 *
 * Return value: fd, -1 on error
 **/
static gboolean
gpm_control_systemd_shutdown (void) {
	GError *error = NULL;
	GDBusProxy *proxy;
	GVariant *res = NULL;

	egg_debug ("Requesting systemd to shutdown");
	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
					       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
					       NULL,
					       "org.freedesktop.login1",
					       "/org/freedesktop/login1",
					       "org.freedesktop.login1.Manager",
					       NULL,
					       &error );
	//append all our arguments
	if (proxy == NULL) {
		egg_error("Error connecting to dbus - %s", error->message);
		g_error_free (error);
		return FALSE;
	}

	res = g_dbus_proxy_call_sync (proxy, "PowerOff",
				      g_variant_new( "(b)", FALSE),
				      G_DBUS_CALL_FLAGS_NONE,
				      -1,
				      NULL,
				      &error
				      );
	if (error != NULL) {
		egg_error ("Error in dbus - %s", error->message);
		g_error_free (error);
		return FALSE;
	}

	g_variant_unref(res);
	return TRUE;
}
static void
do_write_lock(struct app *app)
{
    GVariant *ret;
    GError *error = NULL;
    char *nameowner;

    nameowner = g_dbus_proxy_get_name_owner(app->proxy);
    if (!nameowner) {
        fputs("Server is not running, cannot get write lock!\n", stderr);
        app->ret = EXIT_FAILURE;
        g_main_loop_quit(app->loop);
        return;
    }

    printf("Server at %s, try to get write lock\n", nameowner);
    g_free(nameowner);

    g_signal_connect(app->proxy, "g-properties-changed",
                     G_CALLBACK(on_properties_changed_check_lock),
                     app);

    ret = g_dbus_proxy_call_sync(app->proxy, "RequestWriteLock",
                                 g_variant_new("()"),
                                 G_DBUS_CALL_FLAGS_NONE, -1, NULL,
                                 &error);

    if (!ret) {
        fprintf(stderr, "Could not get write lock: %s\n", error->message);
        g_error_free(error);
        app->ret = EXIT_FAILURE;
        g_main_loop_quit(app->loop);
        return;
    }

    g_variant_unref(ret);
    puts("Got write lock, close program to release it.");
}
Esempio n. 15
0
static gboolean
polkit_system_bus_name_exists_sync (PolkitSubject   *subject,
                                    GCancellable    *cancellable,
                                    GError         **error)
{
  PolkitSystemBusName *name = POLKIT_SYSTEM_BUS_NAME (subject);
  GDBusConnection *connection;
  GVariant *result;
  gboolean ret;

  ret = FALSE;

  connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
  if (connection == NULL)
    goto out;

  result = g_dbus_connection_call_sync (connection,
                                        "org.freedesktop.DBus",   /* name */
                                        "/org/freedesktop/DBus",  /* object path */
                                        "org.freedesktop.DBus",   /* interface name */
                                        "NameHasOwner",           /* method */
                                        g_variant_new ("(s)", name->name),
                                        G_VARIANT_TYPE ("(b)"),
                                        G_DBUS_CALL_FLAGS_NONE,
                                        -1,
                                        cancellable,
                                        error);
  if (result == NULL)
    goto out;

  g_variant_get (result, "(b)", &ret);
  g_variant_unref (result);

 out:
  if (connection != NULL)
    g_object_unref (connection);
  return ret;
}
Esempio n. 16
0
static gboolean
gtk_application_impl_dbus_is_inhibited (GtkApplicationImpl         *impl,
                                        GtkApplicationInhibitFlags  flags)
{
  GtkApplicationImplDBus *dbus = (GtkApplicationImplDBus *) impl;
  GVariant *res;
  GError *error = NULL;
  gboolean inhibited;
  static gboolean warned = FALSE;

  if (dbus->sm_proxy == NULL)
    return FALSE;

  res = g_dbus_proxy_call_sync (dbus->sm_proxy,
                                "IsInhibited",
                                g_variant_new ("(u)", flags),
                                G_DBUS_CALL_FLAGS_NONE,
                                G_MAXINT,
                                NULL,
                                &error);
  if (error)
    {
      if (!warned)
        {
          g_warning ("Calling %s.IsInhibited failed: %s",
                     g_dbus_proxy_get_interface_name (dbus->sm_proxy),
                     error->message);
          warned = TRUE;
        }
      g_error_free (error);
      return FALSE;
    }

  g_variant_get (res, "(b)", &inhibited);
  g_variant_unref (res);

  return inhibited;
}
Esempio n. 17
0
static void
_fcitx_client_create_ic_cb(GObject *source_object,
                           GAsyncResult *res,
                           gpointer user_data)
{
    FcitxClient* self = (FcitxClient*) user_data;
    if (self->priv->cancellable) {
        g_object_unref (self->priv->cancellable);
        self->priv->cancellable = NULL;
    }
    GVariant* result = g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object), res, NULL);

    if (!result) {
        /* unref for _fcitx_client_phase1_finish */
        g_object_unref(self);
        return;
    }

    gboolean enable;
    guint32 key1, state1, key2, state2;
    g_variant_get(result, "(ibuuuu)", &self->priv->id, &enable, &key1, &state1, &key2, &state2);
    g_variant_unref(result);

    sprintf(self->priv->icname, FCITX_IC_DBUS_PATH, self->priv->id);

    self->priv->cancellable = g_cancellable_new ();
    g_dbus_proxy_new(
        fcitx_connection_get_g_dbus_connection(self->priv->connection),
        G_DBUS_PROXY_FLAGS_NONE,
        _fcitx_client_get_clientic_info(),
        self->priv->servicename,
        self->priv->icname,
        FCITX_IC_DBUS_INTERFACE,
        self->priv->cancellable,
        _fcitx_client_create_ic_phase2_finished,
        self
    );
}
Esempio n. 18
0
CAResult_t CAGetLEAdapterState()
{
    CAResult_t result = CA_ADAPTER_NOT_ENABLED;

    ca_mutex_lock(g_context.lock);

    for (GList * l = g_context.adapters; l != NULL; l = l->next)
    {
        GDBusProxy * const adapter = G_DBUS_PROXY(l->data);
        GVariant * const prop =
            g_dbus_proxy_get_cached_property(adapter, "Powered");

        if (prop == NULL)
        {
            // This should never happen!
            result = CA_STATUS_FAILED;
            break;
        }

        gboolean const powered = g_variant_get_boolean(prop);
        g_variant_unref(prop);

        if (powered)
        {
            result = CA_STATUS_OK;
            break;

            /*
              No need to continue iterating since we have at least
              one enabled Bluetooth adapter.
            */
        }
    }

    ca_mutex_unlock(g_context.lock);

    return result;
}
static gboolean
get_caller_pid (GDBusMethodInvocation *context,
                GPid                  *pid)
{
        GVariant      *reply;
        GError        *error;
        guint32        pid_as_int;

        error = NULL;
        reply = g_dbus_connection_call_sync (g_dbus_method_invocation_get_connection (context),
                                             "org.freedesktop.DBus",
                                             "/org/freedesktop/DBus",
                                             "org.freedesktop.DBus",
                                             "GetConnectionUnixProcessID",
                                             g_variant_new ("(s)",
                                                            g_dbus_method_invocation_get_sender (context)),
                                             G_VARIANT_TYPE ("(u)"),
                                             G_DBUS_CALL_FLAGS_NONE,
                                             -1,
                                             NULL,
                                             &error);

        if (reply == NULL) {
                g_warning ("Could not talk to message bus to find uid of sender %s: %s",
                           g_dbus_method_invocation_get_sender (context),
                           error->message);
                g_error_free (error);

                return FALSE;
        }

        g_variant_get (reply, "(u)", &pid_as_int);
        *pid = pid_as_int;

        g_variant_unref (reply);

        return TRUE;
}
static void
on_bss_proxy_acquired (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data)
{
	NMSupplicantInterface *self;
	NMSupplicantInterfacePrivate *priv;
	gs_free_error GError *error = NULL;
	gs_strfreev char **properties = NULL;
	gs_unref_variant GVariant *props = NULL;
	GVariantBuilder builder;
	char **iter;

	if (!g_async_initable_init_finish (G_ASYNC_INITABLE (proxy), result, &error)) {
		if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
			nm_log_dbg (LOGD_SUPPLICANT, "Failed to acquire BSS proxy: (%s)", error->message);
			g_hash_table_remove (NM_SUPPLICANT_INTERFACE_GET_PRIVATE (user_data)->bss_proxies,
			                     g_dbus_proxy_get_object_path (proxy));
		}
		return;
	}

	self = NM_SUPPLICANT_INTERFACE (user_data);
	priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);

	g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));

	iter = properties = g_dbus_proxy_get_cached_property_names (proxy);
	while (iter && *iter) {
		GVariant *copy = g_dbus_proxy_get_cached_property (proxy, *iter);

		g_variant_builder_add (&builder, "{sv}", *iter++, copy);
		g_variant_unref (copy);
	}

	props = g_variant_builder_end (&builder);
	g_signal_emit (self, signals[NEW_BSS], 0,
	               g_dbus_proxy_get_object_path (proxy),
	               g_variant_ref_sink (props));
}
Esempio n. 21
0
static void
state_cell_toggled (GtkCellRendererToggle *cell,
                    const gchar           *path_str,
                    GtkTreeModel          *model)
{
  GActionGroup *group;
  GAction *action;
  gchar *name;
  GtkTreePath *path;
  GtkTreeIter iter;
  GVariant *state;

  group = g_object_get_data (G_OBJECT (model), "group");
  path = gtk_tree_path_new_from_string (path_str);
  gtk_tree_model_get_iter (model, &iter, path);
  gtk_tree_model_get (model, &iter, 0, &name, -1);

  state = g_action_group_get_action_state (group, name);
  action = g_action_map_lookup_action (G_ACTION_MAP (group), name);
  if (state && g_variant_is_of_type (state, G_VARIANT_TYPE_BOOLEAN))
    {
      gboolean b;

      b = g_variant_get_boolean (state);
      g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (!b));
    }
  else
    {
      /* nothing to do */
    }

  gtk_tree_model_row_changed (model, path, &iter);

  g_free (name);
  gtk_tree_path_free (path);
  if (state)
    g_variant_unref (state);
}
Esempio n. 22
0
/**
 * CacheEntrySerialize:
 * @self: #CacheEntry to serialize.
 *
 * Returns: Human-readable string representing @self.
 */
gchar *CacheEntrySerialize(CacheEntry *self) {
  GVariantBuilder builder;
  const gchar *algorithm = NULL;
  GVariant *result_variant = NULL;
  gchar *result = NULL;

  g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
  g_variant_builder_add(&builder, "{sv}", "version",
                        g_variant_new_int32(self->version));
  g_variant_builder_add(&builder, "{sv}", "tries",
                        g_variant_new_int32(self->tries));

  algorithm = CacheUtilHashalgToString(self->algorithm);
  if (algorithm)
    g_variant_builder_add(&builder, "{sv}", "algorithm",
                          g_variant_new_string(algorithm));

  struct {const gchar *name; gchar *value;} attrs[] = {
    {"salt", CacheUtilBytesToString(self->salt)},
    {"hash", CacheUtilBytesToString(self->hash)},
    {"last_verified", CacheUtilDatetimeToString(self->last_verified)},
    {"last_used", CacheUtilDatetimeToString(self->last_used)},
    {"last_tried", CacheUtilDatetimeToString(self->last_tried)},
  };

  for (guint i = 0; i < G_N_ELEMENTS(attrs); i++) {
    if (attrs[i].value) {
      g_variant_builder_add(&builder, "{sv}", attrs[i].name,
                            g_variant_new_string(attrs[i].value));
      g_free(attrs[i].value);
    }
  }

  result_variant = g_variant_builder_end(&builder);
  result = g_variant_print(result_variant, TRUE);
  g_variant_unref(result_variant);
  return result;
}
Esempio n. 23
0
/**
 * Get information on the proxy.
 */
static GDBusNodeInfo *
g_dbus_proxy_get_node_info (GDBusProxy *proxy)
{
  GError *error;                // Error returned by various functions.
  GVariant *response;           // The response from the proxy call.
  GDBusNodeInfo *info;          // Information on the node.
  const gchar *xml;             // XML code for the proxy interface.

  // Get the introspection data
  error = NULL;
  response = 
    g_dbus_proxy_call_sync (proxy, 
                            "org.freedesktop.DBus.Introspectable.Introspect",
                            NULL, 
                            G_DBUS_CALL_FLAGS_NONE,
                            -1,
                            NULL,
                            &error);
  if (response == NULL)
    {
      return NULL;
    } // if (response == NULL)

  // Get the XML from the introspection data
  g_variant_get (response, "(&s)", &xml);

  // Build an object that lets us explore the introspection data.
  error = NULL;
  info = g_dbus_node_info_new_for_xml (xml, &error);
  g_variant_unref (response);
  if (info == NULL)
    {
      return NULL;
    } // if (info == NULL)

  // And return that object
  return info;
} // g_dbus_proxy_get_node_info
/**
 * tracker_miner_manager_is_active:
 * @manager: a #TrackerMinerManager
 * @miner: miner reference
 *
 * Returns the miner's current activity.
 *
 * Returns: %TRUE if the @miner is active, otherwise %FALSE.
 *
 * Since: 0.8
 **/
gboolean
tracker_miner_manager_is_active (TrackerMinerManager *manager,
                                 const gchar         *miner)
{
	TrackerMinerManagerPrivate *priv;
	GError *error = NULL;
	gboolean active = FALSE;
	GVariant *v;

	g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
	g_return_val_if_fail (miner != NULL, FALSE);

	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);

	v = g_dbus_connection_call_sync (priv->connection,
	                                 "org.freedesktop.DBus",
	                                 "/org/freedesktop/DBus",
	                                 "org.freedesktop.DBus",
	                                 "NameHasOwner",
	                                 g_variant_new ("(s)", miner),
	                                 (GVariantType *) "(b)",
	                                 G_DBUS_CALL_FLAGS_NONE,
	                                 -1,
	                                 NULL,
	                                 &error);

	if (error) {
		g_critical ("Could not check whether miner '%s' is currently active: %s",
		            miner, error ? error->message : "no error given");
		g_error_free (error);
		return FALSE;
	}

	g_variant_get (v, "(b)", &active);
	g_variant_unref (v);

	return active;
}
Esempio n. 25
0
static gboolean cancel_auth_check(gpointer user_data) {
	GError *error = NULL;
	GVariant *result;
	struct auth_check *auth_check = user_data;

	g_cancellable_cancel(auth_check->cancellable);

	result = g_dbus_proxy_call_sync(polkit_proxy, "CancelCheckAuthorization",
					g_variant_new("(s)", auth_check->cancel_string),
					G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
	if (!result) {
		g_dbus_error_strip_remote_error(error);
		g_printerr("Failed to cancel authorization check: %s\n", error->message);
		g_error_free(error);
	} else {
		g_variant_unref(result);
	}

	auth_check->cancel_id = 0;

	/* Destroy the timeout */
	return FALSE;
}
static void
on_interface_proxy_properties_changed (GDBusObjectManagerClient *manager,
                                       GDBusObjectProxy         *object_proxy,
                                       GDBusProxy               *interface_proxy,
                                       GVariant                 *changed_properties,
                                       const gchar *const       *invalidated_properties,
                                       gpointer                  user_data)
{
    GVariantIter iter;
    const gchar *key;
    GVariant *value;
    gchar *s;

    g_print ("Properties Changed on %s:\n", g_dbus_object_get_object_path (G_DBUS_OBJECT (object_proxy)));
    g_variant_iter_init (&iter, changed_properties);
    while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
    {
        s = g_variant_print (value, TRUE);
        g_print ("  %s -> %s\n", key, s);
        g_variant_unref (value);
        g_free (s);
    }
}
Esempio n. 27
0
void
nm_dhcp4_config_set_options (NMDhcp4Config *self,
                             GHashTable *options)
{
	NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
	GHashTableIter iter;
	const char *key, *value;
	GVariantBuilder builder;

	g_return_if_fail (NM_IS_DHCP4_CONFIG (self));
	g_return_if_fail (options != NULL);

	g_variant_unref (priv->options);

	g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
	g_hash_table_iter_init (&iter, options);
	while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value))
		g_variant_builder_add (&builder, "{sv}", key, g_variant_new_string (value));

	priv->options = g_variant_builder_end (&builder);
	g_variant_ref_sink (priv->options);
	g_object_notify (G_OBJECT (self), NM_DHCP4_CONFIG_OPTIONS);
}
Esempio n. 28
0
/**
 * Set value of a configuration key in a device instance.
 *
 * @param[in] sdi The device instance. Must not be NULL. sdi->driver and
 *                sdi->priv must not be NULL either.
 * @param[in] cg The channel group on the device for which to list the
 *                    values, or NULL.
 * @param[in] key The configuration key (SR_CONF_*).
 * @param data The new value for the key, as a GVariant with GVariantType
 *        appropriate to that key. A floating reference can be passed
 *        in; its refcount will be sunk and unreferenced after use.
 *
 * @retval SR_OK Success.
 * @retval SR_ERR Error.
 * @retval SR_ERR_ARG The driver doesn't know that key, but this is not to be
 *          interpreted as an error by the caller; merely as an indication
 *          that it's not applicable.
 *
 * @since 0.3.0
 */
SR_API int sr_config_set(const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg,
		uint32_t key, GVariant *data)
{
	int ret;

	g_variant_ref_sink(data);

	if (!sdi || !sdi->driver || !sdi->priv || !data)
		ret = SR_ERR;
	else if (!sdi->driver->config_set)
		ret = SR_ERR_ARG;
	else if (check_key(sdi->driver, sdi, cg, key, SR_CONF_SET, data) != SR_OK)
		return SR_ERR_ARG;
	else if ((ret = sr_variant_type_check(key, data)) == SR_OK) {
		log_key(sdi, cg, key, SR_CONF_SET, data);
		ret = sdi->driver->config_set(key, data, sdi, cg);
	}

	g_variant_unref(data);

	return ret;
}
Esempio n. 29
0
static void to_json_dict_iter(const char *key, GVariant *obj, void *opaque)
{
    ToJsonIterState *s = opaque;
    GVariant *qkey;
    int j;

    if (s->count)
        g_string_append(s->str, ", ");

    if (s->pretty) {
        g_string_append_c(s->str, '\n');
        for (j = 0 ; j < s->indent ; j++)
            g_string_append(s->str, "    ");
    }

    qkey = g_variant_new_string(key);
    to_json(qkey, s->str, s->pretty, s->indent);
    g_variant_unref(qkey);

    g_string_append(s->str, ": ");
    to_json(obj, s->str, s->pretty, s->indent);
    s->count++;
}
static void
on_inhibit_cb (GObject * source_object, GAsyncResult * res, gpointer user_data)
{
  GDBusProxy *proxy = G_DBUS_PROXY (source_object);
  ScreenSaver *screensaver = (ScreenSaver *) user_data;
  GVariant *value;
  GError *error = NULL;

  value = g_dbus_proxy_call_finish (proxy, res, &error);
  if (!value) {
    g_warning ("Problem inhibiting the screensaver: %s", error->message);
    g_error_free (error);
    return;
  }

  /* save the cookie */
  if (g_variant_is_of_type (value, G_VARIANT_TYPE ("(u)")))
    g_variant_get (value, "(u)", &screensaver->cookie);
  else
    screensaver->cookie = 0;

  g_variant_unref (value);
}