SecretValue * _secret_session_decode_secret (SecretSession *session, GVariant *encoded) { SecretValue *result; gconstpointer param; gconstpointer value; gchar *session_path; gchar *content_type; gsize n_param; gsize n_value; GVariant *vparam; GVariant *vvalue; g_return_val_if_fail (session != NULL, NULL); g_return_val_if_fail (encoded != NULL, NULL); /* Parsing (oayays) */ g_variant_get_child (encoded, 0, "o", &session_path); if (session_path == NULL || !g_str_equal (session_path, session->path)) { g_message ("received a secret encoded with wrong session: %s != %s", session_path, session->path); g_free (session_path); return NULL; } vparam = g_variant_get_child_value (encoded, 1); param = g_variant_get_fixed_array (vparam, &n_param, sizeof (guchar)); vvalue = g_variant_get_child_value (encoded, 2); value = g_variant_get_fixed_array (vvalue, &n_value, sizeof (guchar)); g_variant_get_child (encoded, 3, "s", &content_type); #ifdef WITH_GCRYPT if (session->key != NULL) result = service_decode_aes_secret (session, param, n_param, value, n_value, content_type); else #endif result = service_decode_plain_secret (session, param, n_param, value, n_value, content_type); g_variant_unref (vparam); g_variant_unref (vvalue); g_free (content_type); g_free (session_path); return result; }
static void set_calibration (gint *cal, gsize ncal, GSettings *settings) { GVariant *current; /* current calibration */ GVariant *array; /* new calibration */ GVariant **tmp; gsize nvalues; int i; current = g_settings_get_value (settings, "area"); g_variant_get_fixed_array (current, &nvalues, sizeof (gint32)); if ((ncal != 4) || (nvalues != 4)) { g_warning("Unable set set device calibration property. Got %"G_GSIZE_FORMAT" items to put in %"G_GSIZE_FORMAT" slots; expected %d items.\n", ncal, nvalues, 4); return; } tmp = g_malloc (nvalues * sizeof (GVariant*)); for (i = 0; i < ncal; i++) tmp[i] = g_variant_new_int32 (cal[i]); array = g_variant_new_array (G_VARIANT_TYPE_INT32, tmp, nvalues); g_settings_set_value (settings, "area", array); g_free (tmp); }
static void calibrate_button_clicked_cb (GtkButton *button, CcWacomPage *page) { int i, calibration[4]; GVariant *variant; int *current; gsize ncal; gint monitor; monitor = gsd_wacom_device_get_display_monitor (page->priv->stylus); if (monitor < 0) { /* The display the tablet should be mapped to could not be located. * This shouldn't happen if the EDID data is good... */ g_critical("Output associated with the tablet is not connected. Unable to calibrate."); return; } variant = g_settings_get_value (page->priv->wacom_settings, "area"); current = (int *) g_variant_get_fixed_array (variant, &ncal, sizeof (gint32)); if (ncal != 4) { g_warning("Device calibration property has wrong length. Got %"G_GSIZE_FORMAT" items; expected %d.\n", ncal, 4); g_free (current); return; } for (i = 0; i < 4; i++) calibration[i] = current[i]; if (calibration[0] == -1 && calibration[1] == -1 && calibration[2] == -1 && calibration[3] == -1) { gint *device_cal; #ifdef FAKE_AREA GdkScreen *screen; screen = gdk_screen_get_default (); device_cal = g_new0 (int, 4); device_cal[0] = 0; device_cal[1] = gdk_screen_get_width (screen); device_cal[2] = 0; device_cal[3] = gdk_screen_get_height (screen); #else device_cal = gsd_wacom_device_get_area (page->priv->stylus); if (device_cal == NULL) { g_warning ("Failed to get device's area. " "Not running calibration."); return; } #endif /* FAKE_AREA */ for (i = 0; i < 4; i++) calibration[i] = device_cal[i]; g_free (device_cal); }
static char * get_option (GVariant *options, const char *key) { GVariant *value; const guchar *bytes, *s; gsize len; char *converted, *d; if (!g_variant_lookup (options, key, "@ay", &value)) return NULL; bytes = g_variant_get_fixed_array (value, &len, 1); /* Since the DHCP options come through environment variables, they should * already be UTF-8 safe, but just make sure. */ converted = g_malloc (len + 1); for (s = bytes, d = converted; s < bytes + len; s++, d++) { /* Convert NULLs to spaces and non-ASCII characters to ? */ if (*s == '\0') *d = ' '; else if (*s > 127) *d = '?'; else *d = *s; } *d = '\0'; g_variant_unref (value); return converted; }
static void mate_panel_applet_frame_dbus_get_size_hints_cb (MatePanelAppletContainer *container, GAsyncResult *res, MatePanelAppletFrame *frame) { GVariant *value; const gint *sz; gint *size_hints = NULL; gsize n_elements; GError *error = NULL; value = mate_panel_applet_container_child_get_finish (container, res, &error); if (!value) { g_warning ("%s\n", error->message); g_error_free (error); return; } sz = g_variant_get_fixed_array (value, &n_elements, sizeof (gint32)); if (n_elements > 0) { size_hints = g_new (gint32, n_elements); memcpy (size_hints, sz, n_elements * sizeof (gint32)); } _mate_panel_applet_frame_update_size_hints (frame, size_hints, n_elements); g_variant_unref (value); }
/** * Determine whether the specified device instance has the specified * capability. * * @param sdi Pointer to the device instance to be checked. Must not be NULL. * If the device's 'driver' field is NULL (virtual device), this * function will always return FALSE (virtual devices don't have * a hardware capabilities list). * @param[in] key The option that should be checked for is supported by the * specified device. * * @retval TRUE Device has the specified option * @retval FALSE Device does not have the specified option, invalid input * parameters or other error conditions. * * @since 0.2.0 */ SR_API gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key) { GVariant *gvar; const int *devopts; gsize num_opts, i; int ret; if (!sdi || !sdi->driver || !sdi->driver->config_list) return FALSE; if (sdi->driver->config_list(SR_CONF_DEVICE_OPTIONS, &gvar, sdi, NULL) != SR_OK) return FALSE; ret = FALSE; devopts = g_variant_get_fixed_array(gvar, &num_opts, sizeof(int32_t)); for (i = 0; i < num_opts; i++) { if (devopts[i] == key) { ret = TRUE; break; } } g_variant_unref(gvar); return ret; }
void DeviceOptions::bind_samplerate(const QString &name, GVariant *const gvar_list) { GVariant *gvar_list_samplerates; assert(gvar_list); if ((gvar_list_samplerates = g_variant_lookup_value(gvar_list, "samplerate-steps", G_VARIANT_TYPE("at")))) { gsize num_elements; const uint64_t *const elements = (const uint64_t *)g_variant_get_fixed_array( gvar_list_samplerates, &num_elements, sizeof(uint64_t)); assert(num_elements == 3); _properties.push_back(boost::shared_ptr<Property>( new Double(name, 0, QObject::tr("Hz"), make_pair((double)elements[0], (double)elements[1]), (double)elements[2], bind(samplerate_double_getter, _sdi), bind(samplerate_double_setter, _sdi, _1)))); g_variant_unref(gvar_list_samplerates); } else if ((gvar_list_samplerates = g_variant_lookup_value(gvar_list, "samplerates", G_VARIANT_TYPE("at")))) { bind_enum(name, SR_CONF_SAMPLERATE, gvar_list_samplerates, print_samplerate); g_variant_unref(gvar_list_samplerates); } }
gboolean config_key_has_cap(struct sr_dev_driver *driver, const struct sr_dev_inst *sdi, struct sr_channel_group *cg, uint32_t key, uint32_t capability) { GVariant *gvar_opts; const uint32_t *opts; gsize num_opts, i; gboolean result; if (sr_config_list(driver, sdi, cg, SR_CONF_DEVICE_OPTIONS, &gvar_opts) != SR_OK) return FALSE; opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t)); result = FALSE; for (i = 0; i < num_opts; i++) { if ((opts[i] & SR_CONF_MASK) == key) { if ((opts[i] & capability) == capability) result = TRUE; else result = FALSE; break; } } g_variant_unref(gvar_opts); return result; }
/** * Handle @c org.bluez.GattCharacterstic1.WriteValue() method call. * * This handler is triggered when the * @c org.bluez.GattCharacterstic1.WriteValue() method is called by a * client on the BlueZ-based OIC GATT request characteristic. In * particular, IoTivity request data is sent by the GATT client to the * GATT server through this call. The server will retrieve the data * that was sent from the @a value argument. Reassembly of any * request data fragments will begin here. * * @param[in] object @c org.bluez.GattCharacteristic1 skeleton * object associated with this method call. * @param[in] invocation D-Bus method invocation related object used * when sending results/errors asynchronously. * @param[in] value The @c GVariant containing the byte array * (ay) with th request data inside. * @param[in] user_data Pointer to request * @c CAGattCharacteristic object. * * @return @c TRUE to indicate that * @c org.bluez.Characteristic.WriteValue() method is * implemented. */ static gboolean CAGattCharacteristicHandleWriteValue( GattCharacteristic1 * object, GDBusMethodInvocation * invocation, GVariant * value, gpointer user_data) { /* This method is only trigged in a GATT server when receiving data sent by a GATT client, i.e. the client wrote a value to the server, and the server is handling that write request. */ // GLib maps an octet to a guchar, which is of size 1. gsize len = 0; gconstpointer const data = g_variant_get_fixed_array(value, &len, 1); CAGattCharacteristic * const c = user_data; if (CAGattRecv(&c->recv_info, data, (uint32_t) len)) { gatt_characteristic1_complete_write_value(object, invocation); } else { g_dbus_method_invocation_return_dbus_error( invocation, "org.bluez.Error.Failed", "Error when handling GATT request data fragment"); } return TRUE; }
static void photos_main_window_init (PhotosMainWindow *self) { PhotosMainWindowPrivate *priv; GApplication *app; GVariant *variant; PhotosSearchContextState *state; gboolean maximized; const gint32 *position; const gint32 *size; gsize n_elements; self->priv = photos_main_window_get_instance_private (self); priv = self->priv; app = g_application_get_default (); state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app)); priv->settings = photos_settings_new (); variant = g_settings_get_value (priv->settings, "window-size"); size = g_variant_get_fixed_array (variant, &n_elements, sizeof (gint32)); if (n_elements == 2) gtk_window_set_default_size (GTK_WINDOW (self), size[0], size[1]); g_variant_unref (variant); variant = g_settings_get_value (priv->settings, "window-position"); position = g_variant_get_fixed_array (variant, &n_elements, sizeof (gint32)); if (n_elements == 2) gtk_window_move (GTK_WINDOW (self), position[0], position[1]); g_variant_unref (variant); maximized = g_settings_get_boolean (priv->settings, "window-maximized"); if (maximized) gtk_window_maximize (GTK_WINDOW (self)); priv->item_mngr = g_object_ref (state->item_mngr); priv->mode_cntrlr = photos_mode_controller_dup_singleton (); g_signal_connect_swapped (priv->mode_cntrlr, "fullscreen-changed", G_CALLBACK (photos_main_window_fullscreen_changed), self); priv->sel_cntrlr = photos_selection_controller_dup_singleton (); }
static gboolean handle_create_devices (StoragedManagerZRAM *object, GDBusMethodInvocation *invocation, GVariant *sizes_, GVariant *num_streams_, GVariant *options) { StoragedLinuxManagerZRAM *manager = STORAGED_LINUX_MANAGER_ZRAM (object); GError *error = NULL; gsize sizes_len; gsize streams_len; guint64 *sizes; guint64 *num_streams; /* Policy check */ STORAGED_DAEMON_CHECK_AUTHORIZATION (manager->daemon, NULL, zram_policy_action_id, options, N_("Authentication is required to add zRAM kernel module"), invocation); sizes = (guint64*) g_variant_get_fixed_array (sizes_, &sizes_len, sizeof (guint64)); num_streams = (guint64*) g_variant_get_fixed_array (num_streams_, &streams_len, sizeof (guint64)); if (! create_conf_files ((guint64) streams_len, sizes, num_streams, &error)) { g_dbus_method_invocation_take_error (invocation, error); goto out; } if (! bd_kbd_zram_create_devices ((guint64) sizes_len, sizes, num_streams, &error)) { g_dbus_method_invocation_take_error (invocation, error); delete_conf_files (&error); goto out; } storaged_manager_zram_complete_create_devices(object, invocation); out: return TRUE; }
static gint get_n_monitors (NemoDesktopManager *manager) { FETCH_PRIV (manager); gsize n_monitors, i; const gint *indices G_GNUC_UNUSED; GVariant *monitors; GError *error; if (priv->current_run_state == RUN_STATE_FALLBACK) { DEBUG ("Currently in fallback mode, retrieving n_monitors via GdkScreen"); n_monitors = nemo_desktop_utils_get_num_monitors (); goto out; } error = NULL; if (!nemo_cinnamon_call_get_monitors_sync (priv->proxy, &monitors, NULL, &error)) { DEBUG ("Attempting proxy call 'GetMonitors' failed, retrieving n_monitors via GdkScreen: %s", error ? error->message : NULL); g_clear_error (&error); n_monitors = nemo_desktop_utils_get_num_monitors (); goto out; } DEBUG ("Proxy call to 'GetMonitors' succeeded"); indices = g_variant_get_fixed_array (monitors, &n_monitors, sizeof(gint)); g_variant_unref (monitors); out: if (DEBUGGING) { GString *string = g_string_new (NULL); for (i = 0; i < n_monitors; i++) { gchar *m = g_strdup_printf (" %lu", i); string = g_string_append (string, m); g_free (m); } DEBUG ("Found %lu monitor(s):%s", n_monitors, string->str); g_string_free (string, TRUE); } return n_monitors; }
void Peer::handle_property_change (const char *name, GVariant *property) { if (g_strcmp0(name, "State") == 0) { state_changed (g_variant_get_string (property, NULL)); } else if (g_strcmp0(name, "Name") == 0) { name_changed (g_variant_get_string (property, NULL)); } else if (g_strcmp0(name, "Services") == 0) { GVariantIter *service_array, *services; GVariant *spec_val; g_variant_get (property, "a(a{sv})", &service_array); while (g_variant_iter_loop (service_array, "(a{sv})", &services)) { const char *service_name; while (g_variant_iter_loop (services, "{sv}", &service_name, &spec_val)) { if (g_strcmp0 (service_name, "WiFiDisplayIEs") == 0) { uint8_t *bytes; gsize length; bytes = (uint8_t*)g_variant_get_fixed_array (spec_val, &length, 1); std::unique_ptr<P2P::InformationElementArray> array (new P2P::InformationElementArray(length, bytes)); ie_.reset(new P2P::InformationElement (array)); } } } g_variant_iter_free (service_array); } else if (g_strcmp0(name, "IPv4") == 0) { GVariantIter *ips; GVariant *spec_val; char *name; const char *remote = ""; const char *local = ""; g_variant_get (property, "a{sv}", &ips); while (g_variant_iter_loop (ips, "{sv}", &name, &spec_val)) { if (g_strcmp0 (name, "Remote") == 0) { remote = g_variant_get_string (spec_val, NULL); } else if (g_strcmp0 (name, "Local") == 0) { local = g_variant_get_string (spec_val, NULL); } } ips_changed (remote, local); g_variant_iter_free (ips); } }
static void panel_applet_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { PanelApplet *applet = PANEL_APPLET (object); switch (prop_id) { case PROP_ID: applet->priv->id = g_value_dup_string (value); break; case PROP_CLOSURE: applet->priv->closure = g_value_get_pointer (value); /* We know closure should not be NULL, but we'll fail in * panel_applet_constructed() with a proper message if this is * the case. */ if (applet->priv->closure) g_closure_set_marshal (applet->priv->closure, panel_applet_marshal_BOOLEAN__STRING); break; case PROP_SETTINGS_PATH: panel_applet_set_settings_path (applet, g_value_get_string (value)); break; case PROP_ORIENT: panel_applet_set_orient (applet, g_value_get_uint (value)); break; case PROP_FLAGS: panel_applet_set_flags (applet, g_value_get_uint (value)); break; case PROP_SIZE_HINTS: { const int *size_hints; gsize n_elements; size_hints = g_variant_get_fixed_array (g_value_get_pointer (value), &n_elements, sizeof (gint32)); panel_applet_set_size_hints (applet, size_hints, n_elements, 0); } break; case PROP_LOCKED_DOWN: panel_applet_set_locked_down (applet, g_value_get_boolean (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } }
static void calibrate_button_clicked_cb (GtkButton *button, CcWacomPage *page) { int i, calibration[4]; GVariant *variant; int *current; gsize ncal; gint monitor; monitor = csd_wacom_device_get_display_monitor (page->priv->stylus); if (monitor < 0) { /* The display the tablet should be mapped to could not be located. * This shouldn't happen if the EDID data is good... */ g_critical("Output associated with the tablet is not connected. Unable to calibrate."); return; } variant = g_settings_get_value (page->priv->wacom_settings, "area"); current = (int *) g_variant_get_fixed_array (variant, &ncal, sizeof (gint32)); if (ncal != 4) { g_warning("Device calibration property has wrong length. Got %"G_GSIZE_FORMAT" items; expected %d.\n", ncal, 4); g_free (current); return; } for (i = 0; i < 4; i++) calibration[i] = current[i]; if (calibration[0] == -1 && calibration[1] == -1 && calibration[2] == -1 && calibration[3] == -1) { gint *device_cal; device_cal = csd_wacom_device_get_area (page->priv->stylus); for (i = 0; i < 4 && device_cal; i++) { calibration[i] = device_cal[i]; } g_free (device_cal); } run_calibration (page, calibration, monitor); gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE); }
static void mate_panel_applet_frame_dbus_size_hints_changed (MatePanelAppletContainer *container, const gchar *prop_name, GVariant *value, MatePanelAppletFrame *frame) { const gint *sz; gint *size_hints = NULL; gsize n_elements; sz = g_variant_get_fixed_array (value, &n_elements, sizeof (gint32)); if (n_elements > 0) { size_hints = g_new (gint32, n_elements); memcpy (size_hints, sz, n_elements * sizeof (gint32)); } _mate_panel_applet_frame_update_size_hints (frame, size_hints, n_elements); }
static int check_options(struct sr_dev_driver *driver, GSList *options, uint32_t optlist_key, struct sr_dev_inst *sdi, struct sr_channel_group *cg) { struct sr_config *src; const struct sr_key_info *srci; GVariant *gvar_opts; GSList *l; const uint32_t *opts; gsize num_opts, i; int ret; if (sr_config_list(driver, sdi, cg, optlist_key, &gvar_opts) != SR_OK) { /* Driver publishes no options for this optlist. */ return SR_ERR; } ret = SR_OK; opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t)); for (l = options; l; l = l->next) { src = l->data; for (i = 0; i < num_opts; i++) { if (opts[i] == src->key) break; } if (i == num_opts) { if (!(srci = sr_key_info_get(SR_KEY_CONFIG, src->key))) /* Shouldn't happen. */ sr_err("Invalid option %d.", src->key); else sr_err("Invalid option '%s'.", srci->id); ret = SR_ERR_ARG; break; } if (sr_variant_type_check(src->key, src->data) != SR_OK) { ret = SR_ERR_ARG; break; } } g_variant_unref(gvar_opts); return ret; }
/* org.nemomobile.MmsEngine.pushNotify */ static gboolean mms_engine_handle_push_notify( OrgNemomobileMmsEngine* proxy, GDBusMethodInvocation* call, const char* imsi, const char* type, GVariant* data, MMSEngine* engine) { gsize len = 0; const guint8* bytes = g_variant_get_fixed_array(data, &len, 1); MMS_DEBUG("Received %u bytes from %s", (guint)len, imsi); if (!type || g_ascii_strcasecmp(type, MMS_CONTENT_TYPE)) { MMS_ERR("Unsupported content type %s", type); g_dbus_method_invocation_return_error(call, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Unsupported content type"); } else if (!imsi || !imsi[0]) { MMS_ERR_("IMSI is missing"); g_dbus_method_invocation_return_error(call, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "IMSI is missing"); } else if (!bytes || !len) { MMS_ERR_("No data provided"); g_dbus_method_invocation_return_error(call, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No data provided"); } else { GError* err = NULL; GBytes* msg = g_bytes_new(bytes, len); if (mms_dispatcher_handle_push(engine->dispatcher, imsi, msg, &err)) { if (mms_dispatcher_start(engine->dispatcher)) { mms_engine_start_timeout_cancel(engine); } org_nemomobile_mms_engine_complete_push(proxy, call); } else { g_dbus_method_invocation_return_error(call, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "%s", MMS_ERRMSG(err)); g_error_free(err); } g_bytes_unref(msg); } return TRUE; }
/** * Enumerate scan options supported by this driver. * * Before calling sr_driver_scan_options_list(), the user must have previously * initialized the driver by calling sr_driver_init(). * * @param driver The driver to enumerate options for. This must be a pointer * to one of the entries returned by sr_driver_list(). Must not * be NULL. * * @return A GArray * of uint32_t entries, or NULL on invalid arguments. Each * entry is a configuration key that is supported as a scan option. * The array must be freed by the caller using g_array_free(). * * @since 0.4.0 */ SR_API GArray *sr_driver_scan_options_list(const struct sr_dev_driver *driver) { GVariant *gvar; const uint32_t *opts; gsize num_opts; GArray *result; if (sr_config_list(driver, NULL, NULL, SR_CONF_SCAN_OPTIONS, &gvar) != SR_OK) return NULL; opts = g_variant_get_fixed_array(gvar, &num_opts, sizeof(uint32_t)); result = g_array_sized_new(FALSE, FALSE, sizeof(uint32_t), num_opts); g_array_insert_vals(result, 0, opts, num_opts); g_variant_unref(gvar); return result; }
static char * ay_to_string (GVariant *variant, GError **error) { gsize len; const char *data; data = g_variant_get_fixed_array (variant, &len, sizeof (char)); if (len == 0) return NULL; /* Make sure there are no embedded NULs */ if (memchr (data, '\0', len) != NULL) { g_set_error_literal (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "String is shorter than claimed"); return NULL; } return g_strndup (data, len); }
gboolean ostree_set_xattrs (GFile *f, GVariant *xattrs, GCancellable *cancellable, GError **error) { const char *path; gboolean ret = FALSE; int i, n; path = ot_gfile_get_path_cached (f); n = g_variant_n_children (xattrs); for (i = 0; i < n; i++) { const guint8* name; GVariant *value; const guint8* value_data; gsize value_len; gboolean loop_err; g_variant_get_child (xattrs, i, "(^&ay@ay)", &name, &value); value_data = g_variant_get_fixed_array (value, &value_len, 1); loop_err = lsetxattr (path, (char*)name, (char*)value_data, value_len, XATTR_REPLACE) < 0; g_clear_pointer (&value, (GDestroyNotify) g_variant_unref); if (loop_err) { ot_util_set_error_from_errno (error, errno); goto out; } } ret = TRUE; out: return ret; }
/* org.nemomobile.MmsEngine.receiveMessage */ static gboolean mms_engine_handle_receive_message( OrgNemomobileMmsEngine* proxy, GDBusMethodInvocation* call, int database_id, const char* imsi, gboolean automatic, GVariant* data, MMSEngine* engine) { gsize len = 0; const guint8* bytes = g_variant_get_fixed_array(data, &len, 1); MMS_DEBUG("Processing push %u bytes from %s", (guint)len, imsi); if (imsi && bytes && len) { char* id = g_strdup_printf("%d", database_id); GBytes* push = g_bytes_new(bytes, len); GError* error = NULL; if (mms_dispatcher_receive_message(engine->dispatcher, id, imsi, automatic, push, &error)) { if (mms_dispatcher_start(engine->dispatcher)) { mms_engine_start_timeout_cancel(engine); } org_nemomobile_mms_engine_complete_receive_message(proxy, call); } else { g_dbus_method_invocation_return_error(call, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "%s", MMS_ERRMSG(error)); g_error_free(error); } g_bytes_unref(push); g_free(id); } else { g_dbus_method_invocation_return_error(call, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Invalid parameters"); } return TRUE; }
void equalizer_get_eq (int argc, char * * argv) { double preamp = 0.0; GVariant * var = NULL; obj_audacious_call_get_eq_sync (dbus_proxy, & preamp, & var, NULL, NULL); if (! var || ! g_variant_is_of_type (var, G_VARIANT_TYPE ("ad"))) exit (1); audtool_report ("preamp = %.2f", preamp); size_t nbands = 0; const double * bands = g_variant_get_fixed_array (var, & nbands, sizeof (double)); if (nbands != NUM_BANDS) exit (1); for (int i = 0; i < NUM_BANDS; i ++) printf ("%.2f ", bands[i]); printf ("\n"); g_variant_unref (var); }
static void update_sensor_value(IsTemperatureSensor *sensor, IsUdisksPlugin *self) { IsUdisksPluginPrivate *priv; gchar *device, *path; GDBusProxy *proxy; GVariant *var; GError *error = NULL; SkDisk *sk_disk; const gchar *blob; gsize len; guint64 temperature; gdouble value; priv = self->priv; device = g_path_get_basename(is_sensor_get_path(IS_SENSOR(sensor))); path = g_strdup_printf("%s/devices/%s", UDISKS_OBJECT_PATH, device); proxy = g_dbus_proxy_new_sync(priv->connection, G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, NULL, UDISKS_BUS_NAME, path, UDISKS_DEVICE_INTERFACE_NAME, NULL, &error); g_free(path); g_free(device); if (!proxy) { g_prefix_error(&error, _("Error reading new SMART data for sensor %s"), is_sensor_get_path(IS_SENSOR(sensor))); is_sensor_emit_error(IS_SENSOR(sensor), error); g_error_free(error); goto out; } /* update smart data */ var = g_variant_new_strv(NULL, 0); var = g_dbus_proxy_call_sync(proxy, "DriveAtaSmartRefreshData", g_variant_new_tuple(&var, 1), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (!var) { g_prefix_error(&error, _("Error refreshing SMART data for sensor %s"), is_sensor_get_path(IS_SENSOR(sensor))); is_sensor_emit_error(IS_SENSOR(sensor), error); g_error_free(error); g_object_unref(proxy); goto out; } g_variant_unref(var); var = g_dbus_proxy_get_cached_property(proxy, "DriveAtaSmartBlob"); if (!var) { is_debug("udisks", "unable to get atasmartblob for sensor %s", is_sensor_get_path(IS_SENSOR(sensor))); g_object_unref(proxy); goto out; } g_object_unref(proxy); /* can't unref var until done with blob */ blob = g_variant_get_fixed_array(var, &len, sizeof(gchar)); if (!blob) { /* this can occur if udisks doesn't update immediately, * ignore */ g_variant_unref(var); goto out; } sk_disk_open(NULL, &sk_disk); sk_disk_set_blob(sk_disk, blob, len); if (sk_disk_smart_get_temperature(sk_disk, &temperature) < 0) { is_debug("udisks", "Error getting temperature from AtaSmartBlob for sensor %s", is_sensor_get_path(IS_SENSOR(sensor))); sk_disk_free(sk_disk); g_variant_unref(var); /* TODO: emit error */ goto out; } sk_disk_free(sk_disk); g_variant_unref(var); /* Temperature is in mK, so convert it to K first */ temperature /= 1000; value = (gdouble)temperature - 273.15; is_temperature_sensor_set_celsius_value(sensor, value); out: return; }
DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) : _sdi(sdi) { GVariant *gvar_opts, *gvar_list; gsize num_opts; if ((sr_config_list(sdi->driver, sdi, NULL, SR_CONF_DEVICE_CONFIGS, &gvar_opts) != SR_OK)) /* Driver supports no device instance options. */ return; const int *const options = (const int32_t *)g_variant_get_fixed_array( gvar_opts, &num_opts, sizeof(int32_t)); for (unsigned int i = 0; i < num_opts; i++) { const struct sr_config_info *const info = sr_config_info_get(options[i]); if (!info) continue; const int key = info->key; if(sr_config_list(_sdi->driver, _sdi, NULL, key, &gvar_list) != SR_OK) gvar_list = NULL; const QString name(info->label); switch(key) { case SR_CONF_SAMPLERATE: bind_samplerate(name, gvar_list); break; case SR_CONF_CAPTURE_RATIO: bind_int(name, key, "%", pair<int64_t, int64_t>(0, 100)); break; case SR_CONF_PATTERN_MODE: case SR_CONF_BUFFERSIZE: case SR_CONF_TRIGGER_SOURCE: case SR_CONF_FILTER: case SR_CONF_COUPLING: case SR_CONF_EN_CH: case SR_CONF_OPERATION_MODE: case SR_CONF_THRESHOLD: case SR_CONF_ZERO: case SR_CONF_STREAM: case SR_CONF_TEST: case SR_CONF_STATUS: case SR_CONF_FACTOR: bind_enum(name, key, gvar_list); break; case SR_CONF_VTH: bind_double(name, key, "V", pair<double, double>(0.0, 5.0), 1, 0.1); break; case SR_CONF_RLE: bind_bool(name, key); break; case SR_CONF_CLOCK_TYPE: case SR_CONF_CLOCK_EDGE: case SR_CONF_INSTANT: case SR_CONF_DATALOCK: bind_bool(name, key); break; case SR_CONF_TIMEBASE: bind_enum(name, key, gvar_list, print_timebase); break; case SR_CONF_VDIV: bind_enum(name, key, gvar_list, print_vdiv); break; default: gvar_list = NULL; } if (gvar_list) g_variant_unref(gvar_list); } g_variant_unref(gvar_opts); }
DeviceOptions::DeviceOptions(shared_ptr<pv::device::DevInst> dev_inst, const sr_channel_group *group) : _dev_inst(dev_inst), _group(group) { assert(dev_inst); GVariant *gvar_opts; gsize num_opts; if (!(gvar_opts = dev_inst->list_config(group, SR_CONF_DEVICE_OPTIONS))) /* Driver supports no device instance options. */ return; const int *const options = (const int32_t *)g_variant_get_fixed_array( gvar_opts, &num_opts, sizeof(int32_t)); for (unsigned int i = 0; i < num_opts; i++) { const struct sr_config_info *const info = sr_config_info_get(options[i]); if (!info) continue; const int key = info->key; GVariant *const gvar_list = dev_inst->list_config(group, key); const QString name = QString::fromUtf8(info->name); const Property::Getter get = [&, key]() { return _dev_inst->get_config(_group, key); }; const Property::Setter set = [&, key](GVariant *value) { _dev_inst->set_config(_group, key, value); }; switch(key) { case SR_CONF_SAMPLERATE: // Sample rate values are not bound because they are shown // in the SamplingBar break; case SR_CONF_CAPTURE_RATIO: bind_int(name, "%", pair<int64_t, int64_t>(0, 100), get, set); break; case SR_CONF_PATTERN_MODE: case SR_CONF_BUFFERSIZE: case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SLOPE: case SR_CONF_FILTER: case SR_CONF_COUPLING: case SR_CONF_CLOCK_EDGE: bind_enum(name, key, gvar_list, get, set); break; case SR_CONF_EXTERNAL_CLOCK: case SR_CONF_RLE: bind_bool(name, get, set); break; case SR_CONF_TIMEBASE: bind_enum(name, key, gvar_list, get, set, print_timebase); break; case SR_CONF_VDIV: bind_enum(name, key, gvar_list, get, set, print_vdiv); break; case SR_CONF_VOLTAGE_THRESHOLD: bind_enum(name, key, gvar_list, get, set, print_voltage_threshold); break; } if (gvar_list) g_variant_unref(gvar_list); } g_variant_unref(gvar_opts); }
DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) : _sdi(sdi) { GVariant *gvar_opts, *gvar_list; gsize num_opts; if ((sr_config_list(sdi->driver, SR_CONF_DEVICE_CONFIGS, &gvar_opts, sdi) != SR_OK)) /* Driver supports no device instance options. */ return; const int *const options = (const int32_t *)g_variant_get_fixed_array( gvar_opts, &num_opts, sizeof(int32_t)); for (unsigned int i = 0; i < num_opts; i++) { const struct sr_config_info *const info = sr_config_info_get(options[i]); if (!info) continue; const int key = info->key; if(sr_config_list(_sdi->driver, key, &gvar_list, _sdi) != SR_OK) gvar_list = NULL; const QString name(info->name); switch(key) { case SR_CONF_SAMPLERATE: bind_samplerate(name, gvar_list); break; case SR_CONF_CAPTURE_RATIO: bind_int(name, key, "%", pair<int64_t, int64_t>(0, 100)); break; case SR_CONF_DEVICE_MODE: case SR_CONF_PATTERN_MODE: case SR_CONF_BUFFERSIZE: case SR_CONF_TRIGGER_SOURCE: case SR_CONF_FILTER: case SR_CONF_COUPLING: bind_enum(name, key, gvar_list); break; case SR_CONF_RLE: bind_bool(name, key); break; case SR_CONF_CLOCK_TYPE: bind_bool(name, key); break; case SR_CONF_TIMEBASE: bind_enum(name, key, gvar_list, print_timebase); break; case SR_CONF_VDIV: bind_enum(name, key, gvar_list, print_vdiv); break; } if (gvar_list) g_variant_unref(gvar_list); } g_variant_unref(gvar_opts); }
static void get_window_rect_for_monitor (NemoDesktopManager *manager, gint monitor, GdkRectangle *rect) { FETCH_PRIV (manager); GVariant *out_rect_var; GdkRectangle out_rect; gsize n_elem; gint scale_factor; GError *error; error = NULL; out_rect_var = NULL; if (priv->current_run_state == RUN_STATE_FALLBACK) { DEBUG ("Currently in fallback mode, retrieving n_monitors via GdkScreen"); nemo_desktop_utils_get_monitor_geometry (monitor, &out_rect); goto out; } if (!nemo_cinnamon_call_get_monitor_work_rect_sync (priv->proxy, monitor, &out_rect_var, NULL, &error)) { DEBUG ("Attempting proxy call 'GetMonitorWorkRect' failed, retrieving n_monitors via GdkScreen: %s", error ? error->message : NULL); g_clear_error (&error); nemo_desktop_utils_get_monitor_geometry (monitor, &out_rect); goto out; } out_rect = *( (GdkRectangle *) g_variant_get_fixed_array (out_rect_var, &n_elem, sizeof(gint)) ); /* GdkScreen sizes are scaled for hidpi already. But if we've gotten this far, we're using * Cinnamon-provided numbers, which aren't scaled. */ scale_factor = nemo_desktop_utils_get_scale_factor (); out_rect.x /= scale_factor; out_rect.y /= scale_factor; out_rect.width /= scale_factor; out_rect.height /= scale_factor; out: rect->x = out_rect.x; rect->y = out_rect.y; rect->width = out_rect.width; rect->height = out_rect.height; if (out_rect_var != NULL) { g_variant_unref (out_rect_var); } }
static gboolean terminal_receiver_impl_exec (TerminalReceiver *receiver, GDBusMethodInvocation *invocation, GUnixFDList *fd_list, GVariant *options, GVariant *arguments) { TerminalReceiverImpl *impl = TERMINAL_RECEIVER_IMPL (receiver); TerminalReceiverImplPrivate *priv = impl->priv; const char *working_directory; gboolean shell; char **exec_argv, **envv; gsize exec_argc; GVariant *fd_array; GError *error; if (priv->screen == NULL) { g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Terminal already closed"); goto out; } if (!g_variant_lookup (options, "cwd", "^&ay", &working_directory)) working_directory = NULL; if (!g_variant_lookup (options, "shell", "b", &shell)) shell = FALSE; if (!g_variant_lookup (options, "environ", "^a&ay", &envv)) envv = NULL; if (!g_variant_lookup (options, "fd-set", "@a(ih)", &fd_array)) fd_array = NULL; /* Check FD passing */ if ((fd_list != NULL) ^ (fd_array != NULL)) { g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Must pass both fd-set options and a FD list"); goto out; } if (fd_list != NULL && fd_array != NULL) { const int *fd_array_data; gsize fd_array_data_len, i; int n_fds; fd_array_data = g_variant_get_fixed_array (fd_array, &fd_array_data_len, 2 * sizeof (int)); n_fds = g_unix_fd_list_get_length (fd_list); for (i = 0; i < fd_array_data_len; i++) { const int fd = fd_array_data[2 * i]; const int idx = fd_array_data[2 * i + 1]; if (fd == STDIN_FILENO || fd == STDOUT_FILENO || fd == STDERR_FILENO) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Passing of std%s not supported", fd == STDIN_FILENO ? "in" : fd == STDOUT_FILENO ? "out" : "err"); goto out; } if (idx < 0 || idx >= n_fds) { g_dbus_method_invocation_return_error_literal (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Handle out of range"); goto out; } } } if (working_directory != NULL) _terminal_debug_print (TERMINAL_DEBUG_SERVER, "CWD is '%s'\n", working_directory); exec_argv = (char **) g_variant_get_bytestring_array (arguments, &exec_argc); error = NULL; if (!terminal_screen_exec (priv->screen, exec_argc > 0 ? exec_argv : NULL, envv, shell, working_directory, fd_list, fd_array, &error)) { g_dbus_method_invocation_take_error (invocation, error); } else { terminal_receiver_complete_exec (receiver, invocation, NULL /* outfdlist */); } g_free (exec_argv); g_free (envv); if (fd_array) g_variant_unref (fd_array); out: return TRUE; /* handled */ }
/** * Convert a GVariant to a Scheme object. Returns NULL if there's a * problem. */ static Scheme_Object * g_variant_to_scheme_object (GVariant *gv) { const GVariantType *type; // The type of the GVariant const gchar *typestring; // A string that describes the type int i; // A counter variable int len; // Length of arrays and tuples Scheme_Object *lst = NULL; // A list that we build as a result Scheme_Object *sval = NULL; // One value Scheme_Object *result = NULL; // One result to return. // Special case: We'll treat NULL as void. if (gv == NULL) { return scheme_void; } // if (gv == NULL) // Get the type type = g_variant_get_type (gv); typestring = g_variant_get_type_string (gv); // ** Handle most of the basic types ** // Integer if (g_variant_type_equal (type, G_VARIANT_TYPE_INT32)) { // We don't refer to any Scheme objects across allocating calls, // so no need for GC code. int i; i = g_variant_get_int32 (gv); result = scheme_make_integer (i); return result; } // if it's an integer // Double if (g_variant_type_equal (type, G_VARIANT_TYPE_DOUBLE)) { double d; d = g_variant_get_double (gv); result = scheme_make_double (d); return result; } // if it's a double // String if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING)) { // We don't refer to any Scheme objects across allocating calls, // so no need for GC code. const gchar *str; str = g_variant_get_string (gv, NULL); result = scheme_make_locale_string (str); return result; } // if it's a string // ** Handle some special cases ** // We treat arrays of bytes as bytestrings if (g_strcmp0 (typestring, "ay") == 0) { gsize size; guchar *data; data = (guchar *) g_variant_get_fixed_array (gv, &size, sizeof (guchar)); return scheme_make_sized_byte_string ((char *) data, size, 1); } // if it's an array of bytes // ** Handle the compound types ** // Tuple or Array if ( (g_variant_type_is_tuple (type)) || (g_variant_type_is_array (type)) ) { // Find out how many values to put into the list. len = g_variant_n_children (gv); // Here, we are referring to stuff across allocating calls, so we // need to be careful. MZ_GC_DECL_REG (2); MZ_GC_VAR_IN_REG (0, lst); MZ_GC_VAR_IN_REG (1, sval); MZ_GC_REG (); // Start with the empty list. lst = scheme_null; // Step through the items, right to left, adding them to the list. for (i = len-1; i >= 0; i--) { sval = g_variant_to_scheme_object (g_variant_get_child_value (gv, i)); lst = scheme_make_pair (sval, lst); } // for // Okay, we've made it through the list, now we can clean up. MZ_GC_UNREG (); if ((g_variant_type_is_array (type))) { //If type is array, convert to vector scheme_list_to_vector ((char*)lst); }//If array // And we're done. return lst; } // if it's a tuple or an array // Unknown. Give up. scheme_signal_error ("Unknown type %s", typestring); return scheme_void; } // g_variant_to_scheme_object