From 78f1ea769060cd631c210fc01020bb921afe3607 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 5 Aug 2011 10:15:20 +0100 Subject: OSYSTEM: extended installTimerProc() with timer ID parameter --- backends/timer/default/default-timer.cpp | 2 +- backends/timer/default/default-timer.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'backends/timer') diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp index 8480fcc7ee..e17aaea444 100644 --- a/backends/timer/default/default-timer.cpp +++ b/backends/timer/default/default-timer.cpp @@ -109,7 +109,7 @@ void DefaultTimerManager::handler() { } } -bool DefaultTimerManager::installTimerProc(TimerProc callback, int32 interval, void *refCon) { +bool DefaultTimerManager::installTimerProc(TimerProc callback, int32 interval, void *refCon, const Common::String &id) { assert(interval > 0); Common::StackLock lock(_mutex); diff --git a/backends/timer/default/default-timer.h b/backends/timer/default/default-timer.h index 66d2e3b091..33dd46cc57 100644 --- a/backends/timer/default/default-timer.h +++ b/backends/timer/default/default-timer.h @@ -22,6 +22,7 @@ #ifndef BACKENDS_TIMER_DEFAULT_H #define BACKENDS_TIMER_DEFAULT_H +#include "common/str.h" #include "common/timer.h" #include "common/mutex.h" @@ -36,7 +37,7 @@ private: public: DefaultTimerManager(); virtual ~DefaultTimerManager(); - virtual bool installTimerProc(TimerProc proc, int32 interval, void *refCon); + virtual bool installTimerProc(TimerProc proc, int32 interval, void *refCon, const Common::String &id); virtual void removeTimerProc(TimerProc proc); /** -- cgit v1.2.3 From 4c7958450f628937270f259cc480c1191ea2fb2f Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 5 Aug 2011 17:56:04 +0100 Subject: TIMER: Implemented checks for duplicated timers --- backends/timer/default/default-timer.cpp | 16 +++++++++++++++- backends/timer/default/default-timer.h | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'backends/timer') diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp index e17aaea444..449dda2ece 100644 --- a/backends/timer/default/default-timer.cpp +++ b/backends/timer/default/default-timer.cpp @@ -24,10 +24,10 @@ #include "common/util.h" #include "common/system.h" - struct TimerSlot { Common::TimerManager::TimerProc callback; void *refCon; + Common::String id; uint32 interval; // in microseconds uint32 nextFireTime; // in milliseconds @@ -113,9 +113,23 @@ bool DefaultTimerManager::installTimerProc(TimerProc callback, int32 interval, v assert(interval > 0); Common::StackLock lock(_mutex); + if (_callbacks.contains(id)) { + if (_callbacks[id] != callback) { + error("Different callbacks are referred by same name (%s)", id.c_str()); + } + TimerSlotMap::const_iterator i; + + for (i = _callbacks.begin(); i != _callbacks.end(); ++i) { + if (i->_value == callback) { + error("Same callback is referred by different names (%s vs %s)", i->_key.c_str(), id.c_str()); + } + } + _callbacks[id] = callback; + TimerSlot *slot = new TimerSlot; slot->callback = callback; slot->refCon = refCon; + slot->id = id; slot->interval = interval; slot->nextFireTime = g_system->getMillis() + interval / 1000; slot->nextFireTimeMicro = interval % 1000; diff --git a/backends/timer/default/default-timer.h b/backends/timer/default/default-timer.h index 33dd46cc57..e5a9dada79 100644 --- a/backends/timer/default/default-timer.h +++ b/backends/timer/default/default-timer.h @@ -23,6 +23,7 @@ #define BACKENDS_TIMER_DEFAULT_H #include "common/str.h" +#include "common/hash-str.h" #include "common/timer.h" #include "common/mutex.h" @@ -30,9 +31,12 @@ struct TimerSlot; class DefaultTimerManager : public Common::TimerManager { private: + typedef Common::HashMap TimerSlotMap; + Common::Mutex _mutex; void *_timerHandler; TimerSlot *_head; + TimerSlotMap _callbacks; public: DefaultTimerManager(); -- cgit v1.2.3 From 2fa17c44edf07f4f82147a6070950e7d8f7ee2f4 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 5 Aug 2011 21:09:07 +0100 Subject: JANITORIAL: Remove SVN keywords --- backends/timer/default/default-timer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/timer') diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp index 449dda2ece..efb3ec9ad9 100644 --- a/backends/timer/default/default-timer.cpp +++ b/backends/timer/default/default-timer.cpp @@ -116,6 +116,7 @@ bool DefaultTimerManager::installTimerProc(TimerProc callback, int32 interval, v if (_callbacks.contains(id)) { if (_callbacks[id] != callback) { error("Different callbacks are referred by same name (%s)", id.c_str()); + } } TimerSlotMap::const_iterator i; -- cgit v1.2.3 From cea06991ebab97c72e9fd89a4bf63835bcf0de80 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 10 Aug 2011 18:15:00 +0200 Subject: TIMER: Remove name of callback in removeTimerProc. This should fix #3389673 "LOOM: CD-Version crashes at start". It also fixes the same error showing up for me in Monkey CD. The doc changes in 4c7958450f628937270f claims the name is used for the event recorder, but as far as I can tell it is not used right now. Thus depending on how it is used the behavior of SCUMM removing and adding the same timer aagain *might* cause problems. In any way we need to remove the name in removeTimerProc, else RTL + launching the same game again would be broken too. --- backends/timer/default/default-timer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'backends/timer') diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp index efb3ec9ad9..28524bf3b5 100644 --- a/backends/timer/default/default-timer.cpp +++ b/backends/timer/default/default-timer.cpp @@ -161,4 +161,11 @@ void DefaultTimerManager::removeTimerProc(TimerProc callback) { slot = slot->next; } } + + for (TimerSlotMap::iterator i = _callbacks.begin(), end = _callbacks.end(); i != end; ++i) { + if (i->_value == callback) { + _callbacks.erase(i); + break; + } + } } -- cgit v1.2.3 From c443f113ed5729b88792d3b54b77d70033cb24dc Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 10 Aug 2011 18:34:08 +0200 Subject: TIMER: Remove all names associated with a callback, since all callbacks are removed. This makes the name removal consistent with the timer proc removal. It seems we only allow a specific timer proc being added once anymore though. So this should not change too much right now. --- backends/timer/default/default-timer.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'backends/timer') diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp index 28524bf3b5..5b133660e0 100644 --- a/backends/timer/default/default-timer.cpp +++ b/backends/timer/default/default-timer.cpp @@ -163,9 +163,7 @@ void DefaultTimerManager::removeTimerProc(TimerProc callback) { } for (TimerSlotMap::iterator i = _callbacks.begin(), end = _callbacks.end(); i != end; ++i) { - if (i->_value == callback) { + if (i->_value == callback) _callbacks.erase(i); - break; - } } } -- cgit v1.2.3 From 930f626daba5de8ec0b42fd32ba7ddf107e7d95a Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 10 Aug 2011 18:42:19 +0200 Subject: TIMER: Add a comment to explain why we remove the name in removeTimerProc. --- backends/timer/default/default-timer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'backends/timer') diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp index 5b133660e0..e1aadb62b8 100644 --- a/backends/timer/default/default-timer.cpp +++ b/backends/timer/default/default-timer.cpp @@ -162,6 +162,18 @@ void DefaultTimerManager::removeTimerProc(TimerProc callback) { } } + // We need to remove all names referencing the timer proc here. + // + // Else we run into troubles, when the client code removes and readds timer + // callbacks. + // + // Another issues occurs when one plays a game with ALSA as music driver, + // does RTL and starts a different engine game with ALSA as music driver. + // In this case the MPU401 code will add different timer procs with the + // same name, resulting in two different callbacks added with the same + // name and causing installTimerProc to error out. + // A good test case is running a SCUMM with ALSA output and then a KYRA + // game for example. for (TimerSlotMap::iterator i = _callbacks.begin(), end = _callbacks.end(); i != end; ++i) { if (i->_value == callback) _callbacks.erase(i); -- cgit v1.2.3 From 43059b18787cda6dfb6b13b90af276930c52d6d1 Mon Sep 17 00:00:00 2001 From: Chris Warren-Smith Date: Sat, 20 Aug 2011 10:41:32 +1000 Subject: BADA: Moved timer manager to backends/timer/bada --- backends/timer/bada/timer.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++ backends/timer/bada/timer.h | 62 +++++++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100755 backends/timer/bada/timer.cpp create mode 100755 backends/timer/bada/timer.h (limited to 'backends/timer') diff --git a/backends/timer/bada/timer.cpp b/backends/timer/bada/timer.cpp new file mode 100755 index 0000000000..8f5620401f --- /dev/null +++ b/backends/timer/bada/timer.cpp @@ -0,0 +1,115 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#if defined (BADA) + +#include "backends/timer/bada/timer.h" + +// +// TimerSlot +// +TimerSlot::TimerSlot(Common::TimerManager::TimerProc callback, + uint32 interval, void *refCon) : + _timer(0), + _callback(callback), + _interval(interval), + _refCon(refCon) { +} + +TimerSlot::~TimerSlot() { +} + +bool TimerSlot::OnStart() { + _timer = new Osp::Base::Runtime::Timer(); + if (!_timer || IsFailed(_timer->Construct(*this))) { + AppLog("Failed to create timer"); + return false; + } + + if (IsFailed(_timer->Start(_interval))) { + AppLog("failed to start timer"); + return false; + } + + AppLog("started timer %d", _interval); + return true; +} + +void TimerSlot::OnStop() { + AppLog("timer stopped"); + if (_timer) { + _timer->Cancel(); + delete _timer; + _timer = NULL; + } +} + +void TimerSlot::OnTimerExpired(Timer &timer) { + _callback(_refCon); + timer.Start(_interval); +} + +// +// BadaTimerManager +// +BadaTimerManager::BadaTimerManager() { +} + +BadaTimerManager::~BadaTimerManager() { + for (Common::List::iterator slot = _timers.begin(); + slot != _timers.end(); ++slot) { + slot->Stop(); + slot = _timers.erase(slot); + } +} + +bool BadaTimerManager::installTimerProc(TimerProc proc, int32 interval, void *refCon, + const Common::String &id) { + TimerSlot *slot = new TimerSlot(proc, interval / 1000, refCon); + + if (IsFailed(slot->Construct(THREAD_TYPE_EVENT_DRIVEN))) { + AppLog("Failed to create timer thread"); + delete slot; + return false; + } + + if (IsFailed(slot->Start())) { + delete slot; + AppLog("Failed to start timer thread"); + return false; + } + + _timers.push_back(*slot); + return true; +} + +void BadaTimerManager::removeTimerProc(TimerProc proc) { + for (Common::List::iterator slot = _timers.begin(); + slot != _timers.end(); ++slot) { + if (slot->_callback == proc) { + slot->Stop(); + slot = _timers.erase(slot); + } + } +} + +#endif diff --git a/backends/timer/bada/timer.h b/backends/timer/bada/timer.h new file mode 100755 index 0000000000..04ca771c26 --- /dev/null +++ b/backends/timer/bada/timer.h @@ -0,0 +1,62 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef BADA_TIMER_H +#define BADA_TIMER_H + +#include + +#include "common/timer.h" +#include "common/list.h" + +using namespace Osp::Base::Runtime; + +struct TimerSlot: public ITimerEventListener, public Thread { + TimerSlot(Common::TimerManager::TimerProc callback, + uint32 interval, + void *refCon); + ~TimerSlot(); + + bool OnStart(void); + void OnStop(void); + void OnTimerExpired(Timer &timer); + + Timer *_timer; + Common::TimerManager::TimerProc _callback; + uint32 _interval; // in microseconds + void *_refCon; +}; + +class BadaTimerManager : public Common::TimerManager { +public: + BadaTimerManager(); + ~BadaTimerManager(); + + bool installTimerProc(TimerProc proc, int32 interval, void *refCon, + const Common::String &id); + void removeTimerProc(TimerProc proc); + +private: + Common::List _timers; +}; + +#endif -- cgit v1.2.3