예제 #1
0
static void
create_context_for_device (NMDevice *nm_device)
{
        GError *error = NULL;
        guint port;
        GVariant *value;
        char *iface;
        char *ssid = NULL;

        g_object_get (nm_device->manager,
                      "port", &port,
                      NULL);

        value = g_dbus_proxy_get_cached_property (nm_device->proxy,
                                                  "Interface");
        if (G_UNLIKELY (value == NULL))
                return;

        if (G_UNLIKELY (!g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))) {
                g_variant_unref (value);

                return;
        }

        iface = g_variant_dup_string (value, NULL);
        g_variant_unref (value);

        if (nm_device->ap_proxy != NULL) {
                value = g_dbus_proxy_get_cached_property (nm_device->ap_proxy,
                                                          "Ssid");
                if (G_LIKELY (value != NULL)) {
                        ssid = g_strndup (g_variant_get_data (value),
                                          g_variant_get_size (value));
                        g_variant_unref (value);
                }
        }

        nm_device->context = g_initable_new (GUPNP_TYPE_CONTEXT,
                                             NULL,
                                             &error,
                                             "interface", iface,
                                             "network", ssid,
                                             "port", port,
                                             NULL);
        g_free (iface);
        g_free (ssid);

        if (error) {
                g_warning ("Error creating GUPnP context: %s\n",
                           error->message);

                g_error_free (error);

                return;
        }

        g_signal_emit_by_name (nm_device->manager,
                               "context-available",
                               nm_device->context);
}
static void
airplane_mode_changed (GDBusProxy       *proxy,
		       GVariant         *changed_properties,
		       GStrv             invalidated_properties,
		       CcBluetoothPanel *self)
{
	GVariant *v;

	v = g_dbus_proxy_get_cached_property (self->priv->rfkill, "AirplaneMode");
	self->priv->airplane_mode = g_variant_get_boolean (v);
	g_variant_unref (v);

	v = g_dbus_proxy_get_cached_property (self->priv->rfkill, "BluetoothAirplaneMode");
	self->priv->bt_airplane_mode = g_variant_get_boolean (v);
	g_variant_unref (v);

	v = g_dbus_proxy_get_cached_property (self->priv->rfkill, "BluetoothHardwareAirplaneMode");
	self->priv->hardware_airplane_mode = g_variant_get_boolean (v);
	g_variant_unref (v);

	v = g_dbus_proxy_get_cached_property (self->priv->rfkill, "BluetoothHasAirplaneMode");
	self->priv->has_airplane_mode = g_variant_get_boolean (v);
	g_variant_unref (v);

	cc_bluetooth_panel_update_power (self);
}
예제 #3
0
파일: realms.c 프로젝트: pdonlon/cockpit
static GVariant *
get_realm_details (GDBusProxy *realm,
                   GDBusProxy *kerberos)
{
  GVariantBuilder details;
  g_variant_builder_init (&details, G_VARIANT_TYPE("a{sv}"));

  if (realm)
    {
      gs_unref_variant GVariant *d = g_dbus_proxy_get_cached_property (realm, "Details");
      copy_ass_option (&details, d, "server-software");
      copy_ass_option (&details, d, "client-software");
    }

  if (kerberos)
    {
      gs_unref_variant GVariant *j = g_dbus_proxy_get_cached_property (kerberos, "SupportedJoinCredentials");
      if (j)
        g_variant_builder_add (&details, "{sv}", "supported-join-credentials",
                               translate_kerberos_credential_types (j));

      gs_unref_variant GVariant *l = g_dbus_proxy_get_cached_property (kerberos, "SupportedLeaveCredentials");
      if (l)
        g_variant_builder_add (&details, "{sv}", "supported-leave-credentials",
                               translate_kerberos_credential_types (l));

      gs_unref_variant GVariant *a = g_dbus_proxy_get_cached_property (kerberos, "SuggestedAdministrator");
      if (a)
        g_variant_builder_add (&details, "{sv}", "suggested-administrator", a);
    }

  return g_variant_builder_end (&details);
}
static void
update_capabilities (NMSupplicantManager *self)
{
	NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
	NMSupplicantInterface *iface;
	GHashTableIter hash_iter;
	const char **array;
	GVariant *value;

	/* The supplicant only advertises global capabilities if the following
	 * commit has been applied:
	 *
	 * commit 1634ac0654eba8d458640a115efc0a6cde3bac4d
	 * Author: Dan Williams <*****@*****.**>
	 * Date:   Sat Sep 29 19:06:30 2012 +0300
	 *
	 * dbus: Add global capabilities property
	 */
	priv->ap_support = AP_SUPPORT_UNKNOWN;

	value = g_dbus_proxy_get_cached_property (priv->proxy, "Capabilities");
	if (value) {
		if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY)) {
			array = g_variant_get_strv (value, NULL);
			priv->ap_support = AP_SUPPORT_NO;
			if (_nm_utils_string_in_list ("ap", array))
				priv->ap_support = AP_SUPPORT_YES;
			g_free (array);
		}
		g_variant_unref (value);
	}

	/* Tell all interfaces about results of the AP check */
	g_hash_table_iter_init (&hash_iter, priv->ifaces);
	while (g_hash_table_iter_next (&hash_iter, NULL, (gpointer) &iface))
		nm_supplicant_interface_set_ap_support (iface, priv->ap_support);

	nm_log_dbg (LOGD_SUPPLICANT, "AP mode is %ssupported",
	            (priv->ap_support == AP_SUPPORT_YES) ? "" :
	                (priv->ap_support == AP_SUPPORT_NO) ? "not " : "possibly ");

	/* EAP-FAST */
	priv->fast_supported = FALSE;
	value = g_dbus_proxy_get_cached_property (priv->proxy, "EapMethods");
	if (value) {
		if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING_ARRAY)) {
			array = g_variant_get_strv (value, NULL);
			if (_nm_utils_string_in_list ("fast", array))
				priv->fast_supported = TRUE;
			g_free (array);
		}
		g_variant_unref (value);
	}

	nm_log_dbg (LOGD_SUPPLICANT, "EAP-FAST is %ssupported", priv->fast_supported ? "" : "not ");
}
예제 #5
0
파일: gtlm-nfc.c 프로젝트: 01org/libtlm-nfc
void _on_interface_added(GDBusObjectManager *manager,
                         GDBusObject        *object,
                         GDBusInterface     *interface,
                         gpointer            user_data)
{
    GTlmNfc* self = GTLM_NFC(user_data);
    GDBusProxy* proxy = G_DBUS_PROXY(interface);
    g_debug("Object %s added interface %s", 
                    g_dbus_object_get_object_path (object),
                    g_dbus_proxy_get_interface_name (proxy));
    
    if (g_strcmp0(g_dbus_proxy_get_interface_name (proxy),
                "org.neard.Adapter") == 0) {
        _setup_nfc_adapter(self, proxy);
        return;
    }
    if (g_strcmp0(g_dbus_proxy_get_interface_name (proxy),
                "org.neard.Tag") == 0) {
        g_signal_emit(self, signals[SIG_TAG_FOUND], 0, g_dbus_object_get_object_path (object));
        return;
    }

    if (g_strcmp0(g_dbus_proxy_get_interface_name (proxy),
                "org.neard.Record") == 0) {
        GVariant* type_v = g_dbus_proxy_get_cached_property(proxy, "Type");
        if (type_v == NULL || !g_variant_is_of_type(type_v, G_VARIANT_TYPE_STRING)) {
            g_debug("Type property is absent on a record");
            g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0);
            return;
        }
        const gchar* type = g_variant_get_string(type_v, NULL);
        g_debug("Record has type %s", type);
        if (g_strcmp0(type, "MIME") != 0) {
            g_variant_unref(type_v);
            g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0);
            return;
        }
        g_variant_unref(type_v);

        GVariant* mimetype_v = g_dbus_proxy_get_cached_property(proxy, "MIME");
        if (mimetype_v == NULL || !g_variant_is_of_type(type_v, G_VARIANT_TYPE_STRING)) {
            g_debug("MIME property is absent on a record");
            g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0);
            return;
        }
        const gchar* mimetype = g_variant_get_string(mimetype_v, NULL);
        g_debug("Record has MIME type %s", mimetype);
        if (g_strcmp0(mimetype, "application/gtlm-nfc") != 0) {
            g_variant_unref(mimetype_v);
            g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0);
            return;
        }
        g_variant_unref(mimetype_v);
    }
}
예제 #6
0
/* Handle position change callbacks */
static void
geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name,
			 gchar *signal_name, GVariant *parameters,
			 gpointer user_data)
{
	location_geoclue2_state_t *state = user_data;

	/* Only handle LocationUpdated signals */
	if (g_strcmp0(signal_name, "LocationUpdated") != 0) {
		return;
	}

	/* Obtain location path */
	const gchar *location_path;
	g_variant_get_child(parameters, 1, "&o", &location_path);

	/* Obtain location */
	GError *error = NULL;
	GDBusProxy *location = g_dbus_proxy_new_sync(
		g_dbus_proxy_get_connection(client),
		G_DBUS_PROXY_FLAGS_NONE,
		NULL,
		"org.freedesktop.GeoClue2",
		location_path,
		"org.freedesktop.GeoClue2.Location",
		NULL, &error);
	if (location == NULL) {
		g_printerr(_("Unable to obtain location: %s.\n"),
			   error->message);
		g_error_free(error);
		mark_error(state);
		return;
	}

	g_mutex_lock(&state->lock);

	/* Read location properties */
	GVariant *lat_v = g_dbus_proxy_get_cached_property(
		location, "Latitude");
	state->latitude = g_variant_get_double(lat_v);

	GVariant *lon_v = g_dbus_proxy_get_cached_property(
		location, "Longitude");
	state->longitude = g_variant_get_double(lon_v);

	state->available = 1;

	g_mutex_unlock(&state->lock);

	pipeutils_signal(state->pipe_fd_write);
}
예제 #7
0
static void
adapter5_on_acquired (GObject *object, GAsyncResult *res, NMBluezDevice *self)
{
	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
	GError *error;
	GVariant *v;

	priv->adapter5 = g_dbus_proxy_new_for_bus_finish (res, &error);
	if (!priv->adapter5) {
		nm_log_warn (LOGD_BT, "bluez[%s] failed to acquire adapter proxy: %s.", priv->path, error->message);
		g_clear_error (&error);
		g_signal_emit (self, signals[INITIALIZED], 0, FALSE);
	} else {
		g_signal_connect (priv->adapter5, "g-properties-changed",
		                  G_CALLBACK (adapter5_on_properties_changed), self);

		/* Check adapter's powered state */
		v = g_dbus_proxy_get_cached_property (priv->adapter5, "Powered");
		priv->adapter_powered = VARIANT_IS_OF_TYPE_BOOLEAN (v) ? g_variant_get_boolean (v) : FALSE;
		if (v)
			g_variant_unref (v);

		priv->initialized = TRUE;
		g_signal_emit (self, signals[INITIALIZED], 0, TRUE);

		check_emit_usable (self);
	}

	g_object_unref (self);
}
예제 #8
0
static void
use_new_device (GUPnPNetworkManager *manager,
                NMDevice            *nm_device)
{
        NMDeviceState state;
        GVariant *value;

        manager->priv->nm_devices = g_list_append (manager->priv->nm_devices,
                                                   nm_device);

        g_signal_connect (nm_device->proxy,
                          "g-signal",
                          G_CALLBACK (on_device_signal),
                          nm_device);

        value = g_dbus_proxy_get_cached_property (nm_device->proxy, "State");
        if (G_UNLIKELY (value == NULL))
                return;

        if (G_UNLIKELY (!g_variant_is_of_type (value, G_VARIANT_TYPE_UINT32))) {
                g_variant_unref (value);

                return;
        }

        state = g_variant_get_uint32 (value);
        g_variant_unref (value);

        if (state == NM_OLD_DEVICE_STATE_ACTIVATED ||
            state == NM_DEVICE_STATE_ACTIVATED)
                on_device_activated (nm_device);
}
예제 #9
0
static void
on_wifi_device_activated (NMDevice *nm_device)
{
        GVariant *value;
        const char *ap_path;

        value = g_dbus_proxy_get_cached_property (nm_device->wifi_proxy,
                                                  "ActiveAccessPoint");
        if (G_UNLIKELY (value == NULL))
                return;

        if (G_UNLIKELY (!g_variant_is_of_type (value,
                                               G_VARIANT_TYPE_OBJECT_PATH))) {
                g_variant_unref (value);

                return;
        }

        ap_path = g_variant_get_string (value, NULL);
        if (G_UNLIKELY (ap_path == NULL))
                create_context_for_device (nm_device);
        else {
                g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
                                          G_DBUS_PROXY_FLAGS_NONE,
                                          NULL,
                                          DBUS_SERVICE_NM,
                                          ap_path,
                                          AP_INTERFACE,
                                          nm_device->manager->priv->cancellable,
                                          ap_proxy_new_cb,
                                          nm_device);
	}

        g_variant_unref (value);
}
static void
update_location_label (CcPrivacyPanel *self)
{
  CcPrivacyPanelPrivate *priv = self->priv;
  gboolean in_use = FALSE, on;
  const gchar *label;

  if (priv->gclue_manager != NULL)
    {
      GVariant *variant;

      variant = g_dbus_proxy_get_cached_property (priv->gclue_manager, "InUse");
      if (variant != NULL)
        {
          in_use = g_variant_get_boolean (variant);
          g_variant_unref (variant);
        }
    }

  if (in_use)
    {
      gtk_label_set_label (GTK_LABEL (priv->location_label), _("In use"));
      return;
    }

  on = g_settings_get_boolean (priv->location_settings, LOCATION_ENABLED);
  label = on ? C_("Location services status", "On") :
               C_("Location services status", "Off");
  gtk_label_set_label (GTK_LABEL (priv->location_label), label);
}
예제 #11
0
static void
print_playing_song (GDBusProxy *mpris, const char *format)
{
	GHashTable *properties;
	GVariant *v;
	gint64 elapsed = 0;
	char *string;

	properties = get_playing_song_info (mpris);
	if (properties == NULL) {
		g_print ("%s\n", _("Not playing"));
		return;
	}

	v = g_dbus_proxy_get_cached_property (mpris, "Position");
	if (v != NULL) {
		elapsed = g_variant_get_int64 (v);
		g_variant_unref (v);
	}

	string = parse_pattern (format, properties, elapsed);
	g_print ("%s\n", string);
	g_hash_table_destroy (properties);
	g_free (string);
}
static void
device_proxy_new_cb (GObject      *source_object,
                     GAsyncResult *res,
                     gpointer      user_data) {
        GUPnPNetworkManager *manager;
        GDBusProxy *device_proxy;
        NMDevice *nm_device = NULL;
        NMDeviceType type;
        GVariant *value;
        GError *error;

        error = NULL;

        device_proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
        if (G_UNLIKELY (error != NULL)) {
                if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
                        g_message ("Failed to create D-Bus proxy: %s", error->message);
                g_error_free (error);

                goto done;
        }

        manager = GUPNP_NETWORK_MANAGER (user_data);

        value = g_dbus_proxy_get_cached_property (device_proxy, "DeviceType");
        if (G_UNLIKELY (value == NULL)) {
                goto done;
        }

        if (G_UNLIKELY (!g_variant_is_of_type (value, G_VARIANT_TYPE_UINT32))) {
                g_variant_unref (value);

                goto done;
        }

        type = g_variant_get_uint32 (value);
        g_variant_unref (value);

        nm_device = nm_device_new (manager, device_proxy);

        if (type == NM_DEVICE_TYPE_WIFI) {
                const char *path;

                path = g_dbus_proxy_get_object_path (nm_device->proxy);
                g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
                                          G_DBUS_PROXY_FLAGS_NONE,
                                          NULL,
                                          DBUS_SERVICE_NM,
                                          path,
                                          WIFI_INTERFACE,
                                          manager->priv->cancellable,
                                          wifi_proxy_new_cb,
                                          nm_device_ref (nm_device));
        } else
                use_new_device (manager, nm_device);

done:
        g_clear_pointer (&nm_device, (GDestroyNotify) nm_device_unref);
        g_clear_object (&device_proxy);
}
예제 #13
0
gboolean update_display_info(struct DisplayInfo* info)
{
    GError* error = NULL;
    GDBusProxy* proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
                                                      G_DBUS_PROXY_FLAGS_NONE,
                                                      NULL,
                                                      DISPLAY_NAME,
                                                      DISPLAY_PATH,
                                                      DISPLAY_INTERFACE,
                                                      NULL,
                                                      &error
                                                      );
    if (error == NULL) {
        GVariant* res = g_dbus_proxy_get_cached_property(proxy, "PrimaryRect");
        g_variant_get(res, "(nnqq)", &info->x, &info->y, &info->width, &info->height);
        g_debug("%dx%d(%d,%d)", info->width, info->height, info->x, info->y);
        g_object_unref(proxy);
        return TRUE;
    } else {
        g_warning("[%s] connection dbus failed: %s", __func__, error->message);
        g_clear_error(&error);
        info->x = 0;
        info->y = 0;
        info->width = gdk_screen_width();
        info->height = gdk_screen_height();
        return FALSE;
    }
}
예제 #14
0
gboolean update_primary_info(struct DisplayInfo* info)
{
    GError* error = NULL;
    GDBusProxy* proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
                                                      G_DBUS_PROXY_FLAGS_NONE,
                                                      NULL,
                                                      DISPLAY_NAME,
                                                      DISPLAY_PATH,
                                                      DISPLAY_INTERFACE,
                                                      NULL,
                                                      &error);
    if (error == NULL) {
        GVariant* res = g_dbus_proxy_get_cached_property(proxy, "PrimaryRect");
        g_variant_get(res, "(nnqq)", &info->x, &info->y, &info->width,
                      &info->height);
        g_variant_unref(res);
        info->index = update_primary_monitor_n();
        g_message("[%s] Display DBus primaryInfo: %dx%d(%d,%d)\n",
                  __func__, info->width, info->height, info->x, info->y);
        g_object_unref(proxy);
        return TRUE;
    } else {
        g_warning("[%s] dbus connection failed: %s\n", __func__,
                  error->message);
        g_clear_error(&error);
        gboolean result = update_n_monitor_info(update_primary_monitor_n(),
                                                info);
        g_message("[%s] Display DBus primaryInfo: %dx%d(%d,%d)\n", __func__,
                  info->width, info->height, info->x, info->y);
        return result;
    }
}
static void
print_server(GDBusProxy *proxy)
{
    char **props, **itr;
    char *nameowner;

    nameowner = g_dbus_proxy_get_name_owner(proxy);
    if (!nameowner) {
        puts("Server is not running.");
        return;
    }

    printf("Server at %s\n", nameowner);
    props = g_dbus_proxy_get_cached_property_names(proxy);
    if (!props)
        return;

    for (itr = props; *itr != NULL; itr++) {
        GVariant *value = g_dbus_proxy_get_cached_property(proxy, *itr);
        char *str = g_variant_print(value, TRUE);
        printf("\t%s = %s\n", *itr, str);
        g_variant_unref(value);
        g_free(str);
    }
    g_strfreev(props);
    g_free(nameowner);
}
예제 #16
0
PanelSessionManagerPresenceType
panel_session_manager_get_presence (PanelSessionManager *manager)
{
        GVariant *variant;
        PanelSessionManagerPresenceType ret;

	g_return_val_if_fail (PANEL_IS_SESSION_MANAGER (manager),
                              PANEL_SESSION_MANAGER_PRESENCE_AVAILABLE);

	if (!manager->priv->presence_proxy) {
		g_warning ("Session manager service not available.");
		return PANEL_SESSION_MANAGER_PRESENCE_AVAILABLE;
	}

        variant = g_dbus_proxy_get_cached_property (manager->priv->presence_proxy,
                                                    "status");

        if (!variant) {
                g_warning ("Could not get presence from session manager.");
                return PANEL_SESSION_MANAGER_PRESENCE_AVAILABLE;
        }

        g_variant_get (variant, "u", &ret);
        g_variant_unref (variant);

        return ret;
}
예제 #17
0
/* Handle position change callbacks */
static void
geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name,
			 gchar *signal_name, GVariant *parameters,
			 gpointer *user_data)
{
	get_location_data_t *data = (get_location_data_t *)user_data;

	/* Only handle LocationUpdated signals */
	if (g_strcmp0(signal_name, "LocationUpdated") != 0) {
		return;
	}

	/* Obtain location path */
	const gchar *location_path;
	g_variant_get_child(parameters, 1, "&o", &location_path);

	/* Obtain location */
	GError *error = NULL;
	GDBusProxy *location =
		g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
					      G_DBUS_PROXY_FLAGS_NONE,
					      NULL,
					      "org.freedesktop.GeoClue2",
					      location_path,
					      "org.freedesktop.GeoClue2.Location",
					      NULL, &error);
	if (location == NULL) {
		g_printerr(_("Unable to obtain location: %s.\n"),
			   error->message);
		g_error_free(error);
		return;
	}

	/* Read location properties */
	GVariant *lat_v = g_dbus_proxy_get_cached_property(location,
							   "Latitude");
	data->latitude = g_variant_get_double(lat_v);

	GVariant *lon_v = g_dbus_proxy_get_cached_property(location,
							   "Longitude");
	data->longitude = g_variant_get_double(lon_v);

	data->available = 1;

	/* Return from main loop */
	g_main_loop_quit(data->loop);
}
static void
update_failures (EmpathyWebcredentialsMonitor *self)
{
    GVariant *failures, *f;
    GVariantIter iter;
    GList *new_list = NULL;
    guint i;

    failures = g_dbus_proxy_get_cached_property (self->priv->proxy,
               FAILURES_PROP);
    if (failures == NULL)
    {
        g_debug ("Does not implement Failures property");
        return;
    }

    g_variant_iter_init (&iter, failures);
    while ((f = g_variant_iter_next_value (&iter)) != NULL)
    {
        guint32 id;
        AgAccount *account;

        id = g_variant_get_uint32 (f);

        account = ag_manager_get_account (self->priv->manager, id);
        if (account == NULL)
            continue;

        /* Pass ownership of 'account' to the list */
        new_list = g_list_append (new_list, account);

        if (!tp_g_ptr_array_contains (self->priv->failures, account))
        {
            g_ptr_array_add (self->priv->failures, g_object_ref (account));

            g_signal_emit (self, signals[SIG_FAILURE_ADDED], 0, account);
        }

        g_variant_unref (f);
    }

    g_variant_unref (failures);

    for (i = 0; i < self->priv->failures->len; i++)
    {
        AgAccount *account = g_ptr_array_index (self->priv->failures, i);

        if (g_list_find (new_list, account) == NULL)
        {
            g_object_ref (account);
            g_ptr_array_remove (self->priv->failures, account);

            g_signal_emit (self, signals[SIG_FAILURE_REMOVED], 0, account);
            g_object_unref (account);
        }
    }

    g_list_free_full (new_list, g_object_unref);
}
예제 #19
0
gboolean dbus_get_bool_property(GDBusProxy *proxy, gchar * property) {
    GVariant* var;
    gboolean rv;
    var = g_dbus_proxy_get_cached_property(proxy, property);
    g_variant_get(var, "b", &rv);
    g_variant_unref(var);
    return rv;
}
예제 #20
0
파일: set_music.c 프로젝트: yshui/tprj
void tp_get_presence(GDBusProxy *proxy, struct _account *acc){
	GVariant *res = g_dbus_proxy_get_cached_property(proxy, "CurrentPresence");
	guint32 type;
	gchar *status, *message;
	g_variant_get(res, "(uss)", &type, &status, &message);
	acc->status = status;
	acc->status_message = message;
}
예제 #21
0
gchar* dbus_get_string_property(GDBusProxy *proxy, gchar * property) {
    GVariant* var;
    gchar* rv;
    var = g_dbus_proxy_get_cached_property(proxy, property);
    rv = g_variant_dup_string(var, 0);
    g_variant_unref(var);
    return rv;
}
예제 #22
0
static void
add_interface (JsonBuilder *builder,
               GDBusInterface *interface,
               GVariant *changed_properties)
{
  gchar *s;

  json_builder_set_member_name (builder, g_dbus_proxy_get_interface_name (G_DBUS_PROXY (interface)));
  json_builder_begin_object (builder);

  if (changed_properties == NULL)
    {
      gchar **properties;
      guint n;

      properties = g_dbus_proxy_get_cached_property_names (G_DBUS_PROXY (interface));
      for (n = 0; properties != NULL && properties[n] != NULL; n++)
        {
          const gchar *property_name = properties[n];
          GVariant *value;
          value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (interface), property_name);
          if (value != NULL)
            {
              s = g_strconcat ("dbus_prop_", property_name, NULL);
              json_builder_set_member_name (builder, s);
              g_free (s);
              _json_builder_add_gvariant (builder, value);
              g_variant_unref (value);
            }
        }
      g_strfreev (properties);

      if (properties == NULL)
        {
          json_builder_set_member_name (builder, "HackEmpty");
          json_builder_add_string_value (builder, "HackEmpty");
        }
    }
  else
    {
      GVariantIter iter;
      const gchar *property_name;
      GVariant *value;
      g_variant_iter_init (&iter, changed_properties);
      while (g_variant_iter_next (&iter, "{&sv}", &property_name, &value))
        {
          s = g_strconcat ("dbus_prop_", property_name, NULL);
          json_builder_set_member_name (builder, property_name);
          g_free (s);
          _json_builder_add_gvariant (builder, value);
          g_variant_unref (value);
        }
    }

  json_builder_end_object (builder);
}
예제 #23
0
static void
query_properties (NMBluezDevice *self)
{
	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
	GVariant *v;

	switch (priv->bluez_version) {
	case 4:
		g_dbus_proxy_call (priv->proxy, "GetProperties", NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, 3000,
		                   NULL, get_properties_cb_4, g_object_ref (self));
		break;
	case 5:
		g_object_freeze_notify (G_OBJECT (self));
		_take_variant_property_address   (self, g_dbus_proxy_get_cached_property (priv->proxy, "Address"));
		_take_variant_property_connected (self, g_dbus_proxy_get_cached_property (priv->proxy, "Connected"));
		_take_variant_property_name      (self, g_dbus_proxy_get_cached_property (priv->proxy, "Name"));
		_take_variant_property_uuids     (self, g_dbus_proxy_get_cached_property (priv->proxy, "UUIDs"));
		g_object_thaw_notify (G_OBJECT (self));

		v = g_dbus_proxy_get_cached_property (priv->proxy, "Adapter");
		if (VARIANT_IS_OF_TYPE_OBJECT_PATH (v)) {
			g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
			                          G_DBUS_PROXY_FLAGS_NONE,
			                          NULL,
			                          BLUEZ_SERVICE,
			                          g_variant_get_string (v, NULL),
			                          BLUEZ5_ADAPTER_INTERFACE,
			                          NULL,
			                          (GAsyncReadyCallback) adapter5_on_acquired,
			                          g_object_ref (self));
			g_variant_unref (v);
		} else {
			/* If the Adapter property is unset at this point, we won't try to acquire the adapter later on
			 * and the device stays unusable. This should not happen, but if it does, log a debug message. */
			nm_log_dbg (LOGD_BT, "bluez[%s] device has no adapter property and cannot be used.", priv->path);
		}

		/* Check if any connections match this device */
		load_connections (self);

		break;
	}
}
예제 #24
0
static bool uninstall_application(GDBusObjectManager* installed,
                                  const char* appid)
{
  GList* objects = g_dbus_object_manager_get_objects(installed);
  GList* l;
  bool ret = false;

  for (l = objects; l; l = l->next) {
    GDBusObject* object = l->data;
    GDBusInterface* iface = g_dbus_object_get_interface(
        object,
        xwalk_installed_app_iface);
    if (!iface)
      continue;

    GDBusProxy* proxy = G_DBUS_PROXY(iface);

    GVariant* value = g_dbus_proxy_get_cached_property(proxy, "AppID");
    if (!value) {
      g_object_unref(iface);
      continue;
    }

    const char* id;
    g_variant_get(value, "s", &id);

    if (g_strcmp0(appid, id)) {
      g_object_unref(iface);
      continue;
    }

    GError* error = NULL;
    GVariant* result = g_dbus_proxy_call_sync(proxy, "Uninstall", NULL,
                                              G_DBUS_CALL_FLAGS_NONE,
                                              -1, NULL, &error);
    if (!result) {
      g_print("Uninstalling application failed: %s\n", error->message);
      g_error_free(error);
      g_object_unref(iface);
      ret = false;
      goto done;
    }

    g_object_unref(iface);
    ret = true;
    goto done;
  }

  g_print("Application ID '%s' could not be found\n", appid);

done:
  g_list_free_full(objects, g_object_unref);

  return ret;
}
예제 #25
0
파일: where-am-i.c 프로젝트: kalev/geoclue
static void
on_location_proxy_ready (GObject      *source_object,
                         GAsyncResult *res,
                         gpointer      user_data)
{
        GDBusProxy *manager = G_DBUS_PROXY (user_data);
        GDBusProxy *location = G_DBUS_PROXY (source_object);
        GVariant *value;
        gdouble latitude, longitude, accuracy;
        const char *desc;
        gsize desc_len;
        GError *error = NULL;

        location = g_dbus_proxy_new_for_bus_finish (res, &error);
        if (error != NULL) {
            g_critical ("Failed to connect to GeoClue2 service: %s", error->message);

            exit (-5);
        }

        value = g_dbus_proxy_get_cached_property (location, "Latitude");
        latitude = g_variant_get_double (value);
        value = g_dbus_proxy_get_cached_property (location, "Longitude");
        longitude = g_variant_get_double (value);
        value = g_dbus_proxy_get_cached_property (location, "Accuracy");
        accuracy = g_variant_get_double (value);

        g_print ("Latitude: %f\nLongitude: %f\nAccuracy (in meters): %f\n",
                 latitude,
                 longitude,
                 accuracy);

        value = g_dbus_proxy_get_cached_property (location, "Description");
        desc = g_variant_get_string (value, &desc_len);
        if (desc_len > 0)
                g_print ("Description: %s\n", desc);

        g_object_unref (location);
        g_object_unref (manager);

        g_main_loop_quit (main_loop);
}
예제 #26
0
gboolean
accounts_user_get_automatic_login (AccountsUser *user)
{
  GVariant *value;
  gboolean ret;
  g_return_val_if_fail (ACCOUNTS_IS_USER (user), FALSE);
  value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user), "AutomaticLogin");
  ret = g_variant_get_boolean (value);
  g_variant_unref (value);
  return ret;
}
예제 #27
0
const gchar *
accounts_user_get_real_name (AccountsUser *user)
{
  GVariant *value;
  const gchar *ret;
  g_return_val_if_fail (ACCOUNTS_IS_USER (user), NULL);
  value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (user), "RealName");
  ret = g_variant_get_string (value, NULL);
  g_variant_unref (value);
  return ret;
}
예제 #28
0
		bool get_property(GDBusProxy *_proxy, const gchar *_property_name, const gchar *_format, void *_dest)
		{
			GVariant *variant = g_dbus_proxy_get_cached_property(_proxy, _property_name);
			if (variant != nullptr)
			{
				g_variant_get(variant, _format, _dest);
				g_variant_unref(variant);
				return true;
			}
			else
				return false;
		}
예제 #29
0
파일: services.c 프로젝트: imace/cockpit
static void
on_unit_proxy_ready (GObject *object,
                     GAsyncResult *res,
                     gpointer user_data)
{
  Services *services = user_data;
  gs_unref_object GDBusProxy *unit = g_dbus_proxy_new_for_bus_finish (res, NULL);
  if (unit)
    {
      const gchar *name, *description, *load_state, *active_state, *sub_state, *file_state;
      gs_unref_variant GVariant *n = g_dbus_proxy_get_cached_property (unit, "Id");
      gs_unref_variant GVariant *d = g_dbus_proxy_get_cached_property (unit, "Description");
      gs_unref_variant GVariant *l = g_dbus_proxy_get_cached_property (unit, "LoadState");
      gs_unref_variant GVariant *a = g_dbus_proxy_get_cached_property (unit, "ActiveState");
      gs_unref_variant GVariant *s = g_dbus_proxy_get_cached_property (unit, "SubState");
      gs_unref_variant GVariant *f = g_dbus_proxy_get_cached_property (unit, "UnitFileState");
      g_variant_get (n, "&s", &name);
      g_variant_get (d, "&s", &description);
      g_variant_get (l, "&s", &load_state);
      g_variant_get (a, "&s", &active_state);
      g_variant_get (s, "&s", &sub_state);
      g_variant_get (f, "&s", &file_state);

      cockpit_services_emit_service_update (COCKPIT_SERVICES (services),
                                            g_variant_new ("(ssssss)",
                                                           name,
                                                           description,
                                                           load_state,
                                                           active_state,
                                                           sub_state,
                                                           file_state));
    }
}
예제 #30
0
static void list_applications(GDBusObjectManager* installed) {
  GList* objects = g_dbus_object_manager_get_objects(installed);
  GList* l;

  for (l = objects; l; l = l->next) {
    GDBusObject* object = l->data;
    GDBusInterface* iface = g_dbus_object_get_interface(
        object,
        xwalk_installed_app_iface);
    if (!iface)
      continue;

    GDBusProxy* proxy = G_DBUS_PROXY(iface);
    GVariant* id_variant;
    id_variant = g_dbus_proxy_get_cached_property(proxy, "AppID");
    if (!id_variant) {
      g_object_unref(iface);
      continue;
    }

    const char* id;
    g_variant_get(id_variant, "s", &id);

    GVariant* name_variant;
    name_variant = g_dbus_proxy_get_cached_property(proxy, "Name");
    if (!name_variant) {
      g_object_unref(iface);
      continue;
    }

    const char* name;
    g_variant_get(name_variant, "s", &name);

    g_print("%s\t%s\n", id, name);

    g_object_unref(iface);
  }

  g_list_free_full(objects, g_object_unref);
}