Adjusting the testing framework to the new sigslot API.

Introducing SignalHandlingMode to signal_manager to allow forcing all signals being handled directly (needed for test-campvis) or queued.

refs #384
parent b8ebccfe
......@@ -30,7 +30,9 @@
namespace sigslot {
signal_manager::signal_manager() {
signal_manager::signal_manager()
: _handlingMode(DEFAULT)
{
}
......@@ -38,12 +40,22 @@ namespace sigslot {
}
void signal_manager::triggerSignal(_signal_handle_base* signal) const {
void signal_manager::triggerSignal(_signal_handle_base* signal) {
if (_handlingMode == FORCE_QUEUE) {
queueSignal(signal);
return;
}
signal->emitSignal();
delete signal;
}
bool signal_manager::queueSignal(_signal_handle_base* signal) {
if (_handlingMode == FORCE_DIRECT) {
triggerSignal(signal);
return true;
}
tgtAssert(signal != 0, "Signal must not be 0.");
if (signal == 0)
return false;
......@@ -80,6 +92,14 @@ namespace sigslot {
return std::this_thread::get_id() == _this_thread_id;
}
signal_manager::SignalHandlingMode signal_manager::getSignalHandlingMode() const {
return _handlingMode;
}
void signal_manager::setSignalHandlingMode(SignalHandlingMode mode) {
_handlingMode = mode;
}
const std::string signal_manager::loggerCat_;
......
......@@ -57,6 +57,7 @@
#include "tgt/assert.h"
#include <ext/threading.h>
#include <tbb/concurrent_queue.h>
#include <tbb/concurrent_vector.h>
......@@ -270,12 +271,30 @@ namespace sigslot {
friend class tgt::Singleton<signal_manager>;
public:
/// Enumeration of signal handling modes for the signal_manager
enum SignalHandlingMode {
DEFAULT, ///< Default mode is that all signals are queued unless they are emitted from the signal_manager thread.
FORCE_DIRECT, ///< Force all signals being directly handled by the emitting thread.
FORCE_QUEUE ///< Force all signals being queued and handled by the signal_manager thread.
};
/**
* Returns the signal handling mode of this signal_manager.
*/
SignalHandlingMode getSignalHandlingMode() const;
/**
* Sets the signal handling mode of this signal_manager to \mode.
* \param mode New signal handling mode to set.
*/
void setSignalHandlingMode(SignalHandlingMode mode);
/**
* Directly dispatches the signal \a signal to all currently registered listeners.
* \note For using threaded signal dispatching use queueSignal()
* \param signal signal to dispatch
*/
void triggerSignal(_signal_handle_base* signal) const;
void triggerSignal(_signal_handle_base* signal);
/**
* Enqueue \a signal into the list of signals to be dispatched.
......@@ -306,6 +325,7 @@ namespace sigslot {
/// Typedef for the signal queue
typedef tbb::concurrent_queue<_signal_handle_base*> SignalQueue;
SignalHandlingMode _handlingMode; ///< Mode for handling signals
SignalQueue _signalQueue; ///< Queue for signals to be dispatched
std::condition_variable _evaluationCondition; ///< conditional wait to be used when there are currently no jobs to process
......
......@@ -154,7 +154,7 @@ namespace campvis {
MetaProperty* meta = new MetaProperty(reader->getName()+"MetaProp", reader->getName());
meta->addPropertyCollection(*reader);
meta->setVisible(false);
this->addProperty(*meta);
StringProperty* sp = dynamic_cast<StringProperty*>(meta->getProperty("url"));
tgtAssert(sp != 0, "This should not happen.");
......@@ -163,7 +163,6 @@ namespace campvis {
sp->setVisible(false);
}
this->addProperty(*meta);
this->_readers.insert(std::pair<AbstractImageReader*, MetaProperty*>(reader, meta));
return 0;
}
......
......@@ -31,7 +31,7 @@ ADD_EXECUTABLE(test-campvis
ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CampvisModulesDefinitions} ${CampvisApplicationDefinitions} ${QT_DEFINITIONS})
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs} ${CampvisModulesIncludeDirs} ${CampvisHome}/ext/gtest-1.7.0/ ${CampvisHome}/ext/gtest-1.7.0/include)
TARGET_LINK_LIBRARIES(test-campvis campvis-modules campvis-core tgt gtest ${CampvisGlobalExternalLibs} ${CampvisModulesExternalLibs} ${QT_LIBRARIES})
TARGET_LINK_LIBRARIES(test-campvis campvis-modules campvis-core tgt gtest sigslot ${CampvisGlobalExternalLibs} ${CampvisModulesExternalLibs} ${QT_LIBRARIES})
if (CAMPVIS_GROUP_SOURCE_FILES)
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(TestCampvisSources ${CampvisHome}/test "")
......
......@@ -58,6 +58,10 @@ void init() {
// Make Xlib and GLX thread safe under X11
QApplication::setAttribute(Qt::AA_X11InitThreads);
sigslot::signal_manager::init();
sigslot::signal_manager::getRef().setSignalHandlingMode(sigslot::signal_manager::FORCE_DIRECT);
sigslot::signal_manager::getRef().start();
tgt::GlContextManager::init();
campvis::OpenGLJobProcessor::init();
......@@ -121,6 +125,9 @@ void deinit() {
tgt::GlContextManager::deinit();
tgt::deinit();
sigslot::signal_manager::getRef().stop();
sigslot::signal_manager::deinit();
_initialized = false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment