make it possible to start server without using GUI
This commit is contained in:
parent
dd914c411c
commit
ae4fe51982
8 changed files with 69 additions and 50 deletions
|
@ -37,8 +37,10 @@ bool CClient::SetServerAddr(QString strNAddr)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false; /* invalid address */
|
{
|
||||||
|
return false; /* invalid address */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::Init()
|
void CClient::Init()
|
||||||
|
|
|
@ -64,17 +64,10 @@
|
||||||
#define MIN_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SAMPLE_RATE / 1000 )
|
#define MIN_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SAMPLE_RATE / 1000 )
|
||||||
#define MIN_SND_CRD_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000 )
|
#define MIN_SND_CRD_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000 )
|
||||||
|
|
||||||
/* block length in milliseconds (it seems that with the standard windows time
|
|
||||||
a minimum block duration of 10 ms can be used) */
|
|
||||||
#ifdef _WIN32
|
|
||||||
# define BLOCK_DURATION_MS 6 /* ms */
|
|
||||||
#else
|
|
||||||
/* first tests showed that with 24000 kHz a block time shorter than 5 ms leads to
|
/* first tests showed that with 24000 kHz a block time shorter than 5 ms leads to
|
||||||
much higher DSL network latencies. A length of 6 ms seems to be optimal */
|
much higher DSL network latencies. A length of 6 ms seems to be optimal */
|
||||||
# define BLOCK_DURATION_MS 6 /* ms */
|
#define BLOCK_DURATION_MS 6 /* ms */
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SAMPLE_RATE / 1000)
|
#define BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SAMPLE_RATE / 1000)
|
||||||
#define SND_CRD_BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000)
|
#define SND_CRD_BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000)
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
|
CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
|
||||||
const char* name, bool modal, WFlags f) : pClient ( pNCliP ),
|
const char* name, bool modal, WFlags f) : pClient ( pNCliP ),
|
||||||
CLlconClientDlgBase ( parent, name, modal, f )
|
CLlconClientDlgBase ( parent, name, modal, f )
|
||||||
{
|
{
|
||||||
/* add help text to controls */
|
/* add help text to controls */
|
||||||
|
|
|
@ -26,8 +26,9 @@
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
CLlconServerDlg::CLlconServerDlg(QWidget* parent, const char* name, bool modal,
|
CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent,
|
||||||
WFlags f) : CLlconServerDlgBase(parent, name, modal, f)
|
const char* name, bool modal, WFlags f ) : pServer ( pNServP ),
|
||||||
|
CLlconServerDlgBase ( parent, name, modal, f )
|
||||||
{
|
{
|
||||||
/* set text for version and application name */
|
/* set text for version and application name */
|
||||||
TextLabelNameVersion->
|
TextLabelNameVersion->
|
||||||
|
@ -69,13 +70,10 @@ CLlconServerDlg::CLlconServerDlg(QWidget* parent, const char* name, bool modal,
|
||||||
|
|
||||||
/* Init slider control */
|
/* Init slider control */
|
||||||
SliderNetBuf->setRange(1, MAX_NET_BUF_SIZE_NUM_BL);
|
SliderNetBuf->setRange(1, MAX_NET_BUF_SIZE_NUM_BL);
|
||||||
const int iCurNumNetBuf = Server.GetChannelSet()->GetSockBufSize();
|
const int iCurNumNetBuf = pServer->GetChannelSet()->GetSockBufSize();
|
||||||
SliderNetBuf->setValue(iCurNumNetBuf);
|
SliderNetBuf->setValue(iCurNumNetBuf);
|
||||||
TextNetBuf->setText("Size: " + QString().setNum(iCurNumNetBuf));
|
TextNetBuf->setText("Size: " + QString().setNum(iCurNumNetBuf));
|
||||||
|
|
||||||
/* start the server */
|
|
||||||
Server.Start();
|
|
||||||
|
|
||||||
/* Init timing jitter text label */
|
/* Init timing jitter text label */
|
||||||
TextLabelResponseTime->setText("");
|
TextLabelResponseTime->setText("");
|
||||||
|
|
||||||
|
@ -112,7 +110,7 @@ void CLlconServerDlg::OnTimer()
|
||||||
|
|
||||||
ListViewMutex.lock();
|
ListViewMutex.lock();
|
||||||
|
|
||||||
Server.GetConCliParam(vecHostAddresses, vecdSamOffs);
|
pServer->GetConCliParam(vecHostAddresses, vecdSamOffs);
|
||||||
|
|
||||||
/* fill list with connected clients */
|
/* fill list with connected clients */
|
||||||
for (int i = 0; i < MAX_NUM_CHANNELS; i++)
|
for (int i = 0; i < MAX_NUM_CHANNELS; i++)
|
||||||
|
@ -142,7 +140,7 @@ void CLlconServerDlg::OnTimer()
|
||||||
ListViewMutex.unlock();
|
ListViewMutex.unlock();
|
||||||
|
|
||||||
/* response time (if available) */
|
/* response time (if available) */
|
||||||
if ( Server.GetTimingStdDev ( dCurTiStdDev ) )
|
if ( pServer->GetTimingStdDev ( dCurTiStdDev ) )
|
||||||
{
|
{
|
||||||
TextLabelResponseTime->setText(QString().
|
TextLabelResponseTime->setText(QString().
|
||||||
setNum(dCurTiStdDev, 'f', 2) + " ms");
|
setNum(dCurTiStdDev, 'f', 2) + " ms");
|
||||||
|
@ -155,7 +153,7 @@ void CLlconServerDlg::OnTimer()
|
||||||
|
|
||||||
void CLlconServerDlg::OnSliderNetBuf(int value)
|
void CLlconServerDlg::OnSliderNetBuf(int value)
|
||||||
{
|
{
|
||||||
Server.GetChannelSet()->SetSockBufSize( BLOCK_SIZE_SAMPLES, value );
|
pServer->GetChannelSet()->SetSockBufSize( BLOCK_SIZE_SAMPLES, value );
|
||||||
TextNetBuf->setText("Size: " + QString().setNum(value));
|
TextNetBuf->setText("Size: " + QString().setNum(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,18 +51,18 @@ class CLlconServerDlg : public CLlconServerDlgBase
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CLlconServerDlg(QWidget* parent = 0, const char* name = 0,
|
CLlconServerDlg ( CServer* pNServP, QWidget* parent = 0,
|
||||||
bool modal = FALSE, WFlags f = 0);
|
const char* name = 0, bool modal = FALSE, WFlags f = 0 );
|
||||||
|
|
||||||
virtual ~CLlconServerDlg() {}
|
virtual ~CLlconServerDlg () {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QTimer Timer;
|
QTimer Timer;
|
||||||
CServer Server;
|
CServer* pServer;
|
||||||
|
|
||||||
QPixmap BitmCubeGreen;
|
QPixmap BitmCubeGreen;
|
||||||
QPixmap BitmCubeYellow;
|
QPixmap BitmCubeYellow;
|
||||||
QPixmap BitmCubeRed;
|
QPixmap BitmCubeRed;
|
||||||
|
|
||||||
CVector<CServerListViewItem*> vecpListViewItems;
|
CVector<CServerListViewItem*> vecpListViewItems;
|
||||||
QMutex ListViewMutex;
|
QMutex ListViewMutex;
|
||||||
|
|
62
src/main.cpp
62
src/main.cpp
|
@ -35,27 +35,39 @@ QApplication* pApp = NULL;
|
||||||
|
|
||||||
|
|
||||||
int main ( int argc, char** argv )
|
int main ( int argc, char** argv )
|
||||||
{
|
{
|
||||||
/* Application object */
|
|
||||||
QApplication app ( argc, argv );
|
|
||||||
|
|
||||||
/* check if server or client application shall be started */
|
/* check if server or client application shall be started */
|
||||||
bool bIsClient = true;
|
bool bIsClient = true;
|
||||||
|
bool bUseGUI = true;
|
||||||
|
|
||||||
/* QT docu: argv()[0] is the program name, argv()[1] is the first
|
/* QT docu: argv()[0] is the program name, argv()[1] is the first
|
||||||
argument and argv()[argc()-1] is the last argument */
|
argument and argv()[argc()-1] is the last argument */
|
||||||
if ( argc > 1 )
|
if ( argc > 1 )
|
||||||
{
|
{
|
||||||
/* only "-s" is supported right now */
|
std::string strShortOpt;
|
||||||
std::string strShortOpt = "-s";
|
|
||||||
|
/* "-s": start server with GUI enabled */
|
||||||
|
strShortOpt = "-s";
|
||||||
if ( !strShortOpt.compare ( argv[1] ) )
|
if ( !strShortOpt.compare ( argv[1] ) )
|
||||||
{
|
{
|
||||||
bIsClient = false;
|
bIsClient = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/* "-sn": start server with GUI disabled (no GUI used) */
|
||||||
|
strShortOpt = "-sn";
|
||||||
|
if ( !strShortOpt.compare ( argv[1] ) )
|
||||||
|
{
|
||||||
|
bIsClient = false;
|
||||||
|
bUseGUI = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Application object */
|
||||||
|
QApplication app ( argc, argv, bUseGUI );
|
||||||
|
|
||||||
if ( bIsClient )
|
if ( bIsClient )
|
||||||
{
|
{
|
||||||
|
/* client */
|
||||||
// actual client object
|
// actual client object
|
||||||
CClient Client;
|
CClient Client;
|
||||||
|
|
||||||
|
@ -63,7 +75,7 @@ int main ( int argc, char** argv )
|
||||||
CSettings Settings ( &Client );
|
CSettings Settings ( &Client );
|
||||||
Settings.Load ();
|
Settings.Load ();
|
||||||
|
|
||||||
/* client */
|
// GUI object
|
||||||
CLlconClientDlg ClientDlg ( &Client, 0, 0, FALSE, Qt::WStyle_MinMax );
|
CLlconClientDlg ClientDlg ( &Client, 0, 0, FALSE, Qt::WStyle_MinMax );
|
||||||
|
|
||||||
/* Set main window */
|
/* Set main window */
|
||||||
|
@ -79,16 +91,28 @@ int main ( int argc, char** argv )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* server */
|
/* server */
|
||||||
CLlconServerDlg ServerDlg ( 0, 0, FALSE, Qt::WStyle_MinMax );
|
// actual server object
|
||||||
|
CServer Server;
|
||||||
|
|
||||||
|
/* start the server */
|
||||||
|
Server.Start ();
|
||||||
|
|
||||||
|
if ( bUseGUI )
|
||||||
|
{
|
||||||
|
// GUI object for the server
|
||||||
|
CLlconServerDlg ServerDlg ( &Server, 0, 0, FALSE,
|
||||||
|
Qt::WStyle_MinMax );
|
||||||
|
|
||||||
/* Set main window */
|
/* Set main window */
|
||||||
app.setMainWidget ( &ServerDlg );
|
app.setMainWidget ( &ServerDlg );
|
||||||
pApp = &app; /* Needed for post-event routine */
|
pApp = &app; /* Needed for post-event routine */
|
||||||
|
|
||||||
/* Show dialog */
|
/* Show dialog */
|
||||||
ServerDlg.show ();
|
ServerDlg.show ();
|
||||||
app.exec ();
|
}
|
||||||
|
|
||||||
|
app.exec ();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -109,8 +109,10 @@ void CSocket::OnDataReceived ()
|
||||||
{
|
{
|
||||||
/* client */
|
/* client */
|
||||||
/* check if packet comes from the server we want to connect */
|
/* check if packet comes from the server we want to connect */
|
||||||
if ( ! ( pChannel->GetAddress () == RecHostAddr ) )
|
if ( ! ( pChannel->GetAddress () == RecHostAddr ) )
|
||||||
return;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( pChannel->PutData( vecbyRecBuf, iNumBytesRead ) )
|
if ( pChannel->PutData( vecbyRecBuf, iNumBytesRead ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -83,7 +83,7 @@ public:
|
||||||
default, reset */
|
default, reset */
|
||||||
CVector(const CVector<TData>& vecI) :
|
CVector(const CVector<TData>& vecI) :
|
||||||
std::vector<TData>(static_cast<const std::vector<TData>&>(vecI)),
|
std::vector<TData>(static_cast<const std::vector<TData>&>(vecI)),
|
||||||
iVectorSize(vecI.Size()), pData(this->begin()) {}
|
iVectorSize(vecI.Size()) { pData = this->begin(); }
|
||||||
|
|
||||||
void Init(const int iNewSize);
|
void Init(const int iNewSize);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue