Esempio n. 1
0
void Script::execute(uint32 callMode) {
	if (!shouldExecute(callMode)) {
		return;
	}

	if (isSuspended()) {
		// If the script is suspended, check if it can be resumed
		updateSuspended();
	}

	uint32 executedCommands = 0;
	while (1) {
		if (isSuspended()) {
			break;
		}

		if (!_nextCommand) {
			break; // No next command, stop here
		}

		if (isOnEnd()) {
			break; // Reached the end of the script
		}

		_nextCommand = _nextCommand->execute(callMode, this);

		executedCommands++;

		if (executedCommands > 50) {
			break; // Too many consecutive commands
		}
	}

	if (isOnEnd() || !_nextCommand) {
		// Reset ended scripts so they can be started again
		reset();

		// Check if we should return to some caller script
		if (!_returnObjects.empty()) {
			Object *callerObject = _returnObjects.back();
			_returnObjects.pop_back();

			// Resume execution of the caller object
			resumeCallerExecution(callerObject);
		}
	}
}
Esempio n. 2
0
char doJobs( jobs jlist[], int number_of_jobs )
{    
    int result, check;
    int index = 0;
    int mt, d, y, h, m, s, update_index;
    char time_update_buff [strlen(jlist[ index ].dateTime)];
    
    time_t epoch_time;
    struct tm *tm_p = NULL;
    epoch_time = time( NULL );
    tm_p = localtime( &epoch_time );
 
    jberrno = 0;
    
    for ( index; index < number_of_jobs; index++)
    {
        // If the job needs to be executed -> do it
        if( shouldExecute( jlist[ index ].dateTime ))
        {
            result = recursiveCopy( jlist[ index ].from, jlist[ index ].to, 1);
        }
        else
        {
            if (BUGS)
                printf("\nShould not be ran today.\n");
        }

        // If something went wrong with the backup, notify. 
        if ( result )
        {
            jberrno = ERROR_RECURSING_JOB_DIR;
            if(BUGS) printf("\n%s %s\n\n", jbetoa(),  jlist[ index ].title);
        }
        else
        {
            // UPDATE MONTH / DAY to next update period.
            // IF MONTH > -1 : ++month - leave day alone
            // IF MONTH == -1 && day > -1 ++day
            // THIS IS ALL ASSUMING THAT ITS NOT A YEARLY BACKUP, AND 
            // THAT HOUR/MIN/SEC DOESNT CHANGE
            // TURN ALL TO INTS FOR LATER IF NEEDS TO BE MODIFIED
            
            sscanf(jlist[ index ].dateTime, 
            "%d"TIME_SEPARATOR"%d"TIME_SEPARATOR
            "%d"TIME_SEPARATOR"%d"TIME_SEPARATOR
            "%d"TIME_SEPARATOR"%d"TIME_SEPARATOR"%d",
            &y, &mt, &d, &h, &m, &s, &update_index);
            
            // NEED TO BETTER MANAGE THE INCRIMENTING OF DAYS
            if( mt > -1 )
            {
                if( mt+update_index > 12) // If its larger than 12
                {
                     mt = (mt+update_index)%12; //set num months larger.
                }
                else
                {
                    tm_p->tm_mon += update_index+1;     // Adds index to mon, Leave the +1
                    mt = tm_p->tm_mon;
                }
            }
            if( mt == -1 && d > -1 )                    // If mon not given, assume daily
            {
                if ( tm_p->tm_mday >= 28 )              // not quite monthly
                    tm_p->tm_mday = 0;
                tm_p->tm_mday += update_index;
                d = tm_p->tm_mday;
            }
            // Set time_update_buff before updating job file
            check = sprintf(time_update_buff,
            "%d"TIME_SEPARATOR"%d"TIME_SEPARATOR
            "%d"TIME_SEPARATOR"%d"TIME_SEPARATOR
            "%d"TIME_SEPARATOR"%d"TIME_SEPARATOR"%d",
            y, mt, d, h, m, s, update_index);
                
            if ( check < 0 )
            {
                jberrno = ERROR_SETTING_TIME_BUFF;
                if(BUGS) printf("\n%s\n", jbetoa());
                return -1;   
            }
            else
            {
                strcpy(jlist[ index ].dateTime, time_update_buff);
                updateJobFile( jlist, index );
            }
        }   // END OF RESULT ELSE
    }   // END JOB LOOP
	return 0;
}