Ejemplo n.º 1
0
void SimManager::_get_options() {
	getInputInt(&_input, "print_reduced_conf_every", &_print_reduced_conf_every, 0);
	getInputInt(&_input, "print_energy_every", &_print_energy_every, 0);
	getInputInt(&_input, "restart_step_counter", &_restart_step_counter, 0);
	getInputLLInt(&_input, "steps", &_steps, 1);
	if(getInputInt(&_input, "seed", &_seed, 0) == KEY_NOT_FOUND) _seed = time(NULL);
	getInputString(&_input, "conf_file", _conf_file, 1);
}
Ejemplo n.º 2
0
void SimManager::init() {
	srand48(_seed);
	srand(_seed);

	ifstream conf_input(_conf_file);
	if(conf_input.good() == false) _IO.die("Can't read configuration file '%s'", _conf_file);

	// here we handle the SIGTERM signal;
	signal (SIGTERM, gbl_terminate);
	signal (SIGABRT, gbl_terminate);
	signal (SIGINT, gbl_terminate);

	char time_scale[256];
	getInputString(&_input, "time_scale", time_scale, 1);
	if(strcmp(time_scale, "linear") == 0) _time_scale = TS_LIN;
	else if(strcmp(time_scale, "log_lin") == 0) _time_scale = TS_LOG_LIN;
	else _IO.die("Time scale '%s' not supported", time_scale);

	char line[512];
	conf_input.getline(line, 512);
	int res = sscanf(line, "t = %lld", &_start_step);
	if(res != 1) _IO.die("The first line of the configuration file is not correct, aborting");
	if(_restart_step_counter != 0) _start_step = 0;

	// init time_scale_manager
	initTimeScale(&_time_scale_manager, _time_scale);

	int tmp;
	getInputInt(&_input, "print_conf_interval", &tmp, 1);
	setTSInterval(&_time_scale_manager, tmp);

	if(_time_scale == TS_LOG_LIN) {
		getInputInt(&_input, "print_conf_ppc", &tmp, 1);
		setTSPPC(&_time_scale_manager, tmp);
	}
	// end

	setTSInitialStep(&_time_scale_manager, _start_step);

	_IO.init();
	_backend->init(conf_input);

	_max_steps = _start_step + _steps;
}
void CMoodMgr::createSong(int type)
{
	int fileSize=0, transfer, encryption, id, numDays, popularity; //arguement added
	char songName[128], albumName[128], artistName[128], date[128], webLink[128];
	double duration, price;

	getInputString("Song Name: ", songName);
	getInputString("Album Name: ", albumName);
	getInputString("Artist Name: ", artistName);
	getInputInt("File Size: ", &fileSize);
	getInputInt("Transfer (1=Streamable, 2=Downloadable, 3=Both) : ", &transfer);
	getInputString("Date: ", date);
	getInputInt("Popularity (0=Lowest to 100=Highest) : ", &popularity);

	if (type == SONG_SECURE) {
		getInputDouble("Duration: ", &duration);
		getInputInt("Encryption (1=SECURE_1, 2=SECURE_2, 3=SECURE_3): ", &encryption);
		getInputInt("ID: ", &id);

		CSecureSongInfo secureSong;

		secureSong.setSongName(songName);	
		secureSong.setAlbumName(albumName);
		secureSong.setArtistName(artistName);
		secureSong.setFileSize(fileSize);
		secureSong.setTransfer(transfer);
		secureSong.setDate(date);
		secureSong.setPopularity(popularity);  //added line of code
		secureSong.setDuration(duration);
		secureSong.setEncryption(encryption);
		secureSong.setId(id);

		songList.add(&secureSong);
	}
	else if (type == SONG_PROMO) {
		getInputDouble("Price: ", &price);
		getInputString("WebLink: ", webLink);
		getInputInt("Promotion Length: ", &numDays);

		CPromoSongInfo promoSong;

		promoSong.setSongName(songName);
		promoSong.setAlbumName(albumName);
		promoSong.setArtistName(artistName);
		promoSong.setFileSize(fileSize);
		promoSong.setTransfer(transfer);
		promoSong.setDate(date);
		promoSong.setPopularity(popularity);
		promoSong.setPrice(price);
		promoSong.setWebLink(webLink);
		promoSong.setNumDays(numDays);

		songList.add(&promoSong);
	}
	
	cout << endl;
}
void CMoodMgr::deleteSong()
{
	int i;
	int length = songList.length();

	if (length == 0) {
		displayMessage("The song list is empty.");
		return;
	}
	
	getInputInt("Enter song number you wish to delete: ", &i);
	if ((i < 1) || (i > length)) { // Note: first song is displayed as #1
		displayMessage("You must enter a song number from 1 to ", true, length);
		return;
	}

	songList.remove(i-1); // adjustment, see above
}
void CMoodMgr::editSong()
{
	int i;
	int length = songList.length();

	if (length == 0) {
		displayMessage("The song list is empty.");
		return;
	}
	
	getInputInt("Enter song number you wish to edit: ", &i);
	if ((i < 1) || (i > length)) { // Note: first song is displayed as #1
		displayMessage("You must enter a song number from 1 to ", true, length);
		cout << endl;
		return;
	}

	i = i - 1;  // adjustment, see above

	int fileSize=0, transfer, encryption, id, numDays, popularity;
	char songName[128], albumName[128], artistName[128], date[128], webLink[128];
	double duration, price;

	CSongInfo *pSong;
	CSecureSongInfo *pSecure;
	CPromoSongInfo *pPromo;

	pSong = songList.get(i);
	int type = pSong->getType();

	if (type == SONG_SECURE) {
		pSecure = (CSecureSongInfo *)songList.get(i);

		getInputString("Song Name: ", songName, true, pSecure->getSongName());
		getInputString("Album Name: ", albumName, true, pSecure->getAlbumName());
		getInputString("Artist Name: ", artistName, true, pSecure->getArtistName());
		getInputInt("File Size: ", &fileSize, true, pSecure->getFileSize());
		getInputInt("Transfer (1=Streamable, 2=Downloadable, 3=Both: ", &transfer, true, pSecure->getTransfer());
		getInputString("Date: ", date, true, pSecure->getDate());
		getInputInt("Popularity (0=Lowest to 100=Highest) : ", &popularity, true, pSecure->getPopularity());
		getInputDouble("Duration: ", &duration, true, pSecure->getDuration());
		getInputInt("Encryption (1=SECURE_1, 2=SECURE_2, 3=SECURE_3): ", &encryption, true, pSecure->getEncryption());
		getInputInt("ID: ", &id, true, pSecure->getId());

		pSecure->setSongName(songName);	
		pSecure->setAlbumName(albumName);
		pSecure->setArtistName(artistName);
		pSecure->setFileSize(fileSize);
		pSecure->setTransfer(transfer);
		pSecure->setDate(date);
		pSecure->setPopularity(popularity);
		pSecure->setDuration(duration);
		pSecure->setEncryption(encryption);
		pSecure->setId(id);
	}
	else if (type == SONG_PROMO) {
		pPromo = (CPromoSongInfo *)songList.get(i);

		getInputString("Song Name: ", songName, true, pPromo->getSongName());
		getInputString("Album Name: ", albumName, true, pPromo->getAlbumName());
		getInputString("Artist Name: ", artistName, true, pPromo->getArtistName());
		getInputInt("File Size: ", &fileSize, true, pPromo->getFileSize());
		getInputInt("Transfer (1=Streamable, 2=Downloadable, 3=Both: ", &transfer, true, pPromo->getTransfer());
		getInputString("Date: ", date, true, pPromo->getDate());
		getInputInt("Popularity (0=Lowest to 100=Highest) : ", &popularity, true, pPromo->getPopularity());
		getInputDouble("Price: ", &price, true, pPromo->getPrice());
		getInputString("WebLink: ", webLink, true, pPromo->getWebLink());
		getInputInt("Promotion Length: ", &numDays, true, pPromo->getNumDays());

		pPromo->setSongName(songName);
		pPromo->setAlbumName(albumName);
		pPromo->setArtistName(artistName);
		pPromo->setFileSize(fileSize);
		pPromo->setTransfer(transfer);
		pPromo->setDate(date);
		pPromo->setPopularity(popularity);
		pPromo->setPrice(price);
		pPromo->setWebLink(webLink);
		pPromo->setNumDays(numDays);
	}
	
	cout << endl;
}