void ActionGenerateReport::drop_trigger(db_mysql_TriggerRef trigger, bool for_alter) {
  dictionary->addSectionDictionary(kbtr_DROP_TRIGGER)->setValue(kbtr_DROP_TRIGGER_NAME, trigger_name(trigger));
}
Exemple #2
0
PredicateTimerDetails *Predicate::scheduleTimerEvents(PredicateTimerDetails *earliest, MachineInstance *target) // setup timer events that trigger the supplied machine
{
    long scheduled_time = -100000;
    long current_time = 0;
    // below, we check the clauses of this predicate and if we find a timer test
    // we set the above variables. At the end of the method, we actually set the timer

	if (left_p) earliest = left_p->scheduleTimerEvents(earliest, target);

    // clauses like (machine.TIMER >= 10)
    if (left_p
		&& left_p->entry.kind == Value::t_symbol
		&& left_p->entry.token_id == ClockworkToken::TIMER
		&& right_p) {
		//std::cout << "checking timers on " << right_p->entry << " " << left_p->entry << "\n";
        if ( (right_p->entry.kind == Value::t_symbol
			&& target->getValue(right_p->entry.sValue).asInteger(scheduled_time))
            || right_p->entry.asInteger(scheduled_time)) {
            current_time = target->getTimerVal()->iValue;
			if (op == opGT || op == opLE) ++scheduled_time;
		}
        else
            DBG_MSG << "Error: clause " << *this << " does not yield an integer comparison\n";
    }
    else if (left_p
			 && left_p->entry.kind == Value::t_symbol
			 && stringEndsWith(left_p->entry.sValue,".TIMER")) {
		//std::cout << "checking timers on " << right_p->entry << " " << left_p->entry << "\n";
        if ( (right_p->entry.kind == Value::t_symbol
				&& target->getValue(right_p->entry.sValue).asInteger(scheduled_time))
				|| right_p->entry.asInteger(scheduled_time)) {
            // lookup the machine
            MachineInstance *timed_machine = 0;
            size_t pos = left_p->entry.sValue.find('.');
            std::string machine_name(left_p->entry.sValue);
            machine_name.erase(pos);
            timed_machine = target->lookup(machine_name);
            if (timed_machine) {
				current_time = timed_machine->getTimerVal()->iValue;
				if (op == opGT || op == opLE) ++scheduled_time;
			}
        }
        else
            DBG_MSG << "Error: clause " << *this << " does not yield an integer comparison\n";
    }
    
    // clauses like (10 <= TIMER)
    else if (right_p
			&& right_p->entry.kind == Value::t_symbol
			&& right_p->entry.token_id == ClockworkToken::TIMER
			&& left_p) {
		//std::cout << "checking timers on " << left_p->entry << "\n";
        if ( (left_p->entry.kind == Value::t_symbol
				&& target->getValue(left_p->entry.sValue).asInteger(scheduled_time))
				|| left_p->entry.asInteger(scheduled_time)) {
            current_time = target->getTimerVal()->iValue;
			if (op == opGT || op == opLE) ++scheduled_time;
		}
        else
            DBG_MSG << "Error: clause " << *this << " does not yield an integer comparison\n";
    }
	// clauses like (10 <= machine.TIMER)
    else if (right_p
			&& left_p
			&& right_p->entry.kind == Value::t_symbol
			&& stringEndsWith(right_p->entry.sValue,".TIMER")) {
		//std::cout << "checking timers on " << left_p->entry << " " << right_p->entry << "\n";
        if ( (left_p->entry.kind == Value::t_symbol && target->getValue(left_p->entry.sValue).asInteger(scheduled_time))
            || left_p->entry.asInteger(scheduled_time)
			) {
            // lookup and cache the machine
            MachineInstance *timed_machine = 0;
            size_t pos = right_p->entry.sValue.find('.');
            std::string machine_name(right_p->entry.sValue);
            machine_name.erase(pos);
            timed_machine = target->lookup(machine_name);
            if (timed_machine) {
				current_time = timed_machine->getTimerVal()->iValue;
				if (op == opGT || op == opLE) ++scheduled_time;
			}
        }
        else
            DBG_MSG << "Error: clause " << *this << " does not yield an integer comparison\n";
    }
    else {
        
    }
    //TBD there is an issue with testing current_time <= scheduled_time because there may have been some
    // processing delays and current time may already be a little > scheduled time. This is especially
    // true on slow clock cycles. For now we reschedule the trigger for up to 2ms past the necessary time.

	if (scheduled_time != -100000) {
		long t = (scheduled_time - current_time) * 1000;
		if (t > 0) {
			DBG_SCHEDULER << "Predicate scheduling item for " << t << "\n";
			std::string trigger_name("Timer ");
			if (target) trigger_name += target->getName();
			if (!earliest)
				earliest = new PredicateTimerDetails(t, trigger_name);
			else
				earliest->setup(t, trigger_name);

			//Trigger *trigger = new Trigger(trigger_name);
			//Scheduler::instance()->add(new ScheduledItem( t, new FireTriggerAction(target, trigger)));
			//trigger = trigger->release();
		}
		// to allow for the above processing delays we keep the target runnable
		else if (t >= -2000) {
			ProcessingThread::activate(target);
		}
	}
    if (right_p) earliest = right_p->scheduleTimerEvents(earliest, target);
	return earliest;
}