Beispiel #1
0
static void
gck_slot_set_property (GObject *obj, guint prop_id, const GValue *value,
                        GParamSpec *pspec)
{
	GckSlot *self = GCK_SLOT (obj);

	/* All writes to data members below, happen only during construct phase */

	switch (prop_id) {
	case PROP_MODULE:
		g_assert (!self->pv->module);
		self->pv->module = g_value_get_object (value);
		g_assert (self->pv->module);
		g_object_ref (self->pv->module);
		break;
	case PROP_HANDLE:
		g_assert (!self->pv->handle);
		self->pv->handle = g_value_get_ulong (value);
		break;
	}
}
Beispiel #2
0
static void
gst_rnd_buffer_size_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstRndBufferSize *self = GST_RND_BUFFER_SIZE (object);

  switch (prop_id) {
    case ARG_SEED:
      self->seed = g_value_get_ulong (value);
      break;
    case ARG_MINIMUM:
      self->min = g_value_get_long (value);
      break;
    case ARG_MAXIMUM:
      self->max = g_value_get_long (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
Beispiel #3
0
static void 
clutter_alpha_set_property (GObject      *object, 
			    guint         prop_id,
			    const GValue *value, 
			    GParamSpec   *pspec)
{
  ClutterAlpha *alpha = CLUTTER_ALPHA (object);

  switch (prop_id) 
    {
    case PROP_TIMELINE:
      clutter_alpha_set_timeline (alpha, g_value_get_object (value));
      break;

    case PROP_MODE:
      clutter_alpha_set_mode (alpha, g_value_get_ulong (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
static void cell_renderer_bifurcation_set_property(GObject       *object,
						   guint          prop_id,
						   const GValue  *value,
						   GParamSpec    *pspec) {
    CellRendererBifurcation *self = CELL_RENDERER_BIFURCATION(object);

    switch (prop_id) {

    case PROP_ROW_ID:
	self->row_id = g_value_get_ulong(value);
	break;

    case PROP_ANIMATION:
	if (self->animation)
	    g_object_unref(self->animation);
	self->animation = ANIMATION(g_object_ref(g_value_get_object(value)));
	break;

    default:
	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
	break;
    }
}
Beispiel #5
0
    /*
      Same as above but handles size == 0 as not available
     */
    void size_na_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
                                GtkTreeModel *model, GtkTreeIter *iter,
                                gpointer user_data)
    {
        const guint index = GPOINTER_TO_UINT(user_data);

        guint64 size;
        GValue value = { 0 };

        gtk_tree_model_get_value(model, iter, index, &value);

        switch (G_VALUE_TYPE(&value)) {
            case G_TYPE_ULONG:
                size = g_value_get_ulong(&value);
                break;

          case G_TYPE_UINT64:
              size = g_value_get_uint64(&value);
              break;

          default:
              g_assert_not_reached();
        }

        g_value_unset(&value);

        if (size == 0) {
            char *str = g_strdup_printf ("<i>%s</i>", _("N/A"));
            g_object_set(renderer, "markup", str, NULL);
            g_free(str);
        }
        else {
            char *str = procman::format_size(size);
            g_object_set(renderer, "text", str, NULL);
            g_free(str);
        }
    }
Beispiel #6
0
static void
gst_file_src_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstFileSrc *src;

  g_return_if_fail (GST_IS_FILE_SRC (object));

  src = GST_FILE_SRC (object);

  switch (prop_id) {
    case ARG_LOCATION:
      gst_file_src_set_location (src, g_value_get_string (value));
      break;
    case ARG_MMAPSIZE:
      if ((src->mapsize % src->pagesize) == 0) {
        src->mapsize = g_value_get_ulong (value);
      } else {
        GST_INFO_OBJECT (src,
            "invalid mapsize, must be a multiple of pagesize, which is %d",
            src->pagesize);
      }
      break;
    case ARG_TOUCH:
      src->touch = g_value_get_boolean (value);
      break;
    case ARG_SEQUENTIAL:
      src->sequential = g_value_get_boolean (value);
      break;
    case ARG_USEMMAP:
      src->use_mmap = g_value_get_boolean (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
Beispiel #7
0
/**
 * pk_plugin_set_property:
 **/
static void
pk_plugin_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
	PkPlugin *plugin = PK_PLUGIN (object);
	switch (prop_id) {
	case PROP_X:
		plugin->priv->x = g_value_get_uint (value);
		break;
	case PROP_Y:
		plugin->priv->y = g_value_get_uint (value);
		break;
	case PROP_WIDTH:
		plugin->priv->width = g_value_get_uint (value);
		break;
	case PROP_HEIGHT:
		plugin->priv->height = g_value_get_uint (value);
		break;
	case PROP_DISPLAY:
		plugin->priv->display = g_value_get_pointer (value);
		break;
	case PROP_VISUAL:
		plugin->priv->visual = g_value_get_pointer (value);
		break;
	case PROP_STARTED:
		plugin->priv->started = g_value_get_boolean (value);
		break;
	case PROP_WINDOW:
		plugin->priv->window = g_value_get_ulong (value);
		break;
	case PROP_GDKWINDOW:
		plugin->priv->gdk_window = g_value_get_pointer (value);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
static void
gp11_slot_set_property (GObject *obj, guint prop_id, const GValue *value, 
                        GParamSpec *pspec)
{
	GP11SlotData *data = GP11_SLOT_GET_DATA (obj);

	/* All writes to data members below, happen only during construct phase */

	switch (prop_id) {
	case PROP_MODULE:
		g_assert (!data->module);
		data->module = g_value_get_object (value);
		g_assert (data->module);
		g_object_ref (data->module);
		break;
	case PROP_HANDLE:
		g_assert (!data->handle);
		data->handle = g_value_get_ulong (value);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
		break;
	}
}
Beispiel #9
0
void test_set_value_from_string()
{
  GValue val = { 0, };
  
  xmlfile = "gstutils_test_set_value_from_string";
  std_log(LOG_FILENAME_LINE, "Test Started gstutils_test_set_value_from_string");

  /* g_return_if_fail */
  ASSERT_CRITICAL (gst_util_set_value_from_string (NULL, "xyz"));

  g_value_init (&val, G_TYPE_STRING);
  ASSERT_CRITICAL (gst_util_set_value_from_string (&val, NULL));
  g_value_unset (&val);

  /* string => string */
  g_value_init (&val, G_TYPE_STRING);
  gst_util_set_value_from_string (&val, "Y00");
  fail_unless (g_value_get_string (&val) != NULL);
  fail_unless_equals_string (g_value_get_string (&val), "Y00");
  g_value_unset (&val);

  /* string => int */
  g_value_init (&val, G_TYPE_INT);
  gst_util_set_value_from_string (&val, "987654321");
  fail_unless (g_value_get_int (&val) == 987654321);
  g_value_unset (&val);

  g_value_init (&val, G_TYPE_INT);
  ASSERT_CRITICAL (gst_util_set_value_from_string (&val, "xyz"));
  g_value_unset (&val);

  /* string => uint */
  g_value_init (&val, G_TYPE_UINT);
  gst_util_set_value_from_string (&val, "987654321");
  fail_unless (g_value_get_uint (&val) == 987654321);
  g_value_unset (&val);

  /* CHECKME: is this really desired behaviour? (tpm) */
  g_value_init (&val, G_TYPE_UINT);
  gst_util_set_value_from_string (&val, "-999");
  fail_unless (g_value_get_uint (&val) == ((guint) 0 - (guint) 999));
  g_value_unset (&val);

  g_value_init (&val, G_TYPE_UINT);
  ASSERT_CRITICAL (gst_util_set_value_from_string (&val, "xyz"));
  g_value_unset (&val);

  /* string => long */
  g_value_init (&val, G_TYPE_LONG);
  gst_util_set_value_from_string (&val, "987654321");
  fail_unless (g_value_get_long (&val) == 987654321);
  g_value_unset (&val);

  g_value_init (&val, G_TYPE_LONG);
  ASSERT_CRITICAL (gst_util_set_value_from_string (&val, "xyz"));
  g_value_unset (&val);

  /* string => ulong */
  g_value_init (&val, G_TYPE_ULONG);
  gst_util_set_value_from_string (&val, "987654321");
  fail_unless (g_value_get_ulong (&val) == 987654321);
  g_value_unset (&val);

  /* CHECKME: is this really desired behaviour? (tpm) */
  g_value_init (&val, G_TYPE_ULONG);
  gst_util_set_value_from_string (&val, "-999");
  fail_unless (g_value_get_ulong (&val) == ((gulong) 0 - (gulong) 999));
  g_value_unset (&val);

  g_value_init (&val, G_TYPE_ULONG);
  ASSERT_CRITICAL (gst_util_set_value_from_string (&val, "xyz"));
  g_value_unset (&val);

  /* string => boolean */
  g_value_init (&val, G_TYPE_BOOLEAN);
  gst_util_set_value_from_string (&val, "true");
  fail_unless_equals_int (g_value_get_boolean (&val), TRUE);
  g_value_unset (&val);

  g_value_init (&val, G_TYPE_BOOLEAN);
  gst_util_set_value_from_string (&val, "TRUE");
  fail_unless_equals_int (g_value_get_boolean (&val), TRUE);
  g_value_unset (&val);

  g_value_init (&val, G_TYPE_BOOLEAN);
  gst_util_set_value_from_string (&val, "false");
  fail_unless_equals_int (g_value_get_boolean (&val), FALSE);
  g_value_unset (&val);

  g_value_init (&val, G_TYPE_BOOLEAN);
  gst_util_set_value_from_string (&val, "FALSE");
  fail_unless_equals_int (g_value_get_boolean (&val), FALSE);
  g_value_unset (&val);

  g_value_init (&val, G_TYPE_BOOLEAN);
  gst_util_set_value_from_string (&val, "bleh");
  fail_unless_equals_int (g_value_get_boolean (&val), FALSE);
  g_value_unset (&val);

#if 0
  /* string => float (yay, localisation issues involved) */
  g_value_init (&val, G_TYPE_FLOAT);
  gst_util_set_value_from_string (&val, "987.654");
  fail_unless (g_value_get_float (&val) >= 987.653 &&
      g_value_get_float (&val) <= 987.655);
  g_value_unset (&val);

  g_value_init (&val, G_TYPE_FLOAT);
  gst_util_set_value_from_string (&val, "987,654");
  fail_unless (g_value_get_float (&val) >= 987.653 &&
      g_value_get_float (&val) <= 987.655);
  g_value_unset (&val);

  /* string => double (yay, localisation issues involved) */
  g_value_init (&val, G_TYPE_DOUBLE);
  gst_util_set_value_from_string (&val, "987.654");
  fail_unless (g_value_get_double (&val) >= 987.653 &&
      g_value_get_double (&val) <= 987.655);
  g_value_unset (&val);

  g_value_init (&val, G_TYPE_DOUBLE);
  gst_util_set_value_from_string (&val, "987,654");
  fail_unless (g_value_get_double (&val) >= 987.653 &&
      g_value_get_double (&val) <= 987.655);
  g_value_unset (&val);
#endif
  
  std_log(LOG_FILENAME_LINE, "Test Successful");
  create_xml(0);
}
static char *
rb_gvalue_array_to_string (GArray *a)
{
	int i;
	GString *s;

	if (a == NULL)
		return strdup ("");

	s = g_string_new ("(");

	for (i = 0; i < a->len; i++) {
		GValue *val;
	
		if (i != 0)
			g_string_append (s, ", ");

		val = &g_array_index (a, GValue, i);
		switch (G_VALUE_TYPE (val)) {
		case G_TYPE_STRING:
			g_string_append_printf (s, "\"%s\"", g_value_get_string (val));
			break;
		case G_TYPE_BOOLEAN:
			g_string_append_printf (s, "%d", g_value_get_boolean (val));
			break;
		case G_TYPE_INT:
			g_string_append_printf (s, "%d", g_value_get_int (val));
			break;
		case G_TYPE_LONG:
			g_string_append_printf (s, "%ld", g_value_get_long (val));
			break;
		case G_TYPE_ULONG:
			g_string_append_printf (s, "%lu", g_value_get_ulong (val));
			break;
		case G_TYPE_UINT64:
			g_string_append_printf (s, "%" G_GUINT64_FORMAT, g_value_get_uint64 (val));
			break;
		case G_TYPE_FLOAT:
			g_string_append_printf (s, "%f", g_value_get_float (val));
			break;
		case G_TYPE_DOUBLE:
			g_string_append_printf (s, "%f", g_value_get_double (val));
			break;
		case G_TYPE_POINTER:
			g_string_append_printf (s, "P:%p", g_value_get_pointer (val));
			break;
		case G_TYPE_BOXED:
			g_string_append_printf (s, "B:%p", g_value_get_boxed (val));
			break;
		case G_TYPE_OBJECT:
			g_string_append_printf (s, "O:%p", g_value_get_object (val));
			break;
		default:
			g_string_append(s, "Unknown");
		}
	}

	g_string_append_c (s, ')');

	return g_string_free (s, FALSE);
}
Beispiel #11
0
JsonNode *
json_serialize_pspec (const GValue *real_value,
                      GParamSpec   *pspec)
{
  JsonNode *retval = NULL;
  JsonNodeType node_type;

  switch (G_TYPE_FUNDAMENTAL (G_VALUE_TYPE (real_value)))
    {
    /* JSON native types */
    case G_TYPE_INT64:
      retval = json_node_init_int (json_node_alloc (), g_value_get_int64 (real_value));
      break;

    case G_TYPE_BOOLEAN:
      retval = json_node_init_boolean (json_node_alloc (), g_value_get_boolean (real_value));
      break;

    case G_TYPE_DOUBLE:
      retval = json_node_init_double (json_node_alloc (), g_value_get_double (real_value));
      break;

    case G_TYPE_STRING:
      retval = json_node_init_string (json_node_alloc (), g_value_get_string (real_value));
      break;

    /* auto-promoted types */
    case G_TYPE_INT:
      retval = json_node_init_int (json_node_alloc (), g_value_get_int (real_value));
      break;

    case G_TYPE_UINT:
      retval = json_node_init_int (json_node_alloc (), g_value_get_uint (real_value));
      break;

    case G_TYPE_LONG:
      retval = json_node_init_int (json_node_alloc (), g_value_get_long (real_value));
      break;

    case G_TYPE_ULONG:
      retval = json_node_init_int (json_node_alloc (), g_value_get_ulong (real_value));
      break;

    case G_TYPE_UINT64:
      retval = json_node_init_int (json_node_alloc (), g_value_get_uint64 (real_value));
      break;

    case G_TYPE_FLOAT:
      retval = json_node_init_double (json_node_alloc (), g_value_get_float (real_value));
      break;

    case G_TYPE_CHAR:
      retval = json_node_alloc ();
      json_node_init_int (retval, g_value_get_schar (real_value));
      break;

    case G_TYPE_UCHAR:
      retval = json_node_init_int (json_node_alloc (), g_value_get_uchar (real_value));
      break;

    case G_TYPE_ENUM:
      retval = json_node_init_int (json_node_alloc (), g_value_get_enum (real_value));
      break;

    case G_TYPE_FLAGS:
      retval = json_node_init_int (json_node_alloc (), g_value_get_flags (real_value));
      break;

    /* complex types */
    case G_TYPE_BOXED:
      if (G_VALUE_HOLDS (real_value, G_TYPE_STRV))
        {
          gchar **strv = g_value_get_boxed (real_value);
          gint i, strv_len;
          JsonArray *array;

          strv_len = g_strv_length (strv);
          array = json_array_sized_new (strv_len);

          for (i = 0; i < strv_len; i++)
            {
              JsonNode *str = json_node_new (JSON_NODE_VALUE);

              json_node_set_string (str, strv[i]);
              json_array_add_element (array, str);
            }

          retval = json_node_init_array (json_node_alloc (), array);
          json_array_unref (array);
        }
      else if (json_boxed_can_serialize (G_VALUE_TYPE (real_value), &node_type))
        {
          gpointer boxed = g_value_get_boxed (real_value);

          retval = json_boxed_serialize (G_VALUE_TYPE (real_value), boxed);
        }
      else
        g_warning ("Boxed type '%s' is not handled by JSON-GLib",
                   g_type_name (G_VALUE_TYPE (real_value)));
      break;

    case G_TYPE_OBJECT:
      {
        GObject *object = g_value_get_object (real_value);

        retval = json_node_alloc ();

        if (object != NULL)
          {
            json_node_init (retval, JSON_NODE_OBJECT);
            json_node_take_object (retval, json_gobject_dump (object));
          }
        else
          json_node_init_null (retval);
      }
      break;

    case G_TYPE_NONE:
      retval = json_node_new (JSON_NODE_NULL);
      break;

    default:
      g_warning ("Unsupported type `%s'", g_type_name (G_VALUE_TYPE (real_value)));
      break;
    }

  return retval;
}
Beispiel #12
0
static void
test_collection (void)
{
  GValue value = { 0, };
  gchar *error;
  
  g_value_init (&value, G_TYPE_CHAR);
  error = collect (&value, 'c');
  g_assert (error == NULL);
  g_assert (g_value_get_char (&value) == 'c');
  
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_UCHAR);
  error = collect (&value, 129);
  g_assert (error == NULL);
  g_assert (g_value_get_uchar (&value) == 129);
  
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_BOOLEAN);
  error = collect (&value, TRUE);
  g_assert (error == NULL);
  g_assert (g_value_get_boolean (&value) == TRUE);
  
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_INT);
  error = collect (&value, G_MAXINT);
  g_assert (error == NULL);
  g_assert (g_value_get_int (&value) == G_MAXINT);
  
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_UINT);
  error = collect (&value, G_MAXUINT);
  g_assert (error == NULL);
  g_assert (g_value_get_uint (&value) == G_MAXUINT);
  
  g_value_unset (&value);  
  g_value_init (&value, G_TYPE_LONG);
  error = collect (&value, G_MAXLONG);
  g_assert (error == NULL);
  g_assert (g_value_get_long (&value) == G_MAXLONG);
  
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_ULONG);
  error = collect (&value, G_MAXULONG);
  g_assert (error == NULL);
  g_assert (g_value_get_ulong (&value) == G_MAXULONG);
  
  g_value_unset (&value);  
  g_value_init (&value, G_TYPE_INT64);
  error = collect (&value, G_MAXINT64);
  g_assert (error == NULL);
  g_assert (g_value_get_int64 (&value) == G_MAXINT64);
  
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_UINT64);
  error = collect (&value, G_MAXUINT64);
  g_assert (error == NULL);
  g_assert (g_value_get_uint64 (&value) == G_MAXUINT64);
  
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_FLOAT);
  error = collect (&value, G_MAXFLOAT);
  g_assert (error == NULL);
  g_assert (g_value_get_float (&value) == G_MAXFLOAT);
  
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_DOUBLE);
  error = collect (&value, G_MAXDOUBLE);
  g_assert (error == NULL);
  g_assert (g_value_get_double (&value) == G_MAXDOUBLE);
  
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_STRING);
  error = collect (&value, "string ?");
  g_assert (error == NULL);
  g_assert (strcmp (g_value_get_string (&value), "string ?") == 0);
  
  g_value_unset (&value);
  g_value_init (&value, G_TYPE_GTYPE);
  error = collect (&value, G_TYPE_BOXED);
  g_assert (error == NULL);
  g_assert (g_value_get_gtype (&value) == G_TYPE_BOXED);
}
static gint
_gvalues_compare_fixed (const GValue *value1, const GValue *value2)
{
	int ret = 0;

	switch (G_VALUE_TYPE (value1)) {
	case G_TYPE_CHAR: {
		gchar val1 = g_value_get_schar (value1);
		gchar val2 = g_value_get_schar (value2);
		if (val1 != val2)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	case G_TYPE_UCHAR: {
		guchar val1 = g_value_get_uchar (value1);
		guchar val2 = g_value_get_uchar (value2);
		if (val1 != val2)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	case G_TYPE_BOOLEAN: {
		gboolean val1 = g_value_get_boolean (value1);
		gboolean val2 = g_value_get_boolean (value2);
		if (val1 != val2)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	case G_TYPE_LONG: {
		glong val1 = g_value_get_long (value1);
		glong val2 = g_value_get_long (value2);
		if (val1 != val2)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	case G_TYPE_ULONG: {
		gulong val1 = g_value_get_ulong (value1);
		gulong val2 = g_value_get_ulong (value2);
		if (val1 != val2)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	case G_TYPE_INT: {
		gint val1 = g_value_get_int (value1);
		gint val2 = g_value_get_int (value2);
		if (val1 != val2)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	case G_TYPE_UINT: {
		guint val1 = g_value_get_uint (value1);
		guint val2 = g_value_get_uint (value2);
		if (val1 != val2)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	case G_TYPE_INT64: {
		gint64 val1 = g_value_get_int64 (value1);
		gint64 val2 = g_value_get_int64 (value2);
		if (val1 != val2)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	case G_TYPE_UINT64: {
		guint64 val1 = g_value_get_uint64 (value1);
		guint64 val2 = g_value_get_uint64 (value2);
		if (val1 != val2)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	case G_TYPE_FLOAT: {
		gfloat val1 = g_value_get_float (value1);
		gfloat val2 = g_value_get_float (value2);
		/* Can't use == or != here due to inexactness of FP */
		if (fabsf (val1 - val2) > FLOAT_FACTOR)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	case G_TYPE_DOUBLE: {
		gdouble val1 = g_value_get_double (value1);
		gdouble val2 = g_value_get_double (value2);
		if (fabs (val1 - val2) > FLOAT_FACTOR)
			ret = val1 < val2 ? -1 : val1 > val2;
		break;
	}
	default:
		g_warning ("Unhandled fixed size type '%s'", G_VALUE_TYPE_NAME (value1));
	}

	return ret;
}
Beispiel #14
0
static void
bt_song_info_set_property (GObject * const object, const guint property_id,
    const GValue * const value, GParamSpec * const pspec)
{
  const BtSongInfo *const self = BT_SONG_INFO (object);
  return_if_disposed ();
  switch (property_id) {
    case SONG_INFO_SONG:
      self->priv->song = BT_SONG (g_value_get_object (value));
      g_object_try_weak_ref (self->priv->song);
      GST_DEBUG ("set the song for song-info: %p", self->priv->song);
      break;
    case SONG_INFO_FILE_NAME:
      g_free (self->priv->file_name);
      self->priv->file_name = g_value_dup_string (value);
      GST_DEBUG ("set the file-name for song_info: %s", self->priv->file_name);
      break;
    case SONG_INFO_INFO:{
      const gchar *str = g_value_get_string (value);
      if ((self->priv->info != str) && (!self->priv->info || !str
              || strcmp (self->priv->info, str))) {
        g_free (self->priv->info);
        if (str) {
          self->priv->info = g_value_dup_string (value);
          gst_tag_list_add (self->priv->taglist, GST_TAG_MERGE_REPLACE,
              GST_TAG_DESCRIPTION, self->priv->info, NULL);
        } else {
          self->priv->info = NULL;
          gst_tag_list_remove_tag (self->priv->taglist, GST_TAG_DESCRIPTION);
        }
        GST_DEBUG ("set the info for song_info: %s", self->priv->info);
      }
      break;
    }
    case SONG_INFO_NAME:{
      const gchar *str = g_value_get_string (value);
      if ((self->priv->name != str) && (!self->priv->name || !str
              || strcmp (self->priv->name, str))) {
        g_free (self->priv->name);
        if (str) {
          self->priv->name = g_value_dup_string (value);
          gst_tag_list_add (self->priv->taglist, GST_TAG_MERGE_REPLACE,
              GST_TAG_TITLE, self->priv->name, NULL);
        } else {
          self->priv->name = NULL;
          gst_tag_list_remove_tag (self->priv->taglist, GST_TAG_TITLE);
        }
        GST_DEBUG ("set the name for song_info: %s", self->priv->name);
      }
      break;
    }
    case SONG_INFO_GENRE:{
      const gchar *str = g_value_get_string (value);
      if ((self->priv->genre != str) && (!self->priv->genre || !str
              || strcmp (self->priv->genre, str))) {
        g_free (self->priv->genre);
        if (str) {
          self->priv->genre = g_value_dup_string (value);
          gst_tag_list_add (self->priv->taglist, GST_TAG_MERGE_REPLACE,
              GST_TAG_GENRE, self->priv->genre, NULL);
        } else {
          self->priv->genre = NULL;
          gst_tag_list_remove_tag (self->priv->taglist, GST_TAG_GENRE);
        }
        GST_DEBUG ("set the genre for song_info: %s", self->priv->genre);
      }
      break;
    }
    case SONG_INFO_AUTHOR:{
      const gchar *str = g_value_get_string (value);
      if ((self->priv->author != str) && (!self->priv->author || !str
              || strcmp (self->priv->author, str))) {
        g_free (self->priv->author);
        if (str) {
          self->priv->author = g_value_dup_string (value);
          gst_tag_list_add (self->priv->taglist, GST_TAG_MERGE_REPLACE,
              GST_TAG_ARTIST, self->priv->author, NULL);
        } else {
          self->priv->author = NULL;
          gst_tag_list_remove_tag (self->priv->taglist, GST_TAG_ARTIST);
        }
        GST_DEBUG ("set the author for song_info: %s", self->priv->author);
      }
      break;
    }
    case SONG_INFO_BPM:{
      gulong val = g_value_get_ulong (value);
      if (self->priv->beats_per_minute != val) {
        self->priv->beats_per_minute = val;
        gst_tag_list_add (self->priv->taglist, GST_TAG_MERGE_REPLACE,
            GST_TAG_BEATS_PER_MINUTE, (gdouble) self->priv->beats_per_minute,
            NULL);
        bt_song_info_tempo_changed (self);
        GST_DEBUG ("set the bpm for song_info: %lu",
            self->priv->beats_per_minute);
      }
      break;
    }
    case SONG_INFO_TPB:{
      gulong val = g_value_get_ulong (value);
      if (self->priv->ticks_per_beat != val) {
        self->priv->ticks_per_beat = val;
        bt_song_info_tempo_changed (self);
        GST_DEBUG ("set the tpb for song_info: %lu",
            self->priv->ticks_per_beat);
      }
    }
      break;
    case SONG_INFO_BARS:{
      gulong val = g_value_get_ulong (value);
      if (self->priv->bars != val) {
        self->priv->bars = val;
        bt_song_info_tempo_changed (self);
        GST_DEBUG ("set the bars for song_info: %lu", self->priv->bars);
      }
      break;
    }
    case SONG_INFO_CREATE_DTS:{
      const gchar *const dts = g_value_get_string (value);

      if (dts) {
        if (strlen (dts) == DTS_LEN) {
          strcpy (self->priv->create_dts, dts);
        }
      } else {
        time_t now = time (NULL);
        /* this is ISO 8601 Date and Time Format
         * %F     Equivalent to %Y-%m-%d (the ISO 8601 date format). (C99)
         * %T     The time in 24-hour notation (%H:%M:%S). (SU)
         */
        strftime (self->priv->create_dts, DTS_LEN + 1, "%FT%TZ", gmtime (&now));
      }
      break;
    }
    case SONG_INFO_CHANGE_DTS:{
      const gchar *const dts = g_value_get_string (value);

      if (dts) {
        if (strlen (dts) == DTS_LEN) {
          struct tm tm = { 0, };
          strcpy (self->priv->change_dts, dts);
          // parse date and update tag
          strptime (dts, "%FT%TZ", &tm);
          g_date_set_time_t (self->priv->tag_date, mktime (&tm));
          gst_tag_list_add (self->priv->taglist, GST_TAG_MERGE_REPLACE,
              GST_TAG_DATE, self->priv->tag_date, NULL);
        }
      } else {
        time_t now = time (NULL);
        strftime (self->priv->change_dts, DTS_LEN + 1, "%FT%TZ", gmtime (&now));
        g_date_set_time_t (self->priv->tag_date, now);
        gst_tag_list_add (self->priv->taglist, GST_TAG_MERGE_REPLACE,
            GST_TAG_DATE, self->priv->tag_date, NULL);
      }
      break;
    }
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
  }
}
Beispiel #15
0
// make json formated description
void Property::make_description() {
  if (nullptr == property_) {
    g_warning("%s: cannot make description from a nullptr property",
              __PRETTY_FUNCTION__);
    return;
  }
  GValue value = G_VALUE_INIT;
  g_value_init(&value, property_->value_type);

  g_object_get_property(object_, property_->name, &value);
  json_description_->reset();
  json_description_->begin_object();
  // long name
  json_description_->add_string_member("name", long_name_.c_str());
  // name
  json_description_->add_string_member("id", name_.c_str());
  // nickname
  // json_description_->add_string_member ("nickname", g_param_spec_get_nick (property_));

  // short description
  json_description_->add_string_member("description",
                                       g_param_spec_get_blurb(property_));
  json_description_->add_string_member("parent",
                                       get_category().c_str());
  json_description_->add_int_member("order",
                                    get_position_weight());
  // name
  // json_description_->add_string_member ("internal name", g_param_spec_get_name (property_));
  if (property_->flags &G_PARAM_WRITABLE)
    json_description_->add_string_member("writable", "true");
  else
    json_description_->add_string_member("writable", "false");
  switch (G_VALUE_TYPE(&value)) {
    case G_TYPE_STRING:
      {
        const char *string_val = g_value_get_string(&value);
        json_description_->add_string_member("type", "string");
        if (string_val == nullptr)
          json_description_->add_string_member("default value", "");
        else
          json_description_->add_string_member("default value", string_val);
        break;
      }
    case G_TYPE_BOOLEAN:
      {
        gboolean bool_val = g_value_get_boolean(&value);
        json_description_->add_string_member("type", "boolean");
        if (bool_val)
          json_description_->add_string_member("default value", "true");
        else
          json_description_->add_string_member("default value", "false");
        break;
      }
    case G_TYPE_ULONG:
      {
        GParamSpecULong *pulong = G_PARAM_SPEC_ULONG(property_);

        json_description_->add_string_member("type", "ulong");
        gchar *min = g_strdup_printf("%lu", pulong->minimum);
        gchar *max = g_strdup_printf("%lu", pulong->maximum);
        gchar *default_value =
            g_strdup_printf("%lu", g_value_get_ulong(&value));
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_LONG:
      {
        GParamSpecLong *plong = G_PARAM_SPEC_LONG(property_);
        gchar *min = g_strdup_printf("%ld", plong->minimum);
        gchar *max = g_strdup_printf("%ld", plong->maximum);
        gchar *default_value =
            g_strdup_printf("%ld", g_value_get_ulong(&value));
        json_description_->add_string_member("type", "long");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_UINT:
      {
        GParamSpecUInt *puint = G_PARAM_SPEC_UINT(property_);
        gchar *min = g_strdup_printf("%u", puint->minimum);
        gchar *max = g_strdup_printf("%u", puint->maximum);
        gchar *default_value =
            g_strdup_printf("%u", g_value_get_uint(&value));
        json_description_->add_string_member("type", "uint");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_INT:
      {
        GParamSpecInt *pint = G_PARAM_SPEC_INT(property_);
        gchar *min = g_strdup_printf("%d", pint->minimum);
        gchar *max = g_strdup_printf("%d", pint->maximum);
        gchar *default_value = g_strdup_printf("%d", g_value_get_int(&value));
        json_description_->add_string_member("type", "int");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_UINT64:
      {
        GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64(property_);
        gchar *min = g_strdup_printf("%" G_GUINT64_FORMAT, puint64->minimum);
        gchar *max = g_strdup_printf("%" G_GUINT64_FORMAT, puint64->maximum);
        gchar *default_value = g_strdup_printf("%" G_GUINT64_FORMAT,
                                               g_value_get_uint64(&value));
        json_description_->add_string_member("type", "uint64");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_INT64:
      {
        GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64(property_);
        gchar *min = g_strdup_printf("%" G_GINT64_FORMAT, pint64->minimum);
        gchar *max = g_strdup_printf("%" G_GINT64_FORMAT, pint64->maximum);
        gchar *default_value =
            g_strdup_printf("%" G_GINT64_FORMAT, g_value_get_int64(&value));
        json_description_->add_string_member("type", "int64");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_FLOAT:
      {
        GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT(property_);
        gchar *min = g_strdup_printf("%.7g", pfloat->minimum);
        gchar *max = g_strdup_printf("%.7g", pfloat->maximum);
        gchar *default_value =
            g_strdup_printf("%.7g", g_value_get_float(&value));
        json_description_->add_string_member("type", "float");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_DOUBLE:
      {
        GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE(property_);
        gchar *min = g_strdup_printf("%.7g", pdouble->minimum);
        gchar *max = g_strdup_printf("%.7g", pdouble->maximum);
        gchar *default_value =
            g_strdup_printf("%.7g", g_value_get_double(&value));
        json_description_->add_string_member("type", "double");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    default:
      if (property_->value_type == GST_TYPE_CAPS) {
        const GstCaps *caps = gst_value_get_caps(&value);
        json_description_->add_string_member("type", "caps");
        if (!caps)
          json_description_->add_string_member("default value", "");
        else
          json_description_->add_string_member("default value",
                                               gst_caps_to_string(caps));
      } else if (G_IS_PARAM_SPEC_ENUM(property_)) {
        GEnumValue *values;
        guint j = 0;
        gint enum_value;
        const gchar *value_nick = "";
        const gchar *value_name = "";
        json_description_->add_string_member("type", "enum");
        values =
            G_ENUM_CLASS(g_type_class_ref(property_->value_type))->values;
        enum_value = g_value_get_enum(&value);
        while (values[j].value_name) {
          if (values[j].value == enum_value) {
            value_nick = values[j].value_nick;
            value_name = values[j].value_name;
          }
          j++;
        }

        json_description_->set_member_name("default value");
        json_description_->begin_object();
        gchar *value = g_strdup_printf("%d", enum_value);
        json_description_->add_string_member("value", value);
        g_free(value);
        json_description_->add_string_member("nick", value_nick);
        json_description_->add_string_member("name", value_name);
        json_description_->end_object();

        // g_debug ("Enum \"%s\" Default: %d, \"%s\" \"%s\"",
        //  g_type_name (G_VALUE_TYPE (&value)),
        //  enum_value,
        //  value_nick,
        //  value_name);

        j = 0;

        json_description_->set_member_name("values");
        json_description_->begin_array();
        while (values[j].value_name) {
          json_description_->begin_object();
          json_description_->add_string_member("name", values[j].value_name);
          json_description_->add_string_member("nick", values[j].value_nick);
          gchar *values_value = g_strdup_printf("%d", values[j].value);
          json_description_->add_string_member("value", values_value);
          g_free(values_value);
          json_description_->end_object();
          j++;
        }
        json_description_->end_array();

        /* g_type_class_unref (ec); */
      } else if (G_IS_PARAM_SPEC_FLAGS(property_)) {
        g_debug("warning: param spec flags not handled");
        // GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (property_);
        // GFlagsValue *vals;
        // gchar *cur;

        // vals = pflags->flags_class->values;

        // cur = flags_to_string (vals, g_value_get_flags (&value));

        // g_debug ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
        //    g_type_name (G_VALUE_TYPE (&value)),
        //    g_value_get_flags (&value), cur);

        // while (vals[0].value_name) {
        //   g_debug ("");
        //   if (_name)
        //     g_debug ("%s", _name);
        //   g_debug ("%-23.23s    (0x%08x): %-16s - %s", "",
        //      vals[0].value, vals[0].value_nick, vals[0].value_name);
        //   ++vals;
        // }

        // g_free (cur);
      } else if (G_IS_PARAM_SPEC_OBJECT(property_)) {
        g_debug("warning: param spec object not handled");
        // g_debug ("%-23.23s Object of type \"%s\"", "",
        //  g_type_name (property_->value_type));
      } else if (G_IS_PARAM_SPEC_BOXED(property_)) {
        g_debug("warning: param spec boxed not handled");
        // g_debug ("%-23.23s Boxed pointer of type \"%s\"", "",
        //  g_type_name (property_->value_type));
      } else if (G_IS_PARAM_SPEC_POINTER(property_)) {
        g_debug("warning: param spec pointer not handled");
        // if (property_->value_type != G_TYPE_POINTER) {
        //   g_debug ("%-23.23s Pointer of type \"%s\".", "",
        //    g_type_name (property_->value_type));
        // } else if (property_->value_type == G_TYPE_VALUE_ARRAY) {
        // GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (property_);
        // g_debug ("warning: array not handled");
        // if (pvarray->element_spec) {
        //   g_debug ("%-23.23s Array of GValues of type \"%s\"", "",
        //    g_type_name (pvarray->element_spec->value_type));
        // } else {
        //   g_debug ("%-23.23s Array of GValues", "");
        // }
      } else if (GST_IS_PARAM_SPEC_FRACTION(property_)) {
        GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION(property_);
        json_description_->add_string_member("type", "fraction");
        gchar *minnum = g_strdup_printf("%d", pfraction->min_num);
        gchar *minden = g_strdup_printf("%d", pfraction->min_den);
        gchar *maxnum = g_strdup_printf("%d", pfraction->max_num);
        gchar *maxden = g_strdup_printf("%d", pfraction->max_den);
        gchar *defaultnum = g_strdup_printf("%d",
                                            gst_value_get_fraction_numerator
                                            (&value));
        gchar *defaultden = g_strdup_printf("%d",
                                            gst_value_get_fraction_denominator
                                            (&value));
        json_description_->add_string_member("minimum numerator", minnum);
        json_description_->add_string_member("maximum numerator", minden);
        json_description_->add_string_member("minimum denominator", maxnum);
        json_description_->add_string_member("maximum denominator", maxden);
        json_description_->add_string_member("default numerator", defaultnum);
        json_description_->add_string_member("default denominator",
                                             defaultden);
        g_free(minnum);
        g_free(minden);
        g_free(maxnum);
        g_free(maxden);
        g_free(defaultnum);
        g_free(defaultden);
        // g_debug ("Range: %d/%d - %d/%d Default: %d/%d ",
        //  pfraction->min_num, pfraction->min_den,
        //  pfraction->max_num, pfraction->max_den,
        //  gst_value_get_fraction_numerator (&value),
        //  gst_value_get_fraction_denominator (&value));
      } else {
        g_warning("warning: unknown type");
        // g_debug ("%-23.23s Unknown type %ld \"%s\"", "", property_->value_type,
        //  g_type_name (property_->value_type));
      }
      break;
  }
  g_value_reset(&value);
  json_description_->end_object();
}
/*
 * Signature the prototype of (*GClosureMarshall), meeting the requirements
 * to be the second argument to g_closure_set_marshal()
 */
static void
bindings_java_marshaller
(
	GClosure* closure,
	GValue* return_value,
	guint n_param_values,
	const GValue* param_values,
	gpointer invocation_hint,
	gpointer marshal_data
)
{
 	BindingsJavaClosure* bjc;
 	JNIEnv* env;
 	jvalue* jargs;
	guint i;
	GType type;

	// Return values, as necessary
	jboolean _b;
	gboolean b;
	
	jint _e;
	
	jstring _str;
	gchar* str;
	GObject* obj;
	
	/*
	 * Begin marshaller by downcasting the GClosure we got.
	 */

	bjc = (BindingsJavaClosure*) closure;

	/*
	 * Get the JNIEnv interface pointer
	 */

	env = bindings_java_getEnv();
	if (env == NULL) {
		g_critical("Couldn't get JNIEnv interface, aborting marshal");
		return;
	}
		
	/*
	 * Build the parameters for the callback. The signature of the
	 * handlers on the Java side for a signal "name" would be:
	 *
	 * 	receiveName(Signal handler, type arg0, type arg1, ...)
	 *
	 * Note that arg0 is universally the source object (in otherwords, a
	 * method function where the first argument is always a reference to
	 * self).
	 *
	 * In case you didn't know, JNI's jvalue us a rather complex union
	 * which holds any of the possible things you can send across the
	 * boundary. So we allocate an array of them, then for each parameter
	 * passed to the marshaller, whack them in.
	 */

	jargs = g_newa(jvalue, n_param_values + 1);

	jargs[0].l = bjc->handler;

	for(i = 0; i < n_param_values; i++) {
		type = G_VALUE_TYPE(&param_values[i]);
		switch(G_TYPE_FUNDAMENTAL(type)) {
		case G_TYPE_CHAR:
			jargs[i+1].c = g_value_get_char(&param_values[i]);
      			break;

		case G_TYPE_UCHAR:
			jargs[i+1].c = g_value_get_uchar(&param_values[i]);
      			break;

		case G_TYPE_BOOLEAN:
			b = g_value_get_boolean(&param_values[i]);
			jargs[i+1].z = (b == TRUE) ? JNI_TRUE : JNI_FALSE;
			break;

		case G_TYPE_INT:
			jargs[i+1].i = g_value_get_int(&param_values[i]);
			break;

		case G_TYPE_UINT:
			jargs[i+1].i = g_value_get_uint(&param_values[i]);
			break;

		case G_TYPE_ENUM:
			jargs[i+1].i = g_value_get_enum(&param_values[i]);
			break;

		case G_TYPE_FLAGS:
			jargs[i+1].i = g_value_get_flags(&param_values[i]);
			break;

		case G_TYPE_LONG:
			jargs[i+1].j = g_value_get_long(&param_values[i]);
			break;

		case G_TYPE_ULONG:
			jargs[i+1].j = g_value_get_ulong(&param_values[i]);
			break;

		case G_TYPE_FLOAT:
			jargs[i+1].f = g_value_get_float(&param_values[i]);
			break;

		case G_TYPE_DOUBLE:
			jargs[i+1].d = g_value_get_double(&param_values[i]);
			break;

		case G_TYPE_STRING:
			jargs[i+1].l = bindings_java_newString(env, g_value_get_string(&param_values[i]));
      			break;

		case G_TYPE_OBJECT:
		case G_TYPE_INTERFACE:
			/*
			 * GObjects are just pointers, and so we pass up the
			 * address across the boundary to be looked up and
			 * either an existing Proxy returned or a new Proxy
			 * created.
			 */
			obj = g_value_get_object(&param_values[i]);
			bindings_java_memory_cleanup(obj, FALSE);
			jargs[i+1].j = (jlong) obj;
			break;

		case G_TYPE_BOXED:
			/*
			 * We make a copy of the GBoxed so that we own it and
			 * thus it can (will) survive the duration of the
			 * signal in the event that the developer using this
			 * code keeps a reference to the returned Boxed.
			 */
			jargs[i+1].j = (jlong) g_boxed_copy(type, g_value_get_boxed(&param_values[i]));
			break;

		case G_TYPE_PARAM:
			/*
			 * We're ignoring GParamSpec at the moment. They
			 * normally only show up in 'notify' signals, and we
			 * don't need them.
			 */
		case G_TYPE_POINTER:
			/*
			 * and, we're ignoring something that gets registered
			 * as a gpointer, by definition it has no type
			 * information and there's nothing we can do.
			 */
			jargs[i+1].j = (jlong) NULL;
			break;

		default:
			/*
			 * Unrecognized. Probably means we need to add a clause above.
			 */
			g_printerr("Don't know how to marshal a %s", g_type_name(type));
			jargs[i+1].l = 0;
			break;
		}
	}
	
	/*
	 * And now we invoke the callback on the Java side Signal handler; we have to
	 * select the correct function based on what return type is necessary.
	 */

	switch(bjc->returnType) {
	case 'V':
		/*
		 * void return signals
		 */
		(*env)->CallStaticVoidMethodA(env, bjc->receiver, bjc->method, jargs);
		break;

	case 'Z':
		/*
		 * boolean return signals
		 */
		_b = (*env)->CallStaticBooleanMethodA(env, bjc->receiver, bjc->method, jargs);		
		if (_b == JNI_TRUE) {
			b = TRUE;
		} else if (_b == JNI_FALSE) {
			b = FALSE;
		} else {
			g_critical("How did you manage to return a boolean that's neither TRUE nor FALSE?");
			return;
		}
		
		g_value_set_boolean(return_value, b);
		break;

	case 'I':
		/*
		 * integer return signals
		 */
		_e = (*env)->CallStaticIntMethodA(env, bjc->receiver, bjc->method, jargs);
		
		g_value_set_int(return_value, _e);
		break;

	case 'E':
		/*
		 * enum return signals
		 */
		_e = (*env)->CallStaticIntMethodA(env, bjc->receiver, bjc->method, jargs);		
		
		g_value_set_enum(return_value, _e);
		break;

	case 'L':
		/*
		 * String return signals
		 *
		 * L is actually Object, of course, but the only type we need to
		 * worry about is java.lang.String encode it for now, and so make the
		 * enormous assumption that a string is what we get back.
		 */
		_str = (*env)->CallStaticObjectMethodA(env, bjc->receiver, bjc->method, jargs);
		if (_str == NULL) {
			g_warning("Invoking string handler returned null. That's probably bad");
			break;
		}
		
		str = (gchar*) bindings_java_getString(env, _str);
		if (str == NULL) {
			/* OutOfMemoryError already thrown */
			return;
		}
		
		// according to the API docs, this copies the input...
		g_value_set_string(return_value, str);
		
		// ... so we can release str
		bindings_java_releaseString(str);
		break;

	default:
		/*
		 * If it's not void, boolean or gchar*, then what kind of signal is it?
		 */
		g_critical("Invocation for return type %c not implemented", bjc->returnType);
		break;
	}

	/*
	 * Cleanup
	 */

	for(i = 0; i < n_param_values; i++) {
  		type = G_VALUE_TYPE(&param_values[i]);
		switch(G_TYPE_FUNDAMENTAL(type)) {
		case G_TYPE_STRING:
			(*env)->DeleteLocalRef(env, jargs[i+1].l);
			break;

		default:
			break;
		}
	}
	
	/*
	 * Don't need to free jargs - we alloca()'d it
	 */
	
	/*
	 * Now, check if an exception occurred in the callback. There's a
	 * catch: because we're in native code right now [care of the call to
	 * gtk_main()] the exception gets swallowed until we return from that
	 * native call. So we call the function which causes the main loop to
	 * terminate, with the result that the exception will propegate out
	 * and, yes, probably halt the program.
	 *
	 * This is abrupt, but it is deliberate: we need to force developers
	 * to deal with criticals emitted by the underlying libraries.
	 * Otherwise, the next thing that is likely to happen is a
	 * segmentation fault, and not only does that crash the "program" but
	 * it takes out the Java Virtual Machine running it. People don't
	 * like VM crashes.
	 *
	 * Uncaught exceptions of any kind leaving a signal handler are to be
	 * considered programmer error and will be fatal.
	 */

	if ((*env)->ExceptionOccurred(env)) {
		gtk_main_quit();
	}
}
Beispiel #17
0
gint
_gtk_tree_data_list_compare_func (GtkTreeModel *model,
				  GtkTreeIter  *a,
				  GtkTreeIter  *b,
				  gpointer      user_data)
{
  gint column = GPOINTER_TO_INT (user_data);
  GType type = gtk_tree_model_get_column_type (model, column);
  GValue a_value = G_VALUE_INIT;
  GValue b_value = G_VALUE_INIT;
  gint retval;
  const gchar *stra, *strb;

  gtk_tree_model_get_value (model, a, column, &a_value);
  gtk_tree_model_get_value (model, b, column, &b_value);

  switch (get_fundamental_type (type))
    {
    case G_TYPE_BOOLEAN:
      if (g_value_get_boolean (&a_value) < g_value_get_boolean (&b_value))
	retval = -1;
      else if (g_value_get_boolean (&a_value) == g_value_get_boolean (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_CHAR:
      if (g_value_get_schar (&a_value) < g_value_get_schar (&b_value))
	retval = -1;
      else if (g_value_get_schar (&a_value) == g_value_get_schar (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_UCHAR:
      if (g_value_get_uchar (&a_value) < g_value_get_uchar (&b_value))
	retval = -1;
      else if (g_value_get_uchar (&a_value) == g_value_get_uchar (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_INT:
      if (g_value_get_int (&a_value) < g_value_get_int (&b_value))
	retval = -1;
      else if (g_value_get_int (&a_value) == g_value_get_int (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_UINT:
      if (g_value_get_uint (&a_value) < g_value_get_uint (&b_value))
	retval = -1;
      else if (g_value_get_uint (&a_value) == g_value_get_uint (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_LONG:
      if (g_value_get_long (&a_value) < g_value_get_long (&b_value))
	retval = -1;
      else if (g_value_get_long (&a_value) == g_value_get_long (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_ULONG:
      if (g_value_get_ulong (&a_value) < g_value_get_ulong (&b_value))
	retval = -1;
      else if (g_value_get_ulong (&a_value) == g_value_get_ulong (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_INT64:
      if (g_value_get_int64 (&a_value) < g_value_get_int64 (&b_value))
	retval = -1;
      else if (g_value_get_int64 (&a_value) == g_value_get_int64 (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_UINT64:
      if (g_value_get_uint64 (&a_value) < g_value_get_uint64 (&b_value))
	retval = -1;
      else if (g_value_get_uint64 (&a_value) == g_value_get_uint64 (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_ENUM:
      /* this is somewhat bogus. */
      if (g_value_get_enum (&a_value) < g_value_get_enum (&b_value))
	retval = -1;
      else if (g_value_get_enum (&a_value) == g_value_get_enum (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_FLAGS:
      /* this is even more bogus. */
      if (g_value_get_flags (&a_value) < g_value_get_flags (&b_value))
	retval = -1;
      else if (g_value_get_flags (&a_value) == g_value_get_flags (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_FLOAT:
      if (g_value_get_float (&a_value) < g_value_get_float (&b_value))
	retval = -1;
      else if (g_value_get_float (&a_value) == g_value_get_float (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_DOUBLE:
      if (g_value_get_double (&a_value) < g_value_get_double (&b_value))
	retval = -1;
      else if (g_value_get_double (&a_value) == g_value_get_double (&b_value))
	retval = 0;
      else
	retval = 1;
      break;
    case G_TYPE_STRING:
      stra = g_value_get_string (&a_value);
      strb = g_value_get_string (&b_value);
      if (stra == NULL) stra = "";
      if (strb == NULL) strb = "";
      retval = g_utf8_collate (stra, strb);
      break;
    case G_TYPE_VARIANT:
    case G_TYPE_POINTER:
    case G_TYPE_BOXED:
    case G_TYPE_OBJECT:
    default:
      g_warning ("Attempting to sort on invalid type %s\n", g_type_name (type));
      retval = FALSE;
      break;
    }

  g_value_unset (&a_value);
  g_value_unset (&b_value);

  return retval;
}
Beispiel #18
0
static void
bt_wavelevel_set_property (GObject * const object, const guint property_id,
    const GValue * const value, GParamSpec * const pspec)
{
  const BtWavelevel *const self = BT_WAVELEVEL (object);
  return_if_disposed ();
  switch (property_id) {
    case WAVELEVEL_SONG:
      self->priv->song = BT_SONG (g_value_get_object (value));
      g_object_try_weak_ref (self->priv->song);
      //GST_DEBUG("set the song for wavelevel: %p",self->priv->song);
      break;
    case WAVELEVEL_WAVE:
      self->priv->wave = BT_WAVE (g_value_get_object (value));
      g_object_try_weak_ref (self->priv->wave);
      GST_DEBUG ("set the wave for wavelevel: %p", self->priv->wave);
      break;
    case WAVELEVEL_ROOT_NOTE:
      self->priv->root_note = g_value_get_enum (value);
      GST_DEBUG ("set the root-note for wavelevel: %d", self->priv->root_note);
      break;
    case WAVELEVEL_LENGTH:
      self->priv->length = g_value_get_ulong (value);
      GST_DEBUG ("set the length for wavelevel: %lu", self->priv->length);
      break;
    case WAVELEVEL_LOOP_START:
      self->priv->loop_start = g_value_get_ulong (value);
      GST_INFO ("loop: 0 / %lu .. %lu / %lu", self->priv->loop_start,
          self->priv->loop_end, self->priv->length);
      // make sure its less then loop_end/length
      if (self->priv->loop_end > 0) {
        if (self->priv->loop_start >= self->priv->loop_end) {
          GST_DEBUG ("clip loop-start by loop-end: %lu", self->priv->loop_end);
          self->priv->loop_start = self->priv->loop_end - 1;
        }
      }
      if (self->priv->length > 0) {
        if (self->priv->loop_start >= self->priv->length) {
          GST_DEBUG ("clip loop-start by length: %lu", self->priv->length);
          self->priv->loop_start = self->priv->length - 1;
        }
      }
      GST_DEBUG ("set the loop-start for wavelevel: %lu",
          self->priv->loop_start);
      break;
    case WAVELEVEL_LOOP_END:
      self->priv->loop_end = g_value_get_ulong (value);
      GST_INFO ("loop: 0 / %lu .. %lu / %lu", self->priv->loop_start,
          self->priv->loop_end, self->priv->length);
      // make sure its more then loop-start
      if (self->priv->loop_start > 0) {
        if (self->priv->loop_end < self->priv->loop_start) {
          GST_DEBUG ("clip loop-end by loop-start: %lu",
              self->priv->loop_start);
          self->priv->loop_end = self->priv->loop_start + 1;
        }
      }
      // make sure its less then or equal to length
      if (self->priv->length > 0) {
        if (self->priv->loop_end > self->priv->length) {
          GST_DEBUG ("clip loop-end by length: %lu", self->priv->length);
          self->priv->loop_end = self->priv->length;
        }
      }
      GST_DEBUG ("set the loop-start for wavelevel: %lu",
          self->priv->loop_start);
      break;
    case WAVELEVEL_RATE:
      self->priv->rate = g_value_get_ulong (value);
      GST_DEBUG ("set the rate for wavelevel: %lu", self->priv->rate);
      break;
    case WAVELEVEL_DATA:
      g_free (self->priv->sample);
      self->priv->sample = g_value_get_pointer (value);
      GST_DEBUG ("set the data-pointer for wavelevel: %p", self->priv->sample);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
  }
}
Beispiel #19
0
static int get_field(OhmFact *fact, fsif_fldtype_t type,char *name,void *vptr)
{
    GValue  *gv;

    if (!fact || !name || !(gv = ohm_fact_get(fact, name))) {
        OHM_ERROR("resource: [%s] Cant find field %s",
                  __FUNCTION__, name?name:"<null>");
        goto return_empty_value;
    }

    switch (type) {

    case fldtype_string:
        if (G_VALUE_TYPE(gv) != G_TYPE_STRING)
            goto type_mismatch;
        else
            *(const char **)vptr = g_value_get_string(gv);
        break;

    case fldtype_integer:
        switch (G_VALUE_TYPE(gv)) {
        case G_TYPE_LONG: *(long *)vptr = g_value_get_long(gv); break;
        case G_TYPE_INT:  *(long *)vptr = g_value_get_int(gv);  break;
        default:          goto type_mismatch;
        }
        break;

    case fldtype_unsignd:
        if (G_VALUE_TYPE(gv) != G_TYPE_ULONG)
            goto type_mismatch;
        else
            *(unsigned long *)vptr = g_value_get_ulong(gv);
        break;

    case fldtype_floating:
        if (G_VALUE_TYPE(gv) != G_TYPE_DOUBLE)
            goto type_mismatch;
        else
            *(double *)vptr = g_value_get_double(gv);
        break;

    case fldtype_time:
        if (G_VALUE_TYPE(gv) != G_TYPE_UINT64)
            goto type_mismatch;
        else
            *(time_t *)vptr = g_value_get_uint64(gv);
        break;

    default:
        break;
    }

    return TRUE;

 type_mismatch:
    OHM_ERROR("resource: [%s] Type mismatch when fetching field '%s'",
              __FUNCTION__,name);

 return_empty_value:
    switch (type) {
    case fldtype_string:      *(char              **)vptr = NULL;       break;
    case fldtype_integer:     *(long               *)vptr = 0;          break;
    case fldtype_unsignd:     *(unsigned long      *)vptr = 0;          break;
    case fldtype_floating:    *(double             *)vptr = 0.0;        break;
    case fldtype_time:        *(unsigned long long *)vptr = 0ULL;       break;
    default:                                                            break;
    }

    return FALSE;
} 
Beispiel #20
0
/* Syncs an object property to GConf */
static void
prop_binding_sync_prop_to_pref (PropBinding *binding)
{
        GValue value;
        GConfValue *gconf_value;

        memset (&value, 0, sizeof (GValue));

        g_value_init (&value,
                      G_PARAM_SPEC_VALUE_TYPE (binding->prop));
        g_object_get_property (binding->object,
                               binding->prop->name,
                               &value);

        switch (value.g_type) {
        case G_TYPE_STRING:
                gconf_value = gconf_value_new (GCONF_VALUE_STRING);
                gconf_value_set_string (gconf_value,
                                        g_value_get_string (&value));
                break;
        case G_TYPE_INT:
                gconf_value = gconf_value_new (GCONF_VALUE_INT);
                gconf_value_set_int (gconf_value,
                                     g_value_get_int (&value));
                break;
        case G_TYPE_UINT:
                gconf_value = gconf_value_new (GCONF_VALUE_INT);
                gconf_value_set_int (gconf_value,
                                     g_value_get_uint (&value));
                break;
        case G_TYPE_LONG:
                gconf_value = gconf_value_new (GCONF_VALUE_INT);
                gconf_value_set_int (gconf_value,
                                     g_value_get_long (&value));
                break;
        case G_TYPE_ULONG:
                gconf_value = gconf_value_new (GCONF_VALUE_INT);
                gconf_value_set_int (gconf_value,
                                     g_value_get_ulong (&value));
                break;
        case G_TYPE_INT64:
                gconf_value = gconf_value_new (GCONF_VALUE_INT);
                gconf_value_set_int (gconf_value,
                                     g_value_get_int64 (&value));
                break;
        case G_TYPE_UINT64:
                gconf_value = gconf_value_new (GCONF_VALUE_INT);
                gconf_value_set_int (gconf_value,
                                     g_value_get_uint64 (&value));
                break;
        case G_TYPE_CHAR:
                gconf_value = gconf_value_new (GCONF_VALUE_INT);
                gconf_value_set_int (gconf_value,
                                     g_value_get_char (&value));
                break;
        case G_TYPE_UCHAR:
                gconf_value = gconf_value_new (GCONF_VALUE_INT);
                gconf_value_set_int (gconf_value,
                                     g_value_get_uchar (&value));
                break;
        case G_TYPE_ENUM:
                gconf_value = gconf_value_new (GCONF_VALUE_INT);
                gconf_value_set_int (gconf_value,
                                     g_value_get_enum (&value));
                break;
        case G_TYPE_BOOLEAN:
                gconf_value = gconf_value_new (GCONF_VALUE_BOOL);
                gconf_value_set_bool (gconf_value,
                                      g_value_get_boolean (&value));
                break;
        case G_TYPE_DOUBLE:
                gconf_value = gconf_value_new (GCONF_VALUE_FLOAT);
#ifdef HAVE_CORBA_GCONF
                /* FIXME we cast to a float explicitly as CORBA GConf
                 * uses doubles in its API, but treats them as floats
                 * when transporting them over CORBA. See #322837 */
                gconf_value_set_float (gconf_value,
                                       (float) g_value_get_double (&value));
#else
                gconf_value_set_float (gconf_value,
                                       g_value_get_double (&value));
#endif
                break;
        case G_TYPE_FLOAT:
                gconf_value = gconf_value_new (GCONF_VALUE_FLOAT);
                gconf_value_set_float (gconf_value,
                                       g_value_get_float (&value));
                break;
        default:
                if (g_type_is_a (value.g_type, G_TYPE_ENUM)) {
                        gconf_value = gconf_value_new (GCONF_VALUE_INT);
                        gconf_value_set_int (gconf_value,
                                             g_value_get_enum (&value));
                } else {
                        g_warning ("prop_binding_sync_prop_to_pref: "
                                   "Unhandled value type '%s'.\n",
                                   g_type_name (value.g_type));

                        goto done;
                }

                break;
        }

        /* Set to GConf */
        gconf_client_set (bridge->client, binding->key, gconf_value, NULL);

        /* Store until change notification comes in, so that we are able
         * to ignore it */
        binding->val_changes = g_slist_append (binding->val_changes,
                                               gconf_value);

done:
        g_value_unset (&value);
}
Beispiel #21
0
static int is_spurious_event(char *device, int driver, int connected)
{
    /*
     * Filter out obviously spurious/duplicate events. Spurious events are
     * events that obviously do not represent any state change (eg. getting
     * a connected=0 event while already in disconnected state).
     */

    GSList  *list;
    OhmFact *fact;
    GValue  *gval;
    int      val, dmatch, cmatch, spurious = FALSE;
    OhmFactStore *store;

    store = ohm_fact_store_get_fact_store();
    list  = ohm_fact_store_get_facts_by_name(store, FACT_DEVICE_ACCESSIBLE);
    for ( ; list ; list = list->next) {
        fact = (OhmFact *)list->data;
        gval = ohm_fact_get(fact, "name");

        if (!gval || G_VALUE_TYPE(gval) != G_TYPE_STRING)
            continue;

        if (strcmp(g_value_get_string(gval), device))
            continue;

        if (driver != -1 && (gval = ohm_fact_get(fact, "driver")) != NULL) {
            switch (G_VALUE_TYPE(gval)) {
            case G_TYPE_INT:   val = g_value_get_int(gval);   break;
            case G_TYPE_UINT:  val = g_value_get_uint(gval);  break;
            case G_TYPE_LONG:  val = g_value_get_long(gval);  break;
            case G_TYPE_ULONG: val = g_value_get_ulong(gval); break;
            default:           val = driver;    /* ignored (ie. match) */
            }
            dmatch = (val == driver);
        }
        else
            dmatch = TRUE;
        
        if (connected != -1 && (gval=ohm_fact_get(fact,"connected")) != NULL) {
            switch (G_VALUE_TYPE(gval)) {
            case G_TYPE_INT:   val = g_value_get_int(gval);   break;
            case G_TYPE_UINT:  val = g_value_get_uint(gval);  break;
            case G_TYPE_LONG:  val = g_value_get_long(gval);  break;
            case G_TYPE_ULONG: val = g_value_get_ulong(gval); break;
            default:           val = connected; /* ignored (ie. match) */
            }
            cmatch = (val == connected);
        }
        else
            cmatch = TRUE;
        
        spurious = dmatch && cmatch; /* no change is a spurious event */
        break;
    }

    OHM_DEBUG(DBG_INFO, "%s, driver: %d, connected: %d is %sa spurious event",
              device, driver, connected, spurious ? "" : "not ");

    return spurious;
}
Beispiel #22
0
static void updated_cb(void *data,OhmFact *fact,GQuark fldquark,gpointer value)
{
    (void)data;

    GValue        *gval = (GValue *)value;
    char          *name;
    watch_fact_t  *wfact;
    watch_entry_t *wentry;
    fsif_field_t   fld;
    char           valb[256];
    char          *valstr;
    
    if (fact == NULL) {
        OHM_ERROR("resource: %s() called with null fact pointer",__FUNCTION__);
        return;
    }
        
    name = (char *)ohm_structure_get_name(OHM_STRUCTURE(fact));

    if (value != NULL && (wfact = find_watch(name, watch_update)) != NULL) {

        for (wentry = wfact->entries;  wentry != NULL;  wentry = wentry->next){

            fld.name = (char *)g_quark_to_string(fldquark);

            if (matching_entry(fact, wentry->selist) &&
                (!wentry->fldname || !strcmp(fld.name, wentry->fldname))) {
                
                switch (G_VALUE_TYPE(gval)) {
                    
                case G_TYPE_STRING:
                    fld.type = fldtype_string;
                    fld.value.string = (char *)g_value_get_string(gval);
                    break;
                    
                case G_TYPE_LONG:
                    fld.type = fldtype_integer;
                    fld.value.integer = g_value_get_long(gval);
                    break;

                case G_TYPE_INT:
                    fld.type = fldtype_integer;
                    fld.value.integer = g_value_get_int(gval);
                    break;
                    
                case G_TYPE_ULONG:
                    fld.type = fldtype_unsignd;
                    fld.value.unsignd = g_value_get_ulong(gval);
                    break;
                    
                case G_TYPE_DOUBLE:
                    fld.type = fldtype_floating;
                    fld.value.floating = g_value_get_double(gval);
                    break;
                    
                case G_TYPE_UINT64:
                    fld.type = fldtype_time;
                    fld.value.time = g_value_get_uint64(gval);
                    break;
                    
                default:
                    OHM_ERROR("resource: [%s] Unsupported data type (%d) "
                              "for field '%s'",
                              __FUNCTION__, G_VALUE_TYPE(gval), fld.name);
                    return;
                }
                
                valstr = print_value(fld.type, (void *)&fld.value,
                                     valb, sizeof(valb)); 
                OHM_DEBUG(DBG_FS, "field watch point: field '%s:%s' "
                          "changed to '%s'", name, fld.name, valstr);

                wentry->callback.field_watch(fact, name, &fld,wentry->usrdata);
                
                return;
            } /* if matching_entry */
        } /* for */
    } /* if find_watch */
}
static GtkCellEditable *
parasite_property_cell_renderer_start_editing(GtkCellRenderer *renderer,
        GdkEvent *event,
        GtkWidget *widget,
        const gchar *path,
        GdkRectangle *background_area,
        GdkRectangle *cell_area,
        GtkCellRendererState flags)
{
    PangoFontDescription *font_desc;
    GtkCellEditable *editable = NULL;
    GObject *object;
    const char *name;
    GValue gvalue = {0};
    GParamSpec *prop;

    g_object_get(renderer,
                 "object", &object,
                 "name", &name,
                 NULL);

    prop = g_object_class_find_property(G_OBJECT_GET_CLASS(object), name);

    if (!(prop->flags & G_PARAM_WRITABLE))
        return NULL;

    g_value_init(&gvalue, prop->value_type);
    g_object_get_property(object, name, &gvalue);

    if (G_VALUE_HOLDS_ENUM(&gvalue) || G_VALUE_HOLDS_BOOLEAN(&gvalue))
    {
        GtkWidget *combobox = gtk_combo_box_new_text();
        gtk_widget_show(combobox);
        g_object_set(G_OBJECT(combobox), "has-frame", FALSE, NULL);
        GList *renderers;

        if (G_VALUE_HOLDS_BOOLEAN(&gvalue))
        {
            gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "FALSE");
            gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "TRUE");

            gtk_combo_box_set_active(GTK_COMBO_BOX(combobox),
                                     g_value_get_boolean(&gvalue) ? 1 : 0);
        }
        else if (G_VALUE_HOLDS_ENUM(&gvalue))
        {
            gint value = g_value_get_enum(&gvalue);
            GEnumClass *enum_class = G_PARAM_SPEC_ENUM(prop)->enum_class;
            guint i;

            for (i = 0; i < enum_class->n_values; i++)
            {
                GEnumValue *enum_value = &enum_class->values[i];

                gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),
                                          enum_value->value_name);

                if (enum_value->value == value)
                    gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), i);
            }

        }

        renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(combobox));
        g_object_set(G_OBJECT(renderers->data), "scale", TREE_TEXT_SCALE, NULL);
        g_list_free(renderers);

        editable = GTK_CELL_EDITABLE(combobox);
    }
    else if (G_VALUE_HOLDS_STRING(&gvalue))
    {
        GtkWidget *entry = gtk_entry_new();
        gtk_widget_show(entry);
        gtk_entry_set_text(GTK_ENTRY(entry), g_value_get_string(&gvalue));

        editable = GTK_CELL_EDITABLE(entry);
    }
    else if (G_VALUE_HOLDS_INT(&gvalue)    ||
             G_VALUE_HOLDS_UINT(&gvalue)   ||
             G_VALUE_HOLDS_INT64(&gvalue)  ||
             G_VALUE_HOLDS_UINT64(&gvalue) ||
             G_VALUE_HOLDS_LONG(&gvalue)   ||
             G_VALUE_HOLDS_ULONG(&gvalue)  ||
             G_VALUE_HOLDS_DOUBLE(&gvalue))
    {
        double min, max, value;
        GtkWidget *spinbutton;
        guint digits = 0;

        if (G_VALUE_HOLDS_INT(&gvalue))
        {
            GParamSpecInt *paramspec = G_PARAM_SPEC_INT(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_int(&gvalue);
        }
        else if (G_VALUE_HOLDS_UINT(&gvalue))
        {
            GParamSpecUInt *paramspec = G_PARAM_SPEC_UINT(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_uint(&gvalue);
        }
        else if (G_VALUE_HOLDS_INT64(&gvalue))
        {
            GParamSpecInt64 *paramspec = G_PARAM_SPEC_INT64(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_int64(&gvalue);
        }
        else if (G_VALUE_HOLDS_UINT64(&gvalue))
        {
            GParamSpecUInt64 *paramspec = G_PARAM_SPEC_UINT64(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_uint64(&gvalue);
        }
        else if (G_VALUE_HOLDS_LONG(&gvalue))
        {
            GParamSpecLong *paramspec = G_PARAM_SPEC_LONG(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_long(&gvalue);
        }
        else if (G_VALUE_HOLDS_ULONG(&gvalue))
        {
            GParamSpecULong *paramspec = G_PARAM_SPEC_ULONG(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_ulong(&gvalue);
        }
        else if (G_VALUE_HOLDS_DOUBLE(&gvalue))
        {
            GParamSpecDouble *paramspec = G_PARAM_SPEC_DOUBLE(prop);
            min = paramspec->minimum;
            max = paramspec->maximum;
            value = g_value_get_double(&gvalue);
            digits = 2;
        }
        else
        {
            // Shouldn't really be able to happen.
            return NULL;
        }

        spinbutton = gtk_spin_button_new_with_range(min, max, 1);
        gtk_widget_show(spinbutton);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbutton), value);
        gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinbutton), digits);

        editable = GTK_CELL_EDITABLE(spinbutton);
    }

    font_desc = pango_font_description_new();
    pango_font_description_set_size(font_desc, 8 * PANGO_SCALE);
    gtk_widget_modify_font(GTK_WIDGET(editable), font_desc);
    pango_font_description_free(font_desc);

    g_value_unset(&gvalue);

    g_signal_connect(G_OBJECT(editable), "editing_done",
                     G_CALLBACK(parasite_property_cell_renderer_stop_editing),
                     renderer);

    g_object_set_data_full(G_OBJECT(editable), "_prop_name", g_strdup(name),
                           g_free);
    g_object_set_data(G_OBJECT(editable), "_prop_object", object);

    return editable;
}
Beispiel #24
0
static void
print_element_properties_info (GstElement * element)
{
  GParamSpec **property_specs;
  guint num_properties, i;
  gboolean readable;
  gboolean first_flag;

  property_specs = g_object_class_list_properties
      (G_OBJECT_GET_CLASS (element), &num_properties);
  n_print ("\n");
  n_print ("Element Properties:\n");

  for (i = 0; i < num_properties; i++) {
    GValue value = { 0, };
    GParamSpec *param = property_specs[i];

    readable = FALSE;

    g_value_init (&value, param->value_type);

    n_print ("  %-20s: %s\n", g_param_spec_get_name (param),
        g_param_spec_get_blurb (param));

    first_flag = TRUE;
    n_print ("%-23.23s flags: ", "");
    if (param->flags & G_PARAM_READABLE) {
      g_object_get_property (G_OBJECT (element), param->name, &value);
      readable = TRUE;
      g_print ("%s%s", (first_flag) ? "" : ", ", _("readable"));
      first_flag = FALSE;
    } else {
      /* if we can't read the property value, assume it's set to the default
       * (which might not be entirely true for sub-classes, but that's an
       * unlikely corner-case anyway) */
      g_param_value_set_default (param, &value);
    }
    if (param->flags & G_PARAM_WRITABLE) {
      g_print ("%s%s", (first_flag) ? "" : ", ", _("writable"));
      first_flag = FALSE;
    }
    if (param->flags & G_PARAM_DEPRECATED) {
      g_print ("%s%s", (first_flag) ? "" : ", ", _("deprecated"));
      first_flag = FALSE;
    }
    if (param->flags & GST_PARAM_CONTROLLABLE) {
      g_print (", %s", _("controllable"));
      first_flag = FALSE;
    }
    if (param->flags & GST_PARAM_MUTABLE_PLAYING) {
      g_print (", %s", _("changeable in NULL, READY, PAUSED or PLAYING state"));
    } else if (param->flags & GST_PARAM_MUTABLE_PAUSED) {
      g_print (", %s", _("changeable only in NULL, READY or PAUSED state"));
    } else if (param->flags & GST_PARAM_MUTABLE_READY) {
      g_print (", %s", _("changeable only in NULL or READY state"));
    }
    if (param->flags & ~KNOWN_PARAM_FLAGS) {
      g_print ("%s0x%0x", (first_flag) ? "" : ", ",
          param->flags & ~KNOWN_PARAM_FLAGS);
    }
    n_print ("\n");

    switch (G_VALUE_TYPE (&value)) {
      case G_TYPE_STRING:
      {
        const char *string_val = g_value_get_string (&value);

        n_print ("%-23.23s String. ", "");

        if (string_val == NULL)
          g_print ("Default: null");
        else
          g_print ("Default: \"%s\"", string_val);
        break;
      }
      case G_TYPE_BOOLEAN:
      {
        gboolean bool_val = g_value_get_boolean (&value);

        n_print ("%-23.23s Boolean. ", "");

        g_print ("Default: %s", bool_val ? "true" : "false");
        break;
      }
      case G_TYPE_ULONG:
      {
        GParamSpecULong *pulong = G_PARAM_SPEC_ULONG (param);

        n_print ("%-23.23s Unsigned Long. ", "");
        g_print ("Range: %lu - %lu Default: %lu ",
            pulong->minimum, pulong->maximum, g_value_get_ulong (&value));

        GST_ERROR ("%s: property '%s' of type ulong: consider changing to "
            "uint/uint64", GST_OBJECT_NAME (element),
            g_param_spec_get_name (param));
        break;
      }
      case G_TYPE_LONG:
      {
        GParamSpecLong *plong = G_PARAM_SPEC_LONG (param);

        n_print ("%-23.23s Long. ", "");
        g_print ("Range: %ld - %ld Default: %ld ",
            plong->minimum, plong->maximum, g_value_get_long (&value));

        GST_ERROR ("%s: property '%s' of type long: consider changing to "
            "int/int64", GST_OBJECT_NAME (element),
            g_param_spec_get_name (param));
        break;
      }
      case G_TYPE_UINT:
      {
        GParamSpecUInt *puint = G_PARAM_SPEC_UINT (param);

        n_print ("%-23.23s Unsigned Integer. ", "");
        g_print ("Range: %u - %u Default: %u ",
            puint->minimum, puint->maximum, g_value_get_uint (&value));
        break;
      }
      case G_TYPE_INT:
      {
        GParamSpecInt *pint = G_PARAM_SPEC_INT (param);

        n_print ("%-23.23s Integer. ", "");
        g_print ("Range: %d - %d Default: %d ",
            pint->minimum, pint->maximum, g_value_get_int (&value));
        break;
      }
      case G_TYPE_UINT64:
      {
        GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64 (param);

        n_print ("%-23.23s Unsigned Integer64. ", "");
        g_print ("Range: %" G_GUINT64_FORMAT " - %" G_GUINT64_FORMAT
            " Default: %" G_GUINT64_FORMAT " ",
            puint64->minimum, puint64->maximum, g_value_get_uint64 (&value));
        break;
      }
      case G_TYPE_INT64:
      {
        GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64 (param);

        n_print ("%-23.23s Integer64. ", "");
        g_print ("Range: %" G_GINT64_FORMAT " - %" G_GINT64_FORMAT
            " Default: %" G_GINT64_FORMAT " ",
            pint64->minimum, pint64->maximum, g_value_get_int64 (&value));
        break;
      }
      case G_TYPE_FLOAT:
      {
        GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT (param);

        n_print ("%-23.23s Float. ", "");
        g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
            pfloat->minimum, pfloat->maximum, g_value_get_float (&value));
        break;
      }
      case G_TYPE_DOUBLE:
      {
        GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (param);

        n_print ("%-23.23s Double. ", "");
        g_print ("Range: %15.7g - %15.7g Default: %15.7g ",
            pdouble->minimum, pdouble->maximum, g_value_get_double (&value));
        break;
      }
      case G_TYPE_CHAR:
      case G_TYPE_UCHAR:
        GST_ERROR ("%s: property '%s' of type char: consider changing to "
            "int/string", GST_OBJECT_NAME (element),
            g_param_spec_get_name (param));
        /* fall through */
      default:
        if (param->value_type == GST_TYPE_CAPS) {
          const GstCaps *caps = gst_value_get_caps (&value);

          if (!caps)
            n_print ("%-23.23s Caps (NULL)", "");
          else {
            print_caps (caps, "                           ");
          }
        } else if (G_IS_PARAM_SPEC_ENUM (param)) {
          GEnumValue *values;
          guint j = 0;
          gint enum_value;
          const gchar *value_nick = "";

          values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
          enum_value = g_value_get_enum (&value);

          while (values[j].value_name) {
            if (values[j].value == enum_value)
              value_nick = values[j].value_nick;
            j++;
          }

          n_print ("%-23.23s Enum \"%s\" Default: %d, \"%s\"", "",
              g_type_name (G_VALUE_TYPE (&value)), enum_value, value_nick);

          j = 0;
          while (values[j].value_name) {
            g_print ("\n");
            if (_name)
              g_print ("%s", _name);
            g_print ("%-23.23s    (%d): %-16s - %s", "",
                values[j].value, values[j].value_nick, values[j].value_name);
            j++;
          }
          /* g_type_class_unref (ec); */
        } else if (G_IS_PARAM_SPEC_FLAGS (param)) {
          GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (param);
          GFlagsValue *vals;
          gchar *cur;

          vals = pflags->flags_class->values;

          cur = flags_to_string (vals, g_value_get_flags (&value));

          n_print ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
              g_type_name (G_VALUE_TYPE (&value)),
              g_value_get_flags (&value), cur);

          while (vals[0].value_name) {
            g_print ("\n");
            if (_name)
              g_print ("%s", _name);
            g_print ("%-23.23s    (0x%08x): %-16s - %s", "",
                vals[0].value, vals[0].value_nick, vals[0].value_name);
            ++vals;
          }

          g_free (cur);
        } else if (G_IS_PARAM_SPEC_OBJECT (param)) {
          n_print ("%-23.23s Object of type \"%s\"", "",
              g_type_name (param->value_type));
        } else if (G_IS_PARAM_SPEC_BOXED (param)) {
          n_print ("%-23.23s Boxed pointer of type \"%s\"", "",
              g_type_name (param->value_type));
          if (param->value_type == GST_TYPE_STRUCTURE) {
            const GstStructure *s = gst_value_get_structure (&value);
            if (s)
              gst_structure_foreach (s, print_field,
                  (gpointer) "                           ");
          }
        } else if (G_IS_PARAM_SPEC_POINTER (param)) {
          if (param->value_type != G_TYPE_POINTER) {
            n_print ("%-23.23s Pointer of type \"%s\".", "",
                g_type_name (param->value_type));
          } else {
            n_print ("%-23.23s Pointer.", "");
          }
        } else if (param->value_type == G_TYPE_VALUE_ARRAY) {
          GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (param);

          if (pvarray->element_spec) {
            n_print ("%-23.23s Array of GValues of type \"%s\"", "",
                g_type_name (pvarray->element_spec->value_type));
          } else {
            n_print ("%-23.23s Array of GValues", "");
          }
        } else if (GST_IS_PARAM_SPEC_FRACTION (param)) {
          GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION (param);

          n_print ("%-23.23s Fraction. ", "");

          g_print ("Range: %d/%d - %d/%d Default: %d/%d ",
              pfraction->min_num, pfraction->min_den,
              pfraction->max_num, pfraction->max_den,
              gst_value_get_fraction_numerator (&value),
              gst_value_get_fraction_denominator (&value));
        } else {
          n_print ("%-23.23s Unknown type %ld \"%s\"", "",
              (glong) param->value_type, g_type_name (param->value_type));
        }
        break;
    }
    if (!readable)
      g_print (" Write only\n");
    else
      g_print ("\n");

    g_value_reset (&value);
  }
  if (num_properties == 0)
    n_print ("  none\n");

  g_free (property_specs);
}
Beispiel #25
0
VALUE
rbgobj_gvalue_to_rvalue(const GValue* value)
{
    GType type, fundamental_type;
    VALUE rvalue;

    if (!value)
        return Qnil;

    type = G_VALUE_TYPE(value);
    if (rbgobj_convert_gvalue2rvalue(type, value, &rvalue))
        return rvalue;

    fundamental_type = G_TYPE_FUNDAMENTAL(type);
    switch (fundamental_type) {
      case G_TYPE_NONE:
        return Qnil;
      case G_TYPE_CHAR:
        return CHR2FIX(g_value_get_char(value));
      case G_TYPE_UCHAR:
        return INT2FIX(g_value_get_uchar(value));
      case G_TYPE_BOOLEAN:
        return CBOOL2RVAL(g_value_get_boolean(value));
      case G_TYPE_INT:
        return INT2NUM(g_value_get_int(value));
      case G_TYPE_UINT:
        return UINT2NUM(g_value_get_uint(value));
      case G_TYPE_LONG:
        return LONG2NUM(g_value_get_long(value));
      case G_TYPE_ULONG:
        return ULONG2NUM(g_value_get_ulong(value));
      case G_TYPE_INT64:
        return rbglib_int64_to_num(g_value_get_int64(value));
      case G_TYPE_UINT64:
        return rbglib_uint64_to_num(g_value_get_uint64(value));
      case G_TYPE_FLOAT:
        return rb_float_new(g_value_get_float(value));
      case G_TYPE_DOUBLE:
        return rb_float_new(g_value_get_double(value));
      case G_TYPE_STRING:
        return CSTR2RVAL(g_value_get_string(value));
      case G_TYPE_ENUM:
        return rbgobj_make_enum(g_value_get_enum(value), type);
      case G_TYPE_FLAGS:
        return rbgobj_make_flags(g_value_get_flags(value), type);
      case G_TYPE_OBJECT:
      case G_TYPE_INTERFACE:
        {
            GObject* gobj = g_value_get_object(value);
            return gobj ? GOBJ2RVAL(gobj) : Qnil;
        }
      case G_TYPE_PARAM:
        {
            GParamSpec* pspec = g_value_get_param(value);
            return pspec ? rbgobj_ruby_object_from_instance(pspec) : Qnil;
        }
      case G_TYPE_POINTER:
        {
            gpointer ptr = g_value_get_pointer(value);
            if (!ptr)
                return Qnil;
            else
                return rbgobj_ptr_new(type, ptr);
        }

      case G_TYPE_BOXED:
        {
            GType gtype;
            for (gtype = type;
                 gtype != G_TYPE_INVALID;
                 gtype = g_type_parent(gtype))
            {
                GValueToRValueFunc func =
                    g_type_get_qdata(gtype, qGValueToRValueFunc);
                if (!func)
                    continue;
                return func(value);
            }
        }
      default:
        if (!rbgobj_convert_gvalue2rvalue(fundamental_type, value, &rvalue)) {
            GValueToRValueFunc func;
            func = g_type_get_qdata(type, qGValueToRValueFunc);
            if (!func) {
                g_warning("rbgobj_gvalue_to_rvalue: unsupported type: %s\n",
                          g_type_name(type));
            } else {
                rvalue = func(value);
            }
        }
        return rvalue;
    }
}
void
ags_play_dssi_audio_set_property(GObject *gobject,
				 guint prop_id,
				 const GValue *value,
				 GParamSpec *param_spec)
{
  AgsPlayDssiAudio *play_dssi_audio;

  pthread_mutex_t *recall_mutex;

  play_dssi_audio = AGS_PLAY_DSSI_AUDIO(gobject);

  /* get recall mutex */
  pthread_mutex_lock(ags_recall_get_class_mutex());
  
  recall_mutex = AGS_RECALL(gobject)->obj_mutex;
  
  pthread_mutex_unlock(ags_recall_get_class_mutex());

  switch(prop_id){
  case PROP_BANK:
    {
      pthread_mutex_lock(recall_mutex);

      play_dssi_audio->bank = g_value_get_uint(value);
      
      pthread_mutex_unlock(recall_mutex);	
    }
    break;
  case PROP_PROGRAM:
    {
      pthread_mutex_lock(recall_mutex);

      play_dssi_audio->program = g_value_get_uint(value);
      
      pthread_mutex_unlock(recall_mutex);	
    }
    break;
  case PROP_PLUGIN:
    {
      AgsDssiPlugin *dssi_plugin;
      
      dssi_plugin = g_value_get_object(value);

      pthread_mutex_lock(recall_mutex);

      if(play_dssi_audio->plugin == dssi_plugin){
	pthread_mutex_unlock(recall_mutex);
	
	return;
      }

      if(play_dssi_audio->plugin != NULL){
	g_object_unref(play_dssi_audio->plugin);
      }

      if(dssi_plugin != NULL){
	g_object_ref(dssi_plugin);
      }

      play_dssi_audio->plugin = dssi_plugin;

      pthread_mutex_unlock(recall_mutex);
    }
    break;
  case PROP_INPUT_LINES:
    {
      unsigned long effect_input_lines;
      
      effect_input_lines = g_value_get_ulong(value);

      pthread_mutex_lock(recall_mutex);

      if(effect_input_lines == play_dssi_audio->input_lines){
	pthread_mutex_unlock(recall_mutex);

	return;
      }

      play_dssi_audio->input_lines = effect_input_lines;

      pthread_mutex_unlock(recall_mutex);
    }
    break;
  case PROP_OUTPUT_LINES:
    {
      unsigned long effect_output_lines;
      
      effect_output_lines = g_value_get_ulong(value);

      pthread_mutex_lock(recall_mutex);

      if(effect_output_lines == play_dssi_audio->output_lines){
	pthread_mutex_unlock(recall_mutex);

	return;
      }

      play_dssi_audio->output_lines = effect_output_lines;

      pthread_mutex_unlock(recall_mutex);
    }
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec);
    break;
  };
}
Beispiel #27
0
void
_gtk_tree_data_list_value_to_node (GtkTreeDataList *list,
				   GValue          *value)
{
  switch (get_fundamental_type (G_VALUE_TYPE (value)))
    {
    case G_TYPE_BOOLEAN:
      list->data.v_int = g_value_get_boolean (value);
      break;
    case G_TYPE_CHAR:
      list->data.v_char = g_value_get_schar (value);
      break;
    case G_TYPE_UCHAR:
      list->data.v_uchar = g_value_get_uchar (value);
      break;
    case G_TYPE_INT:
      list->data.v_int = g_value_get_int (value);
      break;
    case G_TYPE_UINT:
      list->data.v_uint = g_value_get_uint (value);
      break;
    case G_TYPE_LONG:
      list->data.v_long = g_value_get_long (value);
      break;
    case G_TYPE_ULONG:
      list->data.v_ulong = g_value_get_ulong (value);
      break;
    case G_TYPE_INT64:
      list->data.v_int64 = g_value_get_int64 (value);
      break;
    case G_TYPE_UINT64:
      list->data.v_uint64 = g_value_get_uint64 (value);
      break;
    case G_TYPE_ENUM:
      list->data.v_int = g_value_get_enum (value);
      break;
    case G_TYPE_FLAGS:
      list->data.v_uint = g_value_get_flags (value);
      break;
    case G_TYPE_POINTER:
      list->data.v_pointer = g_value_get_pointer (value);
      break;
    case G_TYPE_FLOAT:
      list->data.v_float = g_value_get_float (value);
      break;
    case G_TYPE_DOUBLE:
      list->data.v_double = g_value_get_double (value);
      break;
    case G_TYPE_STRING:
      g_free (list->data.v_pointer);
      list->data.v_pointer = g_value_dup_string (value);
      break;
    case G_TYPE_OBJECT:
      if (list->data.v_pointer)
	g_object_unref (list->data.v_pointer);
      list->data.v_pointer = g_value_dup_object (value);
      break;
    case G_TYPE_BOXED:
      if (list->data.v_pointer)
	g_boxed_free (G_VALUE_TYPE (value), list->data.v_pointer);
      list->data.v_pointer = g_value_dup_boxed (value);
      break;
    case G_TYPE_VARIANT:
      if (list->data.v_pointer)
	g_variant_unref (list->data.v_pointer);
      list->data.v_pointer = g_value_dup_variant (value);
      break;
    default:
      g_warning ("%s: Unsupported type (%s) stored.", G_STRLOC, g_type_name (G_VALUE_TYPE (value)));
      break;
    }
}
Beispiel #28
0
/* Pass in the pspec so we can get the generic type. For example, a 
 * held in a GParamSpec allowing OBJECT, but the value could be of type
 * VipsImage. generics are much faster to compare.
 */
static unsigned int
vips_value_hash( GParamSpec *pspec, GValue *value )
{
	GType generic = G_PARAM_SPEC_TYPE( pspec );

	/* Not compile-time constants, so we have to use a set of if()s. Could
	 * make a table at run time I guess.
	 */

	if( generic == G_TYPE_PARAM_BOOLEAN )
		return( (unsigned int) g_value_get_boolean( value ) );
	else if( generic == G_TYPE_PARAM_CHAR )
		return( (unsigned int) VIPS_VALUE_GET_CHAR( value ) );
	else if( generic == G_TYPE_PARAM_UCHAR )
		return( (unsigned int) g_value_get_uchar( value ) );
	else if( generic == G_TYPE_PARAM_INT )
		return( (unsigned int) g_value_get_int( value ) );
	else if( generic == G_TYPE_PARAM_UINT )
		return( (unsigned int) g_value_get_uint( value ) );
	else if( generic == G_TYPE_PARAM_LONG )
		return( (unsigned int) g_value_get_long( value ) );
	else if( generic == G_TYPE_PARAM_ULONG )
		return( (unsigned int) g_value_get_ulong( value ) );
	else if( generic == G_TYPE_PARAM_ENUM )
		return( (unsigned int) g_value_get_enum( value ) );
	else if( generic == G_TYPE_PARAM_FLAGS )
		return( (unsigned int) g_value_get_flags( value ) );
	else if( generic == G_TYPE_PARAM_UINT64 ) {
		guint64 i = g_value_get_uint64( value );

		return( INT64_HASH( (gint64 *) &i ) );
	}
	else if( generic == G_TYPE_PARAM_INT64 ) {
		gint64 i = g_value_get_int64( value );

		return( INT64_HASH( &i ) );
	}
	else if( generic == G_TYPE_PARAM_FLOAT ) {
		float f = g_value_get_float( value );

		return( g_direct_hash( (void *) &f ) );
	}
	else if( generic == G_TYPE_PARAM_DOUBLE ) {
		double d = g_value_get_double( value );

		return( DOUBLE_HASH( &d ) );
	}
	else if( generic == G_TYPE_PARAM_STRING ) {
		const char *s = g_value_get_string( value );

		return( s ? g_str_hash( s ) : 0 );
	}
	else if( generic == G_TYPE_PARAM_BOXED ) {
		void *p = g_value_get_boxed( value );

		return( p ? g_direct_hash( p ) : 0 );
	}
	else if( generic == G_TYPE_PARAM_POINTER ) {
		void *p = g_value_get_pointer( value );

		return( p ? g_direct_hash( p ) : 0 );
	}
	else if( generic == G_TYPE_PARAM_OBJECT ) {
		void *p = g_value_get_object( value );

		return( p ? g_direct_hash( p ) : 0 );
	}
	else {
		/* Fallback: convert to a string and hash that. 
		 * This is very slow, print a warning if we use it 
		 * so we can add another case.
		 */
		char *s;
		unsigned int hash;

		s = g_strdup_value_contents( value ); 
		hash = g_str_hash( s );

		printf( "vips_value_hash: no case for %s\n", s );
		printf( "\ttype %d, %s\n", 
			(int) G_VALUE_TYPE( value ),
			g_type_name( G_VALUE_TYPE( value ) ) );
		printf( "\tgeneric %d, %s\n", 
			(int) G_VALUE_TYPE( generic ),
			g_type_name( generic ) );

		g_free( s );

		return( hash );
	}
}
Beispiel #29
0
static HaskellObj
#ifdef GHC_RTS_USES_CAPABILITY
gtk2hs_value_as_haskellobj(Capability *cap, const GValue *value) {
#else
gtk2hs_value_as_haskellobj(const GValue *value) {
#endif
    switch (G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value))) {
    case G_TYPE_INTERFACE:
        if (g_type_is_a(G_VALUE_TYPE(value), G_TYPE_OBJECT))
            return rts_mkPtr(CAP g_value_get_object(value));
        else
            break;
    case G_TYPE_CHAR:
        return rts_mkChar(CAP g_value_get_schar(value));
    case G_TYPE_UCHAR:
        return rts_mkChar(CAP g_value_get_uchar(value));
    case G_TYPE_BOOLEAN:
        return rts_mkBool(CAP g_value_get_boolean(value));
    case G_TYPE_INT:
        return rts_mkInt(CAP g_value_get_int(value));
    case G_TYPE_UINT:
        return rts_mkWord(CAP g_value_get_uint(value));
    case G_TYPE_LONG:
        return rts_mkInt(CAP g_value_get_long(value));
    case G_TYPE_ULONG:
        return rts_mkWord(CAP g_value_get_ulong(value));
    /*    case G_TYPE_INT64:
            return rts_mkInt64(CAP g_value_get_int64(value));
        case G_TYPE_UINT64:
            return rts_mkWord64(CAP g_value_get_uint64(value));   */
    case G_TYPE_ENUM:
        return rts_mkInt(CAP g_value_get_enum(value));
    case G_TYPE_FLAGS:
        return rts_mkWord(CAP g_value_get_enum(value));
    case G_TYPE_FLOAT:
        return rts_mkFloat(CAP g_value_get_float(value));
    case G_TYPE_DOUBLE:
        return rts_mkDouble(CAP g_value_get_double(value));
    case G_TYPE_STRING:
        return rts_mkPtr(CAP (char *)g_value_get_string(value)); /* CHECKME: is the string freed? */
    case G_TYPE_POINTER:
        return rts_mkPtr(CAP g_value_get_pointer(value));
    case G_TYPE_BOXED:
        return rts_mkPtr(CAP g_value_get_boxed(value));
    case G_TYPE_PARAM:
        return rts_mkPtr(CAP g_value_get_param(value));
    case G_TYPE_OBJECT:
        return rts_mkPtr(CAP g_value_get_object(value));
    }
    g_error("gtk2hs_value_as_haskellobj: unable to handle GValue with type %s\n"
            "please report this as a bug to [email protected]",
            g_type_name(G_VALUE_TYPE(value)));
}

void
gtk2hs_value_from_haskellobj(GValue *value, HaskellObj obj) {

    switch (G_TYPE_FUNDAMENTAL(G_VALUE_TYPE(value))) {
    case G_TYPE_INVALID:
    case G_TYPE_NONE:
        return;
    case G_TYPE_INTERFACE:
        /* we only handle interface types that have a GObject prereq */
        if (g_type_is_a(G_VALUE_TYPE(value), G_TYPE_OBJECT)) {
            g_value_set_object(value, rts_getPtr(obj));
        } else {
            break;
        }
        return;
    case G_TYPE_CHAR:
        g_value_set_schar(value, rts_getChar(obj));
        return;
    case G_TYPE_UCHAR:
        g_value_set_schar(value, rts_getChar(obj));
        return;
    case G_TYPE_BOOLEAN:
        g_value_set_boolean(value, rts_getBool(obj));
        return;
    case G_TYPE_INT:
        g_value_set_int(value, rts_getInt(obj));
        return;
    case G_TYPE_UINT:
        g_value_set_uint(value, rts_getWord(obj));
        return;
    case G_TYPE_LONG:
        g_value_set_long(value, rts_getInt(obj));
        return;
    case G_TYPE_ULONG:
        g_value_set_ulong(value, rts_getWord(obj));
        return;
    /*    case G_TYPE_INT64:
            g_value_set_int64(value, rts_getInt64(obj));
            return;
        case G_TYPE_UINT64:
            g_value_set_uint64(value, rts_getWord64(obj));
            return;                                         */
    case G_TYPE_ENUM:
        g_value_set_enum(value, rts_getInt(obj));
        return;
    case G_TYPE_FLAGS:
        g_value_set_flags(value, rts_getInt(obj));
        return;
    case G_TYPE_FLOAT:
        g_value_set_float(value, rts_getFloat(obj));
        return;
    case G_TYPE_DOUBLE:
        g_value_set_double(value, rts_getDouble(obj));
        return;
    case G_TYPE_STRING:
        g_value_set_string(value, rts_getPtr(obj));
        return;
    case G_TYPE_POINTER:
        g_value_set_pointer(value, rts_getPtr(obj));
        return;
    /*    case G_TYPE_BOXED: {
            g_value_set_boxed(value, obj);
            break;
        }
        case G_TYPE_PARAM:
            g_value_set_param(value, (obj));
            break;                                          */
    case G_TYPE_OBJECT:
        g_value_set_object(value, rts_getPtr(obj));
        return;
    }
    g_error("gtk2hs_value_from_haskellobj: unable to handle GValue with type %s\n"
            "please report this as a bug to [email protected]",
            g_type_name(G_VALUE_TYPE(value)));
}
Beispiel #30
0
/* Pass in the pspec so we can get the generic type. For example, a 
 * value could be held in a GParamSpec allowing OBJECT, but the value 
 * could be of type VipsImage. generics are much faster to compare.
 */
static gboolean 
vips_value_equal( GParamSpec *pspec, GValue *v1, GValue *v2 )
{
	GType generic = G_PARAM_SPEC_TYPE( pspec );
	GType t1 = G_VALUE_TYPE( v1 );
	GType t2 = G_VALUE_TYPE( v2 );

	if( t1 != t2 )
		return( FALSE );

	/* Not compile-time constants, so we have to use a set of if()s. Could
	 * make a table at run time I guess.
	 */

	if( generic == G_TYPE_PARAM_BOOLEAN ) 
		return( g_value_get_boolean( v1 ) == 
			g_value_get_boolean( v2 ) );
	else if( generic == G_TYPE_PARAM_CHAR ) 
		return( VIPS_VALUE_GET_CHAR( v1 ) ==
			VIPS_VALUE_GET_CHAR( v2 ) );
	if( generic == G_TYPE_PARAM_UCHAR ) 
		return( g_value_get_uchar( v1 ) ==
			g_value_get_uchar( v2 ) );
	if( generic == G_TYPE_PARAM_INT ) 
		return( g_value_get_int( v1 ) ==
			g_value_get_int( v2 ) );
	if( generic == G_TYPE_PARAM_UINT ) 
		return( g_value_get_uint( v1 ) ==
			g_value_get_uint( v2 ) );
	if( generic == G_TYPE_PARAM_LONG ) 
		return( g_value_get_long( v1 ) ==
			g_value_get_long( v2 ) );
	if( generic == G_TYPE_PARAM_ULONG ) 
		return( g_value_get_ulong( v1 ) ==
			g_value_get_ulong( v2 ) );
	if( generic == G_TYPE_PARAM_ENUM ) 
		return( g_value_get_enum( v1 ) ==
			g_value_get_enum( v2 ) );
	if( generic == G_TYPE_PARAM_FLAGS ) 
		return( g_value_get_flags( v1 ) ==
			g_value_get_flags( v2 ) );
	if( generic == G_TYPE_PARAM_UINT64 ) 
		return( g_value_get_uint64( v1 ) ==
			g_value_get_uint64( v2 ) );
	if( generic == G_TYPE_PARAM_INT64 ) 
		return( g_value_get_int64( v1 ) ==
			g_value_get_int64( v2 ) );
	if( generic == G_TYPE_PARAM_FLOAT ) 
		return( g_value_get_float( v1 ) ==
			g_value_get_float( v2 ) );
	if( generic == G_TYPE_PARAM_DOUBLE ) 
		return( g_value_get_double( v1 ) ==
			g_value_get_double( v2 ) );
	if( generic == G_TYPE_PARAM_STRING ) {
		const char *s1 = g_value_get_string( v1 );
		const char *s2 = g_value_get_string( v2 );

		if( s1 == s2 )
			return( TRUE );
		else
			return( s1 && s2 && strcmp( s1, s2 ) == 0 );
	}
	if( generic == G_TYPE_PARAM_BOXED ) 
		return( g_value_get_boxed( v1 ) ==
			g_value_get_boxed( v2 ) );
	if( generic == G_TYPE_PARAM_POINTER ) 
		return( g_value_get_pointer( v1 ) ==
			g_value_get_pointer( v2 ) );
	if( generic == G_TYPE_PARAM_OBJECT ) 
		return( g_value_get_object( v1 ) ==
			g_value_get_object( v2 ) );
	else {
		/* Fallback: convert to a string and compare that. 
		 * This is very slow, print a warning if we use it 
		 * so we can add another case.
		 */
		char *s1;
		char *s2;
		gboolean equal;

		s1 = g_strdup_value_contents( v1 ); 
		s2 = g_strdup_value_contents( v2 ); 
		equal = strcmp( s1, s2 ) == 0;

		printf( "vips_value_equal: no case for %s, %s\n", 
			s1, s2 );
		printf( "\tt1 %d, %s\n", (int) t1, g_type_name( t1 ) );
		printf( "\tt2 %d, %s\n", (int) t2, g_type_name( t2 ) );
		printf( "\tgeneric %d, %s\n", 
			(int) G_VALUE_TYPE( generic ),
			g_type_name( generic ) );

		g_free( s1 );
		g_free( s2 );

		return( equal );
	}
}