Commit 55233c10 authored by Jussi Lindgren's avatar Jussi Lindgren

Server: Acquisition Thread now controls the 'state' text in the GUI

- Made the state texts less ambiguous
parent ac6b06a9
......@@ -518,12 +518,14 @@ IHeader& CAcquisitionServerGUI::getHeaderCopy(void)
return m_oHeaderCopy;
}
void CAcquisitionServerGUI::setClientCount(uint32 ui32ClientCount)
void CAcquisitionServerGUI::setClientText(const char *sClientText)
{
// Updates 'host count' label when needed
char l_sLabel[1024];
::sprintf(l_sLabel, "%u host%s connected...", (unsigned int)ui32ClientCount, ui32ClientCount?"s":"");
::gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_connected_host_count")), l_sLabel);
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_connected_host_count")), sClientText);
}
void CAcquisitionServerGUI::setStateText(const char *sStateText)
{
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_status")), sStateText);
}
void CAcquisitionServerGUI::setDriftMs(float64 f64DriftMs)
......@@ -560,6 +562,12 @@ void CAcquisitionServerGUI::setDriftMs(float64 f64DriftMs)
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gtk_builder_get_object(m_pBuilderInterface, "progressbar_drift_2")), l_f64DriftRatio);
}
if(std::abs(f64DriftMs)<0.01)
{
// To keep the display steady when fluctuating around 0
f64DriftMs = 0;
}
if(l_bDriftWarning)
{
::sprintf(l_sLabel, "<b>Device drift is too high</b> : %3.2lf ms\n<small>late &lt;-- (tolerance is set to %llu ms) --&gt; early</small>", f64DriftMs, l_ui64DriftToleranceDurationMs);
......@@ -689,9 +697,6 @@ void CAcquisitionServerGUI::buttonConnectToggledCB(::GtkToggleButton* pButton)
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(m_pBuilderInterface, "spinbutton_connection_port")), false);
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(m_pBuilderInterface, "combobox_sample_count_per_sent_block")), false);
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(m_pBuilderInterface, "combobox_driver")), false);
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_status")), "Connected ! Ready...");
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_connected_host_count")), "0 host connected...");
}
else
{
......@@ -725,8 +730,7 @@ void CAcquisitionServerGUI::buttonConnectToggledCB(::GtkToggleButton* pButton)
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(m_pBuilderInterface, "combobox_sample_count_per_sent_block")), true);
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(m_pBuilderInterface, "combobox_driver")), true);
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_status")), "");
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_connected_host_count")), "");
setClientText("");
}
}
......@@ -744,12 +748,12 @@ void CAcquisitionServerGUI::buttonStartPressedCB(::GtkButton* pButton)
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(m_pBuilderInterface, "button_play")), false);
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(m_pBuilderInterface, "button_stop")), true);
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_status")), "Sending...");
setStateText("Starting...");
}
else
{
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_status")), "Failed !");
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_connected_host_count")), "");
setStateText("Start failed !");
setClientText("");
}
}
......@@ -761,13 +765,11 @@ void CAcquisitionServerGUI::buttonStopPressedCB(::GtkButton* pButton)
{
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(m_pBuilderInterface, "button_play")), true);
gtk_widget_set_sensitive(GTK_WIDGET(gtk_builder_get_object(m_pBuilderInterface, "button_stop")), false);
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_status")), "Connected ! Ready...");
}
else
{
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_status")), "Failed !");
gtk_label_set_label(GTK_LABEL(gtk_builder_get_object(m_pBuilderInterface, "label_connected_host_count")), "");
setStateText("Stop failed !");
setClientText("");
}
}
......
......@@ -35,7 +35,9 @@ namespace OpenViBEAcquisitionServer
OpenViBE::uint32 getSampleCountPerBuffer(void);
OpenViBE::uint32 getTCPPort(void);
OpenViBEAcquisitionServer::IHeader& getHeaderCopy(void);
void setClientCount(OpenViBE::uint32 ui32ClientCount);
void setStateText(const char *sStateText);
void setClientText(const char *sClientText);
void setDriftMs(OpenViBE::float64 f64DriftMs);
void setImpedance(OpenViBE::uint32 ui32ChannelIndex, OpenViBE::float64 f64Impedance);
void disconnect(void);
......
......@@ -7,10 +7,10 @@
#include <system/ovCTime.h>
// fwd declare of gtk idle callbacks
static gboolean idle_updateclientcount_cb(void* pUserData);
static gboolean idle_updateimpedance_cb(void* pUserData);
static gboolean idle_updatedrift_cb(void* pUserData);
static gboolean idle_updatedisconnect_cb(void* pUserData);
static gboolean idle_updatestatus_cb(void* pUserData);
namespace OpenViBEAcquisitionServer
{
......@@ -31,7 +31,8 @@ namespace OpenViBEAcquisitionServer
, m_rGUI(rGUI)
, m_rAcquisitionServer(rAcquisitionServer)
, m_ui32Status(Status_Idle)
, m_ui32ClientCount(-1)
, m_ui32LastStatus(-1) // Always call update on start
, m_ui32ClientCount(0)
, m_f64LastDriftMs(-1)
{
}
......@@ -91,11 +92,11 @@ namespace OpenViBEAcquisitionServer
// backends (esp. Windows), delegate the work to g_idle_add() functions.
// As a result, we need to protect access to the variables that the callbacks use
{
if (l_ui32ClientCount != m_ui32ClientCount)
if (m_ui32LastStatus != m_ui32Status || l_ui32ClientCount != m_ui32ClientCount)
{
m_ui32LastStatus = m_ui32Status;
m_ui32ClientCount = l_ui32ClientCount;
gdk_threads_add_idle(idle_updateclientcount_cb, (void *)this);
gdk_threads_add_idle(idle_updatestatus_cb, (void *)this);
}
if (m_vImpedance != m_vImpedanceLast)
......@@ -105,7 +106,7 @@ namespace OpenViBEAcquisitionServer
gdk_threads_add_idle(idle_updateimpedance_cb, (void *)this);
}
if (l_f64DriftMs != m_f64LastDriftMs)
if (std::abs(l_f64DriftMs-m_f64LastDriftMs) > 0.01)
{
m_f64LastDriftMs = l_f64DriftMs;
......@@ -116,6 +117,8 @@ namespace OpenViBEAcquisitionServer
{
gdk_threads_add_idle(idle_updatedisconnect_cb, (void *)this);
}
}
if (l_bShouldSleep)
......@@ -218,13 +221,6 @@ namespace OpenViBEAcquisitionServer
}
// GTK C callbacks call these from the main thread to update the GUI
void updateGUIClientCount(void)
{
DoubleLock lock(&m_rAcquisitionServer.m_oProtectionMutex, &m_rAcquisitionServer.m_oExecutionMutex);
m_rGUI.setClientCount(m_ui32ClientCount);
}
void updateGUIImpedance(void)
{
DoubleLock lock(&m_rAcquisitionServer.m_oProtectionMutex, &m_rAcquisitionServer.m_oExecutionMutex);
......@@ -242,6 +238,44 @@ namespace OpenViBEAcquisitionServer
m_rGUI.setDriftMs(m_f64LastDriftMs);
}
void updateGUIStatus(void)
{
DoubleLock lock(&m_rAcquisitionServer.m_oProtectionMutex, &m_rAcquisitionServer.m_oExecutionMutex);
std::string l_sState;
std::string l_sClientText;
switch(m_ui32Status)
{
case Status_Started:
if(m_ui32ClientCount==0)
{
l_sState = "Receiving...";
}
else
{
l_sState = "Receiving and sending...";
}
char l_sLabel[1024];
::sprintf(l_sLabel, "%u client%s connected...", (unsigned int)m_ui32ClientCount, (m_ui32ClientCount!=1 ? "s" : ""));
l_sClientText = l_sLabel;
break;
case Status_Idle:
l_sState = "Disconnected";
break;
case Status_Connected:
l_sState = "Connected to device!";
l_sClientText = "Press play to start...";
break;
default:
l_sState = "Unknown";
break;
}
m_rGUI.setStateText(l_sState.c_str());
m_rGUI.setClientText(l_sClientText.c_str());
}
void updateGUIDisconnect(void)
{
DoubleLock lock(&m_rAcquisitionServer.m_oProtectionMutex, &m_rAcquisitionServer.m_oExecutionMutex);
......@@ -263,6 +297,7 @@ namespace OpenViBEAcquisitionServer
OpenViBEAcquisitionServer::CAcquisitionServerGUI& m_rGUI;
OpenViBEAcquisitionServer::CAcquisitionServer& m_rAcquisitionServer;
OpenViBE::uint32 m_ui32Status;
OpenViBE::uint32 m_ui32LastStatus;
OpenViBE::uint32 m_ui32ClientCount;
OpenViBE::float64 m_f64LastDriftMs;
......@@ -294,7 +329,7 @@ static gboolean idle_updateclientcount_cb(void* pUserData)
{
OpenViBEAcquisitionServer::CAcquisitionServerThread* l_pPtr = static_cast<OpenViBEAcquisitionServer::CAcquisitionServerThread*>(pUserData);
l_pPtr->updateGUIClientCount();
l_pPtr->updateGUIStatus(); // Delegate to GUI status change
return FALSE; // don't call again
}
......@@ -317,6 +352,15 @@ static gboolean idle_updatedrift_cb(void* pUserData)
return FALSE; // don't call again
}
static gboolean idle_updatestatus_cb(void* pUserData)
{
OpenViBEAcquisitionServer::CAcquisitionServerThread* l_pPtr = static_cast<OpenViBEAcquisitionServer::CAcquisitionServerThread*>(pUserData);
l_pPtr->updateGUIStatus();
return FALSE; // don't call again
}
static gboolean idle_updatedisconnect_cb(void* pUserData)
{
OpenViBEAcquisitionServer::CAcquisitionServerThread* l_pPtr = static_cast<OpenViBEAcquisitionServer::CAcquisitionServerThread*>(pUserData);
......
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