added ping messages in protocol class
This commit is contained in:
parent
c067103684
commit
1b2e1dcb6e
2 changed files with 71 additions and 20 deletions
|
@ -98,8 +98,13 @@ MESSAGES
|
||||||
| 2 bytes number n | n bytes UTF-8 string |
|
| 2 bytes number n | n bytes UTF-8 string |
|
||||||
+------------------+----------------------+
|
+------------------+----------------------+
|
||||||
|
|
||||||
|
- Ping message (for measuring the ping time) PROTMESSID_PING
|
||||||
|
|
||||||
|
+--------------------------------------------------------------------------+
|
||||||
|
| 5 bytes transmit time (1 byte hours, 1 byte min, 1 byte sec, 2 bytes ms) |
|
||||||
|
+--------------------------------------------------------------------------+
|
||||||
|
|
||||||
|
|
||||||
*
|
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
|
@ -370,6 +375,11 @@ for ( int i = 0; i < iNumBytes; i++ ) {
|
||||||
|
|
||||||
EvaluateChatTextMes ( iPos, vecData );
|
EvaluateChatTextMes ( iPos, vecData );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROTMESSID_PING:
|
||||||
|
|
||||||
|
EvaluatePingMes ( iPos, vecData );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send acknowledge message
|
// send acknowledge message
|
||||||
|
@ -603,6 +613,25 @@ void CProtocol::CreateChanNameMes ( const QString strName )
|
||||||
CreateAndSendMessage ( PROTMESSID_CHANNEL_NAME, vecData );
|
CreateAndSendMessage ( PROTMESSID_CHANNEL_NAME, vecData );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CProtocol::EvaluateChanNameMes ( unsigned int iPos, const CVector<uint8_t>& vecData )
|
||||||
|
{
|
||||||
|
// number of bytes for name string (2 bytes)
|
||||||
|
const int iStrLen =
|
||||||
|
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
|
|
||||||
|
// name string (n bytes)
|
||||||
|
QString strName = "";
|
||||||
|
for ( int j = 0; j < iStrLen; j++ )
|
||||||
|
{
|
||||||
|
// byte-by-byte copying of the string data
|
||||||
|
int iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
|
strName += QString ( (char*) &iData );
|
||||||
|
}
|
||||||
|
|
||||||
|
// invoke message action
|
||||||
|
emit ChangeChanName ( strName );
|
||||||
|
}
|
||||||
|
|
||||||
void CProtocol::CreateChatTextMes ( const QString strChatText )
|
void CProtocol::CreateChatTextMes ( const QString strChatText )
|
||||||
{
|
{
|
||||||
unsigned int iPos = 0; // init position pointer
|
unsigned int iPos = 0; // init position pointer
|
||||||
|
@ -628,25 +657,6 @@ void CProtocol::CreateChatTextMes ( const QString strChatText )
|
||||||
CreateAndSendMessage ( PROTMESSID_CHAT_TEXT, vecData );
|
CreateAndSendMessage ( PROTMESSID_CHAT_TEXT, vecData );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CProtocol::EvaluateChanNameMes ( unsigned int iPos, const CVector<uint8_t>& vecData )
|
|
||||||
{
|
|
||||||
// number of bytes for name string (2 bytes)
|
|
||||||
const int iStrLen =
|
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
||||||
|
|
||||||
// name string (n bytes)
|
|
||||||
QString strName = "";
|
|
||||||
for ( int j = 0; j < iStrLen; j++ )
|
|
||||||
{
|
|
||||||
// byte-by-byte copying of the string data
|
|
||||||
int iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
||||||
strName += QString ( (char*) &iData );
|
|
||||||
}
|
|
||||||
|
|
||||||
// invoke message action
|
|
||||||
emit ChangeChanName ( strName );
|
|
||||||
}
|
|
||||||
|
|
||||||
void CProtocol::EvaluateChatTextMes ( unsigned int iPos, const CVector<uint8_t>& vecData )
|
void CProtocol::EvaluateChatTextMes ( unsigned int iPos, const CVector<uint8_t>& vecData )
|
||||||
{
|
{
|
||||||
// number of bytes for name string (2 bytes)
|
// number of bytes for name string (2 bytes)
|
||||||
|
@ -666,6 +676,43 @@ void CProtocol::EvaluateChatTextMes ( unsigned int iPos, const CVector<uint8_t>&
|
||||||
emit ChatTextReceived ( strChatText );
|
emit ChatTextReceived ( strChatText );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CProtocol::CreatePingMes ( const QTime time )
|
||||||
|
{
|
||||||
|
unsigned int iPos = 0; // init position pointer
|
||||||
|
|
||||||
|
// build data vector (5 bytes long)
|
||||||
|
CVector<uint8_t> vecData ( 5 );
|
||||||
|
|
||||||
|
// convert QTime to network time
|
||||||
|
CVector<unsigned char> vNetTimeInfo ( CTimeConv().QTi2NetTi ( time ) );
|
||||||
|
|
||||||
|
// convert all bytes (byte by byte)
|
||||||
|
for ( int j = 0; j < 5; j++ )
|
||||||
|
{
|
||||||
|
// byte-by-byte copying of the string data
|
||||||
|
PutValOnStream ( vecData, iPos,
|
||||||
|
static_cast<uint32_t> ( vNetTimeInfo[j] ), 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateAndSendMessage ( PROTMESSID_PING, vecData );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CProtocol::EvaluatePingMes ( unsigned int iPos, const CVector<uint8_t>& vecData )
|
||||||
|
{
|
||||||
|
// time information vector
|
||||||
|
CVector<unsigned char> vNetTimeInfo ( 5 ); // 5 bytes
|
||||||
|
for ( int j = 0; j < 5; j++ )
|
||||||
|
{
|
||||||
|
// byte-by-byte copying of the time information data
|
||||||
|
int iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
||||||
|
vNetTimeInfo[j] = static_cast<unsigned char> ( iData );
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert time to QTime and invoke message action
|
||||||
|
emit PingReceived ( CTimeConv().NetTi2QTi ( vNetTimeInfo ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
* Message generation (parsing) *
|
* Message generation (parsing) *
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
#include <qmutex.h>
|
#include <qmutex.h>
|
||||||
#include <qtimer.h>
|
#include <qtimer.h>
|
||||||
|
#include <qdatetime.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -72,6 +73,7 @@ public:
|
||||||
void CreateChanGainMes ( const int iChanID, const double dGain );
|
void CreateChanGainMes ( const int iChanID, const double dGain );
|
||||||
void CreateChanNameMes ( const QString strName );
|
void CreateChanNameMes ( const QString strName );
|
||||||
void CreateChatTextMes ( const QString strChatText );
|
void CreateChatTextMes ( const QString strChatText );
|
||||||
|
void CreatePingMes ( const QTime time );
|
||||||
|
|
||||||
void CreateConClientListMes ( const CVector<CChannelShortInfo>& vecChanInfo );
|
void CreateConClientListMes ( const CVector<CChannelShortInfo>& vecChanInfo );
|
||||||
|
|
||||||
|
@ -142,6 +144,7 @@ protected:
|
||||||
void EvaluateChanNameMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
|
void EvaluateChanNameMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
|
||||||
void EvaluateChatTextMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
|
void EvaluateChatTextMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
|
||||||
void EvaluateConClientListMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
|
void EvaluateConClientListMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
|
||||||
|
void EvaluatePingMes ( unsigned int iPos, const CVector<uint8_t>& vecData );
|
||||||
|
|
||||||
int iOldRecID, iOldRecCnt;
|
int iOldRecID, iOldRecCnt;
|
||||||
|
|
||||||
|
@ -165,6 +168,7 @@ signals:
|
||||||
void ChangeChanGain ( int iChanID, double dNewGain );
|
void ChangeChanGain ( int iChanID, double dNewGain );
|
||||||
void ChangeChanName ( QString strName );
|
void ChangeChanName ( QString strName );
|
||||||
void ChatTextReceived ( QString strChatText );
|
void ChatTextReceived ( QString strChatText );
|
||||||
|
void PingReceived ( QTime time );
|
||||||
void ConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo );
|
void ConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo );
|
||||||
void ReqJittBufSize();
|
void ReqJittBufSize();
|
||||||
void ReqConnClientsList();
|
void ReqConnClientsList();
|
||||||
|
|
Loading…
Reference in a new issue