maybe fixed the scheduler bug (#2034?)

This commit is contained in:
fgerlits 2006-11-30 18:27:24 +00:00
parent 9a4c0ca65f
commit 221a45419e
3 changed files with 43 additions and 33 deletions

View file

@ -97,12 +97,9 @@ SchedulerThread :: getNextEvent(Ptr<ptime>::Ref when) throw ()
void void
SchedulerThread :: nextStep(Ptr<ptime>::Ref now) throw () SchedulerThread :: nextStep(Ptr<ptime>::Ref now) throw ()
{ {
if (!nextEvent.get()) { if (nextEvent) {
return;
}
if (imminent(now, nextInitTime)) { if (imminent(now, nextInitTime)) {
debug() << "next event init coming" << std::endl; debug() << "event init coming" << std::endl;
try { try {
nextEvent->initialize(); nextEvent->initialize();
} catch (std::exception &e) { } catch (std::exception &e) {
@ -114,18 +111,26 @@ SchedulerThread :: nextStep(Ptr<ptime>::Ref now) throw ()
<< std::endl; << std::endl;
} }
} else if (imminent(now, nextEventTime)) { } else if (imminent(now, nextEventTime)) {
debug() << "next event start coming" << std::endl; debug() << "event start coming" << std::endl;
Ptr<time_duration>::Ref timeLeft(new time_duration(*nextEventTime Ptr<time_duration>::Ref timeLeft(new time_duration(*nextEventTime
- *now)); - *now));
TimeConversion::sleep(timeLeft); TimeConversion::sleep(timeLeft);
nextEvent->start(); nextEvent->start();
} else if (imminent(now, nextEventEnd)) { currentEvent = nextEvent;
debug() << "next event end coming" << std::endl; currentEventEnd = nextEventEnd;
Ptr<time_duration>::Ref timeLeft(new time_duration(*nextEventEnd Ptr<ptime>::Ref inASecond(new ptime(*now + seconds(1)));
getNextEvent(inASecond);
}
}
if (currentEvent && imminent(now, nextEventEnd)) {
debug() << "event end coming" << std::endl;
Ptr<time_duration>::Ref timeLeft(new time_duration(*currentEventEnd
- *now)); - *now));
TimeConversion::sleep(timeLeft); TimeConversion::sleep(timeLeft);
nextEvent->stop(); currentEvent->stop();
nextEvent->deInitialize(); currentEvent->deInitialize();
currentEvent.reset();
} }
} }

View file

@ -85,6 +85,11 @@ class SchedulerThread : public virtual RunnableInterface
*/ */
Ptr<EventContainerInterface>::Ref eventContainer; Ptr<EventContainerInterface>::Ref eventContainer;
/**
* The event which is being running now.
*/
Ptr<ScheduledEventInterface>::Ref currentEvent;
/** /**
* The next event to execute. * The next event to execute.
*/ */
@ -100,6 +105,11 @@ class SchedulerThread : public virtual RunnableInterface
*/ */
Ptr<ptime>::Ref nextInitTime; Ptr<ptime>::Ref nextInitTime;
/**
* The ending time of the current event.
*/
Ptr<ptime>::Ref currentEventEnd;
/** /**
* The ending time of the next event. * The ending time of the next event.
*/ */

View file

@ -97,7 +97,6 @@ PlaylistEvent :: initialize(void) throw (std::exception)
{ {
DEBUG_BLOCK DEBUG_BLOCK
std::cerr << "PlaylistEvent :: initialize BEGIN\n";
if (state != created) { if (state != created) {
throw std::logic_error("PlaylistEvent in bad state"); throw std::logic_error("PlaylistEvent in bad state");
} }
@ -108,7 +107,6 @@ std::cerr << "PlaylistEvent :: initialize BEGIN\n";
->getId())); ->getId()));
try { try {
playlist = storage->acquirePlaylist(sessionId, playlistId); playlist = storage->acquirePlaylist(sessionId, playlistId);
std::cerr << "PlaylistEvent :: initialize acquired playlist\n";
} catch (Core::XmlRpcException &e) { } catch (Core::XmlRpcException &e) {
std::string errorMessage = "storage server error: "; std::string errorMessage = "storage server error: ";
errorMessage += e.what(); errorMessage += e.what();
@ -126,6 +124,8 @@ std::cerr << "PlaylistEvent :: initialize acquired playlist\n";
void void
PlaylistEvent :: deInitialize(void) throw () PlaylistEvent :: deInitialize(void) throw ()
{ {
DEBUG_BLOCK
if (state != stopped) { if (state != stopped) {
// TODO: handle error? // TODO: handle error?
return; return;
@ -139,7 +139,6 @@ PlaylistEvent :: deInitialize(void) throw ()
} }
playlist.reset(); playlist.reset();
state = deInitialized; state = deInitialized;
std::cerr << "PlaylistEvent :: deInitialize END\n";
} }
@ -151,7 +150,6 @@ PlaylistEvent :: start(void) throw ()
{ {
DEBUG_BLOCK DEBUG_BLOCK
std::cerr << "PlaylistEvent :: start BEGIN\n";
if (state != initialized) { if (state != initialized) {
// TODO: handle error? // TODO: handle error?
return; return;
@ -160,7 +158,6 @@ std::cerr << "PlaylistEvent :: start BEGIN\n";
try { try {
audioPlayer->open(*playlist->getUri()); audioPlayer->open(*playlist->getUri());
audioPlayer->start(); audioPlayer->start();
std::cerr << "PlaylistEvent :: audio player started\n";
playLog->addPlayLogEntry(playlist->getId(), TimeConversion::now()); playLog->addPlayLogEntry(playlist->getId(), TimeConversion::now());
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
@ -182,7 +179,6 @@ PlaylistEvent :: stop(void) throw ()
{ {
DEBUG_BLOCK DEBUG_BLOCK
std::cerr << "PlaylistEvent :: stop BEGIN\n";
if (state != running) { if (state != running) {
// TODO: handle error? // TODO: handle error?
return; return;
@ -191,7 +187,6 @@ std::cerr << "PlaylistEvent :: stop BEGIN\n";
try { try {
audioPlayer->stop(); audioPlayer->stop();
audioPlayer->close(); audioPlayer->close();
std::cerr << "PlaylistEvent :: audio player stopped\n";
} catch (std::logic_error &e) { } catch (std::logic_error &e) {
// TODO: handle error // TODO: handle error
// NOTE: this may not be an error, because the user may have stopped // NOTE: this may not be an error, because the user may have stopped