DistributorDialog::DistributorDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DistributorDialog)
{
    ui->setupUi(this);

    QString appData(getenv("APPDATA"));
    dataFileName = appData.append("\\FileDistributor\\settings.dat");
    copier = new Copier();
    copier->moveToThread(&workerThread);
    dirsModel = new QStringListModel(copier->getDestDirs(), this);

    load();
    icon = new QSystemTrayIcon(QIcon(":/res/FD.ico"), this);
    iconMenu = new QMenu(this);
    iconMenu->addAction("Settings", this, SLOT(show()));
    iconMenu->addSeparator();
    iconMenu->addAction("Close", this, SLOT(quit()));
    icon->setContextMenu(iconMenu);
    icon->show();
    displayMessage("", "FileDistributor is running");
    timer = new QTimer(this);

    connect(icon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
    connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(save()));
    connect(ui->sourceDirBrowse, SIGNAL(clicked()), this, SLOT(browse()));
    connect(ui->addDirB, SIGNAL(clicked()), this, SLOT(addDest()));
    connect(ui->removeDirB, SIGNAL(clicked()), this, SLOT(removeDest()));
    connect(timer, SIGNAL(timeout()), copier, SLOT(startCopy()));
    connect(this, SIGNAL(startCopy()), copier, SLOT(startCopy()));
    connect(copier, SIGNAL(copyStarted()), this, SLOT(copyStarted()));
    workerThread.start();
    emit startCopy();
    timer->start(1000*copier->getRefreshRateSeconds());
}
NewCopyPage::NewCopyPage(Step step, QWidget *parent)
    : QWidget(parent), Ui::NewCopyPage()
{
    //Setup the .ui file.
    setupUi(this);

#ifdef _WIN32
    linuxLabel->setVisible(false);
#endif
#ifdef unix
    windowsLabel->setVisible(false);
#endif

    //Hide parts of the page.
    switch (step) {
    case (StepWarning) : {
        hideProgress();
        hideFinish();
        break;
    }
    case (StepCopy) : {
        startCopy();
        hideFinish();

        break;
    }
    }
}
void DistributorDialog::save()
{
    copier->setRefreshRateSeconds(ui->refreshIntervalS->value());
    copier->setSourceDir(ui->sourceDirEdit->text());
    if (timer->interval() != copier->getRefreshRateSeconds()*1000)
    {
        int timeElapsed = timer->interval() - timer->remainingTime();
        if (timeElapsed > copier->getRefreshRateSeconds()*1000)
        {
            timer->stop();
            timer->start(copier->getRefreshRateSeconds()*1000);
            emit startCopy();
        }
        else
        {
            timer->setInterval(copier->getRefreshRateSeconds()*1000);
        }
    }

    QFile settings(dataFileName);
    QFileInfo info(settings);
    if (!info.absoluteDir().exists())
        info.absoluteDir().mkpath(".");
    if (!settings.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        QMessageBox msgBox;
        msgBox.setText("Error Saving Settings to disk");
        msgBox.exec();
        return;
    }

    QTextStream out(&settings);
    out << REFRESH_KEY << "|" << copier->getRefreshRateSeconds() << endl;
    out << SOURCE_DIR_KEY << "|" << copier->getSourceDir() << endl;

    QStringList destDirs = copier->getDestDirs();

    for (int i=0; i<destDirs.length() ; i++)
    {
        out << DEST_DIR_KEY << "|" << destDirs.at(i) << endl;
    }
    settings.close();

    close();
}
Esempio n. 4
0
void ccCp(char *source, char *dest, char *hostList)
/* Copy source to dest on all files in hostList. */
{
time_t startTime = time(NULL);
time_t curTime, lastTime = 0;
struct machine *machineList = NULL;
struct netSwitch *nsList;
struct machine *m, *m2;
struct dlList *toDoList = newDlList();          /* We haven't done these. */
struct dlList *finishedList = newDlList();	/* All done here. */
struct dlList *sourceList = newDlList();        /* These are sources for copies. */
struct dlList *workingList = newDlList();       /* These are copying data to themselves. */
struct dlList *errList = newDlList();           /* These are messed up 3x or more. */
bool firstOk = FALSE;
struct dlNode *finNode, *node, *sourceNode, *destNode;
struct dyString *cmd = newDyString(256);
int machineCount;
int machinesFinished = 0;
char *thisHost = getenv("HOST");
off_t size;
int goodMachines;
double grandTotal;

/* Get host and switch info. */
readHosts(hostList, &machineList, &nsList);
machineCount = slCount(machineList);

/* Make sure file exists.... */
if (!fileExists(source))
    errAbort("%s doesn't exist\n", source);
size = fileSize(source);
printf("Copying %s (%lld bytes) to %d machines\n", source, (unsigned long long)size, machineCount);

/* Add everything to the to-do list. */
for (m = machineList; m != NULL; m = m->next)
    {
    dlAddValTail(toDoList, m);
    }


/* Loop through to-do list trying to do first copy. */
for (node = toDoList->head; node->next != NULL; node = node->next)
    {
    m = node->val;
    dyStringClear(cmd);
    m = node->val;
    if (sameString(thisHost, m->name))
	{
	if (sameString(source, dest))
	    {
	    /* Hey, this is too easy. */
	    firstOk = TRUE;
	    ++machinesFinished;
	    break;
	    }
	else
	    {
	    dyStringPrintf(cmd, "cp %s %s", source, dest);
	    }
	}
    else
	{
	dyStringPrintf(cmd, "rcp %s %s:%s", source, m->name, dest);
	}
    if (system(cmd->string) == 0)
	{
	dlRemove(node);
	dlAddTail(finishedList, node);
	firstOk = TRUE;
	++machinesFinished;
	break;
	}
    else  /* some error in rcp */
	{
	warn("Problem with %s\n", cmd->string);
	m->errCount += 1;
	}
    }

/* Loop around launching child processes to copy and
 * wait for them to finish. */
while (machinesFinished < machineCount)
    {
    int pid;
    int status;

    /* Start all possible copies. */
    while (matchMaker(finishedList, toDoList, &sourceNode, &destNode))
	{
	dlAddTail(sourceList, sourceNode);
	dlAddTail(workingList, destNode);
	m = destNode->val;
	m->sourceNode = sourceNode;
	startCopy(sourceNode->val, destNode->val, dest, thisHost, cmd);
	}

    curTime = time(NULL);
    if (curTime - lastTime >= 3)
	{
	printf("%d finished in %d seconds, %d in progress, %d to start, %d errors, %d total\n",
	    dlCount(finishedList) + dlCount(sourceList), (int)(curTime - startTime),
	    dlCount(workingList), dlCount(toDoList), dlCount(errList), machineCount);
	lastTime = curTime;
	}

    /* Wait for a child to finish.  Figure out which machine it is. */
    pid = wait(&status);
    finNode = NULL;
    for (node = workingList->head; node->next != NULL; node = node->next)
	{
	m = node->val;
	if (m->pid == pid)
	    {
	    finNode = node;
	    break;
	    }
	}
    if (finNode == NULL)
	{
	errAbort("Returned from wait on unknown child %d\n", pid);
	continue;
	}

    m = finNode->val;
    m->pid = 0;
    dlRemove(finNode);
    dlRemove(m->sourceNode);
    m2 = m->sourceNode->val;
    if (m->netSwitch != m2->netSwitch)
	--crossSwitchCount;
    dlAddTail(finishedList, m->sourceNode);

    if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
	{
	/* Good return - move self and source node to finished list. */
	++machinesFinished;
	dlAddTail(finishedList, finNode);
	}
    else
	{
	/* Bad return.  Increment error count, and maybe move it to
	 * error list. */
	if (++m->errCount >= maxErrCount)
	    {
	    ++machinesFinished;
	    dlAddTail(errList, finNode);
	    fprintf(stderr, "Gave up on %s\n", m->name);
	    }
	else
	    {
	    dlAddMiddle(toDoList, finNode);
	    fprintf(stderr, "Retry %d on %s\n", m->errCount, m->name);
	    }
	}
    }
if (!dlEmpty(errList))
    {
    fprintf(stderr, "errors in:");
    for (node = errList->head; node->next != NULL; node = node->next)
	{
	m = node->val;
	fprintf(stderr, " %s", m->name);
	}
    fprintf(stderr, "\n");
    }
goodMachines = dlCount(finishedList);
grandTotal = (double)goodMachines * (double)size;
printf("Copied to %d of %d machines (grand total %e bytes) in %d seconds\n", 
	goodMachines, machineCount, grandTotal, (int)(time(NULL) - startTime));
}
Esempio n. 5
0
int main(int argc, char** argv)
{
	::dama::XmlFactory damaFactory;
	boost::shared_ptr< ::dama::DamaModel > model = damaFactory.create("data/tasks/config.xml");

	::dama::Timer timer;
	
	/** Configurations */
	//model->debugMode = true;
	
	::std::size_t numRuns = 1;	// 200

	// calculate numRuns seeds (with value in srand you can change the seed set)
	srand(model->groupSeed);
	// srand(time(NULL));
	::std::vector < ::std::size_t > vecSeeds(numRuns, 0);
	for(::std::size_t u=0; u<numRuns; ++u)
		vecSeeds.at(u) = rand();


	// write benchmark header
	std::ofstream benchmarkHeader;
	benchmarkHeader.open("DamaBenchmark.csv", std::ios::app);
	// #iterations: not counted: if sample is unreachable from tree a or is exact a neighbor of tree a or if connected vertex is unreachable from tree b
	benchmarkHeader << "date,robot,nr,seed,solved,tGlobal,tIK,tSampling,tNNSearch,tPropagate,tConnect,iterations,edges,vertices,totalQueries,freeQueries,solVertices,solLength,solLengthMan";
	for(::std::size_t p=0; p<model->vecDamaPrim.size(); ++p)
		benchmarkHeader << "," << model->vecDamaPrim.at(p)->getName() ;
	benchmarkHeader << ::std::endl;
	benchmarkHeader.close();


	::std::vector <bool> vecSolved(numRuns, false);
	::std::vector < ::rl::math::Real > vecTime(numRuns, 0);
	::std::vector < ::std::size_t > vecIterations(numRuns, 0);
	::std::vector < ::std::size_t > vecEdges(numRuns, 0);
	::std::vector < ::std::size_t > vecVertices(numRuns, 0);
	::std::vector < ::std::size_t > vecSolutionVertices(numRuns, 0);
	::std::vector < ::rl::math::Real > vecSolutionLength(numRuns, 0);
	::std::vector < ::rl::math::Real > vecSolutionLengthManipulation(numRuns, 0);
	::std::vector < ::std::vector < ::std::size_t > > vecSolutionManipulationCount(numRuns, ::std::vector < ::std::size_t >(model->vecDamaPrim.size(), 0));


	rl::plan::VectorList path;
	::std::deque< ::std::string > actions;

	/*std::cout << "start: " << (*model->dRrt->start).transpose() << std::endl;
	std::cout << "goal: " << (*model->dRrt->goal).transpose() << std::endl;
	std::cout << "goalDefined: ";
	for(::std::size_t i=0; i<model->dRrt->goalDimDefined->size(); i++)
		std::cout << model->dRrt->goalDimDefined->at(i) << "\t";
	std::cout << std::endl;*/

	for(::std::size_t u=0; u<numRuns; ++u)
	{
		path.clear();
		actions.clear();

		srand(0);
		::std::size_t randSeedNumber = vecSeeds.at(u); //489012115 OR vecSeeds.at(u)
		::boost::mt19937::result_type randSeed = static_cast< ::boost::mt19937::result_type >((double)randSeedNumber);

		if(model->workspaceSampling)
			model->dRrt->setConfig(false, false, false);	// do NOT change this

		model->dRrt->seed(randSeed);
		model->dRrt->resetStatistics();
		model->dRrt->duration = ::std::chrono::duration_cast< ::std::chrono::steady_clock::duration >( ::std::chrono::duration< double >(180.0)); //900.0 //300.0; //1200.0 //boost::lexical_cast< rl::math::Real >(::std::numeric_limits< double >::max());
		// TODO: hierarchical version currently needs this to be redefined ...
		rl::math::Vector startCopy(*(model->dRrt->start));
		model->dRrt->start = &startCopy;
		rl::math::Vector goalCopy(*(model->dRrt->goal));
		model->dRrt->goal = &goalCopy;
		::std::vector < bool > goalDimDefinedCopy(*(model->dRrt->goalDimDefined));
		model->dRrt->goalDimDefined = &goalDimDefinedCopy;
		std::cout << "Start solving nr. " << (u+1) << "/" << numRuns << " with seed " << randSeedNumber << " ... " << std::endl;
		timer.start();
		vecSolved.at(u) = model->dRrt->solveAll(path, actions);
		timer.stop();
		if(vecSolved.at(u))
		{
			::std::string lastAction = "";
			rl::plan::VectorList::iterator i = path.begin();
			rl::plan::VectorList::iterator j = ++path.begin();
			::std::deque< ::std::string >::iterator e = actions.begin();
			for (; i != path.end() && j != path.end() && e != actions.end(); ++i, ++j, ++e)
			{
				::rl::math::Real tempRobotDist = model->cartesianRobotDistance(*i, *j);
				vecSolutionLength.at(u) += tempRobotDist;
				if(*e != ::dama::DamaPrimTransit::getInstance()->getName())
					vecSolutionLengthManipulation.at(u) += tempRobotDist;
				if(lastAction != *e)
				{
					for(::std::size_t p=0; p<vecSolutionManipulationCount.at(u).size(); ++p)
						if(e->substr(0, model->vecDamaPrim.at(p)->getName().size()) == model->vecDamaPrim.at(p)->getName())
							vecSolutionManipulationCount.at(u).at(p) ++;
				}
				lastAction = *e;
			}
		}
		vecTime.at(u) = timer.elapsed();
		vecIterations.at(u) = model->dRrt->getIterationCount();
		vecEdges.at(u) = model->dRrt->getEdgeCount();
		vecVertices.at(u) = model->dRrt->getVertexCount();
		vecSolutionVertices.at(u) = path.size();
		std::cout << "solved: " << vecSolved.at(u) << " \t time: " << vecTime.at(u) << " \t iterations: " << vecIterations.at(u) << " \t edges: " << vecEdges.at(u) << " \t vertices: " << vecVertices.at(u) << " \t vertices (solution): " << vecSolutionVertices.at(u) << " \t length: " << vecSolutionLength.at(u) << " \t length (manipulation only): " << vecSolutionLengthManipulation.at(u) << std::endl;

		// Export statistics to benchmark file
		std::ofstream benchmark;
		benchmark.open("DamaBenchmark.csv", std::ios::app);
#if !QT_KRAMS
		// Current date/time based on current system
		time_t now = time(0);
		// Convert now to tm struct for local timezone
		tm* localtm = localtime(&now);
		benchmark << asctime(localtm) << ",";
#else
		benchmark << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString() << ",";
#endif
		benchmark << model->prefixName << ",";
		benchmark << (u+1) << ",";
		benchmark << randSeedNumber << ",";
		benchmark << (vecSolved.at(u) ? "true" : "false") << ",";
		benchmark << vecTime.at(u) << ",";
		benchmark << model->timeIK << ",";
		benchmark << model->dRrt->getTimeSampling() << ",";
		benchmark << model->dRrt->getTimeNNSearch() << ",";
		benchmark << model->dRrt->getTimePropagate() << ",";
		benchmark << model->dRrt->getTimeConnect() << ",";
		benchmark << vecIterations.at(u) << ",";
		benchmark << vecEdges.at(u) << ",";
		benchmark << vecVertices.at(u) << ",";
		benchmark << model->getTotalQueries() << ",";
		benchmark << model->getFreeQueries() << ",";
		benchmark << vecSolutionVertices.at(u) << ",";
		benchmark << vecSolutionLength.at(u) << ",";
		benchmark << vecSolutionLengthManipulation.at(u) << ",";
		for(::std::size_t p=0; p<vecSolutionManipulationCount.at(u).size(); ++p)
			benchmark << vecSolutionManipulationCount.at(u).at(p) << ",";
		benchmark << std::endl;
		benchmark.close();
	}
	
	
	return EXIT_SUCCESS;
}