maybe fixed the scheduler bug (#2034?)
This commit is contained in:
parent
9a4c0ca65f
commit
221a45419e
|
@ -97,35 +97,40 @@ SchedulerThread :: getNextEvent(Ptr<ptime>::Ref when) throw ()
|
|||
void
|
||||
SchedulerThread :: nextStep(Ptr<ptime>::Ref now) throw ()
|
||||
{
|
||||
if (!nextEvent.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (imminent(now, nextInitTime)) {
|
||||
debug() << "next event init coming" << std::endl;
|
||||
try {
|
||||
nextEvent->initialize();
|
||||
} catch (std::exception &e) {
|
||||
// cancel event by getting the next event after this was
|
||||
// supposed to finish
|
||||
getNextEvent(nextEventEnd);
|
||||
// TODO: log error
|
||||
std::cerr << "event initialization error: " << e.what()
|
||||
<< std::endl;
|
||||
if (nextEvent) {
|
||||
if (imminent(now, nextInitTime)) {
|
||||
debug() << "event init coming" << std::endl;
|
||||
try {
|
||||
nextEvent->initialize();
|
||||
} catch (std::exception &e) {
|
||||
// cancel event by getting the next event after this was
|
||||
// supposed to finish
|
||||
getNextEvent(nextEventEnd);
|
||||
// TODO: log error
|
||||
std::cerr << "event initialization error: " << e.what()
|
||||
<< std::endl;
|
||||
}
|
||||
} else if (imminent(now, nextEventTime)) {
|
||||
debug() << "event start coming" << std::endl;
|
||||
Ptr<time_duration>::Ref timeLeft(new time_duration(*nextEventTime
|
||||
- *now));
|
||||
TimeConversion::sleep(timeLeft);
|
||||
nextEvent->start();
|
||||
currentEvent = nextEvent;
|
||||
currentEventEnd = nextEventEnd;
|
||||
Ptr<ptime>::Ref inASecond(new ptime(*now + seconds(1)));
|
||||
getNextEvent(inASecond);
|
||||
}
|
||||
} else if (imminent(now, nextEventTime)) {
|
||||
debug() << "next event start coming" << std::endl;
|
||||
Ptr<time_duration>::Ref timeLeft(new time_duration(*nextEventTime
|
||||
}
|
||||
|
||||
if (currentEvent && imminent(now, nextEventEnd)) {
|
||||
debug() << "event end coming" << std::endl;
|
||||
Ptr<time_duration>::Ref timeLeft(new time_duration(*currentEventEnd
|
||||
- *now));
|
||||
TimeConversion::sleep(timeLeft);
|
||||
nextEvent->start();
|
||||
} else if (imminent(now, nextEventEnd)) {
|
||||
debug() << "next event end coming" << std::endl;
|
||||
Ptr<time_duration>::Ref timeLeft(new time_duration(*nextEventEnd
|
||||
- *now));
|
||||
TimeConversion::sleep(timeLeft);
|
||||
nextEvent->stop();
|
||||
nextEvent->deInitialize();
|
||||
currentEvent->stop();
|
||||
currentEvent->deInitialize();
|
||||
currentEvent.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,11 @@ class SchedulerThread : public virtual RunnableInterface
|
|||
*/
|
||||
Ptr<EventContainerInterface>::Ref eventContainer;
|
||||
|
||||
/**
|
||||
* The event which is being running now.
|
||||
*/
|
||||
Ptr<ScheduledEventInterface>::Ref currentEvent;
|
||||
|
||||
/**
|
||||
* The next event to execute.
|
||||
*/
|
||||
|
@ -100,6 +105,11 @@ class SchedulerThread : public virtual RunnableInterface
|
|||
*/
|
||||
Ptr<ptime>::Ref nextInitTime;
|
||||
|
||||
/**
|
||||
* The ending time of the current event.
|
||||
*/
|
||||
Ptr<ptime>::Ref currentEventEnd;
|
||||
|
||||
/**
|
||||
* The ending time of the next event.
|
||||
*/
|
||||
|
|
|
@ -97,7 +97,6 @@ PlaylistEvent :: initialize(void) throw (std::exception)
|
|||
{
|
||||
DEBUG_BLOCK
|
||||
|
||||
std::cerr << "PlaylistEvent :: initialize BEGIN\n";
|
||||
if (state != created) {
|
||||
throw std::logic_error("PlaylistEvent in bad state");
|
||||
}
|
||||
|
@ -108,7 +107,6 @@ std::cerr << "PlaylistEvent :: initialize BEGIN\n";
|
|||
->getId()));
|
||||
try {
|
||||
playlist = storage->acquirePlaylist(sessionId, playlistId);
|
||||
std::cerr << "PlaylistEvent :: initialize acquired playlist\n";
|
||||
} catch (Core::XmlRpcException &e) {
|
||||
std::string errorMessage = "storage server error: ";
|
||||
errorMessage += e.what();
|
||||
|
@ -126,6 +124,8 @@ std::cerr << "PlaylistEvent :: initialize acquired playlist\n";
|
|||
void
|
||||
PlaylistEvent :: deInitialize(void) throw ()
|
||||
{
|
||||
DEBUG_BLOCK
|
||||
|
||||
if (state != stopped) {
|
||||
// TODO: handle error?
|
||||
return;
|
||||
|
@ -139,7 +139,6 @@ PlaylistEvent :: deInitialize(void) throw ()
|
|||
}
|
||||
playlist.reset();
|
||||
state = deInitialized;
|
||||
std::cerr << "PlaylistEvent :: deInitialize END\n";
|
||||
}
|
||||
|
||||
|
||||
|
@ -151,7 +150,6 @@ PlaylistEvent :: start(void) throw ()
|
|||
{
|
||||
DEBUG_BLOCK
|
||||
|
||||
std::cerr << "PlaylistEvent :: start BEGIN\n";
|
||||
if (state != initialized) {
|
||||
// TODO: handle error?
|
||||
return;
|
||||
|
@ -160,7 +158,6 @@ std::cerr << "PlaylistEvent :: start BEGIN\n";
|
|||
try {
|
||||
audioPlayer->open(*playlist->getUri());
|
||||
audioPlayer->start();
|
||||
std::cerr << "PlaylistEvent :: audio player started\n";
|
||||
|
||||
playLog->addPlayLogEntry(playlist->getId(), TimeConversion::now());
|
||||
} catch (std::invalid_argument &e) {
|
||||
|
@ -182,7 +179,6 @@ PlaylistEvent :: stop(void) throw ()
|
|||
{
|
||||
DEBUG_BLOCK
|
||||
|
||||
std::cerr << "PlaylistEvent :: stop BEGIN\n";
|
||||
if (state != running) {
|
||||
// TODO: handle error?
|
||||
return;
|
||||
|
@ -191,7 +187,6 @@ std::cerr << "PlaylistEvent :: stop BEGIN\n";
|
|||
try {
|
||||
audioPlayer->stop();
|
||||
audioPlayer->close();
|
||||
std::cerr << "PlaylistEvent :: audio player stopped\n";
|
||||
} catch (std::logic_error &e) {
|
||||
// TODO: handle error
|
||||
// NOTE: this may not be an error, because the user may have stopped
|
||||
|
|
Loading…
Reference in New Issue