Example #1
0
/**
 * clutter_container_child_get:
 * @container: a #ClutterContainer
 * @actor: a #ClutterActor that is a child of @container.
 * @first_prop: name of the first property to be set.
 * @...: value for the first property, followed optionally by more name/value
 * pairs terminated with NULL.
 *
 * Gets @container specific properties of an actor.
 *
 * In general, a copy is made of the property contents and the caller is
 * responsible for freeing the memory in the appropriate manner for the type, for
 * instance by calling free() or g_object_unref().
 *
 * Since: 0.8
 */
void
clutter_container_child_get (ClutterContainer *container,
                             ClutterActor     *actor,
                             const gchar      *first_prop,
                             ...)
{
  GObjectClass *klass;
  const gchar *name;
  va_list var_args;

  g_return_if_fail (CLUTTER_IS_CONTAINER (container));
  g_return_if_fail (CLUTTER_IS_ACTOR (actor));

  klass = G_OBJECT_GET_CLASS (container);

  va_start (var_args, first_prop);

  name = first_prop;
  while (name)
    {
      GValue value = G_VALUE_INIT;
      gchar *error = NULL;
      GParamSpec *pspec;

      pspec = clutter_container_class_find_child_property (klass, name);
      if (!pspec)
        {
          g_warning ("%s: container '%s' has no child property named '%s'",
                     G_STRLOC, G_OBJECT_TYPE_NAME (container), name);
          break;
        }

      if (!(pspec->flags & G_PARAM_READABLE))
        {
          g_warning ("%s: child property '%s' of container '%s' is not readable",
                     G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (container));
          break;
        }

      g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));

      container_get_child_property (container, actor, &value, pspec);

      G_VALUE_LCOPY (&value, var_args, 0, &error);
      if (error)
        {
          g_warning ("%s: %s", G_STRLOC, error);
          free (error);
          g_value_unset (&value);
          break;
        }

      g_value_unset (&value);

      name = va_arg (var_args, gchar*);
    }

  va_end (var_args);
}
Example #2
0
static void
tidy_stylable_get_valist (TidyStylable *stylable,
                          const gchar  *first_property_name,
                          va_list       varargs)
{
  const gchar *name;

  g_object_ref (stylable);

  name = first_property_name;

  while (name)
    {
      GParamSpec *pspec;
      GValue value = { 0, };
      gchar *error;

      pspec = tidy_stylable_find_property (stylable, name);
      if (!pspec)
        {
          g_warning ("%s: no style property named `%s' found for class `%s'",
                     G_STRLOC,
                     name,
                     g_type_name (G_OBJECT_TYPE (stylable)));
          break;
        }

      if (!(pspec->flags & G_PARAM_READABLE))
        {
          g_warning ("Style property `%s' of class `%s' is not readable",
                     pspec->name,
                     g_type_name (G_OBJECT_TYPE (stylable)));
          break;
        }

      g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
      tidy_stylable_get_property_internal (stylable, pspec, &value);

      G_VALUE_LCOPY (&value, varargs, 0, &error);
      if (error)
        {
          g_warning ("%s: %s", G_STRLOC, error);
          g_free (error);
          g_value_unset (&value);
          break;
        }

      g_value_unset (&value);

      name = va_arg (varargs, gchar*);
    }

  g_object_unref (stylable);
}
Example #3
0
static gchar *
lcopy (GValue *value, ...)
{
  gchar *error;
  va_list var_args;

  error = NULL;

  va_start (var_args, value);
  G_VALUE_LCOPY (value, var_args, 0, &error);
  va_end (var_args);

  return error;
}	 
Example #4
0
/**
 * anjuta_shell_get_valist:
 * @shell: A #AnjutaShell interface
 * @first_name: First value name
 * @first_type: First value type
 * @var_args: First value holder, Second value name, Second value type ....
 *
 * Gets a valist of values from the shell. The valist should be in the order -
 * value1, name2, type2, value2,...
 */
void
anjuta_shell_get_valist (AnjutaShell *shell,
                         const char *first_name,
                         GType first_type,
                         va_list var_args)
{
    const char *name;
    GType type;

    g_return_if_fail (shell != NULL);
    g_return_if_fail (ANJUTA_IS_SHELL (shell));
    g_return_if_fail (first_name != NULL);

    name = first_name;
    type = first_type;

    while (name) {
        GValue value = {0, };
        GError *err = NULL;
        char *error;

        g_value_init (&value, type);

        anjuta_shell_get_value (shell, name, &value, &err);

        if (err) {
            g_warning ("Could not get value: %s", err->message);
            g_error_free (err);
            break;
        }

        G_VALUE_LCOPY (&value, var_args, 0, &error);

        if (error) {
            g_warning ("%s: %s", G_STRLOC, error);
            g_free (error);
            break;
        }

        g_value_unset (&value);

        name = va_arg (var_args, char *);
        if (name) {
            type = va_arg (var_args, GType);
        }
    }
}
Example #5
0
static gboolean
get_parameters_from_key_structure (const GstStructure * str,
    const char *first_param, va_list args)
{
  GType expected_type = G_TYPE_INVALID;
  const char *field_name;

  field_name = first_param;
  while (field_name) {
    const GValue *val = NULL;
    gboolean expected;
    gchar *desc = NULL;

    expected_type = va_arg (args, GType);

    val = gst_structure_get_value (str, field_name);
    expected = is_expected_param (field_name);

    if (val == NULL) {
      if (expected) {
        return FALSE;
      } else {
        /* optional parameter. Look for another ones */
        va_arg (args, gpointer);
        field_name = va_arg (args, const gchar *);

        continue;
      }
    }

    if (G_VALUE_TYPE (val) != expected_type) {
      /* values dont have the same type */
      return FALSE;
    }

    G_VALUE_LCOPY (val, args, 0, &desc);
    if (desc != NULL) {
      g_free (desc);
      return FALSE;
    }

    field_name = va_arg (args, const gchar *);
  }

  return TRUE;
}
Example #6
0
/**
 * gst_child_proxy_get_valist:
 * @object: the object to query
 * @first_property_name: name of the first property to get
 * @var_args: return location for the first property, followed optionally by more name/return location pairs, followed by NULL
 *
 * Gets properties of the parent object and its children.
 */
void
gst_child_proxy_get_valist (GstChildProxy * object,
    const gchar * first_property_name, va_list var_args)
{
  const gchar *name;
  gchar *error = NULL;
  GValue value = { 0, };
  GParamSpec *pspec;
  GObject *target;

  g_return_if_fail (GST_IS_CHILD_PROXY (object));

  name = first_property_name;

  /* iterate over pairs */
  while (name) {
    if (!gst_child_proxy_lookup (object, name, &target, &pspec))
      goto not_found;

    g_value_init (&value, pspec->value_type);
    g_object_get_property (target, pspec->name, &value);
    g_object_unref (target);

    G_VALUE_LCOPY (&value, var_args, 0, &error);
    if (error)
      goto cant_copy;
    g_value_unset (&value);
    name = va_arg (var_args, gchar *);
  }
  return;

not_found:
  {
    g_warning ("no property %s in object %s", name,
        (GST_IS_OBJECT (object) ? GST_OBJECT_NAME (object) : ""));
    return;
  }
cant_copy:
  {
    g_warning ("error copying value %s in object %s: %s", pspec->name,
        (GST_IS_OBJECT (object) ? GST_OBJECT_NAME (object) : ""), error);
    g_value_unset (&value);
    return;
  }
}
Example #7
0
/**
 * clutter_layout_manager_child_get:
 * @manager: a #ClutterLayoutManager
 * @container: a #ClutterContainer using @manager
 * @actor: a #ClutterActor child of @container
 * @first_property: the name of the first property
 * @Varargs: a list of property name and return location for the value pairs
 *
 * Retrieves the values for a list of properties out of the
 * #ClutterLayoutMeta created by @manager and attached to the
 * child of a @container
 *
 * Since: 1.2
 */
void
clutter_layout_manager_child_get (ClutterLayoutManager *manager,
                                  ClutterContainer     *container,
                                  ClutterActor         *actor,
                                  const gchar          *first_property,
                                  ...)
{
    ClutterLayoutMeta *meta;
    GObjectClass *klass;
    const gchar *pname;
    va_list var_args;

    g_return_if_fail (CLUTTER_IS_LAYOUT_MANAGER (manager));
    g_return_if_fail (CLUTTER_IS_CONTAINER (container));
    g_return_if_fail (CLUTTER_IS_ACTOR (actor));
    g_return_if_fail (first_property != NULL);

    meta = get_child_meta (manager, container, actor);
    if (meta == NULL)
    {
        g_warning ("Layout managers of type '%s' do not support "
                   "layout metadata",
                   g_type_name (G_OBJECT_TYPE (manager)));
        return;
    }

    klass = G_OBJECT_GET_CLASS (meta);

    va_start (var_args, first_property);

    pname = first_property;
    while (pname)
    {
        GValue value = { 0, };
        GParamSpec *pspec;
        gchar *error;
        gboolean res;

        pspec = g_object_class_find_property (klass, pname);
        if (pspec == NULL)
        {
            g_warning ("%s: Layout managers of type '%s' have no layout "
                       "property named '%s'",
                       G_STRLOC, G_OBJECT_TYPE_NAME (manager), pname);
            break;
        }

        g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));

        res = layout_get_property_internal (manager, G_OBJECT (meta),
                                            pspec,
                                            &value);
        if (!res)
        {
            g_value_unset (&value);
            break;
        }

        G_VALUE_LCOPY (&value, var_args, 0, &error);
        if (error)
        {
            g_warning ("%s: %s", G_STRLOC, error);
            g_free (error);
            g_value_unset (&value);
            break;
        }

        g_value_unset (&value);

        pname = va_arg (var_args, gchar*);
    }

    va_end (var_args);
}
/**
 * gupnp_last_change_parser_parse_last_change_valist:
 * @parser: A #GUPnPLastChangeParser
 * @instance_id: The ID of the AV instance caller is interested in
 * @last_change_xml: The xml from the "LastChange" event to parse
 * @error: The location where to store any error, or NULL
 * @var_args: A va_list of tuples of state variable name, state variable type,
 * and state variable value location, terminated with NULL. The state variable
 * values should be freed after use
 *
 * See gupnp_last_change_parser_parse_last_change(); this version takes a
 * va_list for use by language bindings.
 *
 * Return value: TRUE on success.
 **/
gboolean
gupnp_last_change_parser_parse_last_change_valist
                         (G_GNUC_UNUSED GUPnPLastChangeParser *parser,
                          guint                                instance_id,
                          const char                          *last_change_xml,
                          GError                             **error,
                          va_list                              var_args)
{
        const char *variable_name;
        xmlDoc  *doc;
        xmlNode *instance_node;

        g_return_val_if_fail (last_change_xml, FALSE);

        doc = xmlParseDoc ((const xmlChar *) last_change_xml);
        if (doc == NULL) {
                g_set_error (error,
                             GUPNP_XML_ERROR,
                             GUPNP_XML_ERROR_PARSE,
                             "Could not parse LastChange xml");

                return FALSE;
        }

        instance_node = get_instance_node (doc, instance_id);
        if (instance_node == NULL) {
                /* This is not an error since the caller of this function
                 * doesn't (need to) know if the instance of his interest is
                 * part of the LastChange event received.
                 */
                xmlFreeDoc (doc);

                return FALSE;
        }

        /* Variables */
        variable_name = va_arg (var_args, const char *);
        while (variable_name) {
                GType variable_type;
                GValue value = { 0, };
                char *copy_error = NULL;

                variable_type = va_arg (var_args, GType);

                g_value_init (&value, variable_type);

                if (read_state_variable (variable_name,
                                         &value,
                                         instance_node)) {
                        G_VALUE_LCOPY (&value, var_args, 0, &copy_error);
                } else {
                        va_arg (var_args, gpointer);
                }

                g_value_unset (&value);

                if (copy_error) {
                        g_warning ("Error copying value: %s", copy_error);

                        g_free (copy_error);
                }

                variable_name = va_arg (var_args, const char *);
        }

        /* Cleanup */
        xmlFreeDoc (doc);

        return TRUE;
}
Example #9
0
/*
 * Two mock miners available but only 1 running
 */
gboolean
dbus_g_proxy_call (DBusGProxy *proxy,
                   const gchar *function_name,
                   GError  **error,
                   GType first_arg_type, ...)
{
	va_list args;
	GType   arg_type;
	const gchar *running_services[] = { "org.gnome.Tomboy",
	                                    "org.gnome.GConf",
	                                    MOCK_MINER_1,
	                                    "org.gnome.SessionManager",
	                                    NULL};

	va_start (args, first_arg_type);

	if (g_strcmp0 (function_name, "ListNames") == 0) {
		/*
		 *  G_TYPE_INVALID,
		 *  G_TYPE_STRV, &result,
		 *  G_TYPE_INVALID
		 */
		GValue value = { 0, };
		gchar *local_error = NULL;

		arg_type = va_arg (args, GType);

		g_assert (arg_type == G_TYPE_STRV);
		g_value_init (&value, arg_type);
		g_value_set_boxed (&value, running_services);
		G_VALUE_LCOPY (&value,
		               args, 0,
		               &local_error);
		g_free (local_error);
		g_value_unset (&value);

	} else if (g_strcmp0 (function_name, "NameHasOwner") == 0) {
		/*
		 * G_TYPE_STRING, miner,
		 * G_TYPE_INVALID,
		 * G_TYPE_BOOLEAN, &active,
		 *  G_TYPE_INVALID)) {
		 */
		GValue value = { 0, };
		gchar *local_error = NULL;
		const gchar *miner_name;
		TrackerMinerMock *miner;
		gboolean     active;

		g_value_init (&value, G_TYPE_STRING);
		G_VALUE_COLLECT (&value, args, 0, &local_error);
		g_free (local_error);
		miner_name = g_value_get_string (&value);

		miner = (TrackerMinerMock *)g_hash_table_lookup (miners, miner_name);
		active = !tracker_miner_mock_get_paused (miner);
		g_value_unset (&value);

		arg_type = va_arg (args, GType);
		g_assert (arg_type == G_TYPE_INVALID);

		arg_type = va_arg (args, GType);
		g_assert (arg_type == G_TYPE_BOOLEAN);
		g_value_init (&value, arg_type);
		g_value_set_boolean (&value, active);
		G_VALUE_LCOPY (&value,
		               args, 0,
		               &local_error);
		g_free (local_error);
		g_value_unset (&value);

	} else if (g_strcmp0 (function_name, "GetPauseDetails") == 0) {
		/*
		 *  G_TYPE_INVALID,
		 *  G_TYPE_STRV, &apps,
		 *  G_TYPE_STRV, &reasons,
		 *  G_TYPE_INVALID
		 */
		GValue value = { 0, };
		gchar *local_error = NULL;
		gint   amount;
		gchar **apps, **reasons;
		TrackerMinerMock *miner = (TrackerMinerMock *)proxy;

		arg_type = va_arg (args, GType);
		g_assert (arg_type == G_TYPE_STRV);
		g_value_init (&value, arg_type);
		apps = tracker_miner_mock_get_apps (miner, &amount);
		if (apps == NULL || amount == 0) {
			apps = g_new0 (gchar *, 1);
		}
Example #10
0
void
moo_plugin_call_method_valist (gpointer        plugin,
                               const char     *name,
                               va_list         var_args)
{
    MooPluginMeth *meth;
    GValue *plugin_and_args, *args, *freeme = NULL;
    GValue stack_params[MAX_STACK_VALUES];
    guint i;

    g_return_if_fail (MOO_IS_PLUGIN (plugin));
    g_return_if_fail (name != NULL);

    meth = moo_plugin_lookup_method (plugin, name);

    if (!meth)
    {
        g_warning ("plugin '%s' does not have method '%s'",
                   moo_plugin_id (plugin), name);
        return;
    }

    g_assert (meth->ptype == G_OBJECT_TYPE (plugin));

    if (meth->n_params < MAX_STACK_VALUES)
        plugin_and_args = stack_params;
    else
        plugin_and_args = freeme = g_new (GValue, meth->n_params + 1);

    args = plugin_and_args + 1;

    for (i = 0; i < meth->n_params; i++)
    {
        char *error;
        GType type = meth->param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
        gboolean static_scope = meth->param_types[i] & G_SIGNAL_TYPE_STATIC_SCOPE;

        args[i].g_type = 0;
        g_value_init (args + i, type);
        G_VALUE_COLLECT (args + i, var_args,
                         static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
                         &error);

        if (error)
        {
            g_warning ("%s", error);
            g_free (error);

            while (i--)
                g_value_unset (args + i);

            g_free (freeme);
            return;
        }
    }

    plugin_and_args->g_type = 0;
    g_value_init (plugin_and_args, G_OBJECT_TYPE (plugin));
    g_value_set_object (plugin_and_args, plugin);

    if (meth->return_type == G_TYPE_NONE)
    {
        moo_plugin_call_methodv (plugin_and_args, name, NULL);
    }
    else
    {
        GValue return_val;
        char *error = NULL;
        GType type = meth->return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE;
        gboolean static_scope = meth->return_type & G_SIGNAL_TYPE_STATIC_SCOPE;

        return_val.g_type = 0;
        g_value_init (&return_val, type);

        moo_plugin_call_methodv (plugin_and_args, name, &return_val);

        G_VALUE_LCOPY (&return_val, var_args,
                       static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
                       &error);

        if (!error)
        {
            g_value_unset (&return_val);
        }
        else
        {
            g_warning ("%s", error);
            g_free (error);
        }
    }

    for (i = 0; i < meth->n_params + 1; i++)
        g_value_unset (plugin_and_args + i);

    g_free (freeme);
}