TYPE get_numeric_value(GVariant *variant_, const char *type_str, const char *fallback_type_str) { GTYPE value = 0; if (!variant_) return static_cast<TYPE>(value); if (g_variant_is_of_type(variant_, G_VARIANT_TYPE(type_str))) { g_variant_get(variant_, type_str, &value); } else if (g_variant_is_of_type(variant_, G_VARIANT_TYPE(fallback_type_str))) { g_variant_get(variant_, fallback_type_str, &value); } else { auto const& variant = get_variant(variant_); if (variant) return get_numeric_value<TYPE, GTYPE>(static_cast<GVariant*>(variant), type_str, fallback_type_str); LOG_ERROR(logger) << "You're trying to extract a '" << type_str << "'" << " from a variant which is of type '" << g_variant_type_peek_string(g_variant_get_type(variant_)) << "'"; } return static_cast<TYPE>(value); }
static void Get(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation) { // only update recordings list if empty // so we don't mess around with the index values returned by List if (recordings.Count() == 0) recordings.Update(true); cRecording *recording = NULL; GVariant *first = g_variant_get_child_value(Parameters, 0); GVariant *refValue = first; if (g_variant_is_of_type(first, G_VARIANT_TYPE_VARIANT)) refValue = g_variant_get_child_value(first, 0); if (g_variant_is_of_type(refValue, G_VARIANT_TYPE_STRING)) { const char *path = NULL; g_variant_get(refValue, "&s", &path); if ((path != NULL) && *path) recording = recordings.GetByName(path); } else if (g_variant_is_of_type(refValue, G_VARIANT_TYPE_INT32)) { int number = 0; g_variant_get(refValue, "i", &number); if ((number > 0) && (number <= recordings.Count())) recording = recordings.Get(number - 1); } if (refValue != first) g_variant_unref(refValue); g_variant_unref(first); GVariant *rec = BuildRecording(recording); g_dbus_method_invocation_return_value(Invocation, g_variant_new_tuple(&rec, 1)); };
bool Variant::ASVToHints(HintsMap& hints) const { GVariantIter* hints_iter; char* key = NULL; GVariant* value = NULL; if (!variant_) return false; if (!g_variant_is_of_type (variant_, G_VARIANT_TYPE ("(a{sv})")) && !g_variant_is_of_type (variant_, G_VARIANT_TYPE ("a{sv}"))) { return false; } g_variant_get(variant_, g_variant_get_type_string(variant_), &hints_iter); while (g_variant_iter_loop(hints_iter, "{sv}", &key, &value)) { hints[key] = value; } g_variant_iter_free(hints_iter); return true; }
static GError * _stmt_apply_GV_parameter(sqlite3_stmt *stmt, int pos, GVariant *p) { if (g_variant_is_of_type(p, G_VARIANT_TYPE_UNIT)) { sqlite3_bind_null(stmt, pos); return NULL; } if (g_variant_is_of_type(p, G_VARIANT_TYPE_BASIC)) { return _stmt_apply_GV_parameter_simple(stmt, pos, p); } if (g_variant_is_of_type(p, G_VARIANT_TYPE_UNIT)) { sqlite3_bind_null(stmt, pos); return NULL; } if (g_variant_is_of_type(p, G_VARIANT_TYPE_BYTESTRING)) { sqlite3_bind_blob(stmt, pos, g_variant_get_data(p), g_variant_get_size(p), NULL); return NULL; } return NEWERROR(CODE_BAD_REQUEST, "Unexpected parameter at position %d (type '%s')", pos, (gchar*)g_variant_get_type(p)); }
std::string Variant::GetString() const { const gchar *result = nullptr; if (!variant_) return ""; if (g_variant_is_of_type(variant_, G_VARIANT_TYPE_STRING)) { // g_variant_get_string doesn't duplicate the string result = g_variant_get_string(variant_, nullptr); } else if (g_variant_is_of_type(variant_, G_VARIANT_TYPE("(s)"))) { // As we're using the '&' prefix we don't need to free the string! g_variant_get(variant_, "(&s)", &result); } else { auto const& variant = get_variant(variant_); if (variant) return variant.GetString(); LOG_ERROR(logger) << "You're trying to extract a 's' from a variant which is of type '" << g_variant_type_peek_string(g_variant_get_type(variant_)) << "'"; } return result ? result : ""; }
Scheme_Object * gvariant_to_schemeobj (GVariant *ivalue) { Scheme_Object *fvalue = NULL; const gchar *fstring; gsize length; gsize *plength; gint64 r1; length = g_variant_get_size(ivalue); plength = &length; if (g_variant_is_of_type (ivalue, G_VARIANT_TYPE_INT64)) { g_variant_get (ivalue,"(i)", &r1); fvalue = scheme_make_integer_value(r1); return fvalue; } else if (g_variant_is_of_type (ivalue,G_VARIANT_TYPE_STRING)) { fstring = g_variant_get_string (ivalue, plength); fvalue = scheme_make_utf8_string (fstring); return fvalue; } return fvalue; }
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 int update_one_secret (NMSetting *setting, const char *key, GVariant *value, GError **error) { NMSettingUpdateSecretResult success = NM_SETTING_UPDATE_SECRET_ERROR; g_return_val_if_fail (key != NULL, NM_SETTING_UPDATE_SECRET_ERROR); g_return_val_if_fail (value != NULL, NM_SETTING_UPDATE_SECRET_ERROR); if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) { /* Passing the string properties individually isn't correct, and won't * produce the correct result, but for some reason that's how it used * to be done. So even though it's not correct, keep the code around * for compatibility's sake. */ success = update_secret_string (setting, key, g_variant_get_string (value, NULL), error); } else if (g_variant_is_of_type (value, G_VARIANT_TYPE ("a{ss}"))) { if (strcmp (key, NM_SETTING_VPN_SECRETS) != 0) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_PROPERTY_NOT_SECRET, _("not a secret property")); g_prefix_error (error, "%s.%s ", NM_SETTING_VPN_SETTING_NAME, key); } else success = update_secret_dict (setting, value, error); } else { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("secret is not of correct type")); g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, key); } if (success == NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED) g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS); return success; }
static Login1Seat * add_seat (Login1Service *service, const gchar *id, const gchar *path) { Login1Seat *seat; GVariant *result; GError *error = NULL; seat = g_object_new (LOGIN1_SEAT_TYPE, NULL); seat->priv->connection = g_object_ref (service->priv->connection); seat->priv->id = g_strdup (id); seat->priv->path = g_strdup (path); seat->priv->signal_id = g_dbus_connection_signal_subscribe (seat->priv->connection, LOGIN1_SERVICE_NAME, "org.freedesktop.DBus.Properties", "PropertiesChanged", path, "org.freedesktop.login1.Seat", G_DBUS_SIGNAL_FLAGS_NONE, seat_properties_changed_cb, g_object_ref (seat), g_object_unref); /* Get properties for this seat */ result = g_dbus_connection_call_sync (seat->priv->connection, LOGIN1_SERVICE_NAME, path, "org.freedesktop.DBus.Properties", "GetAll", g_variant_new ("(s)", "org.freedesktop.login1.Seat"), G_VARIANT_TYPE ("(a{sv})"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error) g_warning ("Failed to get seat properties: %s", error->message); g_clear_error (&error); if (result) { GVariantIter *properties; const gchar *name; GVariant *value; g_variant_get (result, "(a{sv})", &properties); while (g_variant_iter_loop (properties, "{&sv}", &name, &value)) { if (strcmp (name, "CanGraphical") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) seat->priv->can_graphical = g_variant_get_boolean (value); else if (strcmp (name, "CanMultiSession") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) seat->priv->can_multi_session = g_variant_get_boolean (value); } g_variant_iter_free (properties); g_variant_unref (result); } service->priv->seats = g_list_append (service->priv->seats, seat); return seat; }
GVariant * g_variant_lookup_value (GVariant *dictionary, const gchar *key, const GVariantType *expected_type) { GVariantIter iter; GVariant *entry; GVariant *value; g_return_val_if_fail (g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{s*}")) || g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{o*}")), NULL); g_variant_iter_init (&iter, dictionary); while ((entry = g_variant_iter_next_value (&iter))) { GVariant *entry_key; gboolean matches; entry_key = g_variant_get_child_value (entry, 0); matches = strcmp (g_variant_get_string (entry_key, NULL), key) == 0; g_variant_unref (entry_key); if (matches) break; g_variant_unref (entry); } if (entry == NULL) return NULL; value = g_variant_get_child_value (entry, 1); g_variant_unref (entry); if (g_variant_is_of_type (value, G_VARIANT_TYPE_VARIANT)) { GVariant *tmp; tmp = g_variant_get_variant (value); g_variant_unref (value); if (expected_type && !g_variant_is_of_type (tmp, expected_type)) { g_variant_unref (tmp); tmp = NULL; } value = tmp; } g_return_val_if_fail (expected_type == NULL || value == NULL || g_variant_is_of_type (value, expected_type), NULL); return value; }
GVariant* GnomeGrabber::Impl::onShellMethodCall(std::string const& method, GVariant* parameters) { LOG_DEBUG(logger) << "Called method '" << method << "'"; if (method == "GrabAccelerators") { if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(a(su))"))) { GVariant* variant; GVariantBuilder builder; GVariantIter* iterator; gchar const* accelerator; guint flags; g_variant_builder_init(&builder, G_VARIANT_TYPE("au")); g_variant_get(parameters, "(a(su))", &iterator); while (g_variant_iter_next(iterator, "(&su)", &accelerator, &flags)) g_variant_builder_add(&builder, "u", grabAccelerator(accelerator, flags)); g_variant_iter_free(iterator); variant = g_variant_builder_end(&builder); return g_variant_new_tuple(&variant, 1); } else LOG_WARN(logger) << "Expected arguments of type (a(su))"; } else if (method == "GrabAccelerator") { if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(su)"))) { GVariant* variant; gchar const* accelerator; guint flags; g_variant_get(parameters, "(&su)", &accelerator, &flags); variant = g_variant_new_uint32(grabAccelerator(accelerator, flags)); return g_variant_new_tuple(&variant, 1); } else LOG_WARN(logger) << "Expected arguments of type (su)"; } else if (method == "UngrabAccelerator") { if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(u)"))) { GVariant* variant; guint action; g_variant_get(parameters, "(u)", &action); variant = g_variant_new_boolean(removeAction(action)); return g_variant_new_tuple(&variant, 1); } else LOG_WARN(logger) << "Expected arguments of type (u)"; } return nullptr; }
static void run_operation_from_params (CcWacomPanel *self, GVariant *parameters) { GVariant *v; CcWacomPage *page; const gchar *operation = NULL; const gchar *device_name = NULL; gint n_params; n_params = g_variant_n_children (parameters); g_variant_get_child (parameters, n_params - 1, "v", &v); device_name = g_variant_get_string (v, NULL); if (!g_variant_is_of_type (v, G_VARIANT_TYPE_STRING)) { g_warning ("Wrong type for the second argument GVariant, expected 's' but got '%s'", g_variant_get_type_string (v)); g_variant_unref (v); return; } g_variant_unref (v); switch (n_params) { case 3: page = set_device_page (self, device_name); if (page == NULL) return; g_variant_get_child (parameters, 1, "v", &v); if (!g_variant_is_of_type (v, G_VARIANT_TYPE_STRING)) { g_warning ("Wrong type for the operation name argument. A string is expected."); g_variant_unref (v); break; } operation = g_variant_get_string (v, NULL); if (g_strcmp0 (operation, "run-calibration") == 0) { if (cc_wacom_page_can_calibrate (page)) cc_wacom_page_calibrate (page); else g_warning ("The device %s cannot be calibrated.", device_name); } else { g_warning ("Ignoring unrecognized operation '%s'", operation); } g_variant_unref (v); case 2: set_device_page (self, device_name); break; case 1: g_assert_not_reached (); default: g_warning ("Unexpected number of parameters found: %d. Request ignored.", n_params); } }
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 "); }
static void init_gsettings (void) { #ifdef HAVE_GSETTINGS GVariant *val; const gchar *const *schemas; int schema_found = 0; #if ! GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif schemas = g_settings_list_schemas (); if (schemas == NULL) return; while (! schema_found && *schemas != NULL) schema_found = strcmp (*schemas++, GSETTINGS_SCHEMA) == 0; if (!schema_found) return; gsettings_client = g_settings_new (GSETTINGS_SCHEMA); if (!gsettings_client) return; g_object_ref_sink (G_OBJECT (gsettings_client)); g_signal_connect (G_OBJECT (gsettings_client), "changed", G_CALLBACK (something_changed_gsettingsCB), NULL); val = g_settings_get_value (gsettings_client, GSETTINGS_TOOL_BAR_STYLE); if (val) { g_variant_ref_sink (val); if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) current_tool_bar_style = map_tool_bar_style (g_variant_get_string (val, NULL)); g_variant_unref (val); } #ifdef HAVE_XFT val = g_settings_get_value (gsettings_client, GSETTINGS_MONO_FONT); if (val) { g_variant_ref_sink (val); if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) current_mono_font = xstrdup (g_variant_get_string (val, NULL)); g_variant_unref (val); } val = g_settings_get_value (gsettings_client, GSETTINGS_FONT_NAME); if (val) { g_variant_ref_sink (val); if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) current_font = xstrdup (g_variant_get_string (val, NULL)); g_variant_unref (val); } #endif /* HAVE_XFT */ #endif /* HAVE_GSETTINGS */ }
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); } }
static void something_changed_gsettingsCB (GSettings *settings, gchar *key, gpointer user_data) { GVariant *val; if (strcmp (key, GSETTINGS_TOOL_BAR_STYLE) == 0) { val = g_settings_get_value (settings, GSETTINGS_TOOL_BAR_STYLE); if (val) { g_variant_ref_sink (val); if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) { const gchar *newstyle = g_variant_get_string (val, NULL); store_tool_bar_style_changed (newstyle, first_dpyinfo); } g_variant_unref (val); } } #ifdef HAVE_XFT else if (strcmp (key, GSETTINGS_MONO_FONT) == 0) { val = g_settings_get_value (settings, GSETTINGS_MONO_FONT); if (val) { g_variant_ref_sink (val); if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) { const gchar *newfont = g_variant_get_string (val, NULL); store_monospaced_changed (newfont); } g_variant_unref (val); } } else if (strcmp (key, GSETTINGS_FONT_NAME) == 0) { val = g_settings_get_value (settings, GSETTINGS_FONT_NAME); if (val) { g_variant_ref_sink (val); if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) { const gchar *newfont = g_variant_get_string (val, NULL); store_font_name_changed (newfont); } g_variant_unref (val); } } #endif /* HAVE_XFT */ }
/** * playerctl_player_print_metadata_prop: * @self: a #PlayerctlPlayer * @property: (allow-none): the property from the metadata to print * @err: (allow-none): the location of a GError or NULL * * Gets the artist from the metadata of the current track, or empty string if * no track is playing. * * Returns: (transfer full): The artist from the metadata of the current track */ gchar *playerctl_player_print_metadata_prop(PlayerctlPlayer *self, gchar *property, GError **err) { GVariant *prop_variant; const gchar **prop_strv; GString *prop; GVariant *metadata; GError *tmp_error = NULL; g_return_val_if_fail(err == NULL || *err == NULL, NULL); if (self->priv->init_error != NULL) { g_propagate_error(err, g_error_copy(self->priv->init_error)); return NULL; } metadata = org_mpris_media_player2_player_get_metadata(self->priv->proxy); if (!metadata) return g_strdup(""); if (!property) return g_variant_print(metadata, FALSE); prop_variant = g_variant_lookup_value(metadata, property, NULL); if (!prop_variant) return g_strdup(""); prop = g_string_new(""); if (g_variant_is_of_type(prop_variant, G_VARIANT_TYPE_STRING_ARRAY)) { gsize prop_count; prop_strv = g_variant_get_strv(prop_variant, &prop_count); for (int i = 0; i < prop_count; i += 1) { g_string_append(prop, prop_strv[i]); if (i != prop_count - 1) { g_string_append(prop, ", "); } } g_free(prop_strv); } else if (g_variant_is_of_type(prop_variant, G_VARIANT_TYPE_STRING)) { g_string_append(prop, g_variant_get_string(prop_variant, NULL)); } else { prop = g_variant_print_string(prop_variant, prop, FALSE); } return g_string_free(prop, FALSE); }
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); }
static void on_notify_signal (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { guint32 notify_id; guint32 reason; gchar* action; if(g_strcmp0(signal_name, "NotificationClosed") == 0) { g_return_if_fail(g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(uu)"))); g_variant_get(parameters, "(uu)", ¬ify_id, &reason); g_print("notify_id = %u, reason = %u\n", notify_id, reason); if(notify_id == g_notify_id) { g_notify_id = 0; g_notified = TRUE; } } else if(g_strcmp0(signal_name, "ActionInvoked") == 0) { g_return_if_fail(g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(us)"))); g_variant_get(parameters, "(us)", ¬ify_id, &action); g_print("notify_id = %u, action = %s\n", notify_id, action); if(notify_id == g_notify_id) { if(g_strcmp0(action, "2") == 0) { GError* error = NULL; if (!org_zlbruce_eyerest_basic_call_delay_sync ( eye_proxy, 180, NULL, &error)) { g_print ("call dbus methed delay failed: %s\n", error->message); return; } } } } }
static void volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, GVariant* value, gpointer userdata) { g_return_if_fail (IS_VOLUME_WIDGET(userdata)); VolumeWidget* mitem = VOLUME_WIDGET(userdata); VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); if(g_ascii_strcasecmp(DBUSMENU_VOLUME_MENUITEM_LEVEL, property) == 0){ g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE_DOUBLE) ); if(priv->grabbed == FALSE){ GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); GtkRange *range = (GtkRange*)slider; gdouble update = g_variant_get_double (value); gtk_range_set_value(range, update); /* g_debug ("volume-widget::volume_widget_property_update - volume - value %f", update); */ update_accessible_desc(update/**priv->indicator*/); } } else if(g_ascii_strcasecmp(DBUSMENU_VOLUME_MENUITEM_MUTE, property) == 0){ g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)); if(priv->grabbed == FALSE){ GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); GtkRange *range = (GtkRange*)slider; gboolean update = g_variant_get_boolean (value); gdouble level; if (update == TRUE){ level = 0; } else{ GVariant* variant = dbusmenu_menuitem_property_get_variant (priv->twin_item, DBUSMENU_VOLUME_MENUITEM_LEVEL); /* g_debug ("variant for the volume - is it null = %i", variant == NULL); */ g_return_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_DOUBLE) ); level = g_variant_get_double (variant); } /* g_debug ("volume-widget::volume_widget_property_update - mute - value %i and level = %f", update, level); */ gtk_range_set_value(range, level); } } }
static void update_property (Login1Seat *seat, const gchar *name, GVariant *value) { if (strcmp (name, "CanGraphical") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE_BOOLEAN)) { seat->priv->can_graphical = g_variant_get_boolean (value); g_signal_emit (seat, seat_signals[CAN_GRAPHICAL_CHANGED], 0); } else if (strcmp (name, "ActiveSession") == 0 && g_variant_is_of_type (value, G_VARIANT_TYPE ("(so)"))) { const gchar *login1_session_id; g_variant_get (value, "(&so)", &login1_session_id, NULL); g_signal_emit (seat, seat_signals[ACTIVE_SESSION_CHANGED], 0, login1_session_id); } }
static void test_parse_partial_str(StateWrapper *wrapper, gconstpointer user_data) { guchar buffer[] = { 0x00, 0x0e, 0x00, 0x73, 0x6f, 0x6f, 0x73, 0x68, 0x69, 0x20 }; wrapper->state->buffer = g_byte_array_append(wrapper->state->buffer, buffer, sizeof(buffer)); SooshiNode *node = g_new0(SooshiNode, 1); node->type = VAL_STR; // First run should return NULL and not remove any bytes from the byte array gulong byte_array_size = wrapper->state->buffer->len; sooshi_node_bytes_to_value(node, wrapper->state->buffer, &node->value); g_assert_null(node->value); g_assert_cmpuint(byte_array_size, ==, wrapper->state->buffer->len); guchar buffer2[] = { 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67 }; wrapper->state->buffer = g_byte_array_append(wrapper->state->buffer, buffer2, sizeof(buffer2)); // Second run should now be able to succesfully parse the string sooshi_node_bytes_to_value(node, wrapper->state->buffer, &node->value); g_assert_nonnull(node->value); g_assert_true(g_variant_is_of_type(node->value, G_VARIANT_TYPE_STRING)); g_assert_cmpstr(g_variant_get_string(node->value, NULL), ==, "sooshi testing"); guchar buffer3[16]; gint length = sooshi_node_value_to_bytes(node, buffer3); g_assert_cmpint(length, ==, sizeof(buffer3)); g_assert_cmpmem(buffer3, sizeof(buffer) - 1, buffer + 1, sizeof(buffer) - 1); g_assert_cmpmem(buffer3 + sizeof(buffer) - 1, sizeof(buffer3) - (sizeof(buffer) - 1), buffer2, sizeof(buffer2)); g_free(node); }
/* < 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; }
gboolean daemon_get_sender_uid (Daemon *daemon, GDBusMethodInvocation *invocation, uid_t *uid) { GError *error = NULL; const char *sender = g_dbus_method_invocation_get_sender (invocation); gs_unref_variant GVariant *reply = NULL; reply = g_dbus_proxy_call_sync (daemon->system_bus_proxy, "org.freedesktop.DBus.GetConnectionUnixUser", g_variant_new ("(s)", sender), 0, -1, NULL, &error); if (reply == NULL) { g_dbus_method_invocation_take_error (invocation, error); return FALSE; } if (g_variant_is_of_type (reply, G_VARIANT_TYPE("(u)"))) g_variant_get (reply, "(u)", uid); else { g_dbus_method_invocation_return_error (invocation, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "DBus is broken"); return FALSE; } return TRUE; }
static void parse_capabilities (NMSupplicantInterface *self, GVariant *capabilities) { NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); gboolean have_active = FALSE, have_ssid = FALSE; gint32 max_scan_ssids = -1; const char **array; g_return_if_fail (capabilities && g_variant_is_of_type (capabilities, G_VARIANT_TYPE_VARDICT)); if (g_variant_lookup (capabilities, "Scan", "^a&s", &array)) { if (_nm_utils_string_in_list ("active", array)) have_active = TRUE; if (_nm_utils_string_in_list ("ssid", array)) have_ssid = TRUE; g_free (array); } if (g_variant_lookup (capabilities, "MaxScanSSID", "i", &max_scan_ssids)) { /* We need active scan and SSID probe capabilities to care about MaxScanSSIDs */ if (max_scan_ssids > 0 && have_active && have_ssid) { /* wpa_supplicant's WPAS_MAX_SCAN_SSIDS value is 16, but for speed * and to ensure we don't disclose too many SSIDs from the hidden * list, we'll limit to 5. */ priv->max_scan_ssids = CLAMP (max_scan_ssids, 0, 5); nm_log_info (LOGD_SUPPLICANT, "(%s) supports %d scan SSIDs", priv->dev, priv->max_scan_ssids); } } }
/** * 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); }
static void on_prompt_completed (GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); SecretPrompt *self = SECRET_PROMPT (g_async_result_get_source_object (user_data)); PerformClosure *closure = g_simple_async_result_get_op_res_gpointer (res); gboolean dismissed; closure->prompting = FALSE; if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(bv)"))) { g_warning ("SecretPrompt received invalid %s signal of type %s", signal_name, g_variant_get_type_string (parameters)); perform_prompt_complete (res, TRUE); } else { g_variant_get (parameters, "(bv)", &dismissed, &closure->result); perform_prompt_complete (res, dismissed); } g_object_unref (self); }
static void get_capabilities_callback(GObject* source, GAsyncResult* res, gpointer user_data UNUSED) { char** caps; GVariant* result; result = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, NULL); if (result == NULL || !g_variant_is_of_type(result, G_VARIANT_TYPE("(as)"))) { if (result != NULL) { g_variant_unref(result); } return; } g_variant_get(result, "(^a&s)", &caps); for (int i = 0; caps[i] != NULL; i++) { if (g_strcmp0(caps[i], "actions") == 0) { server_supports_actions = TRUE; break; } } g_free(caps); g_variant_unref(result); }
static void test_parse_flt(StateWrapper *wrapper, gconstpointer user_data) { float real_value = 12.3456789; guchar buffer[] = { 0x00, ((guchar*)&real_value)[0], ((guchar*)&real_value)[1], ((guchar*)&real_value)[2], ((guchar*)&real_value)[3], }; wrapper->state->buffer = g_byte_array_append(wrapper->state->buffer, buffer, sizeof(buffer)); SooshiNode *node = g_new0(SooshiNode, 1); node->type = VAL_FLT; sooshi_node_bytes_to_value(node, wrapper->state->buffer, &node->value); g_assert_nonnull(node->value); g_assert_true(g_variant_is_of_type(node->value, G_VARIANT_TYPE_DOUBLE)); g_assert_cmpfloat(g_variant_get_double(node->value), ==, real_value); guchar buffer2[4]; gint length = sooshi_node_value_to_bytes(node, buffer2); g_assert_cmpint(length, ==, sizeof(buffer2)); g_assert_cmpmem(buffer2, length, buffer + 1, sizeof(buffer) - 1); g_free(node); }
static void got_users (GObject *object, GAsyncResult *res, gpointer data) { UmUserManager *manager = data; GVariant *result; GError *error = NULL; result = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), res, &error); if (!result) { manager->no_service = TRUE; g_error_free (error); goto done; } if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(ao)"))) { GVariantIter *iter; gchar *object_path; g_variant_get (result, "(ao)", &iter); while (g_variant_iter_loop (iter, "&o", &object_path)) user_added_handler (manager, object_path); g_variant_iter_free (iter); } g_variant_unref (result); done: g_signal_emit (G_OBJECT (manager), signals[USERS_LOADED], 0); }