make it possible to start server without using GUI

This commit is contained in:
Volker Fischer 2006-02-17 19:07:10 +00:00
parent dd914c411c
commit ae4fe51982
8 changed files with 69 additions and 50 deletions

View File

@ -37,8 +37,10 @@ bool CClient::SetServerAddr(QString strNAddr)
return true;
}
else
return false; /* invalid address */
else
{
return false; /* invalid address */
}
}
void CClient::Init()

View File

@ -64,17 +64,10 @@
#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 )
/* 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
much higher DSL network latencies. A length of 6 ms seems to be optimal */
# define BLOCK_DURATION_MS 6 /* ms */
#endif
#define BLOCK_DURATION_MS 6 /* ms */
#define BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SAMPLE_RATE / 1000)
#define SND_CRD_BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000)

View File

@ -27,7 +27,7 @@
/* Implementation *************************************************************/
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 )
{
/* add help text to controls */

View File

@ -26,8 +26,9 @@
/* Implementation *************************************************************/
CLlconServerDlg::CLlconServerDlg(QWidget* parent, const char* name, bool modal,
WFlags f) : CLlconServerDlgBase(parent, name, modal, f)
CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent,
const char* name, bool modal, WFlags f ) : pServer ( pNServP ),
CLlconServerDlgBase ( parent, name, modal, f )
{
/* set text for version and application name */
TextLabelNameVersion->
@ -69,13 +70,10 @@ CLlconServerDlg::CLlconServerDlg(QWidget* parent, const char* name, bool modal,
/* Init slider control */
SliderNetBuf->setRange(1, MAX_NET_BUF_SIZE_NUM_BL);
const int iCurNumNetBuf = Server.GetChannelSet()->GetSockBufSize();
const int iCurNumNetBuf = pServer->GetChannelSet()->GetSockBufSize();
SliderNetBuf->setValue(iCurNumNetBuf);
TextNetBuf->setText("Size: " + QString().setNum(iCurNumNetBuf));
/* start the server */
Server.Start();
/* Init timing jitter text label */
TextLabelResponseTime->setText("");
@ -112,7 +110,7 @@ void CLlconServerDlg::OnTimer()
ListViewMutex.lock();
Server.GetConCliParam(vecHostAddresses, vecdSamOffs);
pServer->GetConCliParam(vecHostAddresses, vecdSamOffs);
/* fill list with connected clients */
for (int i = 0; i < MAX_NUM_CHANNELS; i++)
@ -142,7 +140,7 @@ void CLlconServerDlg::OnTimer()
ListViewMutex.unlock();
/* response time (if available) */
if ( Server.GetTimingStdDev ( dCurTiStdDev ) )
if ( pServer->GetTimingStdDev ( dCurTiStdDev ) )
{
TextLabelResponseTime->setText(QString().
setNum(dCurTiStdDev, 'f', 2) + " ms");
@ -155,7 +153,7 @@ void CLlconServerDlg::OnTimer()
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));
}

View File

@ -51,18 +51,18 @@ class CLlconServerDlg : public CLlconServerDlgBase
Q_OBJECT
public:
CLlconServerDlg(QWidget* parent = 0, const char* name = 0,
bool modal = FALSE, WFlags f = 0);
CLlconServerDlg ( CServer* pNServP, QWidget* parent = 0,
const char* name = 0, bool modal = FALSE, WFlags f = 0 );
virtual ~CLlconServerDlg() {}
virtual ~CLlconServerDlg () {}
protected:
QTimer Timer;
CServer Server;
QTimer Timer;
CServer* pServer;
QPixmap BitmCubeGreen;
QPixmap BitmCubeYellow;
QPixmap BitmCubeRed;
QPixmap BitmCubeGreen;
QPixmap BitmCubeYellow;
QPixmap BitmCubeRed;
CVector<CServerListViewItem*> vecpListViewItems;
QMutex ListViewMutex;

View File

@ -35,27 +35,39 @@ QApplication* pApp = NULL;
int main ( int argc, char** argv )
{
/* Application object */
QApplication app ( argc, argv );
{
/* 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
argument and argv()[argc()-1] is the last argument */
if ( argc > 1 )
{
/* only "-s" is supported right now */
std::string strShortOpt = "-s";
{
std::string strShortOpt;
/* "-s": start server with GUI enabled */
strShortOpt = "-s";
if ( !strShortOpt.compare ( argv[1] ) )
{
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 )
{
/* client */
// actual client object
CClient Client;
@ -63,7 +75,7 @@ int main ( int argc, char** argv )
CSettings Settings ( &Client );
Settings.Load ();
/* client */
// GUI object
CLlconClientDlg ClientDlg ( &Client, 0, 0, FALSE, Qt::WStyle_MinMax );
/* Set main window */
@ -79,16 +91,28 @@ int main ( int argc, char** argv )
}
else
{
/* server */
CLlconServerDlg ServerDlg ( 0, 0, FALSE, Qt::WStyle_MinMax );
/* server */
// 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 */
app.setMainWidget ( &ServerDlg );
pApp = &app; /* Needed for post-event routine */
/* Set main window */
app.setMainWidget ( &ServerDlg );
pApp = &app; /* Needed for post-event routine */
/* Show dialog */
ServerDlg.show ();
app.exec ();
/* Show dialog */
ServerDlg.show ();
}
app.exec ();
}
return 0;

View File

@ -109,8 +109,10 @@ void CSocket::OnDataReceived ()
{
/* client */
/* check if packet comes from the server we want to connect */
if ( ! ( pChannel->GetAddress () == RecHostAddr ) )
return;
if ( ! ( pChannel->GetAddress () == RecHostAddr ) )
{
return;
}
if ( pChannel->PutData( vecbyRecBuf, iNumBytesRead ) )
{

View File

@ -83,7 +83,7 @@ public:
default, reset */
CVector(const CVector<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);