void publish_callback (DNSServiceRef, DNSServiceFlags, DNSServiceErrorType errorCode, const char *name,
		       const char*, const char*, void *context)
{
	QObject *obj = reinterpret_cast<QObject*>(context);
	if (errorCode != kDNSServiceErr_NoError) {
		ErrorEvent err;
		QCoreApplication::sendEvent(obj, &err);
	} else {
		PublishEvent pev(QString::fromUtf8(name));
		QCoreApplication::sendEvent(obj, &pev);
	}
}
Пример #2
0
bool Scheduler::schedule(Event *ev) {
	assert(ev != NULL);
	stringstream info;

	EventPtr pev(ev);

	static bool possibleOverflow = false;
	static bool tooLate = false;
	/*info << "Schedule a " << pev->getEventName() << " (" << ev->id << ")";
	trace(info.str());*/

	if (pev->date < Scheduler::currentDate) {
	        if (!possibleOverflow) {
	            cerr << "WARNING: Attempt to schedule an event in the past (possible overflow detected?)!" << endl;
	            possibleOverflow = true;
	        }
		OUTPUT << "ERROR : An event cannot be scheduled in the past !\n";
		OUTPUT << "current time : " << Scheduler::currentDate << endl;
		OUTPUT << "ev->eventDate : " << pev->date << endl;
		OUTPUT << "ev->getEventName() : " << pev->getEventName() << endl;
		return(false);
	}

	if (pev->date > maximumDate) {
	        if (!tooLate) {
	            cerr << "WARNING: Maximum simulation date reached!" << endl;
	            tooLate = true;
	        }
		OUTPUT << "WARNING : An event should not be scheduled beyond the end of simulation date !\n";
		OUTPUT << "pev->date : " << pev->date << endl;
		OUTPUT << "maximumDate : " << maximumDate << endl;
		return(false);
	}

	lock();

	eventsMap.insert(pair<Time, EventPtr>(pev->date,pev));

	eventsMapSize++;

	StatsCollector::getInstance().updateLargestEventsQueueSize(eventsMapSize);

	unlock();

	return(true);
}