Ejemplo n.º 1
0
static Variant HHVM_STATIC_METHOD(Locale, composeLocale, CArrRef subtags) {
  s_intl_error->clearError();

  if (subtags.exists(s_GRANDFATHERED)) {
    auto val = subtags[s_GRANDFATHERED];
    if (val.isString()) {
      return val;
    }
  }

  if (!subtags.exists(s_LOC_LANG)) {
    s_intl_error->setError(U_ILLEGAL_ARGUMENT_ERROR, "locale_compose: "
                           "parameter array does not contain 'language' tag.");
    return false;
  }
  String ret(subtags[s_LOC_LANG].toString());
  if (!append_multiple_key_values(ret, subtags, LOC_EXTLANG) ||
      !append_key_value(ret, subtags, LOC_SCRIPT) ||
      !append_key_value(ret, subtags, LOC_REGION) ||
      !append_multiple_key_values(ret, subtags, LOC_VARIANT) ||
      !append_multiple_key_values(ret, subtags, LOC_PRIVATE)) {
    return false;
  }
  return ret;
}
Ejemplo n.º 2
0
/* Appends the information about a node to the dbus message. Returns
 * false if not enough memory. */
static dbus_bool_t append_node_dict(DBusMessageIter *iter,
				    const struct cras_iodev_info *dev,
				    const struct cras_ionode_info *node,
				    enum CRAS_STREAM_DIRECTION direction)
{
	DBusMessageIter dict;
	dbus_bool_t is_input;
	dbus_uint64_t id;
	const char *dev_name = dev->name;
	dbus_uint64_t stable_dev_id = node->stable_id;
	const char *node_type = node->type;
	const char *node_name = node->name;
	const char *mic_positions = node->mic_positions;
	dbus_bool_t active;
	dbus_uint64_t plugged_time = node->plugged_time.tv_sec * 1000000ULL +
		node->plugged_time.tv_usec;
	dbus_uint64_t node_volume = node->volume;
	dbus_int64_t node_capture_gain = node->capture_gain;
	char *models, *empty_models = "";

	is_input = (direction == CRAS_STREAM_INPUT);
	id = node->iodev_idx;
	id = (id << 32) | node->ionode_idx;
	active = !!node->active;

	if (!dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "{sv}",
					      &dict))
		return FALSE;
	if (!append_key_value(&dict, "IsInput", DBUS_TYPE_BOOLEAN,
			      DBUS_TYPE_BOOLEAN_AS_STRING, &is_input))
		return FALSE;
	if (!append_key_value(&dict, "Id", DBUS_TYPE_UINT64,
			      DBUS_TYPE_UINT64_AS_STRING, &id))
		return FALSE;
	if (!append_key_value(&dict, "DeviceName", DBUS_TYPE_STRING,
			      DBUS_TYPE_STRING_AS_STRING, &dev_name))
		return FALSE;
	if (!append_key_value(&dict, "StableDeviceId", DBUS_TYPE_UINT64,
			      DBUS_TYPE_UINT64_AS_STRING, &stable_dev_id))
		return FALSE;
	if (!append_key_value(&dict, "Type", DBUS_TYPE_STRING,
			      DBUS_TYPE_STRING_AS_STRING, &node_type))
		return FALSE;
	if (!append_key_value(&dict, "Name", DBUS_TYPE_STRING,
			      DBUS_TYPE_STRING_AS_STRING, &node_name))
		return FALSE;
	if (!append_key_value(&dict, "MicPositions", DBUS_TYPE_STRING,
			      DBUS_TYPE_STRING_AS_STRING, &mic_positions))
		return FALSE;
	if (!append_key_value(&dict, "Active", DBUS_TYPE_BOOLEAN,
			      DBUS_TYPE_BOOLEAN_AS_STRING, &active))
		return FALSE;
	if (!append_key_value(&dict, "PluggedTime", DBUS_TYPE_UINT64,
			      DBUS_TYPE_UINT64_AS_STRING, &plugged_time))
		return FALSE;
	if (!append_key_value(&dict, "NodeVolume", DBUS_TYPE_UINT64,
			      DBUS_TYPE_UINT64_AS_STRING, &node_volume))
		return FALSE;
	if (!append_key_value(&dict, "NodeCaptureGain", DBUS_TYPE_INT64,
			      DBUS_TYPE_INT64_AS_STRING, &node_capture_gain))
		return FALSE;

	models = cras_iodev_list_get_hotword_models(id);
	if (!append_key_value(&dict, "HotwordModels", DBUS_TYPE_STRING,
			      DBUS_TYPE_STRING_AS_STRING,
			      models ? &models : &empty_models)) {
		free(models);
		return FALSE;
	}
	free(models);

	if (!dbus_message_iter_close_container(iter, &dict))
		return FALSE;

	return TRUE;
}