GVariant *
mm_location_cdma_bs_get_dictionary (MMLocationCdmaBs *self)
{
    GVariantBuilder builder;

    /* We do allow NULL */
    if (!self)
        return NULL;

    g_return_val_if_fail (MM_IS_LOCATION_CDMA_BS (self), NULL);

    /* If mandatory parameters are not found, return NULL */
    if (self->priv->longitude == MM_LOCATION_LONGITUDE_UNKNOWN ||
        self->priv->latitude == MM_LOCATION_LATITUDE_UNKNOWN)
        return NULL;

    g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
    g_variant_builder_add (&builder,
                           "{sv}",
                           PROPERTY_LONGITUDE,
                           g_variant_new_double (self->priv->longitude));
    g_variant_builder_add (&builder,
                           "{sv}",
                           PROPERTY_LATITUDE,
                           g_variant_new_double (self->priv->latitude));

    return g_variant_ref_sink (g_variant_builder_end (&builder));
}
Esempio n. 2
0
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	struct dev_context *devc;
	GVariant *range[2];

	(void)cg;

	if (!sdi)
		return SR_ERR_ARG;

	devc = sdi->priv;

	switch (key) {
	case SR_CONF_SAMPLERATE:
		*data = g_variant_new_uint64(devc->cur_samplerate);
		break;
	case SR_CONF_CAPTURE_RATIO:
		*data = g_variant_new_uint64(devc->capture_ratio);
		break;
	case SR_CONF_VOLTAGE_THRESHOLD:
		range[0] = g_variant_new_double(devc->cur_threshold);
		range[1] = g_variant_new_double(devc->cur_threshold);
		*data = g_variant_new_tuple(range, 2);
		break;
	default:
		return SR_ERR_NA;
	}

	return SR_OK;
}
Esempio n. 3
0
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	struct dev_context *devc;
	struct sr_usb_dev_inst *usb;
	GVariant *range[2];
	char str[128];
	int ret;
	unsigned int i;

	(void)cg;

	ret = SR_OK;
	switch (key) {
	case SR_CONF_CONN:
		if (!sdi || !sdi->conn)
			return SR_ERR_ARG;
		usb = sdi->conn;
		if (usb->address == 255)
			/* Device still needs to re-enumerate after firmware
			 * upload, so we don't know its (future) address. */
			return SR_ERR;
		snprintf(str, 128, "%d.%d", usb->bus, usb->address);
		*data = g_variant_new_string(str);
		break;
	case SR_CONF_SAMPLERATE:
		if (!sdi)
			return SR_ERR;
		devc = sdi->priv;
		*data = g_variant_new_uint64(devc->cur_samplerate);
		break;
	case SR_CONF_CAPTURE_RATIO:
		if (!sdi)
			return SR_ERR;
		devc = sdi->priv;
		*data = g_variant_new_uint64(devc->capture_ratio);
		break;
	case SR_CONF_VOLTAGE_THRESHOLD:
		if (!sdi)
			return SR_ERR;
		devc = sdi->priv;
		ret = SR_ERR;
		for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++) {
			if (devc->selected_voltage_range !=
			    volt_thresholds[i].range)
				continue;
			range[0] = g_variant_new_double(volt_thresholds[i].low);
			range[1] = g_variant_new_double(volt_thresholds[i].high);
			*data = g_variant_new_tuple(range, 2);
			ret = SR_OK;
			break;
		}
		break;
	default:
		return SR_ERR_NA;
	}

	return ret;
}
Esempio n. 4
0
static int config_list(uint32_t key, GVariant **data,
	const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
	GVariantBuilder gvb;
	int ret;

	/* Always available. */
	if (key == SR_CONF_SCAN_OPTIONS) {
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
			scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
		return SR_OK;
	}

	if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
			drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
		return SR_OK;
	}

	if (!sdi)
		return SR_ERR_ARG;

	ret = SR_OK;

	if (!cg) {
		/* No channel group: global options. */
		switch (key) {
		case SR_CONF_DEVICE_OPTIONS:
			*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
				devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
			break;
		default:
			return SR_ERR_NA;
		}
	} else {
		switch (key) {
		case SR_CONF_DEVICE_OPTIONS:
			*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
				devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
			break;
		case SR_CONF_CURRENT_LIMIT:
			g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
			/* Min, max, step. */
			g_variant_builder_add_value(&gvb, g_variant_new_double(0.0));
			g_variant_builder_add_value(&gvb, g_variant_new_double(6.0));
			g_variant_builder_add_value(&gvb, g_variant_new_double(0.001)); /* 1mA steps */
			*data = g_variant_builder_end(&gvb);
			break;
		default:
			return SR_ERR_NA;
		}
	}

	return ret;
}
Esempio n. 5
0
static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	struct dev_context *devc;
	struct sr_channel *ch;
	int channel, ret;

	if (!sdi)
		return SR_ERR_ARG;

	devc = sdi->priv;

	ret = SR_OK;
	if (!cg) {
		/* No channel group: global options. */
		switch (key) {
		case SR_CONF_OUTPUT_CHANNEL:
			*data = g_variant_new_string(channel_modes[devc->channel_mode]);
			break;
		case SR_CONF_OVER_CURRENT_PROTECTION:
			*data = g_variant_new_boolean(devc->over_current_protection);
			break;
		default:
			return SR_ERR_NA;
		}
	} else {
		/* We only ever have one channel per channel group in this driver. */
		ch = cg->channels->data;
		channel = ch->index;

		switch (key) {
		case SR_CONF_OUTPUT_VOLTAGE:
			*data = g_variant_new_double(devc->config[channel].output_voltage_last);
			break;
		case SR_CONF_OUTPUT_VOLTAGE_MAX:
			*data = g_variant_new_double(devc->config[channel].output_voltage_max);
			break;
		case SR_CONF_OUTPUT_CURRENT:
			*data = g_variant_new_double(devc->config[channel].output_current_last);
			break;
		case SR_CONF_OUTPUT_CURRENT_MAX:
			*data = g_variant_new_double(devc->config[channel].output_current_max);
			break;
		case SR_CONF_OUTPUT_ENABLED:
			*data = g_variant_new_boolean(devc->config[channel].output_enabled);
			break;
		default:
			return SR_ERR_NA;
		}
	}

	return ret;
}
Esempio n. 6
0
static int config_get(uint32_t key, GVariant **data,
	const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
	struct dev_context *devc;

	(void)cg;

	if (!sdi || !data)
		return SR_ERR_ARG;

	devc = sdi->priv;

	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
		*data = g_variant_new_uint64(devc->limit_samples);
		break;
	case SR_CONF_LIMIT_MSEC:
		*data = g_variant_new_uint64(devc->limit_msec);
		break;
	case SR_CONF_VOLTAGE:
		*data = g_variant_new_double(devc->voltage);
		break;
	case SR_CONF_VOLTAGE_TARGET:
		*data = g_variant_new_double(devc->voltage_max);
		break;
	case SR_CONF_CURRENT:
		*data = g_variant_new_double(devc->current);
		break;
	case SR_CONF_CURRENT_LIMIT:
		*data = g_variant_new_double(devc->current_max);
		break;
	case SR_CONF_ENABLED:
		*data = g_variant_new_boolean(devc->output_enabled);
		break;
	case SR_CONF_REGULATION:
		/* Dual channel not supported. */
		*data = g_variant_new_string((devc->cc_mode[0]) ? "CC" : "CV");
		break;
	case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
		*data = g_variant_new_boolean(devc->ocp_enabled);
		break;
	case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
		*data = g_variant_new_boolean(devc->ovp_enabled);
		break;
	default:
		return SR_ERR_NA;
	}

	return SR_OK;
}
Esempio n. 7
0
/*
 *
 * Fundemental type transformations
 *
 */
static GVariant *
serialize_fundamental(GvsSerializer *self, const GValue *value, gpointer unused)
{
    GVariant *variant;

    switch (G_VALUE_TYPE(value))
    {
        case G_TYPE_BOOLEAN:
            variant = g_variant_new_boolean(g_value_get_boolean(value));
            break;
        case G_TYPE_CHAR:
            variant = g_variant_new_byte(g_value_get_schar(value));
            break;
        case G_TYPE_DOUBLE:
            variant = g_variant_new_double(g_value_get_double(value));
            break;
        case G_TYPE_FLOAT:
            variant = g_variant_new_double(g_value_get_float(value));
            break;
        case G_TYPE_INT:
            variant = g_variant_new_int32(g_value_get_int(value));
            break;
        case G_TYPE_INT64:
        case G_TYPE_LONG:
            variant = g_variant_new_int64(g_value_get_int64(value));
            break;
        case G_TYPE_STRING:
            variant = g_variant_new("ms", g_value_get_string(value));
            break;
        case G_TYPE_UCHAR:
            variant = g_variant_new_byte(g_value_get_uchar(value));
            break;
        case G_TYPE_UINT:
            variant = g_variant_new_uint32(g_value_get_uint(value));
            break;
        case G_TYPE_UINT64:
        case G_TYPE_ULONG:
            variant = g_variant_new_uint64(g_value_get_uint64(value));
            break;
        case G_TYPE_VARIANT:
            variant = g_value_dup_variant(value);
            break;
        default:
            g_assert_not_reached();
            break;
      }

    return variant;
}
Esempio n. 8
0
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	GVariant *gvar, *range[2];
	GVariantBuilder gvb;
	int ret;
	unsigned int i;

	(void)sdi;
	(void)cg;

	ret = SR_OK;
	switch (key) {
	case SR_CONF_SCAN_OPTIONS:
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
				scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
		break;
	case SR_CONF_DEVICE_OPTIONS:
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
				devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
		break;
	case SR_CONF_SAMPLERATE:
		g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
		gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
			samplerates, ARRAY_SIZE(samplerates), sizeof(uint64_t));
		g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
		*data = g_variant_builder_end(&gvb);
		break;
	case SR_CONF_VOLTAGE_THRESHOLD:
		g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
		for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++) {
			range[0] = g_variant_new_double(volt_thresholds[i].low);
			range[1] = g_variant_new_double(volt_thresholds[i].high);
			gvar = g_variant_new_tuple(range, 2);
			g_variant_builder_add_value(&gvb, gvar);
		}
		*data = g_variant_builder_end(&gvb);
		break;
	case SR_CONF_TRIGGER_MATCH:
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
				soft_trigger_matches, ARRAY_SIZE(soft_trigger_matches),
				sizeof(int32_t));
		break;
	default:
		return SR_ERR_NA;
	}

	return ret;
}
Esempio n. 9
0
GVariant *
photos_utils_create_zoom_target_value (gdouble delta, PhotosZoomEvent event)
{
  GEnumClass *zoom_event_class = NULL; /* TODO: use g_autoptr */
  GEnumValue *event_value;
  GVariant *delta_value;
  GVariant *event_nick_value;
  GVariant *ret_val = NULL;
  g_auto (GVariantBuilder) builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT);
  const gchar *event_nick = "none";

  g_return_val_if_fail (delta >= 0.0, NULL);
  g_return_val_if_fail (event != PHOTOS_ZOOM_EVENT_NONE, NULL);

  delta_value = g_variant_new_double (delta);
  g_variant_builder_add (&builder, "{sv}", "delta", delta_value);

  zoom_event_class = G_ENUM_CLASS (g_type_class_ref (PHOTOS_TYPE_ZOOM_EVENT));

  event_value = g_enum_get_value (zoom_event_class, (gint) event);
  if (event_value != NULL)
    event_nick = event_value->value_nick;

  event_nick_value = g_variant_new_string (event_nick);
  g_variant_builder_add (&builder, "{sv}", "event", event_nick_value);

  ret_val = g_variant_builder_end (&builder);

  g_type_class_unref (zoom_event_class);
  g_return_val_if_fail (g_variant_is_floating (ret_val), ret_val);
  return ret_val;
}
Esempio n. 10
0
static int convert_meta(struct srd_proto_data *pdata, PyObject *obj)
{
	long long intvalue;
	double dvalue;

	if (pdata->pdo->meta_type == G_VARIANT_TYPE_INT64) {
		if (!PyLong_Check(obj)) {
			PyErr_Format(PyExc_TypeError, "This output was registered "
					"as 'int', but '%s' was passed.", obj->ob_type->tp_name);
			return SRD_ERR_PYTHON;
		}
		intvalue = PyLong_AsLongLong(obj);
		if (PyErr_Occurred())
			return SRD_ERR_PYTHON;
		pdata->data = g_variant_new_int64(intvalue);
	} else if (pdata->pdo->meta_type == G_VARIANT_TYPE_DOUBLE) {
		if (!PyFloat_Check(obj)) {
			PyErr_Format(PyExc_TypeError, "This output was registered "
					"as 'float', but '%s' was passed.", obj->ob_type->tp_name);
			return SRD_ERR_PYTHON;
		}
		dvalue = PyFloat_AsDouble(obj);
		if (PyErr_Occurred())
			return SRD_ERR_PYTHON;
		pdata->data = g_variant_new_double(dvalue);
	}

	return SRD_OK;
}
static gboolean
change_interval (gpointer user_data)
{
    g_message ("change interval");

    IndicatorTestService *indicator = user_data;

    GAction* action_switch = g_action_map_lookup_action(G_ACTION_MAP(indicator->actions), "action.switch");
    actual_switch(G_SIMPLE_ACTION(action_switch));

    GAction* action_checkbox = g_action_map_lookup_action(G_ACTION_MAP(indicator->actions), "action.checkbox");
    actual_switch(G_SIMPLE_ACTION(action_checkbox));

    GAction* action_accessPoint = g_action_map_lookup_action(G_ACTION_MAP(indicator->actions), "action.accessPoint");
    actual_switch(G_SIMPLE_ACTION(action_accessPoint));

    GAction* action_slider = g_action_map_lookup_action(G_ACTION_MAP(indicator->actions), "action.slider");
    static double old_value = 0.25;
    double new_value = old_value == 0.25 ? 0.75 : 0.25;
    old_value = new_value;
    Action* slide_action = malloc(sizeof(Action));
    slide_action->action = G_SIMPLE_ACTION(action_slider);
    slide_action->value = g_variant_new_double(new_value);
    actual_slide(slide_action);

    return TRUE;
}
static void
ide_preferences_spin_button_value_changed (IdePreferencesSpinButton *self,
                                           GParamSpec               *pspec,
                                           GtkSpinButton            *spin_button)
{
  GVariant *variant = NULL;
  gdouble value;

  g_assert (IDE_IS_PREFERENCES_SPIN_BUTTON (self));
  g_assert (pspec != NULL);
  g_assert (GTK_IS_SPIN_BUTTON (spin_button));

  value = gtk_spin_button_get_value (spin_button);

  if (g_variant_type_equal (self->type, G_VARIANT_TYPE_DOUBLE))
    variant = g_variant_new_double (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_INT16))
    variant = g_variant_new_int16 (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_UINT16))
    variant = g_variant_new_uint16 (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_INT32))
    variant = g_variant_new_int32 (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_UINT32))
    variant = g_variant_new_uint32 (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_INT64))
    variant = g_variant_new_int64 (value);
  else if (g_variant_type_equal (self->type, G_VARIANT_TYPE_UINT64))
    variant = g_variant_new_uint64 (value);
  else
    g_return_if_reached ();

  g_variant_ref_sink (variant);
  g_settings_set_value (self->settings, self->key, variant);
  g_clear_pointer (&variant, g_variant_unref);
}
Esempio n. 13
0
static GVariant*
_field_to_gvariant(gpointer bean, guint position)
{
	gpointer pf = FIELD(bean, position);

	if (!_bean_has_field(bean, position))
		return g_variant_new_tuple(NULL, 0);

	switch (DESCR_FIELD(bean,position)->type) {
		case FT_BOOL:
			return g_variant_new_byte(*((gboolean*)pf) ? 1 : 0);
		case FT_INT:
			return g_variant_new_int64(*((gint64*)pf));
		case FT_REAL:
			return g_variant_new_double(*((gdouble*)pf));
		case FT_TEXT:
			if (!*((gpointer*)(pf)))
				return g_variant_new_tuple(NULL, 0);
			return g_variant_new_string(GSTR(pf)->str);
		case FT_BLOB:
			if (!*((gpointer*)(pf)))
				return g_variant_new_tuple(NULL, 0);
			return _gba_to_gvariant(GBA(pf));
		default:
			g_assert_not_reached();
			break;
	}

	g_assert_not_reached();
	return NULL;
}
static GVariant *
handle_get_property (GDBusConnection *connection,
		     const gchar     *sender,
		     const gchar     *object_path,
		     const gchar     *interface_name,
		     const gchar     *property_name,
		     GError         **error,
		     gpointer         user_data)
{
	SensorData *data = user_data;

	g_assert (data->connection);

	if (g_strcmp0 (property_name, "HasAccelerometer") == 0)
		return g_variant_new_boolean (driver_type_exists (data, DRIVER_TYPE_ACCEL));
	if (g_strcmp0 (property_name, "AccelerometerOrientation") == 0)
		return g_variant_new_string (orientation_to_string (data->previous_orientation));
	if (g_strcmp0 (property_name, "HasAmbientLight") == 0)
		return g_variant_new_boolean (driver_type_exists (data, DRIVER_TYPE_LIGHT));
	if (g_strcmp0 (property_name, "LightLevelUnit") == 0)
		return g_variant_new_string (data->uses_lux ? "lux" : "vendor");
	if (g_strcmp0 (property_name, "LightLevel") == 0)
		return g_variant_new_double (data->previous_level);

	return NULL;
}
Esempio n. 15
0
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                      const struct sr_channel_group *cg)
{
    struct dev_context *devc;
    struct sr_channel *ch;
    struct analog_gen *ag;
    int pattern;

    if (!sdi)
        return SR_ERR_ARG;

    devc = sdi->priv;
    switch (key) {
    case SR_CONF_SAMPLERATE:
        *data = g_variant_new_uint64(devc->cur_samplerate);
        break;
    case SR_CONF_LIMIT_SAMPLES:
        *data = g_variant_new_uint64(devc->limit_samples);
        break;
    case SR_CONF_LIMIT_MSEC:
        *data = g_variant_new_uint64(devc->limit_msec);
        break;
    case SR_CONF_AVERAGING:
        *data = g_variant_new_boolean(devc->avg);
        break;
    case SR_CONF_AVG_SAMPLES:
        *data = g_variant_new_uint64(devc->avg_samples);
        break;
    case SR_CONF_PATTERN_MODE:
        if (!cg)
            return SR_ERR_CHANNEL_GROUP;
        /* Any channel in the group will do. */
        ch = cg->channels->data;
        if (ch->type == SR_CHANNEL_LOGIC) {
            pattern = devc->logic_pattern;
            *data = g_variant_new_string(logic_pattern_str[pattern]);
        } else if (ch->type == SR_CHANNEL_ANALOG) {
            ag = g_hash_table_lookup(devc->ch_ag, ch);
            pattern = ag->pattern;
            *data = g_variant_new_string(analog_pattern_str[pattern]);
        } else
            return SR_ERR_BUG;
        break;
    case SR_CONF_AMPLITUDE:
        if (!cg)
            return SR_ERR_CHANNEL_GROUP;
        /* Any channel in the group will do. */
        ch = cg->channels->data;
        if (ch->type != SR_CHANNEL_ANALOG)
            return SR_ERR_ARG;
        ag = g_hash_table_lookup(devc->ch_ag, ch);
        *data = g_variant_new_double(ag->amplitude);
        break;
    default:
        return SR_ERR_NA;
    }

    return SR_OK;
}
Esempio n. 16
0
static const struct sr_option *get_options(void)
{
	/* Default to a scaling factor of 1.0. */
	if (!options[0].def)
		options[0].def = g_variant_ref_sink(g_variant_new_double(1.0));

	return options;
}
Esempio n. 17
0
/**
 * mm_signal_get_dictionary:
 * @self: A #MMSignal.
 *
 * Gets a variant dictionary with the contents of @self.
 *
 * Returns: (transfer full): A dictionary with the signal values. The returned value should be freed with g_variant_unref().
 */
GVariant *
mm_signal_get_dictionary (MMSignal *self)
{
    GVariantBuilder builder;

    /* We do allow NULL */
    if (!self)
        return NULL;

    g_return_val_if_fail (MM_IS_SIGNAL (self), NULL);

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

    if (self->priv->rssi != MM_SIGNAL_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               PROPERTY_RSSI,
                               g_variant_new_double (self->priv->rssi));

    if (self->priv->ecio != MM_SIGNAL_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               PROPERTY_ECIO,
                               g_variant_new_double (self->priv->ecio));

    if (self->priv->sinr != MM_SIGNAL_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               PROPERTY_SINR,
                               g_variant_new_double (self->priv->sinr));

    if (self->priv->io != MM_SIGNAL_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               PROPERTY_IO,
                               g_variant_new_double (self->priv->io));

    if (self->priv->rsrp != MM_SIGNAL_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               PROPERTY_RSRP,
                               g_variant_new_double (self->priv->rsrp));

    if (self->priv->rsrq != MM_SIGNAL_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               PROPERTY_RSRQ,
                               g_variant_new_double (self->priv->rsrq));

    if (self->priv->snr != MM_SIGNAL_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               PROPERTY_SNR,
                               g_variant_new_double (self->priv->snr));

    return g_variant_ref_sink (g_variant_builder_end (&builder));
}
Esempio n. 18
0
static GVariant *
g_settings_set_mapping_unsigned_int (const GValue       *value,
                                     const GVariantType *expected_type)
{
  GVariant *variant = NULL;
  guint64 u;

  if (G_VALUE_HOLDS_UINT (value))
    u = g_value_get_uint (value);
  else if (G_VALUE_HOLDS_UINT64 (value))
    u = g_value_get_uint64 (value);
  else
    return NULL;

  if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT16))
    {
      if (u <= G_MAXINT16)
        variant = g_variant_new_int16 ((gint16) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT16))
    {
      if (u <= G_MAXUINT16)
        variant = g_variant_new_uint16 ((guint16) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT32))
    {
      if (u <= G_MAXINT32)
        variant = g_variant_new_int32 ((gint) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT32))
    {
      if (u <= G_MAXUINT32)
        variant = g_variant_new_uint32 ((guint) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT64))
    {
      if (u <= G_MAXINT64)
        variant = g_variant_new_int64 ((gint64) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT64))
    {
      if (u <= G_MAXUINT64)
        variant = g_variant_new_uint64 ((guint64) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_HANDLE))
    {
      if (u <= G_MAXUINT32)
        variant = g_variant_new_handle ((guint) u);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_DOUBLE))
    variant = g_variant_new_double ((gdouble) u);

  return variant;
}
Esempio n. 19
0
static GVariant *
g_settings_set_mapping_float (const GValue       *value,
                              const GVariantType *expected_type)
{
  GVariant *variant = NULL;
  gdouble d;
  gint64 l;

  if (G_VALUE_HOLDS_DOUBLE (value))
    d = g_value_get_double (value);
  else
    return NULL;

  l = (gint64) d;
  if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT16))
    {
      if (G_MININT16 <= l && l <= G_MAXINT16)
        variant = g_variant_new_int16 ((gint16) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT16))
    {
      if (0 <= l && l <= G_MAXUINT16)
        variant = g_variant_new_uint16 ((guint16) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT32))
    {
      if (G_MININT32 <= l && l <= G_MAXINT32)
        variant = g_variant_new_int32 ((gint) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT32))
    {
      if (0 <= l && l <= G_MAXUINT32)
        variant = g_variant_new_uint32 ((guint) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_INT64))
    {
      if (G_MININT64 <= l && l <= G_MAXINT64)
        variant = g_variant_new_int64 ((gint64) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_UINT64))
    {
      if (0 <= l && l <= G_MAXUINT64)
        variant = g_variant_new_uint64 ((guint64) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_HANDLE))
    {
      if (0 <= l && l <= G_MAXUINT32)
        variant = g_variant_new_handle ((guint) l);
    }
  else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_DOUBLE))
    variant = g_variant_new_double ((gdouble) d);

  return variant;
}
Esempio n. 20
0
GVariant *
scheme_obj_to_gvariant (Scheme_Object *list)
{
 
  GVariant *rvalue;
  Scheme_Object *firstelement;
  int length;
  long i;
  char* rstring;
  double rdouble;

  rvalue = NULL; 
  length = scheme_list_length (list);
  if (length == 0)
    {
      return rvalue ;
    }  
  
  else if (length == 1)
    {
      // Get the first element of the argument
      firstelement = scheme_car (list);
 
      // checking the scheme_type to see whether it is an integer or not
      // Eventually see if we can convert this to a switch statement.
      if (SCHEME_TYPE (firstelement)== scheme_integer_type)
	{
	  // we saved the return value at &i
	  scheme_get_int_val (list,&i);
	  // we concert it to g_variant
          rvalue = g_variant_new ("(i)", i);
	  return rvalue;
	} // if it's an integer
      else if (SCHEME_TYPE (firstelement) == scheme_char_type)
	{
	  //getting the string out of the scheme_object
	  rstring = SCHEME_BYTE_STR_VAL(list);
	  // we will convert it to g_variant
	  rvalue = g_variant_new_string(rstring);
	  return rvalue;
	} // if it's a character
      else if (SCHEME_TYPE (firstelement) == scheme_double_type)
	{
	  //getting the double out of the scheme_object
	  rdouble = scheme_real_to_double(list);
	  // we will convert it to g_variant
	  rvalue = g_variant_new_double(rdouble);
	  return rvalue;
	} // if it's a double
    } // if we have a single element
 
  return rvalue;
} // scheme_obj_to_gvariant
GVariant *
mm_location_gps_raw_get_dictionary (MMLocationGpsRaw *self)
{
    GVariantBuilder builder;

    /* We do allow NULL */
    if (!self)
        return NULL;

    g_return_val_if_fail (MM_IS_LOCATION_GPS_RAW (self), NULL);

    /* If mandatory parameters are not found, return NULL */
    if (!self->priv->utc_time ||
        self->priv->longitude == MM_LOCATION_LONGITUDE_UNKNOWN ||
        self->priv->latitude == MM_LOCATION_LATITUDE_UNKNOWN)
        return NULL;

    g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
    g_variant_builder_add (&builder,
                           "{sv}",
                           PROPERTY_UTC_TIME,
                           g_variant_new_string (self->priv->utc_time));
    g_variant_builder_add (&builder,
                           "{sv}",
                           PROPERTY_LONGITUDE,
                           g_variant_new_double (self->priv->longitude));
    g_variant_builder_add (&builder,
                           "{sv}",
                           PROPERTY_LATITUDE,
                           g_variant_new_double (self->priv->latitude));

    /* Altitude is optional */
    if (self->priv->altitude != MM_LOCATION_ALTITUDE_UNKNOWN)
        g_variant_builder_add (&builder,
                               "{sv}",
                               PROPERTY_ALTITUDE,
                               g_variant_new_double (self->priv->altitude));

    return g_variant_ref_sink (g_variant_builder_end (&builder));
}
Esempio n. 22
0
static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	struct dev_context *devc;

	(void)cg;

	switch (id) {
	case SR_CONF_SAMPLERATE:
		if (sdi) {
			devc = sdi->priv;
			*data = g_variant_new_uint64(devc->cur_samplerate);
			sr_spew("Returning samplerate: %" PRIu64 "Hz.",
				devc->cur_samplerate);
		} else
			return SR_ERR_ARG;
		break;
	case SR_CONF_CAPTURE_RATIO:
		if (sdi) {
			devc = sdi->priv;
			*data = g_variant_new_uint64(devc->capture_ratio);
		} else
			return SR_ERR_ARG;
		break;
	case SR_CONF_VOLTAGE_THRESHOLD:
		if (sdi) {
			GVariant *range[2];
			devc = sdi->priv;
			range[0] = g_variant_new_double(devc->cur_threshold);
			range[1] = g_variant_new_double(devc->cur_threshold);
			*data = g_variant_new_tuple(range, 2);
		} else
			return SR_ERR_ARG;
		break;
	default:
		return SR_ERR_NA;
	}

	return SR_OK;
}
GVariant *convertVariant(const QVariant &variant)
{
    switch (variant.type()) {
    case QVariant::Bool:
        return g_variant_new_boolean(variant.toBool());
    case QVariant::Char:
        return g_variant_new_byte(variant.toChar().toLatin1());
    case QVariant::Int:
        return g_variant_new_int32(variant.toInt());
    case QVariant::UInt:
        return g_variant_new_uint32(variant.toUInt());
    case QVariant::LongLong:
        return g_variant_new_int64(variant.toLongLong());
    case QVariant::ULongLong:
        return g_variant_new_uint64(variant.toULongLong());
    case QVariant::Double:
        return g_variant_new_double(variant.toDouble());
    case QVariant::String:
        return g_variant_new_string(variant.toString().toUtf8().constData());
    case QVariant::StringList: {
        QStringList value = variant.toStringList();

        GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
        foreach (QString item ,value)
            g_variant_builder_add(builder, "s", item.toUtf8().constData());

        GVariant *result = g_variant_new("as", builder);
        g_variant_builder_unref(builder);
        return result;
    }
    case QVariant::ByteArray:
        return g_variant_new_bytestring(variant.toByteArray().constData());
    case QVariant::Url:
        return g_variant_new_string(variant.toUrl().toString().toUtf8().constData());
    case QVariant::Color:
        return g_variant_new_string(variant.toString().toUtf8().constData());
    default: {
#ifndef QT_NO_DATASTREAM
        QByteArray a;
        QDataStream s(&a, QIODevice::WriteOnly);
        s.setVersion(QDataStream::Qt_4_0);
        s << variant;
        return g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING, a.constData(),
                                       a.size(), TRUE, NULL, NULL);
#else
        Q_ASSERT(!"QConfiguration: Cannot save custom types without QDataStream support");
#endif
    }
    }

    return 0;
}
void 
volume_widget_update(VolumeWidget* self, gdouble update, const gchar* label)
{
  const gchar* source = NULL;
  source = label;
  if (label == NULL){
    source = "v widget update";
  }
  VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self);
  gdouble clamped = CLAMP(update, 0, 100);
  GVariant* new_volume = g_variant_new_double(clamped);
  dbusmenu_menuitem_handle_event (priv->twin_item, source, new_volume, 0);
}
Esempio n. 25
0
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	struct dev_context *devc;

	(void)cg;

	if (!sdi)
		return SR_ERR_ARG;

	devc = sdi->priv;

	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
	case SR_CONF_LIMIT_MSEC:
		return sr_sw_limits_config_get(&devc->limits, key, data);
	case SR_CONF_VOLTAGE:
		*data = g_variant_new_double(devc->voltage);
		break;
	case SR_CONF_VOLTAGE_TARGET:
		*data = g_variant_new_double(devc->voltage_max);
		break;
	case SR_CONF_CURRENT:
		*data = g_variant_new_double(devc->current);
		break;
	case SR_CONF_CURRENT_LIMIT:
		*data = g_variant_new_double(devc->current_max);
		break;
	case SR_CONF_ENABLED:
		*data = g_variant_new_boolean(devc->output_enabled);
		break;
	default:
		return SR_ERR_NA;
	}

	return SR_OK;
}
static GVariantBuilder* _icd_state_value_to_gvariant_builder(OCRepPayload *repr)
{
	int total_len;
	GVariant *var = NULL;
	GVariantBuilder *builder;
	OCRepPayloadValue *val = repr->values;

	builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));

	while (val) {
		switch (val->type) {
		case OCREP_PROP_INT:
			var = g_variant_new_int32(val->i);
			break;
		case OCREP_PROP_BOOL:
			var = g_variant_new_boolean(val->b);
			break;
		case OCREP_PROP_DOUBLE:
			var = g_variant_new_double(val->d);
			break;
		case OCREP_PROP_STRING:
			var = g_variant_new_string(val->str);
			break;
		case OCREP_PROP_BYTE_STRING:
			var = g_variant_new_fixed_array(G_VARIANT_TYPE("y"), val->ocByteStr.bytes,
					val->ocByteStr.len, sizeof(uint8_t));
			break;
		case OCREP_PROP_NULL:
			var = g_variant_new_string(IC_STR_NULL);
			break;
		case OCREP_PROP_ARRAY:
			total_len = calcDimTotal(val->arr.dimensions);
			var = _icd_state_array_to_gvariant(&(val->arr), 0, total_len, 0);
			break;
		case OCREP_PROP_OBJECT:
			var = _icd_state_value_to_gvariant(val->obj);
			break;
		default:
			ERR("Invalid Type(%d)", val->type);
		}
		if (var) {
			g_variant_builder_add(builder, "{sv}", val->name, var);
			var = NULL;
		}
		val = val->next;
	}

	return builder;
}
Esempio n. 27
0
static void
parse_scheduled_contents (Manager *manager,
                          const char *contents)
{
  char **lines = NULL;
  char **lines_iter = NULL;
  const char *mode = NULL;
  gboolean found_usec = FALSE;
  guint64 usec = 0;

  lines = g_strsplit (contents, "\n", -1);

  for (lines_iter = lines; *lines_iter; lines_iter++)
    {
      const char *line = *lines_iter;

      if (g_str_has_prefix (line, "USEC="))
        {
          usec = g_ascii_strtoull (line + strlen ("USEC="), NULL, 10);
          found_usec = TRUE;
        }
      else if (g_str_has_prefix (line, "MODE="))
        {
          mode = line + strlen ("MODE=");
        }
      else
        continue;
    }

  if (mode && found_usec)
    {
      GVariantBuilder schedule;
      g_variant_builder_init (&schedule, G_VARIANT_TYPE("a{sv}"));
      g_variant_builder_add (&schedule, "{sv}", "when_seconds",
                             g_variant_new_double (usec / 1.0e6));
      if (strcmp (mode, "poweroff") == 0)
        mode = "shutdown";
      else if (strcmp (mode, "reboot") == 0)
        mode = "restart";
      g_variant_builder_add (&schedule, "{sv}", "kind",
                             g_variant_new_string (mode));
      cockpit_manager_set_shutdown_schedule (COCKPIT_MANAGER (manager),
                                             g_variant_builder_end (&schedule));
    }
  else
    g_warning ("Failed to parse scheduled shutdown file");

  g_strfreev (lines);
}
Esempio n. 28
0
GVariant* DeviceOptions::samplerate_double_getter(
	const struct sr_dev_inst *sdi)
{
	GVariant *const gvar = config_getter(sdi, SR_CONF_SAMPLERATE);

	if(!gvar)
		return NULL;

	GVariant *const gvar_double = g_variant_new_double(
		g_variant_get_uint64(gvar));

	g_variant_unref(gvar);

	return gvar_double;
}
Esempio n. 29
0
SR_PRIV int scpi_cmd_resp(const struct sr_dev_inst *sdi, const struct scpi_command *cmdtable,
		GVariant **gvar, const GVariantType *gvtype, int command, ...)
{
	struct sr_scpi_dev_inst *scpi;
	va_list args;
	double d;
	int ret;
	char *s;
	const char *cmd;

	if (!(cmd = scpi_cmd_get(cmdtable, command))) {
		/* Device does not implement this command, that's OK. */
		return SR_OK;
	}

	scpi = sdi->conn;
	va_start(args, command);
	ret = sr_scpi_send_variadic(scpi, cmd, args);
	va_end(args);
	if (ret != SR_OK)
		return ret;

	/* Straight SCPI getters to GVariant types. */
	if (g_variant_type_equal(gvtype, G_VARIANT_TYPE_BOOLEAN)) {
		if ((ret = sr_scpi_get_string(scpi, NULL, &s)) != SR_OK)
			return ret;
		if (!g_ascii_strcasecmp(s, "ON") || !g_ascii_strcasecmp(s, "1")
				|| !g_ascii_strcasecmp(s, "YES"))
			*gvar = g_variant_new_boolean(TRUE);
		else if (!g_ascii_strcasecmp(s, "OFF") || !g_ascii_strcasecmp(s, "0")
				|| !g_ascii_strcasecmp(s, "NO"))
			*gvar = g_variant_new_boolean(FALSE);
		else
			ret = SR_ERR;
		g_free(s);
	} if (g_variant_type_equal(gvtype, G_VARIANT_TYPE_DOUBLE)) {
		if ((ret = sr_scpi_get_double(scpi, NULL, &d)) == SR_OK)
			*gvar = g_variant_new_double(d);
	} if (g_variant_type_equal(gvtype, G_VARIANT_TYPE_STRING)) {
		if ((ret = sr_scpi_get_string(scpi, NULL, &s)) == SR_OK)
			*gvar = g_variant_new_string(s);
	} else {
		sr_err("Unable to convert to desired GVariant type.");
		ret = SR_ERR_NA;
	}

	return ret;
}
static GVariant *
set_large_text_mapping (const GValue       *value,
                        const GVariantType *expected_type,
                        gpointer            user_data)
{
  gboolean large;
  GSettings *settings = user_data;
  GVariant *ret = NULL;

  large = g_value_get_boolean (value);
  if (large)
    ret = g_variant_new_double (DPI_FACTOR_LARGE);
  else
    g_settings_reset (settings, KEY_TEXT_SCALING_FACTOR);

  return ret;
}