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

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

View file

@ -64,16 +64,9 @@
#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_SIZE_SAMPLES (BLOCK_DURATION_MS * SAMPLE_RATE / 1000)
#define SND_CRD_BLOCK_SIZE_SAMPLES (BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000)

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,14 +51,14 @@ 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 () {}
protected:
QTimer Timer;
CServer Server;
CServer* pServer;
QPixmap BitmCubeGreen;
QPixmap BitmCubeYellow;

View file

@ -36,26 +36,38 @@ 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 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 */
@ -80,7 +92,17 @@ int main ( int argc, char** argv )
else
{
/* 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 */
app.setMainWidget ( &ServerDlg );
@ -88,6 +110,8 @@ int main ( int argc, char** argv )
/* Show dialog */
ServerDlg.show ();
}
app.exec ();
}

View file

@ -110,7 +110,9 @@ void CSocket::OnDataReceived ()
/* client */
/* check if packet comes from the server we want to connect */
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);