Mentions légales du service

Skip to content
Snippets Groups Projects

jlindgre std threads

Merged Jussi Lindgren requested to merge wip-jlindgre-std-threads into wip-all-openvibe20-base
4 unresolved threads
23 files
+ 372
234
Compare changes
  • Side-by-side
  • Inline
Files
23
@@ -93,14 +93,53 @@ const char* CDriverBioSemiActiveTwo::getName(void)
return "BioSemi Active Two (MkI and MkII)";
}
void CDriverBioSemiActiveTwo::setupInformationWindow(void)
{
if (!m_pInformationWindow)
{
m_rDriverContext.getLogManager() << LogLevel_Error << "Information window not allocated\n";
return;
}
std::lock_guard<std::mutex> l_lock(m_pInformationWindow->m_oMutex);
m_pInformationWindow->m_pBuilderConfigureInterface=gtk_builder_new();
if(!gtk_builder_add_from_file(m_pInformationWindow->m_pBuilderConfigureInterface, OpenViBE::Directories::getDataDir() + "/applications/acquisition-server/interface-BioSemi-ActiveTwo.ui", NULL))
{
m_rDriverContext.getLogManager() << LogLevel_Error << "File not found: "<< OpenViBE::Directories::getDataDir() << "/applications/acquisition-server/interface-BioSemi-ActiveTwo.ui\n";
return;
}
gtk_label_set_markup(GTK_LABEL(gtk_builder_get_object(m_pInformationWindow->m_pBuilderConfigureInterface, "label-device-type")), (m_oBridge.isDeviceMarkII() ? "- <i>ActiveTwo Mark II</i> -" : "- <i>ActiveTwo Mark I</i> -"));
m_pInformationWindow->m_bIsCMSInRange = m_oBridge.isCMSInRange();
m_pInformationWindow->m_bIsBatteryLow = m_oBridge.isBatteryLow();
m_pInformationWindow->m_bIsChanged = true;
gtk_widget_show_all(GTK_WIDGET(gtk_builder_get_object(m_pInformationWindow->m_pBuilderConfigureInterface, "device-information")));
return;
}
//___________________________________________________________________//
// //
gint setup_information_window_callback(void* pUserData)
{
CDriverBioSemiActiveTwo* pTmp = static_cast<CDriverBioSemiActiveTwo*>(pUserData);
pTmp->setupInformationWindow();
return FALSE; // Don't run again
}
gint information_window_callback(void* pInformationWindow)
{
if (!pInformationWindow)
{
// Not initialized yet?
return TRUE;
}
SInformationWindow* l_pInformationWindow = reinterpret_cast<SInformationWindow*>(pInformationWindow);
boost::mutex::scoped_lock l_lock(reinterpret_cast<SInformationWindow*>(pInformationWindow)->m_oMutex);
std::lock_guard<std::mutex> l_lock(reinterpret_cast<SInformationWindow*>(pInformationWindow)->m_oMutex);
// If nothing changed, directly return from the callback
if(!l_pInformationWindow->m_bIsChanged)
{
@@ -111,6 +150,10 @@ gint information_window_callback(void* pInformationWindow)
// If the acquisition is ended, delete the window
gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object(l_pInformationWindow->m_pBuilderConfigureInterface, "device-information")));
g_object_unref(l_pInformationWindow->m_pBuilderConfigureInterface);
// If we get here, we know that the other thread has passed uninitialize() and will no longer access
// l_pInformationMindow.
delete l_pInformationWindow;
// The loop should now be stopped
return FALSE;
}
@@ -230,23 +273,15 @@ boolean CDriverBioSemiActiveTwo::initialize(
}
}
// Initialize information window
gdk_threads_enter();
m_pInformationWindow = new SInformationWindow();
m_pInformationWindow->m_pBuilderConfigureInterface=gtk_builder_new();
if(!gtk_builder_add_from_file(m_pInformationWindow->m_pBuilderConfigureInterface, OpenViBE::Directories::getDataDir() + "/applications/acquisition-server/interface-BioSemi-ActiveTwo.ui", NULL))
{
m_rDriverContext.getLogManager() << LogLevel_Error << "File not found: "<< OpenViBE::Directories::getDataDir() << "/applications/acquisition-server/interface-BioSemi-ActiveTwo.ui\n";
}
gtk_label_set_markup(GTK_LABEL(gtk_builder_get_object(m_pInformationWindow->m_pBuilderConfigureInterface, "label-device-type")), (m_oBridge.isDeviceMarkII() ? "- <i>ActiveTwo Mark II</i> -" : "- <i>ActiveTwo Mark I</i> -"));
m_pInformationWindow->m_bIsCMSInRange = m_oBridge.isCMSInRange();
m_pInformationWindow->m_bIsBatteryLow = m_oBridge.isBatteryLow();
m_pInformationWindow->m_bIsChanged = true;
gtk_widget_show_all(GTK_WIDGET(gtk_builder_get_object(m_pInformationWindow->m_pBuilderConfigureInterface, "device-information")));
// Initialize information window
// n.b. do all gtk stuff from callbacks to avoid threading issues.
gdk_threads_add_idle(setup_information_window_callback, this);
//Launch idle loop: update the information window in a separate glib thread
g_idle_add(information_window_callback, m_pInformationWindow);
gdk_threads_leave();
gdk_threads_add_idle(information_window_callback, m_pInformationWindow);
return true;
}
@@ -284,7 +319,7 @@ boolean CDriverBioSemiActiveTwo::loop(void)
// we consume one sample per channel, values are given in uV
if(!m_oBridge.consumeOneSamplePerChannel(&m_vSample[0], l_ui32Max))
{
boost::mutex::scoped_lock l_lock(m_pInformationWindow->m_oMutex);
std::lock_guard<std::mutex> l_lock(m_pInformationWindow->m_oMutex);
m_rDriverContext.getLogManager() << LogLevel_Error << "Something bad happened while consuming samples from device.\n";
m_pInformationWindow->m_bIsChanged = true;
m_pInformationWindow->m_sErrorMessage = "<span color=\"darkred\">Something bad happened while consuming samples from device.</span>\n";
@@ -348,7 +383,7 @@ boolean CDriverBioSemiActiveTwo::loop(void)
m_rDriverContext.getLogManager() << "\t The corresponding sample range has been tagged with OVTK_StimulationId_SegmentStart and OVTK_StimulationId_SegmentStop.\n";
m_rDriverContext.getLogManager() << "\t Possible causes include broken wires, damaged cable isolation, bad connector contacts, defect IC inside the electrode.\n";
{
boost::mutex::scoped_lock l_lock(m_pInformationWindow->m_oMutex);
std::lock_guard<std::mutex> l_lock(m_pInformationWindow->m_oMutex);
m_pInformationWindow->m_bIsCMSInRange = false;
m_pInformationWindow->m_bIsChanged = true;
}
@@ -382,7 +417,7 @@ boolean CDriverBioSemiActiveTwo::loop(void)
m_bCMSBackInRange = true;
m_rDriverContext.getLogManager() << LogLevel_Info << "Back in range \n";
{
boost::mutex::scoped_lock l_lock(m_pInformationWindow->m_oMutex);
std::lock_guard<std::mutex> l_lock(m_pInformationWindow->m_oMutex);
m_pInformationWindow->m_bIsCMSInRange = true;
m_pInformationWindow->m_bIsChanged = true;
}
@@ -397,7 +432,7 @@ boolean CDriverBioSemiActiveTwo::loop(void)
l_bWarningDisplayed = true;
m_rDriverContext.getLogManager() << LogLevel_Warning << "("<<((System::Time::getTime() - m_ui32StartTime)/1000)<<"') Device battery is low !\n";
{
boost::mutex::scoped_lock l_lock(m_pInformationWindow->m_oMutex);
std::lock_guard<std::mutex> l_lock(m_pInformationWindow->m_oMutex);
m_pInformationWindow->m_bIsBatteryLow = true;
m_pInformationWindow->m_bIsChanged = true;
}
@@ -420,7 +455,7 @@ boolean CDriverBioSemiActiveTwo::loop(void)
m_bBatteryBackOk = true;
m_rDriverContext.getLogManager() << LogLevel_Info << "Back in range \n";
{
boost::mutex::scoped_lock l_lock(m_pInformationWindow->m_oMutex);
std::lock_guard<std::mutex> l_lock(m_pInformationWindow->m_oMutex);
m_pInformationWindow->m_bIsBatteryLow = false;
m_pInformationWindow->m_bIsChanged = true;
}
@@ -442,7 +477,7 @@ boolean CDriverBioSemiActiveTwo::loop(void)
m_rDriverContext.getLogManager() << LogLevel_Error << "An error occured while reading data from device !\n";
m_bAcquisitionStopped = true;
{
boost::mutex::scoped_lock l_lock(m_pInformationWindow->m_oMutex);
std::lock_guard<std::mutex> l_lock(m_pInformationWindow->m_oMutex);
m_pInformationWindow->m_sErrorMessage = "<span color=\"darkred\">An error occured while reading data from device !</span>";
m_pInformationWindow->m_bIsChanged = true;
}
@@ -462,7 +497,7 @@ boolean CDriverBioSemiActiveTwo::loop(void)
m_rDriverContext.getLogManager() << LogLevel_Error << "An error occured while dropping samples.\n";
m_bAcquisitionStopped = true;
{
boost::mutex::scoped_lock l_lock(m_pInformationWindow->m_oMutex);
std::lock_guard<std::mutex> l_lock(m_pInformationWindow->m_oMutex);
m_pInformationWindow->m_sErrorMessage = "<span color=\"darkred\">An error occured while dropping samples.</span>";
m_pInformationWindow->m_bIsChanged = true;
}
@@ -475,7 +510,7 @@ boolean CDriverBioSemiActiveTwo::loop(void)
m_rDriverContext.getLogManager() << LogLevel_Error << "An error occured while reading data from device (drop)!\n";
m_bAcquisitionStopped = true;
{
boost::mutex::scoped_lock l_lock(m_pInformationWindow->m_oMutex);
std::lock_guard<std::mutex> l_lock(m_pInformationWindow->m_oMutex);
m_pInformationWindow->m_sErrorMessage = "<span color=\"darkred\">An error occured while reading data from device (drop)!</span>";
m_pInformationWindow->m_bIsChanged = true;
}
@@ -499,10 +534,13 @@ boolean CDriverBioSemiActiveTwo::stop(void)
boolean CDriverBioSemiActiveTwo::uninitialize(void)
{
{
boost::mutex::scoped_lock l_lock(m_pInformationWindow->m_oMutex);
std::lock_guard<std::mutex> l_lock(m_pInformationWindow->m_oMutex);
m_pInformationWindow->m_bIsChanged = true;
m_pInformationWindow->m_bIsAcquisitionEnded = true;
m_pInformationWindow = NULL; // The callback will free the memory
}
// Rename EX channels as "" so that the names are not saved as settings
if(m_oBridge.isUseEXChannels())
{
@@ -520,7 +558,7 @@ boolean CDriverBioSemiActiveTwo::uninitialize(void)
m_rDriverContext.getLogManager() << LogLevel_Warning << "Could not close the device.\n";
return false;
}
m_rDriverContext.getLogManager() << LogLevel_Error << "Driver uninitialized...\n";
m_rDriverContext.getLogManager() << LogLevel_Info << "Driver uninitialized...\n";
return true;
}
Loading