예제 #1
0
void TDMTeam::checkPowerUps() {
    std::vector<Ship*> ships = ships::getShips();
    bool existAny(false);

    for (std::vector<Ship*>::const_iterator it = ships.begin(); it != ships.end(); ++it)
        if ((*it)->getOwner()->team() != this && (*it)->attackable()) {
            existAny = true;
            break;
        }

    powerUpLocations_.clear();
    std::list<PowerUp*> const& powerUps = items::getPowerUps();
    for (std::list<PowerUp*>::const_iterator it=powerUps.begin(); it!=powerUps.end(); ++it) {
        if (!(*it)->isCollected()) {
            powerUpLocations_.push_back((*it)->location());
            switch ((*it)->type()) {
                case items::puFuel:     addJob(Job(Job::jGetPUFuel,    70, &powerUpLocations_.back())); break;
                case items::puHealth:   addJob(Job(Job::jGetPUHealth,  70, &powerUpLocations_.back())); break;
                case items::puReverse:  if (existAny) addJob(Job(Job::jGetPUReverse, 70, &powerUpLocations_.back())); break;
                case items::puShield:   addJob(Job(Job::jGetPUShield,  70, &powerUpLocations_.back())); break;
                default:                if (existAny) addJob(Job(Job::jGetPUSleep,   70, &powerUpLocations_.back())); break;
            }
        }
    }
}
예제 #2
0
void TDMTeam::createJobs() {
    checkEnemies();
    checkPowerUps();

    for (int i=0; i<botControllers_.size(); ++i) {
        addJob(Job(Job::jLand, 4));
        addJob(Job(Job::jCharge, 4));
    }
}
예제 #3
0
/** Creates a new CheckOperation.
    @param d the Device where the Partition to check is on.
    @param p the Partition to check
*/
CheckOperation::CheckOperation(Device& d, Partition& p) :
    Operation(),
    m_TargetDevice(d),
    m_CheckedPartition(p),
    m_CheckJob(new CheckFileSystemJob(checkedPartition())),
    m_MaximizeJob(new ResizeFileSystemJob(targetDevice(), checkedPartition()))
{
    addJob(checkJob());
    addJob(maximizeJob());
}
예제 #4
0
void* CMgrJob :: dwLoopIOWork(){
	
	LPTESTCASE  IOJob;
	while(loopWorking){
		if(IOJob = getIOJob())
		{
			switch(IOJob->getStage())
			{
				case INIT_STAGE:			
					IOJob->doReading();
					IOJob->setStage(READ_END_STAGE);
					addJob(IOJob);
					break;
				case MODEL_END_STAGE:
					IOJob->doWriting();
					IOJob->setStage(WRITE_END_STAGE);
					delete IOJob;
					break;
				default:
					break;
			}
			//IOJob->doParsing(IOJob);
			//addIOJob(dealJob);
			//sleep(1);
		}
		else
		{
			//cout<<"sleeping"<<endl;
			//sleep(1);
		}
		//cout<<"loopWorking"<<endl;
	}
	
	return 0;
}
예제 #5
0
/*组合键命令ctrl+c*/
void ctrl_C(){
	Job *now = NULL;
    //前台没有作业直接返回
	if(fgPid == 0){
	    return;
	}
    //SIGNCHLD信号产生自此函数
	ingnore = 1;

	now = head;
	while (now != NULL && now -> pid != fgPid)
		now = now -> next;

	if (now == NULL){
		now = addJob(fgPid);    //没有前台作业则根据fgPid 添加
	}

	strcpy(now -> state, DONE);
	now -> cmd[strlen(now -> cmd)] = '&';
	now -> cmd[strlen(now -> cmd) + 1] = '\0';
	printf("[%d]\t%s\t\t%s\n",now -> pid, now -> state, now -> cmd);

	kill (fgPid, SIGKILL);             //sigstop -> sigkill
	fgPid = 0;

	//需要删除在作业链表中的当前作业
	
	head = now->next;
	
	free(now);
}
예제 #6
0
/**
 * @brief Process a PSP_ACCOUNT_LOG msg.
 *
 * This message is send from the logger with information
 * only the logger knows.
 *
 * @param msg The msg to handle.
 *
 * @return No return value.
 */
static void handleAccountLog(DDTypedBufferMsg_t *msg)
{
    PStask_ID_t logger;
    Job_t *job;
    size_t used = 0;

    PSP_getTypedMsgBuf(msg, &used, __func__, "logger", &logger, sizeof(logger));

    /* get job */
    job = findJobByLogger(logger);
    if (!job) job = addJob(logger);

    uint64_t dummy;
    PSP_getTypedMsgBuf(msg, &used, __func__, "rank(skipped)", &dummy,
		       sizeof(int32_t));
    PSP_getTypedMsgBuf(msg, &used, __func__, "uid(skipped)", &dummy,
		       sizeof(uid_t));
    PSP_getTypedMsgBuf(msg, &used, __func__, "gid(skipped)", &dummy,
		       sizeof(gid_t));
    PSP_getTypedMsgBuf(msg, &used, __func__, "total children (skipped)", &dummy,
		       sizeof(int32_t));

    /* set the job ID */
    if (!job->jobid) job->jobid = ustrdup(msg->buf+used);
}
///function that redirects output
void redirectOutput(char** argv, char* outfile, char* cline)
{
	pid_t id1;
	int id;
	

	int fd1 = open(outfile, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
	
	if ((id1 = fork()) < 0) 
	{
		perror("fork");
		exit(0);
	}
	id = id1;
	if (id1 == 0)
	{	
		
		///send output to the outfile
		dup2(fd1, STDOUT_FILENO);
		close(fd1);
		execvp(argv[0], argv);
		fprintf(stderr, "%s: Command not found.\n", argv[0]);
	}
	else
	{
		addJob(id, cline);
		if (back == 0)
			waitpid(id1, NULL, 0);
	}
}
///function that executes a program
void execute(char* prog, char* argv[], char* cmd)
{
	
	struct stat statbuf;

		
		int id;
		lstat(prog, &statbuf);
		
	   	
		   	int pid;
		   	
			if ((pid = fork()) < 0)
			{
				perror("fork");
				exit(-1);
			}
			id = pid;
			globalPid = pid;
			//addJob(pid, cmd);
			if (pid == 0)
			{
				execvp(prog, argv);
				
				fprintf(stderr, "%s: Command not found.\n", prog);
				exit(-1);
			}
			else
			{
				addJob(id, cmd);
				if (back == 0)
					waitpid(pid, NULL, 0);
			}
	   	
}
///function that redirects input
void redirectInput(char** argv, char* infile, char* cline)
{
	
	pid_t id1;
	int id;
	
	if ((id1 = fork()) < 0) 
	{
		perror("fork");
		exit(0);
	}
	id = id1;
	if (id1 == 0)
	{	
		int fd1 = open(infile, O_RDONLY, S_IRUSR);
		///send input from the infile
		dup2(fd1, STDIN_FILENO);
		close(fd1);
		execvp(argv[0], argv);
		
		fprintf(stderr, "%s: Command not found.\n", argv[0]);
	}
	else
	{
		addJob(id, cline);
		if (back == 0)
			waitpid(id1, NULL, 0);
	}
}
예제 #10
0
/*组合键命令ctrl+z*/
void ctrl_Z(){
    Job *now = NULL;
    
    if(fgPid == 0){ //前台没有作业则直接返回
        return;
    }
    
    //SIGCHLD信号产生自ctrl+z
    ingnore = 1;
    
	now = head;
	while(now != NULL && now->pid != fgPid)
		now = now->next;

    if(now == NULL){ //未找到前台作业,则根据fgPid添加前台作业
        now = addJob(fgPid);
    }
    
	//修改前台作业的状态及相应的命令格式,并打印提示信息
    strcpy(now->state, STOPPED); 
    now->cmd[strlen(now->cmd)] = '&';
    now->cmd[strlen(now->cmd) + 1] = '\0';
    printf("[%d]\t%s\t\t%s\n", now->pid, now->state, now->cmd);
    
	//发送SIGSTOP信号给正在前台运作的工作,将其停止
    kill(fgPid, SIGSTOP);
    fgPid = 0;
}
예제 #11
0
/** Creates a new CreatePartitionTableOperation.
    @param d the Device to create the new PartitionTable on
    @param ptable pointer to the new partition table object. the operation takes ownership.
*/
CreatePartitionTableOperation::CreatePartitionTableOperation(Device& d, PartitionTable* ptable) :
    Operation(),
    m_TargetDevice(d),
    m_OldPartitionTable(targetDevice().partitionTable()),
    m_PartitionTable(ptable),
    m_CreatePartitionTableJob(new CreatePartitionTableJob(targetDevice()))
{
    addJob(createPartitionTableJob());
}
예제 #12
0
/** Creates a new CreatePartitionTableOperation.
    @param d the Device to create the new PartitionTable on
    @param t the type for the new PartitionTable
*/
CreatePartitionTableOperation::CreatePartitionTableOperation(Device& d, PartitionTable::TableType t) :
    Operation(),
    m_TargetDevice(d),
    m_OldPartitionTable(targetDevice().partitionTable()),
    m_PartitionTable(new PartitionTable(t, PartitionTable::defaultFirstUsable(d, t), PartitionTable::defaultLastUsable(d, t))),
    m_CreatePartitionTableJob(new CreatePartitionTableJob(targetDevice()))
{
    addJob(createPartitionTableJob());
}
예제 #13
0
void DownloadQueueSet::retryJobs()
{
    while ( !m_retryQueue.isEmpty() ) {
        HttpJob * const job = m_retryQueue.dequeue();
        mDebug() << "Requeuing" << job->destinationFileName();
        // FIXME: addJob calls activateJobs every time
        addJob( job );
    }
}
예제 #14
0
void JobManager::update()
{
    bool resume = m_resumeId.isEmpty();
    foreach(const Region &region, m_regions) {
        resume = resume || region.id() == m_resumeId;
        if (resume) {
            addJob(region);
        }
    }
예제 #15
0
/*
 * Called externally to add a job to be run.
 */
long deferNanoSec(callback_t callback, void *proc_obj, long long nanoSecs)
{ 
	timer_t timerid;
	struct sigevent sev;
	struct itimerspec its;
	sigset_t mask;
	struct sigaction sa;

	sa.sa_flags = SA_SIGINFO;
	sa.sa_sigaction = handler;
	sigemptyset(&sa.sa_mask);
	if (sigaction(SIG, &sa, NULL) == -1)
		printf("sigaction");

	/* Block timer signal temporarily */
	sigemptyset(&mask);
	sigaddset(&mask, SIG);
	if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1)
		printf("sigprocmask");
	
	struct timespec tp, waitTime;
	clock_gettime(CLOCK_MONOTONIC, &tp);
	waitTime.tv_sec = nanoSecs / 1000000000;
	waitTime.tv_nsec = nanoSecs % 1000000000;

	Job* job = malloc( sizeof(Job) );
	job->callback = callback;
	job->proc_obj = proc_obj;
	job->creationTime = tp;
	job->waitTime = waitTime;

	addJob( &g_jobs, job );
	
	
	/* Create the timer */
	sev.sigev_notify = SIGEV_SIGNAL;
	sev.sigev_signo = SIG;
	sev.sigev_value.sival_ptr = &timerid;
	if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1)
		printf("timer_create");

	/* Start the timer */
	its.it_value = waitTime;
	its.it_interval.tv_sec = 0;
	its.it_interval.tv_nsec = 0;

	if (timer_settime(timerid, 0, &its, NULL) == -1)
		printf("timer_settime");

	/* Unlock the timer signal, so that timer notification
	 *               can be delivered */
	if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1)
		printf("sigprocmask");

	return (long)job;
}
예제 #16
0
void TDMTeam::checkEnemies() {
    std::vector<Ship*> ships = ships::getShips();
    bool existAny(false);

    for (std::vector<Ship*>::const_iterator it = ships.begin(); it != ships.end(); ++it)
        if ((*it)->getOwner()->team() != this && (*it)->attackable()) {
            existAny = true;
            break;
        }

    if (existAny) {
        for (int i=0; i<botControllers_.size(); ++i)
            addJob(Job(Job::jAttackAny, 60));
    }
    else {
        for (int i=0; i<botControllers_.size(); ++i)
            addJob(Job(Job::jEscape, 6));
    }
}
예제 #17
0
void JobListWidget::setJobs(QMap<QString, JobPtr> jobs)
{
    setUpdatesEnabled(false);
    clear();
    for(const JobPtr &job : jobs)
    {
        addJob(job);
    }
    setUpdatesEnabled(true);
}
예제 #18
0
/** Creates a new SetPartFlagsOperation.
    @param d the Device on which the Partition to set flags for is
    @param p the Partition to set new flags for
    @param flags the new flags to set
*/
SetPartFlagsOperation::SetPartFlagsOperation(Device& d, Partition& p, const PartitionTable::Flags& flags) :
    Operation(),
    m_TargetDevice(d),
    m_FlagPartition(p),
    m_OldFlags(flagPartition().activeFlags()),
    m_NewFlags(flags),
    m_FlagsJob(new SetPartFlagsJob(targetDevice(), flagPartition(), newFlags()))
{
    addJob(flagsJob());
}
예제 #19
0
void ThreadPool::join(void)
{
    std::vector<boost::thread *>::iterator itr;

    // To break infinite loop to join, give dummy 'break job'
    addJob(breakLoop, 0);
    
    for(itr = threads.begin(); itr != threads.end(); ++itr){
        (*itr)->join();
    }
}
QTreeWidgetItem* ProgressTree2::findItem(Job* job, bool create)
{
    QList<Job*> path;
    Job* v = job;
    while (v) {
        path.insert(0, v);
        v = v->parentJob;
    }

    QTreeWidgetItem* c = 0;
    for (int i = 0; i < path.count(); i++) {
        Job* toFind = path.at(i);
        QTreeWidgetItem* found = 0;
        if (i == 0) {
            for (int j = 0; j < this->topLevelItemCount(); j++) {
                QTreeWidgetItem* item = this->topLevelItem(j);
                Job* v = getJob(*item);
                if (v == toFind) {
                    found = item;
                    break;
                }
            }
        } else {
            for (int j = 0; j < c->childCount(); j++) {
                QTreeWidgetItem* item = c->child(j);
                Job* v = getJob(*item);
                if (v == toFind) {
                    found = item;
                    break;
                }
            }
        }
        if (found)
            c = found;
        else {
            if (create) {
                if (!toFind->parentJob)
                    c = addJob(toFind);
                else {
                    QTreeWidgetItem* subItem = new QTreeWidgetItem(c);
                    fillItem(subItem, toFind);
                    if (autoExpandNodes)
                        c->setExpanded(true);
                    c = subItem;
                }
            } else {
                c = 0;
                break;
            }
        }
    }

    return c;
}
예제 #21
0
/** Creates a new DeleteOperation
    @param d the Device to delete a Partition on
    @param p pointer to the Partition to delete. May not be nullptr
*/
DeleteOperation::DeleteOperation(Device& d, Partition* p, ShredAction shred) :
    Operation(),
    m_TargetDevice(d),
    m_DeletedPartition(p),
    m_ShredAction(shred),
    m_DeletePartitionJob(new DeletePartitionJob(targetDevice(), deletedPartition()))
{
    switch (shredAction()) {
    case NoShred:
        m_DeleteFileSystemJob = static_cast<Job*>(new DeleteFileSystemJob(targetDevice(), deletedPartition()));
        break;
    case ZeroShred:
        m_DeleteFileSystemJob = static_cast<Job*>(new ShredFileSystemJob(targetDevice(), deletedPartition(), false));
        break;
    case RandomShred:
        m_DeleteFileSystemJob = static_cast<Job*>(new ShredFileSystemJob(targetDevice(), deletedPartition(), true));
    }

    addJob(deleteFileSystemJob());
    addJob(deletePartitionJob());
}
void XournalScheduler::addRepaintSidebar(SidebarPreviewBaseEntry* preview)
{
	XOJ_CHECK_TYPE(XournalScheduler);

	if (existsSource(preview, JOB_TYPE_PREVIEW, JOB_PRIORITY_HIGH))
	{
		return;
	}

	PreviewJob* job = new PreviewJob(preview);
	addJob(job, JOB_PRIORITY_HIGH);
	job->unref();
}
void XournalScheduler::addRerenderPage(PageView* view)
{
	XOJ_CHECK_TYPE(XournalScheduler);

	if (existsSource(view, JOB_TYPE_RENDER, JOB_PRIORITY_URGENT))
	{
		return;
	}

	RenderJob* job = new RenderJob(view);
	addJob(job, JOB_PRIORITY_URGENT);
	job->unref();
}
/** Creates a new RestoreOperation.
	@param d the Device to restore the Partition to
	@param p pointer to the Partition that will be restored. May not be NULL.
	@param filename name of the image file to restore from
*/
RestoreOperation::RestoreOperation(Device& d, Partition* p, const QString& filename) :
	Operation(),
	m_TargetDevice(d),
	m_RestorePartition(p),
	m_FileName(filename),
	m_OverwrittenPartition(NULL),
	m_MustDeleteOverwritten(false),
	m_ImageLength(QFileInfo(filename).size() / 512), // 512 being the "sector size" of an image file.
	m_CreatePartitionJob(NULL),
	m_RestoreJob(NULL),
	m_CheckTargetJob(NULL),
	m_MaximizeJob(NULL)
{
	restorePartition().setState(Partition::StateRestore);

	Q_ASSERT(targetDevice().partitionTable());

	Partition* dest = targetDevice().partitionTable()->findPartitionBySector(restorePartition().firstSector(), PartitionRole(PartitionRole::Primary | PartitionRole::Logical | PartitionRole::Unallocated));

	Q_ASSERT(dest);

	if (dest == NULL)
		qWarning() << "destination partition not found at sector " << restorePartition().firstSector();

	if (dest && !dest->roles().has(PartitionRole::Unallocated))
	{
		restorePartition().setLastSector(dest->lastSector());
		setOverwrittenPartition(dest);
		removePreviewPartition(targetDevice(), *dest);
	}

	if (!overwrittenPartition())
		addJob(m_CreatePartitionJob = new CreatePartitionJob(targetDevice(), restorePartition()));

	addJob(m_RestoreJob = new RestoreFileSystemJob(targetDevice(), restorePartition(), fileName()));
	addJob(m_CheckTargetJob = new CheckFileSystemJob(restorePartition()));
	addJob(m_MaximizeJob = new ResizeFileSystemJob(targetDevice(), restorePartition()));
}
예제 #25
0
SimulateThread::SimulateThread(RoadRunner* rri, bool autoStart)
:
RoadRunnerThread()
{
	if(rri)
    {
    	addJob(rri);
    }

	if(autoStart && rri != NULL)
    {
    	start();
    }
}
예제 #26
0
파일: SBTeam.cpp 프로젝트: AlohaWu/M.A.R.S.
void SBTeam::checkBall() {
    Ball* ball = balls::getBall();
    if (ball) {
        if (!ball->isVisible()) {
            int waitCount(settings::C_iDumb*(botControllers_.size()+1)/200);
            for (int i=0; i<waitCount; ++i)
                addJob(Job(Job::jWaitForBall, 5, ball));
        }
        else {
            int ballZone(zones::isInside(this, *ball));
            switch (ballZone) {
                case OWN_HOME:
                    for (int i=0; i<botControllers_.size(); ++i)
                        addJob(Job(Job::jKickOutHome, 90, ball));
                    break;

                case OWN_TEAM: {
                    std::map<float, TacticalZone*> zones(zones::toProtect(this));
                    std::map<float, TacticalZone*>::iterator currentZone = zones.begin();
                    int protectJobs(botControllers_.size()*0.5);
                    while(protectJobs > 0) {
                        for (int i=0; i<(protectJobs+1)*0.5; ++i)
                            addJob(Job(Job::jProtectZone, 30,  currentZone->second));
                        protectJobs /= 2;
                        if (++currentZone == zones.end())
                            currentZone = zones.begin();
                    }
                    for (int i=botControllers_.size()*0.5f; i<botControllers_.size(); ++i)
                        addJob(Job(Job::jKickToEnemy, 60, ball));
                    for (int i=0; i<botControllers_.size()*0.5; ++i)
                        addJob(Job(Job::jKickOutHome, 40, ball));

                    break;
                }
                default: {
                    std::map<float, TacticalZone*> zones(zones::toProtect(this));
                    std::map<float, TacticalZone*>::iterator currentZone = zones.begin();
                    int protectJobs(botControllers_.size()*0.4);
                    while(protectJobs > 0) {
                        for (int i=0; i<(protectJobs+1)*0.5; ++i)
                            addJob(Job(Job::jProtectZone, 20,  currentZone->second));
                        protectJobs /= 2;
                        if (++currentZone == zones.end())
                            currentZone = zones.begin();
                    }
                    for (int i=0; i<botControllers_.size()*0.6f; ++i)
                        addJob(Job(Job::jKickToEnemy, 60, ball));
                }
            }
        }
    }
}
예제 #27
0
/** Creates a new NewOperation.
    @param d the Device to create a new Partition on
    @param p pointer to the new Partition to create. May not be nullptr.
*/
NewOperation::NewOperation(Device& d, Partition* p) :
    Operation(),
    m_TargetDevice(d),
    m_NewPartition(p),
    m_CreatePartitionJob(new CreatePartitionJob(targetDevice(), newPartition())),
    m_CreateFileSystemJob(nullptr),
    m_SetPartFlagsJob(nullptr),
    m_SetFileSystemLabelJob(nullptr),
    m_CheckFileSystemJob(nullptr)
{
    addJob(createPartitionJob());

    const FileSystem& fs = newPartition().fileSystem();

    if (fs.type() != FileSystem::Extended) {
        // It would seem tempting to skip the CreateFileSystemJob or the
        // SetFileSystemLabelJob if either has nothing to do (unformatted FS or
        // empty label). However, the user might later on decide to change FS or
        // label. The operation stack will merge these operations with this one here
        // and if the jobs don't exist things will break.

        m_CreateFileSystemJob = new CreateFileSystemJob(targetDevice(), newPartition());
        addJob(createFileSystemJob());

        if (fs.type() == FileSystem::Lvm2_PV) {
            m_SetPartFlagsJob = new SetPartFlagsJob(targetDevice(), newPartition(), PartitionTable::FlagLvm);
            addJob(setPartFlagsJob());
        }

        m_SetFileSystemLabelJob = new SetFileSystemLabelJob(newPartition(), fs.label());
        addJob(setLabelJob());

        m_CheckFileSystemJob = new CheckFileSystemJob(newPartition());
        addJob(checkJob());
    }
}
void SupportiveTranslationUnitInitializer::checkIfParseJobFinished(const Jobs::RunningJob &job)
{
    QTC_CHECK(m_state == State::WaitingForParseJob);
    if (abortIfDocumentIsClosed())
        return;

    if (job.jobRequest.type == JobRequest::Type::ParseSupportiveTranslationUnit) {
        m_jobs.setJobFinishedCallback([this](const Jobs::RunningJob &runningJob) {
            checkIfReparseJobFinished(runningJob);
        });

        addJob(JobRequest::Type::ReparseSupportiveTranslationUnit);

        m_state = State::WaitingForReparseJob;
    }
}
void SupportiveTranslationUnitInitializer::startInitializing()
{
    QTC_CHECK(m_state == State::NotInitialized);
    if (abortIfDocumentIsClosed())
        return;

    m_document.translationUnits().createAndAppend();

    m_jobs.setJobFinishedCallback([this](const Jobs::RunningJob &runningJob) {
        checkIfParseJobFinished(runningJob);
    });
    addJob(JobRequest::Type::ParseSupportiveTranslationUnit);
    m_jobs.process();

    m_state = State::WaitingForParseJob;
}
void SupportiveTranslationUnitInitializer::checkIfReparseJobFinished(const Jobs::RunningJob &job)
{
    QTC_CHECK(m_state == State::WaitingForReparseJob);
    if (abortIfDocumentIsClosed())
        return;

    if (job.jobRequest.type == JobRequest::Type::ReparseSupportiveTranslationUnit) {
        if (m_document.translationUnits().areAllTranslationUnitsParsed()) {
            m_jobs.setJobFinishedCallback(nullptr);
            m_state = State::Initialized;
        } else {
            // The supportive translation unit was reparsed, but the document
            // revision changed in the meanwhile, so try again.
            addJob(JobRequest::Type::ReparseSupportiveTranslationUnit);
        }
    }
}