This commit is contained in:
Volker Fischer 2006-03-04 11:11:26 +00:00
parent a9183633bc
commit 83d61351bb
4 changed files with 87 additions and 15 deletions

View file

@ -27,7 +27,37 @@
/******************************************************************************\
* CChannelSet *
\******************************************************************************/
\******************************************************************************/
CChannelSet::CChannelSet()
{
// TEST for a test just connect each channel in a separate function
// TODO better solution!!!
QObject::connect ( &vecChannels[0], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessageCh0 ( CVector<uint8_t> ) ) );
QObject::connect ( &vecChannels[1], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessageCh0 ( CVector<uint8_t> ) ) );
QObject::connect ( &vecChannels[2], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessageCh0 ( CVector<uint8_t> ) ) );
QObject::connect ( &vecChannels[3], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessageCh0 ( CVector<uint8_t> ) ) );
QObject::connect ( &vecChannels[4], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessageCh0 ( CVector<uint8_t> ) ) );
QObject::connect ( &vecChannels[5], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessageCh0 ( CVector<uint8_t> ) ) );
QObject::connect ( &vecChannels[6], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessageCh0 ( CVector<uint8_t> ) ) );
QObject::connect ( &vecChannels[7], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessageCh0 ( CVector<uint8_t> ) ) );
QObject::connect ( &vecChannels[8], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessageCh0 ( CVector<uint8_t> ) ) );
QObject::connect ( &vecChannels[9], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessageCh0 ( CVector<uint8_t> ) ) );
}
int CChannelSet::GetFreeChan()
{
/* look for a free channel */
@ -226,16 +256,16 @@ CChannel::CChannel ()
void CChannel::OnSendProtMessage ( CVector<uint8_t> vecMessage )
{
// only send messages if we are connected, otherwise delete complete queue
// if ( IsConnected () )
// {
if ( IsConnected () )
{
// emit message to actually send the data
emit MessReadyForSending ( vecMessage );
// }
// else
// {
// // delete send message queue
// Protocol.DeleteSendMessQueue();
// }
}
else
{
// delete send message queue
Protocol.DeleteSendMessQueue();
}
}
void CChannel::SetSockBufSize ( const int iNewBlockSize, const int iNumBlocks )

View file

@ -143,10 +143,12 @@ signals:
/* CChannelSet (for server) ------------------------------------------------- */
class CChannelSet
{
class CChannelSet : public QObject
{
Q_OBJECT
public:
CChannelSet() {}
CChannelSet();
virtual ~CChannelSet() {}
bool PutData(const CVector<unsigned char>& vecbyRecBuf,
@ -176,7 +178,26 @@ protected:
/* do not use the vector class since CChannel does not have appropriate
copy constructor/operator */
CChannel vecChannels[MAX_NUM_CHANNELS];
QMutex Mutex;
QMutex Mutex;
public slots:
// TODO better solution!!!
void OnSendProtMessageCh0(CVector<uint8_t> mess) { emit MessReadyForSending(0,mess); }
void OnSendProtMessageCh1(CVector<uint8_t> mess) { emit MessReadyForSending(1,mess); }
void OnSendProtMessageCh2(CVector<uint8_t> mess) { emit MessReadyForSending(2,mess); }
void OnSendProtMessageCh3(CVector<uint8_t> mess) { emit MessReadyForSending(3,mess); }
void OnSendProtMessageCh4(CVector<uint8_t> mess) { emit MessReadyForSending(4,mess); }
void OnSendProtMessageCh5(CVector<uint8_t> mess) { emit MessReadyForSending(5,mess); }
void OnSendProtMessageCh6(CVector<uint8_t> mess) { emit MessReadyForSending(6,mess); }
void OnSendProtMessageCh7(CVector<uint8_t> mess) { emit MessReadyForSending(7,mess); }
void OnSendProtMessageCh8(CVector<uint8_t> mess) { emit MessReadyForSending(8,mess); }
void OnSendProtMessageCh9(CVector<uint8_t> mess) { emit MessReadyForSending(9,mess); }
signals:
void MessReadyForSending ( int iChID, CVector<uint8_t> vecMessage );
};

View file

@ -37,12 +37,32 @@ CServer::CServer () : Socket ( &ChannelSet, this )
QObject::connect ( &Timer, SIGNAL ( timeout () ),
this, SLOT ( OnTimer () ) );
// connection for protocol
QObject::connect ( &ChannelSet,
SIGNAL ( MessReadyForSending ( int, CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessage ( int, CVector<uint8_t> ) ) );
#ifdef _WIN32
// event handling of custom events seems not to work under Windows in this
// class, do not use automatic start/stop of server in Windows version
Start ();
#endif
}
}
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
{
// convert unsigned uint8_t in char, TODO convert all buffers in uint8_t
CVector<unsigned char> vecbyDataConv ( vecMessage.Size () );
for ( int i = 0; i < vecMessage.Size (); i++ ) {
vecbyDataConv[i] = static_cast<unsigned char> ( vecMessage[i] );
}
// the protocol queries me to call the function to send the message
// send it through the network
Socket.SendPacket ( vecbyDataConv,
ChannelSet.GetAddress ( iChID ) );
}
void CServer::Start ()
{

View file

@ -75,7 +75,8 @@ protected:
QTime TimeLastBlock;
public slots:
void OnTimer ();
void OnTimer();
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );
};