Пример #1
0
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	GVariant *gvar, *grange[2];
	GVariantBuilder gvb;
	int ret;

	(void)sdi;
	(void)cg;

	ret = SR_OK;
	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;
	case SR_CONF_SAMPLERATE:
		g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
		gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
			sl2_samplerates, ARRAY_SIZE(sl2_samplerates),
			sizeof(uint64_t));
		g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
		*data = g_variant_builder_end(&gvb);
		break;
	case SR_CONF_TRIGGER_MATCH:
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
				trigger_matches, ARRAY_SIZE(trigger_matches),
				sizeof(int32_t));
		break;
	case SR_CONF_LIMIT_SAMPLES:
		grange[0] = g_variant_new_uint64(0);
		grange[1] = g_variant_new_uint64(MAX_SAMPLES);
		*data = g_variant_new_tuple(grange, 2);
		break;
	default:
		return SR_ERR_NA;
	}

	return ret;
}
Пример #2
0
static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	GVariant *tuple, *rational[2];
	GVariantBuilder gvb;
	unsigned int i;

	(void)sdi;
	(void)cg;

	switch (key) {
	case SR_CONF_DEVICE_OPTIONS:
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
				hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
		break;
	case SR_CONF_SAMPLE_INTERVAL:
		g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
		for (i = 0; i < ARRAY_SIZE(kecheng_kc_330b_sample_intervals); i++) {
			rational[0] = g_variant_new_uint64(kecheng_kc_330b_sample_intervals[i][0]);
			rational[1] = g_variant_new_uint64(kecheng_kc_330b_sample_intervals[i][1]);
			tuple = g_variant_new_tuple(rational, 2);
			g_variant_builder_add_value(&gvb, tuple);
		}
		*data = g_variant_builder_end(&gvb);
		break;
	case SR_CONF_SPL_WEIGHT_FREQ:
		*data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
		break;
	case SR_CONF_SPL_WEIGHT_TIME:
		*data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
		break;
	case SR_CONF_DATA_SOURCE:
		*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
		break;
	default:
		return SR_ERR_NA;
	}

	return SR_OK;
}
Пример #3
0
static gboolean
register_display (State        *state,
                  GCancellable *cancellable)
{
        GdmDBusManager  *manager = NULL;
        GError          *error = NULL;
        gboolean         registered = FALSE;
        GVariantBuilder  details;

        manager = gdm_dbus_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                                                           G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
                                                           G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
                                                           "org.gnome.DisplayManager",
                                                           "/org/gnome/DisplayManager/Manager",
                                                           cancellable,
                                                           &error);

        if (!manager) {
                g_debug ("could not contact display manager: %s", error->message);
                g_error_free (error);
                goto out;
        }

        g_variant_builder_init (&details, G_VARIANT_TYPE ("a{ss}"));
        g_variant_builder_add (&details, "{ss}", "session-type", "x11");
        g_variant_builder_add (&details, "{ss}", "x11-display-name", state->display_name);

        registered = gdm_dbus_manager_call_register_display_sync (manager,
                                                                  g_variant_builder_end (&details),
                                                                  cancellable,
                                                                  &error);
        if (error != NULL) {
                g_debug ("Could not register display: %s", error->message);
                g_error_free (error);
        }

out:
        g_clear_object (&manager);
        return registered;
}
Пример #4
0
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_GPS_RAW_LONGITUDE_UNKNOWN ||
        self->priv->latitude == MM_LOCATION_GPS_RAW_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_GPS_RAW_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));
}
Пример #5
0
static int
korva_control_push (KorvaController1 *controller, const char *path, const char *uid, const char *title)
{
    GFile *source;
    GVariantBuilder *builder;
    char *out_tag;
    GError *error = NULL;

    if (g_str_has_prefix (path, "~")) {
        source = g_file_parse_name (path);
    } else {
        source = g_file_new_for_commandline_arg (path);
    }
    builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
    g_variant_builder_add (builder, "{sv}", "URI", g_variant_new_string (g_file_get_uri (source)));
    if (title != NULL) {
        g_variant_builder_add (builder, "{sv}", "Title", g_variant_new_string (title));
    }

    korva_controller1_call_push_sync (controller,
                                      g_variant_builder_end (builder),
                                      device,
                                      &out_tag,
                                      NULL,
                                      &error);
    if (error != NULL) {
        g_print ("Failed to Push %s to %s: %s\n",
                 file,
                 device,
                 error->message);

        g_error_free (error);

        return 1;
    } else {
        g_print ("Pushed %s to %s. The ID is %s\n", file, device, out_tag);

        return 0;
    }
}
Пример #6
0
static void prv_wl_notify_prop(dlr_manager_t *manager,
			       const gchar *prop_name,
			       GVariant *prop_val)
{
	GVariant *val;
	GVariantBuilder array;

	g_variant_builder_init(&array, G_VARIANT_TYPE("a{sv}"));
	g_variant_builder_add(&array, "{sv}", prop_name, prop_val);

	val = g_variant_new("([email protected]{sv}as)", DLEYNA_SERVER_INTERFACE_MANAGER,
			    g_variant_builder_end(&array),
			    NULL);

	(void) dlr_renderer_get_connector()->notify(
					manager->connection,
					DLEYNA_SERVER_OBJECT,
					DLR_INTERFACE_PROPERTIES,
					DLR_INTERFACE_PROPERTIES_CHANGED,
					val,
					NULL);
}
Пример #7
0
static void steadyflow_iapp_service_proxy_set_visible (SteadyflowIAppService* self, gboolean visible, GError** error) {
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GDBusMessage *_reply_message;
	G_IO_ERROR;
	_message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "net.launchpad.steadyflow.App", "SetVisible");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_boolean (visible));
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_message_set_body (_message, _arguments);
	_reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error);
	g_object_unref (_message);
	if (!_reply_message) {
		return;
	}
	if (g_dbus_message_to_gerror (_reply_message, error)) {
		g_object_unref (_reply_message);
		return;
	}
	g_object_unref (_reply_message);
}
Пример #8
0
void RatingsFilter::UpdateState(float raw_rating)
{
    if (!IsValid())
        return;

    bool new_filtering = raw_rating > 0.0f;

    GVariantBuilder b;
    g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
    g_variant_builder_add(&b, "{sv}", "rating", g_variant_new("d", raw_rating));

    IgnoreChanges(true);
    dee_model_set_value(model_,iter_,
                        FilterColumn::RENDERER_STATE,
                        g_variant_builder_end(&b));
    dee_model_set_value(model_, iter_,
                        FilterColumn::FILTERING,
                        g_variant_new("b", new_filtering ? TRUE : FALSE));
    IgnoreChanges(false);

    filtering.EmitChanged(filtering);
}
Пример #9
0
/**
 * fcitx_input_method_set_imlist:
 * @im: A #FcitxInputMethod
 * @array: (element-type FcitxIMItem) (transfer none): A #FcitxIMItem List
 *
 * Set Fcitx all im list
 **/
FCITX_EXPORT_API
void fcitx_input_method_set_imlist(FcitxInputMethod *im, GPtrArray *array) {
    GVariantBuilder builder;
    g_variant_builder_init(&builder, G_VARIANT_TYPE("a(sssb)"));
    g_ptr_array_foreach(array, _fcitx_im_item_foreach_cb, &builder);
    GVariant *value = g_variant_builder_end(&builder);
    GError *error = NULL;
    GVariant *result = g_dbus_connection_call_sync(
        g_dbus_proxy_get_connection(G_DBUS_PROXY(im)),
        g_dbus_proxy_get_name(G_DBUS_PROXY(im)), FCITX_IM_DBUS_PATH,
        "org.freedesktop.DBus.Properties", "Set",
        g_variant_new("(ssv)", FCITX_IM_DBUS_INTERFACE, "IMList", value),
        G_VARIANT_TYPE_UNIT, G_DBUS_CALL_FLAGS_NONE, -1, /* timeout */
        NULL, &error);

    if (error) {
        g_warning("%s", error->message);
        g_error_free(error);
    }

    g_variant_unref(result);
}
Пример #10
0
GVariant *
nm_supplicant_config_to_variant (NMSupplicantConfig *self)
{
	NMSupplicantConfigPrivate *priv;
	GVariantBuilder builder;
	GHashTableIter iter;
	ConfigOption *option;
	const char *key;

	g_return_val_if_fail (NM_IS_SUPPLICANT_CONFIG (self), NULL);

	priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE (self);

	g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);

	g_hash_table_iter_init (&iter, priv->config);
	while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &option)) {
		switch (option->type) {
		case TYPE_INT:
			g_variant_builder_add (&builder, "{sv}", key, g_variant_new_int32 (atoi (option->value)));
			break;
		case TYPE_BYTES:
		case TYPE_UTF8:
			g_variant_builder_add (&builder, "{sv}",
			                       key,
			                       g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
			                                                  option->value, option->len, 1));
			break;
		case TYPE_KEYWORD:
		case TYPE_STRING:
			g_variant_builder_add (&builder, "{sv}", key, g_variant_new_string (option->value));
			break;
		default:
			break;
		}
	}

	return g_variant_builder_end (&builder);
}
Пример #11
0
gboolean
appendStringToVariantIfUnique (GVariant	  **variant,
			       const char *string)
{
    GVariantBuilder newVariantBuilder;
    FindItemInVariantData findItemData;

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

    findItemData.item = string;

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

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

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

    return !findItemData.found;
}
Пример #12
0
static void
g_menu_exporter_menu_items_changed (GMenuModel *model,
                                    gint        position,
                                    gint        removed,
                                    gint        added,
                                    gpointer    user_data)
{
  GMenuExporterMenu *menu = user_data;
  GSequenceIter *point;
  gint i;

  g_assert (menu->model == model);
  g_assert (menu->item_links != NULL);
  g_assert (position + removed <= g_sequence_get_length (menu->item_links));

  point = g_sequence_get_iter_at_pos (menu->item_links, position + removed);
  g_sequence_remove_range (g_sequence_get_iter_at_pos (menu->item_links, position), point);

  for (i = position; i < position + added; i++)
    g_sequence_insert_before (point, g_menu_exporter_menu_create_links (menu, i));

  if (g_menu_exporter_group_is_subscribed (menu->group))
    {
      GVariantBuilder builder;

      g_variant_builder_init (&builder, G_VARIANT_TYPE ("(uuuuaa{sv})"));
      g_variant_builder_add (&builder, "u", g_menu_exporter_group_get_id (menu->group));
      g_variant_builder_add (&builder, "u", menu->id);
      g_variant_builder_add (&builder, "u", position);
      g_variant_builder_add (&builder, "u", removed);

      g_variant_builder_open (&builder, G_VARIANT_TYPE ("aa{sv}"));
      for (i = position; i < position + added; i++)
        g_variant_builder_add_value (&builder, g_menu_exporter_menu_describe_item (menu, i));
      g_variant_builder_close (&builder);

      g_menu_exporter_report (g_menu_exporter_group_get_exporter (menu->group), g_variant_builder_end (&builder));
    }
}
Пример #13
0
static gboolean
update_bus_environment (State        *state,
                        GCancellable *cancellable)
{
        GVariantBuilder      builder;
        GVariant            *reply = NULL;
        GError              *error = NULL;
        gboolean             environment_updated = FALSE;

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

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

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

        g_variant_unref (reply);

        environment_updated = TRUE;

out:
        g_clear_error (&error);

        return environment_updated;
}
Пример #14
0
static gboolean
parse_keyvalue_strings (char             **strings,
                        GVariant         **out_metadata,
                        GError           **error)
{
  gboolean ret = FALSE;
  char **iter;
  g_autoptr(GVariantBuilder) builder = NULL;

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

  for (iter = strings; *iter; iter++)
    {
      const char *s;
      const char *eq;
      g_autofree char *key = NULL;

      s = *iter;

      eq = strchr (s, '=');
      if (!eq)
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Missing '=' in KEY=VALUE metadata '%s'", s);
          goto out;
        }
          
      key = g_strndup (s, eq - s);
      g_variant_builder_add (builder, "{sv}", key,
                             g_variant_new_string (eq + 1));
    }

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

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

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

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

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

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

	props = g_variant_builder_end (&builder);
	g_signal_emit (self, signals[NEW_BSS], 0,
	               g_dbus_proxy_get_object_path (proxy),
	               g_variant_ref_sink (props));
}
Пример #16
0
static GVariant *
build_metadata(XmrMprisPlugin *plugin)
{
	GVariantBuilder *builder;
	GVariant *v = NULL;

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

	g_variant_builder_add(builder, "{sv}", "mpris:trackid",
				g_variant_new ("o", "/org/mpris/MediaPlayer2/Track/track0"));

	g_variant_builder_add(builder, "{sv}", "mpris:length",
				g_variant_new("x", plugin->duration / 1000));

	if (plugin->current_song != NULL)
	{
		if (plugin->current_song->album_name)
			g_variant_builder_add(builder, "{sv}", "xesam:album",
								  g_variant_new("s", plugin->current_song->album_name));
		
		if (plugin->current_song->artist_name)
			g_variant_builder_add(builder, "{sv}", "xesam:artist",
								  variant_for_metadata(plugin->current_song->artist_name, TRUE));
		
		if (plugin->current_song->song_name)
			g_variant_builder_add(builder, "{sv}", "xesam:title",
								  g_variant_new("s", plugin->current_song->song_name));
		
		if (plugin->current_song->location)
			g_variant_builder_add(builder, "{sv}", "xesam:url",
								  g_variant_new("s", plugin->current_song->location));
	}

	v = g_variant_builder_end (builder);
	g_variant_builder_unref (builder);

	return v;
}
Пример #17
0
/**
 * CacheEntrySerialize:
 * @self: #CacheEntry to serialize.
 *
 * Returns: Human-readable string representing @self.
 */
gchar *CacheEntrySerialize(CacheEntry *self) {
  GVariantBuilder builder;
  const gchar *algorithm = NULL;
  GVariant *result_variant = NULL;
  gchar *result = NULL;

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

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

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

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

  result_variant = g_variant_builder_end(&builder);
  result = g_variant_print(result_variant, TRUE);
  g_variant_unref(result_variant);
  return result;
}
Пример #18
0
/**
 * @memberof GstSwitchController
 *
 * Remoting method stub of "get_preview_ports".
 */
static GVariant *
gst_switch_controller__get_preview_ports (GstSwitchController * controller,
    GDBusConnection * connection, GVariant * parameters)
{
  GVariant *result = NULL;
  if (controller->server) {
    GArray *serves = NULL, *types = NULL;
    GArray *ports =
        gst_switch_server_get_preview_sink_ports (controller->server, &serves,
        &types);
    int n;
    GVariantBuilder *builder;
    GVariant *value;
    gchar *res;

    builder = g_variant_builder_new (G_VARIANT_TYPE ("a(iii)"));
    for (n = 0; n < ports->len; ++n) {
      g_variant_builder_add (builder, "(iii)",
          g_array_index (ports, gint, n),
          g_array_index (serves, gint, n), g_array_index (types, gint, n));
    }
    value = g_variant_builder_end (builder);
    //result = g_variant_new_tuple (&value, 1);
    res = g_variant_print (value, FALSE);
    result = g_variant_new ("(s)", res);

    /*
       INFO ("value: %s (%d)", g_variant_get_type_string (value),
       g_variant_n_children (value));
       INFO ("result: %s, %s", g_variant_get_type_string (result), res);
     */

    g_free (res);
    g_array_free (ports, TRUE);
    g_array_free (types, TRUE);
  }
  return result;
}
Пример #19
0
GVariant *
mm_unlock_retries_get_dictionary (MMUnlockRetries *self)
{
    GVariantBuilder builder;
    GHashTableIter iter;
    gpointer key, value;

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

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

    g_hash_table_iter_init (&iter, self->priv->ht);
    while (g_hash_table_iter_next (&iter, &key, &value)) {
        g_variant_builder_add (&builder,
                               "{uu}",
                               GPOINTER_TO_UINT (key),
                               GPOINTER_TO_UINT (value));
    }

    return g_variant_ref_sink (g_variant_builder_end (&builder));
}
Пример #20
0
void
nm_dhcp4_config_set_options (NMDhcp4Config *self,
                             GHashTable *options)
{
	NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
	GHashTableIter iter;
	const char *key, *value;
	GVariantBuilder builder;

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

	g_variant_unref (priv->options);

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

	priv->options = g_variant_builder_end (&builder);
	g_variant_ref_sink (priv->options);
	g_object_notify (G_OBJECT (self), NM_DHCP4_CONFIG_OPTIONS);
}
gboolean
nm_supplicant_interface_request_scan (NMSupplicantInterface *self, const GPtrArray *ssids)
{
	NMSupplicantInterfacePrivate *priv;
	GVariantBuilder builder;
	guint i;

	g_return_val_if_fail (NM_IS_SUPPLICANT_INTERFACE (self), FALSE);

	priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);

	/* Scan parameters */
	g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
	g_variant_builder_add (&builder, "{sv}", "Type", g_variant_new_string ("active"));
	if (ssids) {
		GVariantBuilder ssids_builder;

		g_variant_builder_init (&ssids_builder, G_VARIANT_TYPE_BYTESTRING_ARRAY);
		for (i = 0; i < ssids->len; i++) {
			GByteArray *ssid = g_ptr_array_index (ssids, i);
			g_variant_builder_add (&ssids_builder, "@ay",
			                       g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE,
			                                                  ssid->data, ssid->len, 1));
		}
		g_variant_builder_add (&builder, "{sv}", "SSIDs", g_variant_builder_end (&ssids_builder));
	}

	g_dbus_proxy_call (priv->iface_proxy,
	                   "Scan",
	                   g_variant_new ("(a{sv})", &builder),
	                   G_DBUS_CALL_FLAGS_NONE,
	                   -1,
	                   priv->other_cancellable,
	                   (GAsyncReadyCallback) scan_request_cb,
	                   self);
	return TRUE;
}
Пример #22
0
/**
 * cd_sensor_get_metadata_as_variant:
 **/
static GVariant *
cd_sensor_get_metadata_as_variant (CdSensor *sensor)
{
	CdSensorPrivate *priv = GET_PRIVATE (sensor);
	GList *l;
	GVariantBuilder builder;
	g_autoptr(GList) list = NULL;

	/* we always must have at least one bit of metadata */
	if (g_hash_table_size (priv->metadata) == 0)
		return g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);

	/* add all the keys in the dictionary to the variant builder */
	list = g_hash_table_get_keys (priv->metadata);
	g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
	for (l = list; l != NULL; l = l->next) {
		g_variant_builder_add (&builder,
				       "{ss}",
				       l->data,
				       g_hash_table_lookup (priv->metadata,
							    l->data));
	}
	return g_variant_builder_end (&builder);
}
Пример #23
0
/**
 * cd_sensor_get_options_as_variant:
 **/
static GVariant *
cd_sensor_get_options_as_variant (CdSensor *sensor)
{
	CdSensorPrivate *priv = GET_PRIVATE (sensor);
	GList *l;
	GVariantBuilder builder;
	g_autoptr(GList) list = NULL;

	/* do not try to build an empty array */
	if (g_hash_table_size (priv->options) == 0)
		return g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);

	/* add all the keys in the dictionary to the variant builder */
	list = g_hash_table_get_keys (priv->options);
	g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
	for (l = list; l != NULL; l = l->next) {
		g_variant_builder_add (&builder,
				       "{sv}",
				       l->data,
				       g_hash_table_lookup (priv->options,
							    l->data));
	}
	return g_variant_builder_end (&builder);
}
Пример #24
0
void dlr_manager_get_all_props(dlr_manager_t *manager,
			       dleyna_settings_t *settings,
			       dlr_task_t *task,
			       dlr_manager_task_complete_t cb)
{
	dlr_async_task_t *cb_data = (dlr_async_task_t *)task;
	dlr_task_get_props_t *task_data = &task->ut.get_props;
	gchar *i_name = task_data->interface_name;
	GVariantBuilder vb;

	DLEYNA_LOG_DEBUG("Enter");
	DLEYNA_LOG_DEBUG("Path: %s", task->path);
	DLEYNA_LOG_DEBUG("Interface %s", i_name);

	cb_data->cb = cb;

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

	if (!strcmp(i_name, DLEYNA_SERVER_INTERFACE_MANAGER) ||
	    !strcmp(i_name, "")) {
		prv_add_all_props(settings, &vb);

		cb_data->task.result = g_variant_ref_sink(
						g_variant_builder_end(&vb));
	} else {
		DLEYNA_LOG_WARNING("Interface is unknown.");

		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_UNKNOWN_INTERFACE,
					     "Interface is unknown.");
	}

	(void) g_idle_add(dlr_async_task_complete, cb_data);

	DLEYNA_LOG_DEBUG("Exit");
}
Пример #25
0
static void
load_applet_into_window (const char *title,
			 const char *prefs_path,
			 guint       size,
			 guint       orientation)
{
	GtkWidget       *container;
	GtkWidget       *applet_window;
	GVariantBuilder  builder;

	container = mate_panel_applet_container_new ();

	applet_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	//FIXME: we could set the window icon with the applet icon
	gtk_window_set_title (GTK_WINDOW (applet_window), title);
	gtk_container_add (GTK_CONTAINER (applet_window), container);
	gtk_widget_show (container);

	g_signal_connect (container, "applet-broken",
			  G_CALLBACK (applet_broken_cb),
			  applet_window);

	g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
	g_variant_builder_add (&builder, "{sv}",
			       "prefs-path", g_variant_new_string (prefs_path));
	g_variant_builder_add (&builder, "{sv}",
			       "size", g_variant_new_uint32 (size));
	g_variant_builder_add (&builder, "{sv}",
			       "orient", g_variant_new_uint32 (orientation));
	mate_panel_applet_container_add (MATE_PANEL_APPLET_CONTAINER (container),
				    gtk_widget_get_screen (applet_window),
				    title, NULL,
				    (GAsyncReadyCallback)applet_activated_cb,
				    applet_window,
				    g_variant_builder_end (&builder));
}
Пример #26
0
static void
send_dbus_event (ControlData     *data)
{
	GVariantBuilder props_builder;
	GVariant *props_changed = NULL;

	g_assert (data->connection);

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

	g_variant_builder_add (&props_builder, "{sv}", "HasDualGpu",
			       g_variant_new_boolean (data->available));

	props_changed = g_variant_new ("([email protected]{sv}@as)", CONTROL_PROXY_IFACE_NAME,
				       g_variant_builder_end (&props_builder),
				       g_variant_new_strv (NULL, 0));

	g_dbus_connection_emit_signal (data->connection,
				       NULL,
				       CONTROL_PROXY_DBUS_PATH,
				       "org.freedesktop.DBus.Properties",
				       "PropertiesChanged",
				       props_changed, NULL);
}
Пример #27
0
static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	GVariant *gvar;
	GVariantBuilder gvb;

	(void)sdi;
	(void)cg;

	switch (key) {
	case SR_CONF_SCAN_OPTIONS:
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
				hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
		break;
	case SR_CONF_DEVICE_OPTIONS:
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
				hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_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_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 SR_OK;
}
Пример #28
0
static gboolean
gb_vim_command_search (GtkWidget      *active_widget,
                       const gchar    *command,
                       const gchar    *options,
                       GError        **error)
{
  GtkSourceView  *source_view;
  GtkTextBuffer *buffer;
  const gchar *search_begin = NULL;
  const gchar *search_end = NULL;
  const gchar *replace_begin = NULL;
  const gchar *replace_end = NULL;
  gchar *search_text = NULL;
  gchar *replace_text = NULL;
  gunichar separator;
  gboolean confirm_replace = FALSE;

  g_assert (GTK_IS_WIDGET (active_widget));
  g_assert (g_str_has_prefix (command, "%s") || g_str_has_prefix (command, "s"));

  if (IDE_IS_EDITOR_VIEW (active_widget))
    source_view = GTK_SOURCE_VIEW (IDE_EDITOR_VIEW (active_widget)->frame1->source_view);
  else
    return gb_vim_set_source_view_error (error);

  if (*command == '%')
    command++;
  command++;

  separator = g_utf8_get_char (command);
  if (!separator)
    goto invalid_request;

  search_begin = command = g_utf8_next_char (command);

  for (; *command; command = g_utf8_next_char (command))
    {
      if (*command == '\\')
        {
          command = g_utf8_next_char (command);
          if (!*command)
            goto invalid_request;
          continue;
        }

      if (g_utf8_get_char (command) == separator)
        {
          search_end = command;
          break;
        }
    }

  if (!search_end)
    goto invalid_request;

  replace_begin = command = g_utf8_next_char (command);

  for (; *command; command = g_utf8_next_char (command))
    {
      if (*command == '\\')
        {
          command = g_utf8_next_char (command);
          if (!*command)
            goto invalid_request;
          continue;
        }

      if (g_utf8_get_char (command) == separator)
        {
          replace_end = command;
          break;
        }
    }

  if (!replace_end)
    goto invalid_request;

  command = g_utf8_next_char (command);

  if (*command)
    {
      for (; *command; command++)
        {
          switch (*command)
            {
            case 'c':
              confirm_replace = TRUE;
              break;

            case 'g':
              break;

            /* what other options are supported? */
            default:
              break;
            }
        }
    }

  search_text = g_strndup (search_begin, search_end - search_begin);
  replace_text = g_strndup (replace_begin, replace_end - replace_begin);

  if (confirm_replace)
    {
      GVariant *variant;
      GVariantBuilder builder;

      g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY);
      g_variant_builder_add (&builder, "s", search_text);
      g_variant_builder_add (&builder, "s", replace_text);
      variant = g_variant_builder_end (&builder);

      ide_widget_action (GTK_WIDGET (IDE_EDITOR_VIEW (active_widget)->frame1),
                         "frame",
                         "replace-confirm",
                         variant);
      return TRUE;
    }

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (source_view));

  if (gtk_text_buffer_get_has_selection (buffer))
    {
      GtkTextIter begin;
      GtkTextIter end;

      gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
      gtk_text_iter_order (&begin, &end);
      gb_vim_do_search_and_replace (buffer, &begin, &end, search_text, replace_text, FALSE);
    }
  else
    gb_vim_do_search_and_replace (buffer, NULL, NULL, search_text, replace_text, TRUE);

  g_free (search_text);
  g_free (replace_text);

  return TRUE;

invalid_request:
  g_set_error (error,
               GB_VIM_ERROR,
               GB_VIM_ERROR_UNKNOWN_OPTION,
               _("Invalid search and replace request"));
  return FALSE;
}
Пример #29
0
GVariant* js_to_dbus(JSContextRef ctx, const JSValueRef jsvalue, const GVariantType* sig, JSValueRef *exception)
{
    if (g_variant_type_is_array(sig)) {
        GVariantBuilder builder;
        g_variant_builder_init(&builder, sig);
        JSPropertyNameArrayRef array = JSObjectCopyPropertyNames(ctx, (JSObjectRef)jsvalue);

        const GVariantType* child_sig = g_variant_type_element(sig);

        if (g_variant_type_is_dict_entry(child_sig)) {

            const GVariantType* key_sig = g_variant_type_first(child_sig);
            const GVariantType* value_sig = g_variant_type_next(key_sig);
            for (size_t i=0; i < JSPropertyNameArrayGetCount(array); i++) {
                if (filter_function_child(ctx, jsvalue, i)) continue;

                g_variant_builder_open(&builder, child_sig);
                JSValueRef key = JSValueMakeString(ctx, JSPropertyNameArrayGetNameAtIndex(array, i));
                JSValueRef value = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, NULL);
                g_variant_builder_add_value(&builder, js_to_dbus(ctx, key, key_sig, exception));
                g_variant_builder_add_value(&builder, js_to_dbus(ctx, value, value_sig, exception));
                g_variant_builder_close(&builder);
            }
            return g_variant_builder_end(&builder);

	} else {
	    GVariantBuilder builder;
	    g_variant_builder_init(&builder, sig);
	    JSPropertyNameArrayRef array = JSObjectCopyPropertyNames(ctx, (JSObjectRef)jsvalue);
	    const GVariantType* child_sig = g_variant_type_element(sig);
	    for (size_t i=0; i < JSPropertyNameArrayGetCount(array); i++) {
		if (filter_array_child(ctx, array, i)) continue;
		g_variant_builder_add_value(&builder, js_to_dbus(ctx, JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, NULL), child_sig, exception));
	    }
	    JSPropertyNameArrayRelease(array);
	    return g_variant_builder_end(&builder);
	}
    } else if (g_variant_type_is_tuple(sig)) {
	    GVariantBuilder builder;
	    g_variant_builder_init(&builder, sig);
	    JSPropertyNameArrayRef array = JSObjectCopyPropertyNames(ctx, (JSObjectRef)jsvalue);
	    const GVariantType* current_sig = g_variant_type_first(sig);
            for (size_t i=0; i < JSPropertyNameArrayGetCount(array); i++) {
                if (filter_array_child(ctx, array, i)) continue;
                g_variant_builder_add_value(&builder, js_to_dbus(ctx, JSObjectGetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, NULL), current_sig, exception));
		current_sig = g_variant_type_next(current_sig);
            }
            JSPropertyNameArrayRelease(array);
            return g_variant_builder_end(&builder);
    } else {
        switch (g_variant_type_peek_string(sig)[0]) {
            case 'y':
                return g_variant_new_byte(JSValueToNumber(ctx, jsvalue, exception));
            case 'n':
                return g_variant_new_int16(JSValueToNumber(ctx, jsvalue, exception));
            case 'q':
                return g_variant_new_uint16(JSValueToNumber(ctx, jsvalue, exception));
            case 'i':
                return g_variant_new_int32(JSValueToNumber(ctx, jsvalue, exception));
            case 'u':
                return g_variant_new_uint32(JSValueToNumber(ctx, jsvalue, exception));
            case 'x':
                return g_variant_new_int64(JSValueToNumber(ctx, jsvalue, exception));
            case 't':
                return g_variant_new_uint64(JSValueToNumber(ctx, jsvalue, exception));
            case 'd':
                return g_variant_new_double(JSValueToNumber(ctx, jsvalue, exception));
            case 'h':
                return g_variant_new_handle(JSValueToNumber(ctx, jsvalue, exception));
            case 'b':
                return g_variant_new_boolean(JSValueToBoolean(ctx, jsvalue));
            case 's':
                {
                    char* v = jsvalue_to_cstr(ctx, jsvalue);
                    GVariant* r = g_variant_new_string(v);
                    g_free(v);
                    return r;
                }
            case 'v':
                {
                    //TODO:
                    /*g_variant_new_variant()*/
                    g_assert_not_reached();
                }
        }
    }
    g_assert_not_reached();
}
Пример #30
0
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	GVariant *tuple, *rational[2];
	GVariantBuilder gvb;
	unsigned int i;
	GVariant *gvar;

	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;
	} else 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;

	if (!cg) {
		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;
		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;
		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_COUPLING:
			*data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
			break;
		case SR_CONF_VDIV:
			g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
			for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
				rational[0] = g_variant_new_uint64(vdivs[i][0]);
				rational[1] = g_variant_new_uint64(vdivs[i][1]);
				tuple = g_variant_new_tuple(rational, 2);
				g_variant_builder_add_value(&gvb, tuple);
			}
			*data = g_variant_builder_end(&gvb);
			break;
		default:
			return SR_ERR_NA;
		}
	}

	return SR_OK;
}