// Returns vector with all users information.
std::vector<User> RadioStation::loadAllUsersToVector() {

	std::vector <User> allUsersVec;

	std::string filename = "users.csv";
	ifstream file(filename);

	std::string tempStr;

	// Temporary user information.
	unsigned int newID, newAge, newHits;
	std::string newName, newGender, newPass;
	bool newSpecial;

	if(file.is_open()) {
		getline(file, tempStr); // Get first line (fields titles).

		while(getline(file, tempStr)) {
			// Gets user information from file.
			newID = convertStrInt(extractInfo(tempStr));
			newName = extractInfo(tempStr);
			newAge = convertStrInt(extractInfo(tempStr));
			newGender = extractInfo(tempStr);
			newSpecial = convertToBool(convertStrInt(extractInfo(tempStr)));
			newPass = extractInfo(tempStr);
			newHits = convertStrInt(extractInfo(tempStr));
			// Stores user information to vector.
			allUsersVec.push_back(User(newID, newName, newAge, newGender, newSpecial, newPass, newHits, true));
		}

		file.close();
	}

	return allUsersVec;
}
void AccessController::LdacConsumerPermissionCallback::operationNeeded()
{

    QString operation;
    QString messageType = message.getType();

    // Deserialize the message to get the operation
    QByteArray jsonRequest = message.getPayload();

    if (messageType == JoynrMessage::VALUE_MESSAGE_TYPE_REQUEST) {

        QScopedPointer<Request> request(JsonSerializer::deserialize<Request>(jsonRequest));
        if (!request.isNull()) {
            operation = request->getMethodName();
        }
    } else if (messageType == JoynrMessage::VALUE_MESSAGE_TYPE_SUBSCRIPTION_REQUEST) {

        QScopedPointer<SubscriptionRequest> request(
                JsonSerializer::deserialize<SubscriptionRequest>(jsonRequest));
        if (!request.isNull()) {
            operation = request->getSubscribeToName();
        }
    } else if (messageType == JoynrMessage::VALUE_MESSAGE_TYPE_BROADCAST_SUBSCRIPTION_REQUEST) {

        QScopedPointer<BroadcastSubscriptionRequest> request(
                JsonSerializer::deserialize<BroadcastSubscriptionRequest>(jsonRequest));
        if (!request.isNull()) {
            operation = request->getSubscribeToName();
        }
    }

    if (operation.isEmpty()) {
        LOG_ERROR(logger, "Could not deserialize request");
        callback->hasConsumerPermission(false);
        return;
    }

    // Get the permission for given operation
    QtPermission::Enum permission =
            owningAccessController.localDomainAccessController.getConsumerPermission(
                    message.getHeaderCreatorUserId().toStdString(),
                    domain.toStdString(),
                    interfaceName.toStdString(),
                    operation.toStdString(),
                    QtTrustLevel::createStd(trustlevel));

    bool hasPermission = convertToBool(permission);

    if (hasPermission == false) {
        LOG_ERROR(logger,
                  QString("Message %1 to domain %2, interface/operation %3/%4 failed ACL check")
                          .arg(message.getHeaderMessageId())
                          .arg(domain)
                          .arg(interfaceName)
                          .arg(operation));
    }

    callback->hasConsumerPermission(hasPermission);
}
// Loads Radio Station Music List from csv file. Returns true if successfully loaded.
void RadioStation::loadRadioStationMusicsListFromFile() {
	// ============================================================
	// Variables
	// ============================================================
	std::string filename = "radioStationMusics.csv";
	ifstream file(filename);
	
	std::string line;
	std::string delimiter = ",";
	size_t delimiter_pos = 0;
	std::vector <string> tokens;
	unsigned int pos;
	// ============================================================

	if(file.is_open()) {
		// Discards first line.
		getline(file, line);
		
		// Gets musics.
		while(getline(file, line)) {
			while((pos = line.find(delimiter)) != std::string::npos) {
				tokens.push_back(line.substr(0, pos));
				//std::cout << line.substr(0,pos) << std::endl;
				line.erase(0, pos + delimiter.length());
			}
			// Saves last token.
			tokens.push_back(line);
			// Saves song to vector.
			allMusicsList.push_back(MusicTrack(convertStrInt(tokens[0]), tokens[1], tokens[2], tokens[3], tokens[4],
				convertStrInt(tokens[5]), convertStrInt(tokens[6]), convertStrInt(tokens[7]), convertToBool(convertStrInt(tokens[8]))));
			// Clear tokens vector.
			tokens.clear();
			// Clear pos variable.
			pos = 0;
		}

		file.close();

	}
}
/**
 * @brief OptionDefinition::convertValue
 * @param stringValue
 * @return
 */
QVariant OptionDefinition::convertValue(const QString &stringValue) const
{
    QVariant value(QVariant::Invalid);
    switch (d->m_dataType) {
    case QVariant::Bool:
        value.setValue(convertToBool(stringValue));
        break;
    case QVariant::Date:
        value.setValue(convertToDate(stringValue));
        break;
    case QVariant::DateTime:
        value.setValue(convertToDateTime(stringValue));
        break;
    case QVariant::Double:
        value.setValue(convertToDouble(stringValue));
        break;
    case QVariant::Int:
        value.setValue(convertToInt(stringValue));
        break;
    case QVariant::LongLong:
        value.setValue(convertToLongLong(stringValue));
        break;
    case QVariant::String:
        value.setValue(stringValue);
        break;
    case QVariant::Time:
        value.setValue(convertToTime(stringValue));
        break;
    case QVariant::UInt:
        value.setValue(convertToUInt(stringValue));
        break;
    case QVariant::ULongLong:
        value.setValue(convertToULongLong(stringValue));
        break;
    default:
        break;
    }

    return value;
}
// Checks for users that have a hit on their playlist.
void RadioStation::checkForHitsOnAllUsers() {
	User userObj;
	// Vector that will hold all the user. Backup purposes.
	vector<User> allUsersVec;

	string line;

	unsigned int newID, newAge, newHits;
	string newName, newGender, newPass;
	bool newSpecial;
	
	string filename = "users.csv";
	ifstream file(filename);

	if(file.is_open()) {
		getline(file, line); // Gets fields titles.

		while(getline(file, line)) {

			newID = convertStrInt(extractInfo(line));
			newName = extractInfo(line);
			newAge = convertStrInt(extractInfo(line));
			newGender = extractInfo(line);
			newSpecial = convertToBool(convertStrInt(extractInfo(line)));
			newPass = extractInfo(line);
			newHits = convertStrInt(extractInfo(line));

			allUsersVec.push_back(User(newID, newName, newAge, newGender, newSpecial, newPass, newHits, true));
		}
		file.close();
	} else {
		return;
	}

	for(vector<User>::iterator vecPtr = allUsersVec.begin(); vecPtr != allUsersVec.end(); vecPtr++) {
		vecPtr->checkForHits(playlistOfTheDay);
	}
}
// Loads playlist of the day from csv file.
void RadioStation::loadPlaylistOfTheDayFromFile() {

	std::string newTitle, newAuthor, newAlbum, newGenre; 
	unsigned int newID, newYear, newLikes, newDislikes;
	bool newSpecial;

	std::string filename = "playlistOfTheDay.csv";
	std::string line;
	ifstream file(filename);

	if(file.is_open()) {

		playlistOfTheDay.clear();

		getline(file, line); // Gets fields titles.

		while(getline(file, line)) {

			newID = convertStrInt(extractInfo(line));
			newTitle = extractInfo(line);
			newAuthor = extractInfo(line);
			newAlbum = extractInfo(line);
			newGenre = extractInfo(line);
			newYear = convertStrInt(extractInfo(line));
			newLikes = convertStrInt(extractInfo(line));
			newDislikes = convertStrInt(extractInfo(line));
			newSpecial = convertToBool(convertStrInt(extractInfo(line)));

			playlistOfTheDay.push_back(MusicTrack(newID, newTitle, newAuthor, newAlbum, newGenre, newYear, 
				newLikes, newDislikes, newSpecial));
		}
		file.close();
	} else {
		return;
	}
	
}
Exemple #7
0
State Sensor::getValue() {
    return convertToBool(analogRead(pin));
}
Exemple #8
0
bool moProperty::asBool() {
	return convertToBool(this->type, this->val);
}