Ejemplo n.º 1
0
void read_counts(Tree &T, Counts &data, std::string fname, long nalpha) {
  int i;
  unsigned int j;
  long id;
  State sta, sta2;
  std::string str;
  std::vector<long> d;

  // The number of letters is fixed to 4 in read_fasta.
  if (nalpha != 4) {
    std::cout << "Reading counts only implemented for 4 letters." << std::endl;
  }

  // reads in the alignment. The data is in _orbits and _couts.
  read_alignment(fname);

  // Now we fill in the Counts structure.
  data.nalpha = 4;
  data.nspecies = g_numSpecies;
  data.nstates = 1;

  // calculate the power:
  for (i=0; i < data.nspecies; i++) {
    data.nstates = data.nstates*data.nalpha;
  }

  // Creates a state of a given dimension
  create_state(sta, data.nspecies, data.nalpha);
  create_state(sta2, data.nspecies, data.nalpha);

  // Matches the species in the fasta with the ones in the tree.
  if (!match_species(T, g_nameSpecies, g_numSpecies, d)) {
    throw std::length_error( "Could not match species in tree with species in fasta." );
  }

  // Stores the counts in the Counts structure.
  data.c.resize(data.nstates);
  data.N = 0;
  for (j=0; j < _orbitals.size(); j++) {
    str = transform_adn_chain_val_to_string(_orbitals[j]);
    string2state(str, sta);
    permute_state(d, sta, sta2);
    id = state2index(sta2);
    data.c[id] = (double) _counts[j];
    data.N = data.N + data.c[id];
  }

  // Stores the species names
  data.species.resize(data.nspecies);
  for (i=0; i < T.nleaves; i++) {
    data.species[i] = T.names[i];
  }
}
Ejemplo n.º 2
0
static DBusMessage *notify_update(DBusConnection *conn,
					DBusMessage *msg, void *user_data)
{
	struct test_session *session = user_data;
	struct test_session_info *info = session->info;
	DBusMessageIter iter, array;
	GSList *allowed_bearers;

	LOG("session %p notify %s", session, session->notify_path);

	dbus_message_iter_init(msg, &iter);
	dbus_message_iter_recurse(&iter, &array);

	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
		DBusMessageIter entry, value;
		const char *key;

		dbus_message_iter_recurse(&array, &entry);
		dbus_message_iter_get_basic(&entry, &key);

		dbus_message_iter_next(&entry);
		dbus_message_iter_recurse(&entry, &value);

		switch (dbus_message_iter_get_arg_type(&value)) {
		case DBUS_TYPE_ARRAY:
			if (g_str_equal(key, "AllowedBearers") == TRUE) {
				allowed_bearers = session_parse_allowed_bearers(&value);

				g_slist_foreach(info->allowed_bearers,
						bearer_info_cleanup, NULL);
				g_slist_free(info->allowed_bearers);

				info->allowed_bearers = allowed_bearers;

			} else if (g_str_equal(key, "IPv4") == TRUE) {
				/* XXX */

			} else if (g_str_equal(key, "IPv6") == TRUE) {
				/* XXX */

			} else {
				g_assert(FALSE);
				return __connman_error_invalid_arguments(msg);
			}
			break;
		case DBUS_TYPE_BOOLEAN:
			if (g_str_equal(key, "Priority") == TRUE) {
				dbus_message_iter_get_basic(&value,
							&info->priority);

			} else if (g_str_equal(key, "AvoidHandover") == TRUE) {
				dbus_message_iter_get_basic(&value,
							&info->avoid_handover);

			} else if (g_str_equal(key, "StayConnected") == TRUE) {
				dbus_message_iter_get_basic(&value,
							&info->stay_connected);

			} else if (g_str_equal(key, "EmergencyCall") == TRUE) {
				dbus_message_iter_get_basic(&value,
							&info->ecall);

			} else {
				g_assert(FALSE);
				return __connman_error_invalid_arguments(msg);
			}
			break;
		case DBUS_TYPE_UINT32:
			if (g_str_equal(key, "PeriodicConnect") == TRUE) {
				dbus_message_iter_get_basic(&value,
							&info->periodic_connect);

			} else if (g_str_equal(key, "IdleTimeout") == TRUE) {
				dbus_message_iter_get_basic(&value,
							&info->idle_timeout);

			} else if (g_str_equal(key, "SessionMarker") == TRUE) {
				dbus_message_iter_get_basic(&value,
							&info->marker);

			} else {
				g_assert(FALSE);
				return __connman_error_invalid_arguments(msg);
			}
			break;
		case DBUS_TYPE_STRING:
			if (g_str_equal(key, "State") == TRUE) {
				const char *val;
				dbus_message_iter_get_basic(&value, &val);

				info->state = string2state(val);
			} else if (g_str_equal(key, "Bearer") == TRUE) {
				const char *val;
				dbus_message_iter_get_basic(&value, &val);

				if (info->bearer != NULL)
					g_free(info->bearer);

				info->bearer = g_strdup(val);

			} else if (g_str_equal(key, "Name") == TRUE) {
				const char *val;
				dbus_message_iter_get_basic(&value, &val);

				if (info->name != NULL)
					g_free(info->name);

				info->name = g_strdup(val);

			} else if (g_str_equal(key, "RoamingPolicy") == TRUE) {
				const char *val;
				dbus_message_iter_get_basic(&value, &val);
				info->roaming_policy =
					string2roamingpolicy(val);

			} else if (g_str_equal(key, "Interface") == TRUE) {
				const char *val;
				dbus_message_iter_get_basic(&value, &val);

				if (info->interface != NULL)
					g_free(info->interface);

				info->interface = g_strdup(val);

			} else if (g_str_equal(key, "ConnectionType")
								== TRUE) {
				const char *val;
				dbus_message_iter_get_basic(&value, &val);

				info->type = string2type(val);
			} else {
				g_assert(FALSE);
				return __connman_error_invalid_arguments(msg);
			}
			break;
		default:
			g_assert(FALSE);
			return __connman_error_invalid_arguments(msg);
		}
		dbus_message_iter_next(&array);
	}

	if (session->notify != NULL)
		session->notify(session);

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
Ejemplo n.º 3
0
static void state_change(struct supplicant_task *task, DBusMessage *msg)
{
	DBusError error;
	const char *newstate, *oldstate;
	unsigned char bssid[ETH_ALEN];
	unsigned int bssid_len;
	enum supplicant_state state, ostate;

	dbus_error_init(&error);

	if (dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &newstate,
						DBUS_TYPE_STRING, &oldstate,
						DBUS_TYPE_INVALID) == FALSE) {
		if (dbus_error_is_set(&error) == TRUE) {
			connman_error("%s", error.message);
			dbus_error_free(&error);
		} else
			connman_error("Wrong arguments for state change");
		return;
	}

	connman_info("%s state change %s -> %s%s", task->ifname,
			oldstate, newstate,
			task->scanning == TRUE ? " (scanning)" : "");

	state = string2state(newstate);
	if (state == WPA_INVALID)
		return;

	if (task->scanning == TRUE && state != WPA_SCANNING) {
		connman_device_set_scanning(task->device, FALSE);
		task->scanning = FALSE;
	}

	ostate = task->state;
	task->state = state;

	if (task->network == NULL)
		return;

	switch (task->state) {
	case WPA_COMPLETED:
		if (ostate != WPA_ASSOCIATED && ostate != WPA_GROUP_HANDSHAKE)
			goto badstate;

		/* reset bg scan reschedule */
		connman_device_reset_scan(task->device);

		if (get_bssid(task->device, bssid, &bssid_len) == 0)
			connman_network_set_address(task->network,
							bssid, bssid_len);

		/* carrier on */
		connman_network_set_connected(task->network, TRUE);
		break;

	case WPA_ASSOCIATING:
		if (ostate != WPA_SCANNING && ostate != WPA_COMPLETED)
			goto badstate;

		if (ostate == WPA_SCANNING)
			connman_network_set_associating(task->network, TRUE);
		break;

	case WPA_INACTIVE:
		if (ostate != WPA_SCANNING && ostate != WPA_DISCONNECTED)
			goto badstate;
		/* fall thru... */
	case WPA_DISCONNECTED:
		/* carrier off */
		connman_network_set_connected(task->network, FALSE);

		if (task->disconnecting == TRUE) {
			connman_network_unref(task->network);
			task->disconnecting = FALSE;

			if (task->pending_network != NULL) {
				task->network = task->pending_network;
				task->pending_network = NULL;
				task_connect(task);
			} else
				task->network = NULL;
		}
		break;

	default:
		connman_network_set_associating(task->network, FALSE);
		break;
	}
	return;
badstate:
	connman_error("%s invalid state change %s -> %s%s", task->ifname,
			oldstate, newstate,
			task->scanning == TRUE ? " (scanning)" : "");
}