예제 #1
0
파일: modif.c 프로젝트: zizoumgs/Aman
//! edit
gboolean modifEdi(GtkWidget* parent , gpointer data){
	gboolean status = FALSE;
	gint id = GPOINTER_TO_INT(data);
	gint result = GTK_RESPONSE_OK;
	if(data == NULL){
		GtkWidget *comboId = gtk_combo_box_new ();
		GtkWidget *dialog = modifGetPilihanId(comboId);
		gtk_widget_show_all(dialog);
		result 	= 	gtk_dialog_run (dialog);	// block
		id 		=	globalConStrToInt(gtk_combo_box_get_active_text(comboId));
		gtk_widget_destroy(dialog);
	}	
	if(result==GTK_RESPONSE_OK){
		modifStruct_ *modif = struct_new(modifStruct_);
		gchar *title = g_strdup_printf ("Edit Data dengan id %d", id);
		GtkWidget *dialog = modifGetDialogWithStruct(parent , modif , title);
		//! mengambil data dari database
		GValueArray* varr = 	g_value_array_new (-1);		
		GValue a = {0};
		g_assert (!G_VALUE_HOLDS_STRING (&a));			
		g_value_init (&a, G_TYPE_INT);
		g_value_set_int (&a, id );
		varr =	g_value_array_append(varr,&a);
		gchar *sql = g_strdup_printf ("%s and isi.id=?", globalGetDefCom() );
		GValueArray *hasil = databaseGetDatasFromDb( sql	 , varr , &status);		
		modifSetItemToWidget(modif,hasil);
		//! show 
		gtk_widget_show_all(dialog);
		result = gtk_dialog_run (dialog);	// block
		if (result==GTK_RESPONSE_OK){
			//! sekarang kita akan masuk pada database
			//! mengambil data
			char *filename;
			char* jamchar = globalPutZeroToWkt(gtk_spin_button_get_value_as_int(modif->jam));
			char* mntchar = globalPutZeroToWkt(gtk_spin_button_get_value_as_int(modif->mnt));		
			gchar *jamMnt	= g_strdup_printf ("%s:%s", jamchar,mntchar);
			gchar * hari 	= gtk_combo_box_get_active_text ( modif->hari);
			gchar * bagian 	= gtk_combo_box_get_active_text ( modif->bagian );
			gint	total   = gtk_spin_button_get_value_as_int (modif->total);
			filename = fuGetNameFile( gtk_button_get_label(modif->filePilih));
			//! update database
			gint idHari = databaseGetIdHari(hari);
			GValueArray* varr = 	g_value_array_new (-1);		
			GValue a = {0};
			g_assert (!G_VALUE_HOLDS_STRING (&a));			
			g_value_init (&a, G_TYPE_INT);
			g_value_set_int (&a, idHari);			//! 1
			varr =	g_value_array_append(varr,&a);
			g_value_set_int (&a, total);			//! 2
			varr =	g_value_array_append(varr,&a);
			g_value_unset (&a);
			g_value_init (&a, G_TYPE_STRING);
			g_value_set_string (&a, jamMnt);		//! 3
			varr =	g_value_array_append(varr,&a);								
			g_value_set_string (&a, bagian);		//! 4
			varr =	g_value_array_append(varr,&a);								
			g_value_set_string (&a, filename);		//! 5
			varr =	g_value_array_append(varr,&a);
			g_value_unset (&a);
			g_value_init (&a, G_TYPE_INT);
			g_value_set_int (&a, id);			//! 6
			varr =	g_value_array_append(varr,&a);
			GValueArray *hasil = databaseGetDatasFromDb("update isi set dal=? , X=?,jam=?,bagian=?,alarm=? where id = ?" , varr,&status);
			//! free
			g_value_array_free (varr);
			g_value_array_free (hasil);
			//! aslinya harus di cek kembali
			status = TRUE;
		}
		else{
		}
		//! free all
		g_value_array_free (varr);
		g_value_array_free (hasil);
		gtk_widget_destroy(dialog);				
	}
	return TRUE;
}
예제 #2
0
static gpointer
build_ip6_address_or_route (const char *key_name, const char *address_str, guint32 plen, const char *gateway_str, const char *metric_str, gboolean route)
{
	GValueArray *result;
	struct in6_addr addr;
	GByteArray *address;
	GByteArray *gateway;
	guint32 metric = 0;
	GValue value = G_VALUE_INIT;
	int err;

	g_return_val_if_fail (address_str, NULL);

	result = g_value_array_new (3);

	/* add address */
	err = inet_pton (AF_INET6, address_str, &addr);
	if (err <= 0) {
		g_warning ("%s: ignoring invalid IPv6 address '%s'", __func__, address_str);
		goto error_out;
	}
	address = g_byte_array_new ();
	g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
	g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
	g_value_take_boxed (&value, address);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add prefix length */
	g_value_init (&value, G_TYPE_UINT);
	g_value_set_uint (&value, plen);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add gateway */
	if (gateway_str && gateway_str[0]) {
		err = inet_pton (AF_INET6, gateway_str, &addr);
		if (err <= 0) {
			/* Try workaround for routes written by broken keyfile writer.
			 * Due to bug bgo#719851, an older version of writer would have
			 * written "a:b:c:d::/plen,metric" if the gateway was ::, instead
			 * of "a:b:c:d::/plen,,metric" or "a:b:c:d::/plen,::,metric"
			 * Try workaround by interepeting gateway_str as metric to accept such
			 * invalid routes. This broken syntax should not be not officially
			 * supported.
			 **/
			if (route && !metric_str && get_one_int (gateway_str, G_MAXUINT32, NULL, &metric))
				addr = in6addr_any;
			else {
				g_warning ("%s: ignoring invalid IPv6 gateway '%s'", __func__, gateway_str);
				goto error_out;
			}
		}
	} else
		addr = in6addr_any;

	/* parse metric, default to 0 */
	if (metric_str) {
		if (!get_one_int (metric_str, G_MAXUINT32, key_name, &metric))
			goto error_out;
	}

	gateway = g_byte_array_new ();
	g_byte_array_append (gateway, (guint8 *) addr.s6_addr, 16);
	g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
	g_value_take_boxed (&value, gateway);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add metric (for routing) */
	if (route) {
		g_value_init (&value, G_TYPE_UINT);
		g_value_set_uint (&value, metric);
		g_value_array_append (result, &value);
		g_value_unset (&value);
	}

	return result;

error_out:
	g_value_array_free (result);
	return NULL;
}
예제 #3
0
static void
change_background(PanelApplet * widget,
                  PanelAppletBackgroundType type,
                  GdkColor * color,
                  GdkPixmap * pixmap,
                  void *data)
{
  static GdkPixmap *keep = NULL;
  long xid = 0;
  GValueArray *val = g_value_array_new(4);

  if (type == PANEL_NO_BACKGROUND)
    {
      GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(widget));

      if (style->bg_pixmap[GTK_STATE_NORMAL])
        {
          pixmap = style->bg_pixmap[GTK_STATE_NORMAL];
          type = PANEL_PIXMAP_BACKGROUND;
        }
      else
        {
          color = &style->bg[GTK_STATE_NORMAL];
          if (color != NULL)
            {
              type = PANEL_COLOR_BACKGROUND;
            }
        }
    }
  
  if (type == PANEL_COLOR_BACKGROUND && color != NULL)
    {
      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 0), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 0), color->pixel);
 
      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 1), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 1), color->red);
      
      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 2), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 2), color->green);

      g_value_array_append(val, NULL);
      g_value_init(g_value_array_get_nth(val, 3), G_TYPE_UINT);
      g_value_set_uint(g_value_array_get_nth(val, 3), color->blue);
    }
  else
    {
      int i;
      for (i = 0; i < 4; i++)
        {
          g_value_array_prepend(val, NULL);
          g_value_init(g_value_array_get_nth(val, 0), G_TYPE_UINT);
          g_value_set_uint(g_value_array_get_nth(val, 0), 0);
        }
    }
  
  if (type == PANEL_PIXMAP_BACKGROUND)
    {
      if (keep != NULL)
        {
          gdk_pixmap_unref(keep);
          keep = pixmap;
        }
      if (pixmap != NULL)
        {
          gdk_pixmap_ref(pixmap);
        }

      xid = GDK_PIXMAP_XID(pixmap);
    }

  if (g_applet->support != NULL && workrave_is_running())
    {
      dbus_g_proxy_begin_call(g_applet->support, "SetBackground", dbus_callback, NULL, NULL,
                              G_TYPE_UINT, type,
                              G_TYPE_VALUE_ARRAY, val,
                              G_TYPE_UINT, xid,
                              G_TYPE_INVALID);
      

    }

  g_value_array_free(val);
}
예제 #4
0
static void
gst_raw_video_parse_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
{
  GstRawVideoParse *raw_video_parse = GST_RAW_VIDEO_PARSE (object);
  GstRawVideoParseConfig *props_cfg = &(raw_video_parse->properties_config);

  switch (prop_id) {
    case PROP_WIDTH:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_int (value, props_cfg->width);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_HEIGHT:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_int (value, props_cfg->height);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_FORMAT:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_enum (value, props_cfg->format);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_PIXEL_ASPECT_RATIO:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      gst_value_set_fraction (value, props_cfg->pixel_aspect_ratio_n,
          props_cfg->pixel_aspect_ratio_d);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);

      break;

    case PROP_FRAMERATE:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      gst_value_set_fraction (value, props_cfg->framerate_n,
          props_cfg->framerate_d);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_INTERLACED:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_boolean (value, props_cfg->interlaced);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_TOP_FIELD_FIRST:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_boolean (value, props_cfg->top_field_first);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_PLANE_STRIDES:
    {
      guint i, n_planes;
      GValue val = G_VALUE_INIT;
      GValueArray *valarray;

      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);

      n_planes = GST_VIDEO_INFO_N_PLANES (&(props_cfg->info));
      valarray = g_value_array_new (n_planes);
      g_value_init (&val, G_TYPE_UINT);

      for (i = 0; i < n_planes; ++i) {
        g_value_set_uint (&val, props_cfg->plane_strides[i]);
        g_value_array_insert (valarray, i, &val);
      }

      g_value_unset (&val);

      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);

      /* Pass on ownership to the value array,
       * since we don't need it anymore */
      g_value_take_boxed (value, valarray);
      break;
    }

    case PROP_PLANE_OFFSETS:
    {
      guint i, n_planes;
      GValue val = G_VALUE_INIT;
      GValueArray *valarray;

      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);

      n_planes = GST_VIDEO_INFO_N_PLANES (&(props_cfg->info));
      valarray = g_value_array_new (n_planes);
      g_value_init (&val, G_TYPE_UINT);

      for (i = 0; i < n_planes; ++i) {
        g_value_set_uint (&val, props_cfg->plane_offsets[i]);
        g_value_array_insert (valarray, i, &val);
      }

      g_value_unset (&val);

      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);

      /* Pass on ownership to the value array,
       * since we don't need it anymore */
      g_value_take_boxed (value, valarray);
      break;
    }

    case PROP_FRAME_STRIDE:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_uint (value, raw_video_parse->properties_config.frame_stride);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
예제 #5
0
GParameter *
jingle_get_params(JabberStream *js, const gchar *relay_ip, guint relay_udp,
	guint relay_tcp, guint relay_ssltcp, const gchar *relay_username,
    const gchar *relay_password, guint *num)
{
	/* don't set a STUN server if one is set globally in prefs, in that case
	 this will be handled in media.c */
	gboolean has_account_stun = js->stun_ip && !purple_network_get_stun_ip();
	guint num_params = has_account_stun ?
		(relay_ip ? 3 : 2) : (relay_ip ? 1 : 0);
	GParameter *params = NULL;
	int next_index = 0;
	
	if (num_params > 0) {
		params = g_new0(GParameter, num_params);

		if (has_account_stun) {
			purple_debug_info("jabber", 
				"setting param stun-ip for stream using Google auto-config: %s\n",
				js->stun_ip);
			params[next_index].name = "stun-ip";
			g_value_init(&params[next_index].value, G_TYPE_STRING);
			g_value_set_string(&params[next_index].value, js->stun_ip);
			purple_debug_info("jabber", 
				"setting param stun-port for stream using Google auto-config: %d\n",
				js->stun_port);
			next_index++;
			params[next_index].name = "stun-port";
			g_value_init(&params[next_index].value, G_TYPE_UINT);
			g_value_set_uint(&params[next_index].value, js->stun_port);
			next_index++;
		}
	
		if (relay_ip) {
			GValueArray *relay_info = g_value_array_new(0);

			if (relay_udp) {
				relay_info = 
					jingle_create_relay_info(relay_ip, relay_udp, relay_username,
						relay_password, "udp", relay_info);
			}
			if (relay_tcp) {
				relay_info = 
					jingle_create_relay_info(relay_ip, relay_tcp, relay_username,
						relay_password, "tcp", relay_info);
			}
			if (relay_ssltcp) {
				relay_info = 
					jingle_create_relay_info(relay_ip, relay_ssltcp, relay_username,
						relay_password, "tls", relay_info);
			}
			params[next_index].name = "relay-info";
			g_value_init(&params[next_index].value, G_TYPE_VALUE_ARRAY);
			g_value_set_boxed(&params[next_index].value, relay_info);
			g_value_array_free(relay_info);
		}
	}

	*num = num_params;
	return params;
}
예제 #6
0
static gpointer
build_ip6_address_or_route (const char *address_str, guint32 plen, const char *gateway_str, guint32 metric, gboolean route)
{
	GValueArray *result;
	struct in6_addr addr;
	GByteArray *address;
	GByteArray *gateway;
	GValue value = { 0, };
	int err;

	g_return_val_if_fail (address_str, NULL);

	result = g_value_array_new (3);

	/* add address */
	err = inet_pton (AF_INET6, address_str, &addr);
	if (err <= 0) {
		g_warning ("%s: ignoring invalid IPv6 address '%s'", __func__, address_str);
		g_value_array_free (result);
		return NULL;
	}
	address = g_byte_array_new ();
	g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
	g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
	g_value_take_boxed (&value, address);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add prefix length */
	g_value_init (&value, G_TYPE_UINT);
	g_value_set_uint (&value, plen);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add gateway */
	if (gateway_str) {
		err = inet_pton (AF_INET6, gateway_str, &addr);
		if (err <= 0) {
			g_warning ("%s: ignoring invalid IPv6 gateway '%s'", __func__, gateway_str);
			g_value_array_free (result);
			return NULL;
		}
	} else
		memset (&addr, 0, 16);
	gateway = g_byte_array_new ();
	g_byte_array_append (gateway, (guint8 *) addr.s6_addr, 16);
	g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
	g_value_take_boxed (&value, gateway);
	g_value_array_append (result, &value);
	g_value_unset (&value);

	/* add metric (for routing) */
	if (route) {
		g_value_init (&value, G_TYPE_UINT);
		g_value_set_uint (&value, metric);
		g_value_array_append (result, &value);
		g_value_unset (&value);
	}

	return result;
}
예제 #7
0
static void
get_property (GObject *object,
              guint property_id,
              GValue *value,
              GParamSpec *pspec)
{
  ExampleCallableMediaStream *self = EXAMPLE_CALLABLE_MEDIA_STREAM (object);

  switch (property_id)
    {
    case PROP_ID:
      g_value_set_uint (value, self->priv->id);
      break;

    case PROP_HANDLE:
      g_value_set_uint (value, self->priv->handle);
      break;

    case PROP_TYPE:
      g_value_set_uint (value, self->priv->type);
      break;

    case PROP_STATE:
      g_value_set_uint (value, self->priv->state);
      break;

    case PROP_PENDING_SEND:
      g_value_set_uint (value, self->priv->pending_send);
      break;

    case PROP_DIRECTION:
      g_value_set_uint (value, self->priv->direction);
      break;

    case PROP_CHANNEL:
      g_value_set_object (value, self->priv->channel);
      break;

    case PROP_STREAM_INFO:
        {
          GValueArray *va = g_value_array_new (6);
          guint i;

          for (i = 0; i < 6; i++)
            {
              g_value_array_append (va, NULL);
              g_value_init (va->values + i, G_TYPE_UINT);
            }

          g_value_set_uint (va->values + 0, self->priv->id);
          g_value_set_uint (va->values + 1, self->priv->handle);
          g_value_set_uint (va->values + 2, self->priv->type);
          g_value_set_uint (va->values + 3, self->priv->state);
          g_value_set_uint (va->values + 4, self->priv->direction);
          g_value_set_uint (va->values + 5, self->priv->pending_send);

          g_value_take_boxed (value, va);
        }
      break;

    case PROP_SIMULATION_DELAY:
      g_value_set_uint (value, self->priv->simulation_delay);
      break;

    case PROP_LOCALLY_REQUESTED:
      g_value_set_boolean (value, self->priv->locally_requested);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}
예제 #8
0
GPtrArray*
imgur_list_records (void)
{
	GPtrArray *result;
	GKeyFile *keyfile;
	gchar **entries, **cursor;
	gchar *path;
	GList *candidates = NULL, *candidate_cursor;
	long count = 0;

	path = get_path ();
	keyfile = get_keyfile (path);

	if (!keyfile)
	{
		g_free (path);
		return g_ptr_array_new ();
	}

	entries = g_key_file_get_groups (keyfile, NULL);

	for (cursor=entries; *cursor; cursor++)
	{
		gchar *thumbnail,
			*thumbnail_extension,
			*time,
			*our_file_uri,
			*our_thumbnail;
		long timestamp;
		ListEntry *entry;
		GValue *value;

		thumbnail = g_key_file_get_string (keyfile,
			*cursor,
			"small_thumbnail",
			NULL);

		if (!thumbnail)
		{
			g_warning ("Group %s has no thumbnail",
				*cursor);
			continue;
		}

		thumbnail_extension = strrchr (thumbnail, '.');

		if (!thumbnail_extension)
		{
			g_warning ("Group %s has an invalid thumbnail",
				*cursor);
			continue;
		}

		time = g_key_file_get_string (keyfile,
			*cursor,
			"time",
			NULL);

		if (time)
		{
			timestamp = atol (time);
		}
		else
		{
			/* well, it won't kill us */
			timestamp = 0;
		}

		our_thumbnail = g_strdup_printf (
			"%s/%s%s",
			path,
			*cursor,
			thumbnail_extension);

		if (!g_file_test (our_thumbnail,
			G_FILE_TEST_IS_REGULAR))
		{
			g_free (time);
			g_free (thumbnail);
			g_free (our_thumbnail);
			continue;
		}

		our_file_uri = g_filename_to_uri (our_thumbnail,
				NULL,
				/* FIXME: Should we really be ignoring errors? */
				NULL);

		entry = g_malloc (sizeof (ListEntry));
		entry->time = timestamp;
		entry->details = g_value_array_new (2);

		/* FIXME Check this carefully for memory leaks */
		value = g_malloc0 (sizeof (GValue));
		g_value_init (value, G_TYPE_STRING);
		g_value_set_string (value, *cursor);
		g_value_array_append (entry->details, value);

		value = g_malloc0 (sizeof (GValue));
		g_value_init (value, G_TYPE_STRING);
		g_value_set_string (value, our_file_uri);
		g_value_array_append (entry->details, value);

		count++;
		candidates = g_list_prepend (candidates,
			entry);

		g_free (time);
		g_free (thumbnail);
		g_free (our_file_uri);
	}

	g_strfreev (entries);
	g_free (path);

	candidates = g_list_sort (candidates,
		compare_entries);

	result = g_ptr_array_sized_new (count);

	/* Now go through and pick out the details */

	for (candidate_cursor = candidates;
		candidate_cursor;
		candidate_cursor = candidate_cursor->next)
	{
		ListEntry *entry = (ListEntry*) candidate_cursor->data;

		g_ptr_array_add (result, entry->details);
		g_free (entry);
	}

	g_list_free (candidates);

	return result;
}
static GPtrArray *
read_ip6_addresses (GKeyFile *file,
                    const char *setting_name,
                    const char *key)
{
	GPtrArray *addresses;
	struct in6_addr addr, gw;
	guint32 prefix;
	int i = 0;

	addresses = g_ptr_array_sized_new (3);

	/* Look for individual addresses */
	while (i++ < 1000) {
		char *tmp, *key_name, *str_prefix, *str_gw;
		int ret;
		GValueArray *values;
		GByteArray *address;
		GByteArray *gateway;
		GValue value = { 0 };

		key_name = g_strdup_printf ("%s%d", key, i);
		tmp = g_key_file_get_string (file, setting_name, key_name, NULL);
		g_free (key_name);

		if (!tmp)
			break; /* all done */

		/* convert the string array into IPv6 addresses */
		values = g_value_array_new (2); /* NMIP6Address has 2 items */

		/* Split the address and prefix */
		str_prefix = split_prefix (tmp);

		/* address */
		ret = inet_pton (AF_INET6, tmp, &addr);
		if (ret <= 0) {
			g_warning ("%s: ignoring invalid IPv6 %s element '%s'", __func__, key_name, tmp);
			g_value_array_free (values);
			goto next;
		}

		address = g_byte_array_new ();
		g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
		g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
		g_value_take_boxed (&value, address);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		/* prefix */
		prefix = 0;
		if (str_prefix) {
			if (!get_one_int (str_prefix, 128, key_name, &prefix)) {
				g_value_array_free (values);
				goto next;
			}
		} else {
			/* Missing prefix defaults to /64 */
			prefix = 64;
		}

		g_value_init (&value, G_TYPE_UINT);
		g_value_set_uint (&value, prefix);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		/* Gateway (optional) */
		str_gw = split_gw (str_prefix);
		if (str_gw) {
			ret = inet_pton (AF_INET6, str_gw, &gw);
			if (ret <= 0) {
				g_warning ("%s: ignoring invalid IPv6 %s gateway '%s'", __func__, key_name, tmp);
				g_value_array_free (values);
				goto next;
			}

			if (!IN6_IS_ADDR_UNSPECIFIED (&gw)) {
				gateway = g_byte_array_new ();
				g_byte_array_append (gateway, (guint8 *) gw.s6_addr, 16);
				g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
				g_value_take_boxed (&value, gateway);
				g_value_array_append (values, &value);
				g_value_unset (&value);
			}
		}

		g_ptr_array_add (addresses, values);

next:
		g_free (tmp);
	}

	if (addresses->len < 1) {
		g_ptr_array_free (addresses, TRUE);
		addresses = NULL;
	}

	return addresses;
}
static GPtrArray *
read_ip6_routes (GKeyFile *file,
                 const char *setting_name,
                 const char *key)
{
	GPtrArray *routes;
	struct in6_addr addr;
	guint32 prefix, metric;
	int i = 0;

	routes = g_ptr_array_sized_new (3);

	/* Look for individual routes */
	while (i++ < 1000) {
		gchar **tmp;
		char *key_name, *str_prefix;
		gsize length = 0;
		int ret;
		GValueArray *values;
		GByteArray *address;
		GValue value = { 0 };

		key_name = g_strdup_printf ("%s%d", key, i);
		tmp = g_key_file_get_string_list (file, setting_name, key_name, &length, NULL);
		g_free (key_name);

		if (!tmp || !length)
			break; /* all done */

		if (length != 3) {
			g_warning ("%s: ignoring invalid IPv6 address item '%s'", __func__, key_name);
			goto next;
		}

		/* convert the string array into IPv6 routes */
		values = g_value_array_new (4); /* NMIP6Route has 4 items */

		/* Split the route and prefix */
		str_prefix = split_prefix (tmp[0]);

		/* destination address */
		ret = inet_pton (AF_INET6, tmp[0], &addr);
		if (ret <= 0) {
			g_warning ("%s: ignoring invalid IPv6 %s element '%s'", __func__, key_name, tmp[0]);
			g_value_array_free (values);
			goto next;
		}
		address = g_byte_array_new ();
		g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
		g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
		g_value_take_boxed (&value, address);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		/* prefix */
		prefix = 0;
		if (str_prefix) {
			if (!get_one_int (str_prefix, 128, key_name, &prefix)) {
				g_value_array_free (values);
				goto next;
			}
		} else {
			/* default to 64 if unspecified */
			prefix = 64;
		}
		g_value_init (&value, G_TYPE_UINT);
		g_value_set_uint (&value, prefix);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		/* next hop address */
		ret = inet_pton (AF_INET6, tmp[1], &addr);
		if (ret <= 0) {
			g_warning ("%s: ignoring invalid IPv6 %s element '%s'", __func__, key_name, tmp[1]);
			g_value_array_free (values);
			goto next;
		}
		address = g_byte_array_new ();
		g_byte_array_append (address, (guint8 *) addr.s6_addr, 16);
		g_value_init (&value, DBUS_TYPE_G_UCHAR_ARRAY);
		g_value_take_boxed (&value, address);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		/* metric */
		metric = 0;
		if (!get_one_int (tmp[2], G_MAXUINT32, key_name, &metric)) {
			g_value_array_free (values);
			goto next;
		}
		g_value_init (&value, G_TYPE_UINT);
		g_value_set_uint (&value, metric);
		g_value_array_append (values, &value);
		g_value_unset (&value);

		g_ptr_array_add (routes, values);

next:
		g_strfreev (tmp);
	}

	if (routes->len < 1) {
		g_ptr_array_free (routes, TRUE);
		routes = NULL;
	}

	return routes;
}
예제 #11
0
static void
gst_raw_audio_parse_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
{
  GstRawAudioParse *raw_audio_parse = GST_RAW_AUDIO_PARSE (object);

  switch (prop_id) {
    case PROP_FORMAT:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_enum (value, raw_audio_parse->properties_config.format);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_PCM_FORMAT:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_enum (value, raw_audio_parse->properties_config.pcm_format);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_SAMPLE_RATE:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_int (value, raw_audio_parse->properties_config.sample_rate);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_NUM_CHANNELS:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_int (value, raw_audio_parse->properties_config.num_channels);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_INTERLEAVED:
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);
      g_value_set_boolean (value,
          raw_audio_parse->properties_config.interleaved);
      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);
      break;

    case PROP_CHANNEL_POSITIONS:
    {
      GstRawAudioParseConfig *config;
      GValueArray *valarray;

      GST_RAW_BASE_PARSE_CONFIG_MUTEX_LOCK (object);

      valarray = NULL;
      config = &(raw_audio_parse->properties_config);

      /* Copy channel positions into the valuearray */
      if (config->num_channels > 0) {
        guint i;
        GValue val = G_VALUE_INIT;
        g_assert (config->channel_positions);

        g_value_init (&val, GST_TYPE_AUDIO_CHANNEL_POSITION);
        valarray = g_value_array_new (config->num_channels);

        for (i = 0; i < config->num_channels; ++i) {
          g_value_set_enum (&val, config->channel_positions[i]);
          g_value_array_insert (valarray, i, &val);
        }

        g_value_unset (&val);
      }

      GST_RAW_BASE_PARSE_CONFIG_MUTEX_UNLOCK (object);

      /* Pass on ownership to the value array,
       * since we don't need it anymore */
      g_value_take_boxed (value, valarray);

      break;
    }

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
예제 #12
0
static void format_contact(DBusContact* contact, ContactData* c) {
    gchar* firstname;
    gchar* lastname;
    GValueArray* email = NULL;
    GValue email_member = {0};
    gchar* str;   
	gchar* image = NULL;
	gsize size;
    
    contact->data = hash_table_new();
    contact->emails = g_value_email_new();
    firstname = lastname = NULL;
    
    if (c->name) {
        gchar* pos = strchr(c->name, ' ');
        if (pos) {
            firstname = g_strndup(c->name, pos - c->name);
            lastname = g_strdup(++pos);
            g_hash_table_replace(contact->data,
                g_strdup("first-name"), convert_2_utf8(firstname));
            g_hash_table_replace(contact->data,
                g_strdup("last-name"), convert_2_utf8(lastname));
        }
        else {
            lastname = g_strdup(c->name);
            g_hash_table_replace(contact->data,
                g_strdup("last-name"), convert_2_utf8(lastname));
        }
        g_free(firstname);
        g_free(lastname);
    }
	if (c->cn) {
		g_hash_table_replace(contact->data,
			g_strdup("cn"), convert_2_utf8(c->cn));
	}

	if (c->picture) {
		gdk_pixbuf_save_to_buffer(
			c->picture, &image, &size, "png", NULL, NULL);
		g_hash_table_replace(contact->data,
			g_strdup("image"), g_base64_encode((const guchar *) image, size));
	}
	
    email = g_value_array_new(0);

	/* Alias is not available but needed so make an empty string */
    g_value_init(&email_member, G_TYPE_STRING);
    g_value_set_string(&email_member, "");
    g_value_array_append(email, &email_member);
    g_value_unset(&email_member);

    if (c->email)
        str = convert_2_utf8(c->email);
    else
        str = g_strdup("");

    g_value_init(&email_member, G_TYPE_STRING);
    g_value_set_string(&email_member, str);
    g_value_array_append(email, &email_member);
    g_value_unset(&email_member);
    g_free(str);

    if (c->remarks)
        str = convert_2_utf8(c->remarks);
    else
        str = g_strdup("");
    
    g_value_init(&email_member, G_TYPE_STRING);
    g_value_set_string(&email_member, str);
    g_value_array_append(email, &email_member);
    g_value_unset(&email_member);
    g_free(str);

    g_ptr_array_add(contact->emails, email);
}
예제 #13
0
GValueArray *
gst_multiudpsink_get_stats (GstMultiUDPSink * sink, const gchar * host,
    gint port)
{
  GstUDPClient *client;
  GValueArray *result = NULL;
  GstUDPClient udpclient;
  GList *find;
  GValue value = { 0 };

  udpclient.host = (gchar *) host;
  udpclient.port = port;

  g_mutex_lock (sink->client_lock);

  find = g_list_find_custom (sink->clients, &udpclient,
      (GCompareFunc) client_compare);
  if (!find)
    goto not_found;

  GST_DEBUG_OBJECT (sink, "stats for client with host %s, port %d", host, port);

  client = (GstUDPClient *) find->data;

  /* Result is a value array of (bytes_sent, packets_sent,
   * connect_time, disconnect_time), all as uint64 */
  result = g_value_array_new (4);

  g_value_init (&value, G_TYPE_UINT64);
  g_value_set_uint64 (&value, client->bytes_sent);
  result = g_value_array_append (result, &value);
  g_value_unset (&value);

  g_value_init (&value, G_TYPE_UINT64);
  g_value_set_uint64 (&value, client->packets_sent);
  result = g_value_array_append (result, &value);
  g_value_unset (&value);

  g_value_init (&value, G_TYPE_UINT64);
  g_value_set_uint64 (&value, client->connect_time);
  result = g_value_array_append (result, &value);
  g_value_unset (&value);

  g_value_init (&value, G_TYPE_UINT64);
  g_value_set_uint64 (&value, client->disconnect_time);
  result = g_value_array_append (result, &value);
  g_value_unset (&value);

  g_mutex_unlock (sink->client_lock);

  return result;

  /* ERRORS */
not_found:
  {
    g_mutex_unlock (sink->client_lock);
    GST_WARNING_OBJECT (sink, "client with host %s, port %d not found",
        host, port);
    /* Apparently (see comment in gstmultifdsink.c) returning NULL from here may
     * confuse/break python bindings */
    return g_value_array_new (0);
  }
}
static void _parse_and_forward_one(IdleParser *parser, gchar **tokens, IdleParserMessageCode code, const gchar *format) {
	IdleParserPrivate *priv = IDLE_PARSER_GET_PRIVATE(parser);
	GValueArray *args = g_value_array_new(3);
	GSList *link_ = priv->handlers[code];
	IdleParserHandlerResult result = IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED;
	gboolean success = TRUE;
	gchar **iter = tokens;
	/* We keep a ref to each unique handle in a message so that we can unref them after calling all handlers */
	TpHandleSet *contact_reffed = tp_handle_set_new(tp_base_connection_get_handles(TP_BASE_CONNECTION(priv->conn), TP_HANDLE_TYPE_CONTACT));
	TpHandleSet *room_reffed = tp_handle_set_new(tp_base_connection_get_handles(TP_BASE_CONNECTION(priv->conn), TP_HANDLE_TYPE_ROOM));

	IDLE_DEBUG("message code %u", code);

	while ((*format != '\0') && success && (*iter != NULL)) {
		GValue val = {0};

		if (*format == 'v') {
			format++;
			while (*iter != NULL) {
				if (!_parse_atom(parser, args, *format, iter[0], contact_reffed, room_reffed)) {
					success = FALSE;
					break;
				}

				iter += 2;
			}
		} else if ((*format == ':') || (*format == '.')) {
			/* Assume the happy case of the trailing parameter starting after the :
			 * in the trailing string as the RFC intended */
			const gchar *trailing = iter[1] + 1;

			/* Some IRC proxies *cough* bip *cough* omit the : in the trailing
			 * parameter if that parameter is just one word, to cope with that check
			 * if there are no more tokens after the current one and if so, accept a
			 * trailing string without the : prefix. */
			if (iter[0][0] != ':') {
				if (iter[2] == NULL) {
					trailing = iter[1];
				} else {
					success = FALSE;
					break;
				}
			}

			/*
			 * because of the way things are tokenized, if there is a
			 * space immediately after the the ':', the current token will only be
			 * ":", so we check that the trailing string is non-NULL rather than
			 * checking iter[0][1] (since iter[0] is a NULL-terminated token string
			 * whereas trailing is a pointer into the full message string
			 */
			if (trailing[0] == '\0') {
				success = FALSE;
				break;
			}

			g_value_init(&val, G_TYPE_STRING);
			g_value_set_string(&val, trailing);
			g_value_array_append(args, &val);
			g_value_unset(&val);

			IDLE_DEBUG("set string \"%s\"", trailing);
		} else {
			if (!_parse_atom(parser, args, *format, iter[0], contact_reffed, room_reffed)) {
				success = FALSE;
				break;
			}
		}

		format++;
		iter += 2;
	}

	if (!success && (*format != '.')) {
		IDLE_DEBUG("failed to parse \"%s\"", tokens[1]);

		goto cleanup;
	}

	if (*format && (*format != '.')) {
		IDLE_DEBUG("missing args in message \"%s\"", tokens[1]);

		goto cleanup;
	}

	IDLE_DEBUG("successfully parsed");

	while (link_) {
		MessageHandlerClosure *closure = link_->data;
		result = closure->handler(parser, code, args, closure->user_data);
		if (result == IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED) {
			link_ = link_->next;
		} else if (result == IDLE_PARSER_HANDLER_RESULT_HANDLED) {
			break;
		} else if (result == IDLE_PARSER_HANDLER_RESULT_NO_MORE_PLEASE) {
			GSList *tmp = link_->next;
			g_free(closure);
			priv->handlers[code] = g_slist_remove_link(priv->handlers[code], link_);
			link_ = tmp;
		} else {
			g_assert_not_reached();
		}
	}

cleanup:

	g_value_array_free(args);

	tp_handle_set_destroy(contact_reffed);
	tp_handle_set_destroy(room_reffed);
}
/* Test that setting the IPv6 setting's 'addresses' property using the old
 * IPv6 address format still works, i.e. that the GValue transformation function
 * from old->new is working correctly.
 */
static void
test_setting_ip6_config_old_address_array (void)
{
	NMSettingIP6Config *s_ip6;
	GPtrArray *addresses, *read_addresses;
	GValueArray *array, *read_array;
	GValue element = {0, }, written_value = {0, }, read_value = {0, };
	GByteArray *ba;
	const guint8 addr[16] = { 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11,
	                          0x11, 0x22, 0x33, 0x44, 0x66, 0x77, 0x88, 0x99 };
	const guint8 gw[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
	guint32 prefix = 56;
	GValue *read_addr, *read_prefix, *read_gw;

	s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
	ASSERT (s_ip6 != NULL,
	        "ip6-old-addr", "error creating IP6 setting");

	g_value_init (&written_value, OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS);

	addresses = g_ptr_array_new ();
	array = g_value_array_new (3);

	/* IP address */
	g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
	ba = g_byte_array_new ();
	g_byte_array_append (ba, &addr[0], sizeof (addr));
	g_value_take_boxed (&element, ba);
	g_value_array_append (array, &element);
	g_value_unset (&element);

	/* Prefix */
	g_value_init (&element, G_TYPE_UINT);
	g_value_set_uint (&element, prefix);
	g_value_array_append (array, &element);
	g_value_unset (&element);

	g_ptr_array_add (addresses, array);
	g_value_set_boxed (&written_value, addresses);

	/* Set the address array on the object */
	g_object_set_property (G_OBJECT (s_ip6), NM_SETTING_IP6_CONFIG_ADDRESSES, &written_value);

	/* Get it back so we can compare it */
	g_value_init (&read_value, DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS);
	g_object_get_property (G_OBJECT (s_ip6), NM_SETTING_IP6_CONFIG_ADDRESSES, &read_value);

	ASSERT (G_VALUE_HOLDS (&read_value, DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS),
	        "ip6-old-addr", "wrong addresses property value type '%s'",
	        G_VALUE_TYPE_NAME (&read_value));

	read_addresses = (GPtrArray *) g_value_get_boxed (&read_value);
	ASSERT (read_addresses != NULL,
	        "ip6-old-addr", "missing addresses on readback");
	ASSERT (read_addresses->len == 1,
	        "ip6-old-addr", "expected one address on readback");

	read_array = (GValueArray *) g_ptr_array_index (read_addresses, 0);

	read_addr = g_value_array_get_nth (read_array, 0);
	ba = g_value_get_boxed (read_addr);
	ASSERT (ba->len == sizeof (addr),
	        "ip6-old-addr", "unexpected address item length %d", ba->len);
	ASSERT (memcmp (ba->data, &addr[0], sizeof (addr)) == 0,
	        "ip6-old-addr", "unexpected failure comparing addresses");

	read_prefix = g_value_array_get_nth (read_array, 1);
	ASSERT (g_value_get_uint (read_prefix) == prefix,
	        "ip6-old-addr", "unexpected failure comparing prefix");

	/* Ensure the gateway is all zeros, which is how the 2-item to 3-item
	 * conversion happens.
	 */
	read_gw = g_value_array_get_nth (read_array, 2);
	ba = g_value_get_boxed (read_gw);
	ASSERT (ba->len == sizeof (gw),
	        "ip6-old-addr", "unexpected gateway item length %d", ba->len);
	ASSERT (memcmp (ba->data, &gw[0], sizeof (gw)) == 0,
	        "ip6-old-addr", "unexpected failure comparing gateways");

	g_value_unset (&written_value);
	g_value_unset (&read_value);
	g_object_unref (s_ip6);
}
예제 #16
0
static void
fluts_pmt_stream_info_init (FluTsPmtStreamInfo *pmt_stream_info, FluTsPmtStreamInfoClass *klass)
{
  pmt_stream_info->languages = g_value_array_new ( 0 );
  pmt_stream_info->descriptors = g_value_array_new (0);
}
static void
compare_ip6_addresses (void)
{
	GValueArray *array1;
	GValueArray *array2;
	GValueArray *array3;
	GByteArray *ba1;
	GByteArray *ba2;
	GByteArray *ba3;
	GValue element = { 0 };
	GValue value1 = { 0 };
	GValue value2 = { 0 };
	struct in6_addr addr1;
	struct in6_addr addr2;
	struct in6_addr addr3;
	guint32 prefix1 = 64;
	guint32 prefix2 = 64;
	guint32 prefix3 = 0;

	inet_pton (AF_INET6, "1:2:3:4:5:6:7:8", &addr1, sizeof (struct in6_addr));
	inet_pton (AF_INET6, "ffff:2:3:4:5:6:7:8", &addr2, sizeof (struct in6_addr));
	inet_pton (AF_INET6, "::", &addr3, sizeof (struct in6_addr));

	/* address 1 */
	ba1 = g_byte_array_new ();
	array1 = g_value_array_new (2);
	g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
	g_byte_array_append (ba1, (guint8 *) addr1.s6_addr, 16);
	g_value_take_boxed (&element, ba1);
	g_value_array_append (array1, &element);
	g_value_unset (&element);

	g_value_init (&element, G_TYPE_UINT);
	g_value_set_uint (&element, prefix1);
	g_value_array_append (array1, &element);
	g_value_unset (&element);

	/* address 2 */
	ba2 = g_byte_array_new ();
	array2 = g_value_array_new (2);
	g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
	g_byte_array_append (ba2, (guint8 *) addr2.s6_addr, 16);
	g_value_take_boxed (&element, ba2);
	g_value_array_append (array2, &element);
	g_value_unset (&element);

	g_value_init (&element, G_TYPE_UINT);
	g_value_set_uint (&element, prefix2);
	g_value_array_append (array2, &element);
	g_value_unset (&element);

	/* address 3 */
	ba3 = g_byte_array_new ();
	array3 = g_value_array_new (2);
	g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
	g_byte_array_append (ba3, (guint8 *) addr3.s6_addr, 16);
	g_value_take_boxed (&element, ba3);
	g_value_array_append (array3, &element);
	g_value_unset (&element);

	g_value_init (&element, G_TYPE_UINT);
	g_value_set_uint (&element, prefix3);
	g_value_array_append (array3, &element);
	g_value_unset (&element);

	g_value_init (&value1, DBUS_TYPE_G_IP6_ADDRESS);
	g_value_init (&value2, DBUS_TYPE_G_IP6_ADDRESS);

	g_value_set_boxed (&value1, array1);
	g_value_set_boxed (&value2, array1);
	g_print ("Comparing identical IPv6 address structures: %d\n", _gvalues_compare (&value1, &value2));

	g_value_set_boxed (&value1, array1);
	g_value_set_boxed (&value2, array2);
	g_print ("Comparing different IPv6 address structures: %d\n", _gvalues_compare (&value1, &value2));

	g_value_set_boxed (&value1, array1);
	g_value_set_boxed (&value2, array3);
	g_print ("Comparing different IPv6 address structures: %d\n", _gvalues_compare (&value1, &value2));
}
static void
gst_pocketsphinx_get_property(GObject * object, guint prop_id,
                              GValue * value, GParamSpec * pspec)
{
    GstPocketSphinx *ps = GST_POCKETSPHINX(object);

    switch (prop_id) {
    case PROP_DECODER:
        g_value_set_boxed(value, ps->ps);
        break;
    case PROP_CONFIGURED:
        g_value_set_boolean(value, ps->ps != NULL);
        break;
    case PROP_HMM_DIR:
        g_value_set_string(value, cmd_ln_str_r(ps->config, "-hmm"));
        break;
    case PROP_LM_FILE:
        g_value_set_string(value, cmd_ln_str_r(ps->config, "-lm"));
        break;
    case PROP_LMCTL_FILE:
        g_value_set_string(value, cmd_ln_str_r(ps->config, "-lmctl"));
        break;
    case PROP_LM_NAME:
        g_value_set_string(value, cmd_ln_str_r(ps->config, "-lmname"));
        break;
    case PROP_DICT_FILE:
        g_value_set_string(value, cmd_ln_str_r(ps->config, "-dict"));
        break;
    case PROP_MLLR_FILE:
        g_value_set_string(value, cmd_ln_str_r(ps->config, "-mllr"));
        break;
    case PROP_FSG_FILE:
        g_value_set_string(value, cmd_ln_str_r(ps->config, "-fsg"));
        break;
    case PROP_FWDFLAT:
        g_value_set_boolean(value, cmd_ln_boolean_r(ps->config, "-fwdflat"));
        break;
    case PROP_BESTPATH:
        g_value_set_boolean(value, cmd_ln_boolean_r(ps->config, "-bestpath"));
        break;
    case PROP_LATDIR:
        g_value_set_string(value, ps->latdir);
        break;
    case PROP_LATTICE: {
        ps_lattice_t *dag;

        if (ps->ps && (dag = ps_get_lattice(ps->ps)))
            g_value_set_boxed(value, dag);
        else
            g_value_set_boxed(value, NULL);
        break;
    }
    case PROP_MAXHMMPF:
        g_value_set_int(value, cmd_ln_int32_r(ps->config, "-maxhmmpf"));
        break;
    case PROP_MAXWPF:
        g_value_set_int(value, cmd_ln_int32_r(ps->config, "-maxwpf"));
        break;
    case PROP_BEAM:
        g_value_set_double(value, cmd_ln_float_r(ps->config, "-beam"));
        break;
    case PROP_PBEAM:
        g_value_set_double(value, cmd_ln_float_r(ps->config, "-pbeam"));
        break;
    case PROP_WBEAM:
        g_value_set_double(value, cmd_ln_float_r(ps->config, "-wbeam"));
        break;
    case PROP_DSRATIO:
        g_value_set_int(value, cmd_ln_int32_r(ps->config, "-ds"));
        break;
    case PROP_NBEST_SIZE:
        g_value_set_int(value, ps->n_best_size);
        break;
    case PROP_NBEST: {
        int i = 0, out_score = 0;
        GValueArray *arr;
        if (!ps->ps) {
            break;
        }
	arr = g_value_array_new(1);
        ps_nbest_t *ps_nbest_list = ps_nbest(ps->ps, 0, -1, NULL, NULL);   
        if (ps_nbest_list) {
            ps_nbest_list = ps_nbest_next(ps_nbest_list);
            while ((i < ps->n_best_size) && (ps_nbest_list != NULL)) {
                GValue value1 = { 0 };
                g_value_init (&value1, G_TYPE_STRING);
                const char* hyp = ps_nbest_hyp(ps_nbest_list, &out_score);
                g_value_set_string(&value1, hyp);
                g_value_array_append(arr, &value1);  
                ps_nbest_list = ps_nbest_next(ps_nbest_list);
                i++;
            }
            if (ps_nbest_list) {
                ps_nbest_free(ps_nbest_list);
            }
        }
        g_value_set_boxed (value, arr);
        break;
    }
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
        break;
    }
}
예제 #19
0
파일: pygtype.c 프로젝트: nzjrs/pygobject
static int
pyg_value_array_from_pyobject(GValue *value,
			      PyObject *obj,
			      const GParamSpecValueArray *pspec)
{
    int len;
    GValueArray *value_array;
    int i;

    len = PySequence_Length(obj);
    if (len == -1) {
	PyErr_Clear();
	return -1;
    }

    if (pspec && pspec->fixed_n_elements > 0 && len != pspec->fixed_n_elements)
	return -1;

    value_array = g_value_array_new(len);

    for (i = 0; i < len; ++i) {
	PyObject *item = PySequence_GetItem(obj, i);
	GType type;
	GValue item_value = { 0, };
	int status;

	if (! item) {
	    PyErr_Clear();
	    g_value_array_free(value_array);
	    return -1;
	}

	if (pspec && pspec->element_spec)
	    type = G_PARAM_SPEC_VALUE_TYPE(pspec->element_spec);
	else if (item == Py_None)
	    type = G_TYPE_POINTER; /* store None as NULL */
	else {
	    type = pyg_type_from_object((PyObject*)Py_TYPE(item));
	    if (! type) {
		PyErr_Clear();
		g_value_array_free(value_array);
		Py_DECREF(item);
		return -1;
	    }
	}

	g_value_init(&item_value, type);
	status = (pspec && pspec->element_spec)
	    ? pyg_param_gvalue_from_pyobject(&item_value, item, pspec->element_spec)
	    : pyg_value_from_pyobject(&item_value, item);
	Py_DECREF(item);

	if (status == -1) {
	    g_value_array_free(value_array);
	    g_value_unset(&item_value);
	    return -1;
	}

	g_value_array_append(value_array, &item_value);
	g_value_unset(&item_value);
    }

    g_value_take_boxed(value, value_array);
    return 0;
}
static GValueArray *
gst_mio_video_src_probe_get_values (GstPropertyProbe * probe, guint prop_id,
    const GParamSpec * pspec)
{
  GValueArray *values;
  GstCoreMediaCtx *ctx = NULL;
  GError *error = NULL;
  GList *devices = NULL, *walk;
  guint device_idx;

  values = g_value_array_new (3);

  ctx = gst_core_media_ctx_new (GST_MIO_REQUIRED_APIS, &error);
  if (error != NULL)
    goto beach;

  devices = gst_mio_video_device_list_create (ctx);
  if (devices == NULL)
    goto beach;

  for (walk = devices, device_idx = 0; walk != NULL; walk = walk->next) {
    GstMIOVideoDevice *device = walk->data;
    GValue value = { 0, };

    switch (prop_id) {
      case PROP_DEVICE_UID:
      case PROP_DEVICE_NAME:
      {
        const gchar *str;

        if (prop_id == PROP_DEVICE_UID)
          str = gst_mio_video_device_get_uid (device);
        else
          str = gst_mio_video_device_get_name (device);

        g_value_init (&value, G_TYPE_STRING);
        g_value_set_string (&value, str);

        break;
      }
      case PROP_DEVICE_INDEX:
      {
        g_value_init (&value, G_TYPE_INT);
        g_value_set_int (&value, device_idx);

        break;
      }
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
        goto beach;
    }

    g_value_array_append (values, &value);
    g_value_unset (&value);

    device_idx++;
  }

beach:
  if (devices != NULL)
    gst_mio_video_device_list_destroy (devices);
  if (ctx != NULL)
    g_object_unref (ctx);
  g_clear_error (&error);

  return values;
}
예제 #21
0
GValueArray *
plug_in_params_to_args (GParamSpec **pspecs,
                        gint         n_pspecs,
                        GPParam     *params,
                        gint         n_params,
                        gboolean     return_values,
                        gboolean     full_copy)
{
  GValueArray *args;
  gint         i;

  g_return_val_if_fail ((pspecs != NULL && n_pspecs  > 0) ||
                        (pspecs == NULL && n_pspecs == 0), NULL);
  g_return_val_if_fail ((params != NULL && n_params  > 0) ||
                        (params == NULL && n_params == 0), NULL);

  args = g_value_array_new (n_params);

  for (i = 0; i < n_params; i++)
    {
      GValue value = { 0, };
      GType  type;
      gint   count;

      /*  first get the fallback compat GType that matches the pdb type  */
      type = gimp_pdb_compat_arg_type_to_gtype (params[i].type);

      /*  then try to try to be more specific by looking at the param
       *  spec (return values have one additional value (the status),
       *  skip that, it's not in the array of param specs)
       */
      if (i > 0 || ! return_values)
        {
          gint pspec_index = i;

          if (return_values)
            pspec_index--;

          /*  are there param specs left?  */
          if (pspec_index < n_pspecs)
            {
              GimpPDBArgType pspec_arg_type;

              pspec_arg_type = gimp_pdb_compat_arg_type_from_gtype
                (G_PARAM_SPEC_VALUE_TYPE (pspecs[pspec_index]));

              /*  if the param spec's GType, mapped to a pdb type, matches
               *  the passed pdb type, use the param spec's GType
               */
              if (pspec_arg_type == params[i].type)
                {
                  type = G_PARAM_SPEC_VALUE_TYPE (pspecs[pspec_index]);
                }
            }
        }

      g_value_init (&value, type);

      switch (gimp_pdb_compat_arg_type_from_gtype (type))
        {
        case GIMP_PDB_INT32:
          if (G_VALUE_HOLDS_INT (&value))
            g_value_set_int (&value, params[i].data.d_int32);
          else if (G_VALUE_HOLDS_UINT (&value))
            g_value_set_uint (&value, params[i].data.d_int32);
          else if (G_VALUE_HOLDS_ENUM (&value))
            g_value_set_enum (&value, params[i].data.d_int32);
          else if (G_VALUE_HOLDS_BOOLEAN (&value))
            g_value_set_boolean (&value, params[i].data.d_int32 ? TRUE : FALSE);
          else
            {
              g_printerr ("%s: unhandled GIMP_PDB_INT32 type: %s\n",
                          G_STRFUNC, g_type_name (G_VALUE_TYPE (&value)));
              g_return_val_if_reached (args);
            }
          break;

        case GIMP_PDB_INT16:
          g_value_set_int (&value, params[i].data.d_int16);
          break;

        case GIMP_PDB_INT8:
          g_value_set_uint (&value, params[i].data.d_int8);
          break;

        case GIMP_PDB_FLOAT:
          g_value_set_double (&value, params[i].data.d_float);
          break;

        case GIMP_PDB_STRING:
          if (full_copy)
            g_value_set_string (&value, params[i].data.d_string);
          else
            g_value_set_static_string (&value, params[i].data.d_string);
          break;

        case GIMP_PDB_INT32ARRAY:
          count = g_value_get_int (&args->values[i - 1]);
          if (full_copy)
            gimp_value_set_int32array (&value,
                                       params[i].data.d_int32array,
                                       count);
          else
            gimp_value_set_static_int32array (&value,
                                              params[i].data.d_int32array,
                                              count);
          break;

        case GIMP_PDB_INT16ARRAY:
          count = g_value_get_int (&args->values[i - 1]);
          if (full_copy)
            gimp_value_set_int16array (&value,
                                       params[i].data.d_int16array,
                                       count);
          else
            gimp_value_set_static_int16array (&value,
                                              params[i].data.d_int16array,
                                              count);
          break;

        case GIMP_PDB_INT8ARRAY:
          count = g_value_get_int (&args->values[i - 1]);
          if (full_copy)
            gimp_value_set_int8array (&value,
                                      params[i].data.d_int8array,
                                      count);
          else
            gimp_value_set_static_int8array (&value,
                                             params[i].data.d_int8array,
                                             count);
          break;

        case GIMP_PDB_FLOATARRAY:
          count = g_value_get_int (&args->values[i - 1]);
          if (full_copy)
            gimp_value_set_floatarray (&value,
                                       params[i].data.d_floatarray,
                                       count);
          else
            gimp_value_set_static_floatarray (&value,
                                              params[i].data.d_floatarray,
                                              count);
          break;

        case GIMP_PDB_STRINGARRAY:
          count = g_value_get_int (&args->values[i - 1]);
          if (full_copy)
            gimp_value_set_stringarray (&value,
                                        (const gchar **) params[i].data.d_stringarray,
                                        count);
          else
            gimp_value_set_static_stringarray (&value,
                                               (const gchar **) params[i].data.d_stringarray,
                                               count);
          break;

        case GIMP_PDB_COLOR:
          gimp_value_set_rgb (&value, &params[i].data.d_color);
          break;

        case GIMP_PDB_ITEM:
          g_value_set_int (&value, params[i].data.d_item);
          break;

        case GIMP_PDB_DISPLAY:
          g_value_set_int (&value, params[i].data.d_display);
          break;

        case GIMP_PDB_IMAGE:
          g_value_set_int (&value, params[i].data.d_image);
          break;

        case GIMP_PDB_LAYER:
          g_value_set_int (&value, params[i].data.d_layer);
          break;

        case GIMP_PDB_CHANNEL:
          g_value_set_int (&value, params[i].data.d_channel);
          break;

        case GIMP_PDB_DRAWABLE:
          g_value_set_int (&value, params[i].data.d_drawable);
          break;

        case GIMP_PDB_SELECTION:
          g_value_set_int (&value, params[i].data.d_selection);
          break;

        case GIMP_PDB_COLORARRAY:
          count = g_value_get_int (&args->values[i - 1]);
          if (full_copy)
            gimp_value_set_colorarray (&value,
                                      params[i].data.d_colorarray,
                                      count);
          else
            gimp_value_set_static_colorarray (&value,
                                             params[i].data.d_colorarray,
                                             count);
          break;

        case GIMP_PDB_VECTORS:
          g_value_set_int (&value, params[i].data.d_vectors);
          break;

        case GIMP_PDB_PARASITE:
          if (full_copy)
            g_value_set_boxed (&value, &params[i].data.d_parasite);
          else
            g_value_set_static_boxed (&value, &params[i].data.d_parasite);
          break;

        case GIMP_PDB_STATUS:
          g_value_set_enum (&value, params[i].data.d_status);
          break;

        case GIMP_PDB_END:
          break;
        }

      g_value_array_append (args, &value);
      g_value_unset (&value);
    }

  return args;
}
static GValueArray *
gst_dshowvideosrc_get_device_name_values (GstDshowVideoSrc * src)
{
    GValueArray *array = g_value_array_new (0);
    ICreateDevEnum *devices_enum = NULL;
    IEnumMoniker *moniker_enum = NULL;
    IMoniker *moniker = NULL;
    HRESULT hres = S_FALSE;
    ULONG fetched;

    hres = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
                             IID_ICreateDevEnum, (LPVOID *) & devices_enum);
    if (hres != S_OK) {
        GST_ERROR ("Can't create system device enumerator (error=0x%x)", hres);
        array = NULL;
        goto clean;
    }

    hres = devices_enum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory,
            &moniker_enum, 0);
    if (hres != S_OK || !moniker_enum) {
        GST_ERROR ("Can't get enumeration of video devices (error=0x%x)", hres);
        array = NULL;
        goto clean;
    }

    moniker_enum->Reset ();

    while (hres = moniker_enum->Next (1, &moniker, &fetched), hres == S_OK) {
        IPropertyBag *property_bag = NULL;

        hres =
            moniker->BindToStorage (NULL, NULL, IID_IPropertyBag,
                                    (LPVOID *) & property_bag);
        if (SUCCEEDED (hres) && property_bag) {
            VARIANT varFriendlyName;

            VariantInit (&varFriendlyName);
            hres = property_bag->Read (L"FriendlyName", &varFriendlyName, NULL);
            if (hres == S_OK && varFriendlyName.bstrVal) {
                gchar *friendly_name =
                    g_utf16_to_utf8 ((const gunichar2 *) varFriendlyName.bstrVal,
                                     wcslen (varFriendlyName.bstrVal), NULL, NULL, NULL);

                GValue value = { 0 };
                g_value_init (&value, G_TYPE_STRING);
                g_value_set_string (&value, friendly_name);
                g_value_array_append (array, &value);
                g_value_unset (&value);
                g_free (friendly_name);
                SysFreeString (varFriendlyName.bstrVal);
            }
            property_bag->Release ();
        }
        moniker->Release ();
    }

clean:
    if (moniker_enum)
        moniker_enum->Release ();

    if (devices_enum)
        devices_enum->Release ();

    return array;
}
static GValue *getValue(JsonNode *node)
{
    GValue *p = new GValue;
    GValue &ret = *p;

    switch (JSON_NODE_TYPE(node))
    {
    case JSON_NODE_OBJECT:
        {
            JsonObject *node_object;
            node_object = json_node_get_object (node);
            g_assert (node_object != NULL);

            GHashTable *object = g_hash_table_new(g_str_hash, g_str_equal);
            json_object_foreach_member(node_object, parseMembers, object);

            g_value_init(&ret, G_TYPE_HASH_TABLE);
            g_value_set_boxed(&ret, object);
        }
        break;
    case JSON_NODE_ARRAY:
        {
            JsonArray *node_array;
            node_array = json_node_get_array (node);
            g_assert (node_array != NULL);

            GValueArray *array = g_value_array_new(0);
            json_array_foreach_element(node_array, parseElements, array);

            g_value_init(&ret, G_TYPE_VALUE_ARRAY);
            g_value_set_boxed(&ret, array);
        }
        break;
    case JSON_NODE_VALUE:
        {
            switch (json_node_get_value_type(node))
            {
            case G_TYPE_INT64:
                {
                    gint64 val = json_node_get_int(node);
                    g_value_init (&ret, G_TYPE_INT64);
                    g_value_set_int64(&ret, val);
                }
                break;

            case G_TYPE_DOUBLE:
                {
                    double val = json_node_get_double(node);
                    g_value_init (&ret, G_TYPE_INT64);
                    g_value_set_double(&ret, val);
                }
                break;

            case G_TYPE_BOOLEAN:
                {
                    bool val = json_node_get_boolean(node);
                    g_value_init (&ret, G_TYPE_INT64);
                    g_value_set_boolean(&ret, val);
                }
                break;

            case G_TYPE_STRING:
                {
                    const gchar * str = json_node_get_string(node);
                    g_value_init (&ret, G_TYPE_STRING);
                    g_value_set_string(&ret, str);
                }
                break;
            default:
                break;
            }
        }
        break;
    case JSON_NODE_NULL:
        break;
    }
    return &ret;
}
예제 #24
0
/* run automatically started extensions */
static void
gimp_plug_in_manager_run_extensions (GimpPlugInManager  *manager,
                                     GimpContext        *context,
                                     GimpInitStatusFunc  status_callback)
{
  Gimp   *gimp = manager->gimp;
  GSList *list;
  GList  *extensions = NULL;
  gint    n_extensions;

  /* build list of automatically started extensions */
  for (list = manager->plug_in_procedures; list; list = list->next)
    {
      GimpPlugInProcedure *proc = list->data;

      if (proc->prog                                         &&
          GIMP_PROCEDURE (proc)->proc_type == GIMP_EXTENSION &&
          GIMP_PROCEDURE (proc)->num_args  == 0)
        {
          extensions = g_list_prepend (extensions, proc);
        }
    }

  extensions   = g_list_reverse (extensions);
  n_extensions = g_list_length (extensions);

  /* run the available extensions */
  if (extensions)
    {
      GList *list;
      gint   nth;

      status_callback (_("Starting Extensions"), "", 0.0);

      for (list = extensions, nth = 0; list; list = g_list_next (list), nth++)
        {
          GimpPlugInProcedure *proc = list->data;
          GValueArray         *args;
          GError              *error = NULL;

          if (gimp->be_verbose)
            g_print ("Starting extension: '%s'\n", gimp_object_get_name (proc));

          status_callback (NULL, gimp_object_get_name (proc),
                           (gdouble) nth / (gdouble) n_extensions);

          args = g_value_array_new (0);

          gimp_procedure_execute_async (GIMP_PROCEDURE (proc),
                                        gimp, context, NULL,
                                        args, NULL, &error);

          g_value_array_free (args);

          if (error)
            {
              gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR,
				    error->message);
              g_clear_error (&error);
            }
        }

      g_list_free (extensions);

      status_callback (NULL, "", 1.0);
    }
}
static GstMessage *
update_rms_from_buffer (GstVideoFrameAudioLevel * self, GstBuffer * inbuf)
{
  GstMapInfo map;
  guint8 *in_data;
  gsize in_size;
  gdouble CS;
  guint i;
  guint num_frames, frames;
  guint num_int_samples = 0;    /* number of interleaved samples
                                 * ie. total count for all channels combined */
  gint channels, rate, bps;
  GValue v = G_VALUE_INIT;
  GValue va = G_VALUE_INIT;
  GValueArray *a;
  GstStructure *s;
  GstMessage *msg;
  GstClockTime duration, running_time;

  channels = GST_AUDIO_INFO_CHANNELS (&self->ainfo);
  bps = GST_AUDIO_INFO_BPS (&self->ainfo);
  rate = GST_AUDIO_INFO_RATE (&self->ainfo);

  gst_buffer_map (inbuf, &map, GST_MAP_READ);
  in_data = map.data;
  in_size = map.size;

  num_int_samples = in_size / bps;

  GST_LOG_OBJECT (self, "analyzing %u sample frames at ts %" GST_TIME_FORMAT,
      num_int_samples, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (inbuf)));

  g_return_val_if_fail (num_int_samples % channels == 0, NULL);

  num_frames = num_int_samples / channels;
  frames = num_frames;
  duration = GST_FRAMES_TO_CLOCK_TIME (frames, rate);
  if (num_frames > 0) {
    for (i = 0; i < channels; ++i) {
      self->process (in_data + (bps * i), num_int_samples, channels, &CS);
      GST_LOG_OBJECT (self,
          "[%d]: cumulative squares %lf, over %d samples/%d channels",
          i, CS, num_int_samples, channels);
      self->CS[i] += CS;
    }
    in_data += num_frames * bps;

    self->total_frames += num_frames;
  }
  running_time =
      self->first_time + gst_util_uint64_scale (self->total_frames, GST_SECOND,
      rate);

  a = g_value_array_new (channels);
  s = gst_structure_new ("videoframe-audiolevel", "running-time", G_TYPE_UINT64,
      running_time, "duration", G_TYPE_UINT64, duration, NULL);

  g_value_init (&v, G_TYPE_DOUBLE);
  g_value_init (&va, G_TYPE_VALUE_ARRAY);
  for (i = 0; i < channels; i++) {
    gdouble rms;
    if (frames == 0 || self->CS[i] == 0) {
      rms = 0;                  /* empty buffer */
    } else {
      rms = sqrt (self->CS[i] / frames);
    }
    self->CS[i] = 0.0;
    g_value_set_double (&v, rms);
    g_value_array_append (a, &v);
  }
  g_value_take_boxed (&va, a);
  gst_structure_take_value (s, "rms", &va);
  msg = gst_message_new_element (GST_OBJECT (self), s);

  gst_buffer_unmap (inbuf, &map);

  return msg;
}
예제 #26
0
GValueArray *
gimp_procedure_get_return_values (GimpProcedure *procedure,
                                  gboolean       success,
                                  const GError  *error)
{
  GValueArray *args;
  GValue       value = { 0, };
  gint         i;

  g_return_val_if_fail (success == FALSE || GIMP_IS_PROCEDURE (procedure),
                        NULL);

  if (success)
    {
      args = g_value_array_new (procedure->num_values + 1);

      g_value_init (&value, GIMP_TYPE_PDB_STATUS_TYPE);
      g_value_set_enum (&value, GIMP_PDB_SUCCESS);
      g_value_array_append (args, &value);
      g_value_unset (&value);

      for (i = 0; i < procedure->num_values; i++)
        {
          g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (procedure->values[i]));
          g_value_array_append (args, &value);
          g_value_unset (&value);
        }
    }
  else
    {
      args = g_value_array_new ((error && error->message) ? 2 : 1);

      g_value_init (&value, GIMP_TYPE_PDB_STATUS_TYPE);

      /*  errors in the GIMP_PDB_ERROR domain are calling errors  */
      if (error && error->domain == GIMP_PDB_ERROR)
        {
          switch ((GimpPdbErrorCode) error->code)
            {
            case GIMP_PDB_PROCEDURE_NOT_FOUND:
            case GIMP_PDB_INVALID_ARGUMENT:
            case GIMP_PDB_INVALID_RETURN_VALUE:
            case GIMP_PDB_INTERNAL_ERROR:
              g_value_set_enum (&value, GIMP_PDB_CALLING_ERROR);
              break;

            case GIMP_PDB_CANCELLED:
              g_value_set_enum (&value, GIMP_PDB_CANCEL);
              break;

            default:
              g_assert_not_reached ();
            }
        }
      else
        {
          g_value_set_enum (&value, GIMP_PDB_EXECUTION_ERROR);
        }

      g_value_array_append (args, &value);
      g_value_unset (&value);

      if (error && error->message)
        {
          g_value_init (&value, G_TYPE_STRING);
          g_value_set_string (&value, error->message);
          g_value_array_append (args, &value);
          g_value_unset (&value);
        }
    }

  return args;
}
예제 #27
0
static void
mpegts_pmt_info_init (MpegTsPmtInfo * pmt_info, MpegTsPmtInfoClass * klass)
{
  pmt_info->streams = g_value_array_new (0);
  pmt_info->descriptors = g_value_array_new (0);
}
예제 #28
0
GValueArray *
gst_oss4_property_probe_get_values (GstObject * probe, const gchar * pname)
{
  struct oss_sysinfo si = { {0,}, };
  GValueArray *array = NULL;
  GstObject *obj;
  GList *devices, *l;
  int cap_mask, fd = -1;

  if (!g_str_equal (pname, "device")) {
    GST_WARNING_OBJECT (probe, "invalid property");
    return NULL;
  }

  obj = GST_OBJECT (probe);

  GST_OBJECT_LOCK (obj);

  /* figure out whether the element is a source or sink */
  if (GST_IS_OSS4_SINK (probe)) {
    GST_DEBUG_OBJECT (probe, "probing available output devices");
    cap_mask = PCM_CAP_OUTPUT;
    fd = GST_OSS4_SINK (probe)->fd;
  } else if (GST_IS_OSS4_SOURCE (probe)) {
    GST_DEBUG_OBJECT (probe, "probing available input devices");
    cap_mask = PCM_CAP_INPUT;
    fd = GST_OSS4_SOURCE (probe)->fd;
  } else {
    GST_OBJECT_UNLOCK (obj);
    g_return_val_if_reached (NULL);
  }

  /* copy fd if it's open, so we can just unconditionally close() later */
  if (fd != -1)
    fd = dup (fd);

  /* this will also catch the unlikely case where the above dup() failed */
  if (fd == -1) {
    fd = open ("/dev/mixer", O_RDONLY | O_NONBLOCK, 0);
    if (fd < 0)
      goto open_failed;
    else if (!gst_oss4_audio_check_version (GST_OBJECT (probe), fd))
      goto legacy_oss;
  }

  if (ioctl (fd, SNDCTL_SYSINFO, &si) == -1)
    goto no_sysinfo;

  if (cap_mask != 0) {
    devices =
        gst_oss4_property_probe_get_audio_devices (obj, fd, &si, cap_mask);
  } else {
    devices = gst_oss4_property_probe_get_mixer_devices (obj, fd, &si);
  }

  if (devices == NULL) {
    GST_DEBUG_OBJECT (obj, "No devices found");
    goto done;
  }

  array = g_value_array_new (1);

  for (l = devices; l != NULL; l = l->next) {
    GValue val = { 0, };

    g_value_init (&val, G_TYPE_STRING);
    g_value_take_string (&val, (gchar *) l->data);
    l->data = NULL;
    g_value_array_append (array, &val);
    g_value_unset (&val);
  }

  GST_OBJECT_UNLOCK (obj);

  g_list_free (devices);

done:

  close (fd);

  return array;

/* ERRORS */
open_failed:
  {
    GST_OBJECT_UNLOCK (GST_OBJECT (probe));
    GST_WARNING_OBJECT (probe, "Can't open file descriptor to probe "
        "available devices: %s", g_strerror (errno));
    return NULL;
  }
legacy_oss:
  {
    close (fd);
    GST_OBJECT_UNLOCK (GST_OBJECT (probe));
    GST_DEBUG_OBJECT (probe, "Legacy OSS (ie. not OSSv4), not supported");
    return NULL;
  }
no_sysinfo:
  {
    close (fd);
    GST_OBJECT_UNLOCK (GST_OBJECT (probe));
    GST_WARNING_OBJECT (probe, "Can't open file descriptor to probe "
        "available devices: %s", g_strerror (errno));
    return NULL;
  }
}
예제 #29
0
static void
mame_gui_prefs_init (MameGuiPrefs *pr)
{
	gboolean load_result;
	gint *int_array;
	gsize columnsize;
	guint i;
	
	GMAMEUI_DEBUG ("Creating GUI prefs object");	
	pr->priv = g_new0 (MameGuiPrefsPrivate, 1);
	
	int_array = g_new0 (gint, NUMBER_COLUMN);       /* Used for loading integer lists from prefs file */
	
	pr->priv->cols_shown = g_value_array_new (NUMBER_COLUMN);
	pr->priv->cols_width = g_value_array_new (NUMBER_COLUMN);
	
	pr->priv->executable_paths = g_value_array_new (4);     /* FIXME TODO MAX_EXECUTABLES */
	pr->priv->rom_paths = g_value_array_new (4);    /* FIXME TODO - define max number */
	pr->priv->sample_paths = g_value_array_new (4); /* FIXME TODO - define max number */

	/* The gmameui.ini pref file should be stored in the following locations:
	     ~/.config/gmameui (on Linux)
	 */
	pr->priv->filename = g_build_filename (get_gmameui_config_dir (), "gmameui.ini", NULL);

	pr->priv->prefs_ini_file = g_key_file_new ();
	GError *error = NULL;
	load_result = g_key_file_load_from_file (pr->priv->prefs_ini_file, pr->priv->filename,
						 G_KEY_FILE_KEEP_COMMENTS, &error);

	if (!load_result) {
		GMAMEUI_DEBUG ("Error loading %s - %s", pr->priv->filename, error->message);	
	
		g_error_free (error);
		error = NULL;
	}

	/* UI preferences */
	pr->priv->ui_width = mame_gui_prefs_get_int_property_from_key_file (pr, "ui-width");
	pr->priv->ui_height = mame_gui_prefs_get_int_property_from_key_file (pr, "ui-height");
	pr->priv->show_toolbar = mame_gui_prefs_get_bool_property_from_key_file (pr, "show-toolbar");
	pr->priv->show_statusbar = mame_gui_prefs_get_bool_property_from_key_file (pr, "show-statusbar");
	pr->priv->show_filterlist = mame_gui_prefs_get_bool_property_from_key_file (pr, "show-filterlist");
	pr->priv->show_screenshot = mame_gui_prefs_get_bool_property_from_key_file (pr, "show-screenshot");
	pr->priv->current_rom_filter = mame_gui_prefs_get_int_property_from_key_file (pr, "current-rom-filter");
	pr->priv->current_mode = mame_gui_prefs_get_int_property_from_key_file (pr, "current-mode");
	pr->priv->previous_mode = mame_gui_prefs_get_int_property_from_key_file (pr, "previous-mode");
	int_array = g_key_file_get_integer_list (pr->priv->prefs_ini_file, "Preferences", "cols-shown", &columnsize, &error);
	for (i = 0; i < NUMBER_COLUMN; ++i) {
		GValue val = { 0, };
		
		g_value_init (&val, G_TYPE_INT);
		g_value_set_int (&val, int_array != NULL ? int_array[i] : 1);	/* If not available, default to shown */

		GMAMEUI_DEBUG ("Value for cols-shown at %d is %d", i, g_value_get_int (&val));
		g_value_array_append (pr->priv->cols_shown, &val);
	}
	if (error) {
		GMAMEUI_DEBUG ("Error retrieving cols-shown: %s", error->message);
		g_error_free (error);
		error = NULL;
	}

	int_array = g_key_file_get_integer_list (pr->priv->prefs_ini_file, "Preferences", "cols-width", &columnsize, &error);
	for (i = 0; i < NUMBER_COLUMN; ++i) {
		GValue val = { 0, };
		/* FIXME TODO 0 means auto sized columns */
		g_value_init (&val, G_TYPE_INT);
		g_value_set_int (&val, int_array != NULL ? int_array[i] : 0);	/* If not available, default to 0 */
		GMAMEUI_DEBUG ("Value for cols-width at %d is %d", i, g_value_get_int (&val));
		g_value_array_append (pr->priv->cols_width, &val);
	}
	if (error) {
		GMAMEUI_DEBUG ("Error retrieving cols-width: %s", error->message);
		g_error_free (error);
		error = NULL;
	}

	pr->priv->sort_col = mame_gui_prefs_get_int_property_from_key_file (pr, "sort-col");
	pr->priv->sort_col_direction = mame_gui_prefs_get_int_property_from_key_file (pr, "sort-col-direction");
	pr->priv->xpos_filters = mame_gui_prefs_get_int_property_from_key_file (pr, "xpos-filters");
	pr->priv->xpos_gamelist = mame_gui_prefs_get_int_property_from_key_file (pr, "xpos-gamelist");
	
	/* Startup preferences */
	pr->priv->GameCheck = mame_gui_prefs_get_bool_property_from_key_file (pr, "gamecheck");
	pr->priv->VersionCheck = mame_gui_prefs_get_bool_property_from_key_file (pr, "versioncheck");
	pr->priv->use_xmame_options = mame_gui_prefs_get_bool_property_from_key_file (pr, "usexmameoptions");
	pr->priv->prefercustomicons = mame_gui_prefs_get_bool_property_from_key_file (pr, "prefercustomicons");
	pr->priv->gui_joy = mame_gui_prefs_get_bool_property_from_key_file (pr, "usejoyingui");
	pr->priv->joystick_name = mame_gui_prefs_get_string_property_from_key_file (pr, "joystick-name");
	if (!pr->priv->joystick_name)
		pr->priv->joystick_name = g_strdup (get_joy_dev ());
	
	/* Miscellaneous preferences */
	pr->priv->theprefix = mame_gui_prefs_get_bool_property_from_key_file (pr, "theprefix");

	pr->priv->current_rom_name = mame_gui_prefs_get_string_property_from_key_file (pr, "current-rom");
	pr->priv->current_executable_name = mame_gui_prefs_get_string_property_from_key_file (pr, "current-executable");

	/* Load the executable paths */
	pr->priv->executable_paths = mame_gui_prefs_get_stringlist_property_from_key_file (pr, "Preferences", "executable-paths");
	
	/* Load the ROM paths */
	pr->priv->rom_paths = mame_gui_prefs_get_stringlist_property_from_key_file (pr, "Preferences", "rom-paths");
	
	/* Load the Samples paths */
	pr->priv->sample_paths = mame_gui_prefs_get_stringlist_property_from_key_file (pr, "Preferences", "sample-paths");

	/* Directory preferences */
	GMAMEUI_DEBUG ("Reading directories preferences from file");
	for (i = 0; i < NUM_DIRS; i++) {
		pr->priv->directories[i] = mame_gui_prefs_get_string_property_from_key_file (pr, directory_prefs[i].name);
		
		/* If no values set, set default values */
		if (!pr->priv->directories[i])
			pr->priv->directories[i] = g_strdup (directory_prefs[i].default_dir);   /* strdup, since we free in finalize */
		GMAMEUI_DEBUG ("Setting directory %d (%s) to %s", i, directory_prefs[i].name, pr->priv->directories[i]);
		
		/* If directory does not exist under $HOME/.config/mame, create it */
		if (i >= DIR_CFG) {
			gchar *dir;
			dir = g_build_filename (g_get_user_config_dir (), "mame", directory_prefs[i].default_dir, NULL);
			if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
				GMAMEUI_DEBUG ("Directory %s does not exist, creating it", dir);
				g_mkdir (dir, S_IRWXU);
			}
			g_free (dir);
		}
		
	}
	GMAMEUI_DEBUG ("Reading directories preferences from file... done");
	
	/* Set handlers so that whenever the values are changed (from anywhere), the signal handler
	   is invoked; the callback then saves to the g_key_file */
	g_signal_connect (pr, "notify::ui-width", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::ui-height", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::show-toolbar", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::show-statusbar", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::show-filterlist", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::show-screenshot", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::current-rom-filter", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::current-mode", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::previous-mode", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::cols-shown", (GCallback) mame_gui_prefs_save_int_arr, NULL);
	g_signal_connect (pr, "notify::cols-width", (GCallback) mame_gui_prefs_save_int_arr, NULL);
	g_signal_connect (pr, "notify::sort-col", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::sort-col-direction", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::xpos-filters", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::xpos-gamelist", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::gamecheck", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::versioncheck", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::usexmameoptions", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::prefercustomicons", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::usejoyingui", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::joystick-name", (GCallback) mame_gui_prefs_save_string, NULL);
	g_signal_connect (pr, "notify::theprefix", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::current-rom", (GCallback) mame_gui_prefs_save_string, NULL);
	g_signal_connect (pr, "notify::current-executable", (GCallback) mame_gui_prefs_save_string, NULL);
	g_signal_connect (pr, "notify::executable-paths", (GCallback) mame_gui_prefs_save_string_arr, NULL);
	g_signal_connect (pr, "notify::rom-paths", (GCallback) mame_gui_prefs_save_string_arr, NULL);
	g_signal_connect (pr, "notify::sample-paths", (GCallback) mame_gui_prefs_save_string_arr, NULL); 
	
	for (i = 0; i < NUM_DIRS; i++) {
		gchar *signal_name;
		signal_name = g_strdup_printf("notify::%s", directory_prefs[i].name);
		GMAMEUI_DEBUG("Connecting signal %s", signal_name);
		g_signal_connect (pr, signal_name, (GCallback) mame_gui_prefs_save_string, NULL);
		g_free (signal_name);
	}
GMAMEUI_DEBUG ("Creating GUI prefs object... done");
}