improved serialisation methods in RsGxsNet items, and added serialisation for RsGrpConfigItem

This commit is contained in:
csoler 2016-12-06 22:17:03 +01:00
parent 661038d9b2
commit a4c14c2212
3 changed files with 335 additions and 349 deletions

View File

@ -4460,7 +4460,7 @@ uint32_t RsGxsNetService::getSyncAge(const RsGxsGroupId& grpId)
if(it == mServerGrpConfigMap.end()) if(it == mServerGrpConfigMap.end())
return RS_GXS_DEFAULT_MSG_REQ_PERIOD ; return RS_GXS_DEFAULT_MSG_REQ_PERIOD ;
else else
return it->second.msg_keep_delay ; return it->second.msg_req_delay ;
} }
uint32_t RsGxsNetService::getKeepAge(const RsGxsGroupId& grpId,uint32_t default_value) uint32_t RsGxsNetService::getKeepAge(const RsGxsGroupId& grpId,uint32_t default_value)
{ {
@ -4471,7 +4471,7 @@ uint32_t RsGxsNetService::getKeepAge(const RsGxsGroupId& grpId,uint32_t default_
if(it == mServerGrpConfigMap.end()) if(it == mServerGrpConfigMap.end())
return default_value ; return default_value ;
else else
return it->second.msg_req_delay ; return it->second.msg_keep_delay ;
} }
int RsGxsNetService::requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId) int RsGxsNetService::requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId)

View File

@ -26,23 +26,15 @@
#include "rsgxsupdateitems.h" #include "rsgxsupdateitems.h"
#include "rsbaseserial.h" #include "rsbaseserial.h"
/**********************************************************************************************/
/* CLEAR */
/**********************************************************************************************/
void RsGxsGrpUpdateItem::clear() void RsGxsGrpUpdateItem::clear()
{ {
grpUpdateTS = 0; grpUpdateTS = 0;
peerID.clear(); peerID.clear();
} }
std::ostream& RsGxsGrpUpdateItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsGrpUpdateItem", indent);
uint16_t int_Indent = indent + 2;
out << "peerId: " << peerID << std::endl;
printIndent(out, int_Indent);
out << "grpUpdateTS: " << grpUpdateTS << std::endl;
printIndent(out, int_Indent);
return out ;
}
void RsGxsMsgUpdateItem::clear() void RsGxsMsgUpdateItem::clear()
{ {
@ -50,6 +42,23 @@ void RsGxsMsgUpdateItem::clear()
peerID.clear(); peerID.clear();
} }
void RsGxsServerMsgUpdateItem::clear()
{
msgUpdateTS = 0;
grpId.clear();
}
void RsGxsServerGrpUpdateItem::clear()
{
grpUpdateTS = 0;
}
/**********************************************************************************************/
/* PRINT */
/**********************************************************************************************/
std::ostream& RsGxsMsgUpdateItem::print(std::ostream& out, uint16_t indent) std::ostream& RsGxsMsgUpdateItem::print(std::ostream& out, uint16_t indent)
{ {
RsPeerId peerId; RsPeerId peerId;
@ -75,13 +84,15 @@ std::ostream& RsGxsMsgUpdateItem::print(std::ostream& out, uint16_t indent)
return out; return out;
} }
std::ostream& RsGxsGrpUpdateItem::print(std::ostream& out, uint16_t indent)
void RsGxsServerMsgUpdateItem::clear()
{ {
msgUpdateTS = 0; printRsItemBase(out, "RsGxsGrpUpdateItem", indent);
grpId.clear(); uint16_t int_Indent = indent + 2;
out << "peerId: " << peerID << std::endl;
printIndent(out, int_Indent);
out << "grpUpdateTS: " << grpUpdateTS << std::endl;
printIndent(out, int_Indent);
return out ;
} }
std::ostream& RsGxsServerMsgUpdateItem::print(std::ostream& out, uint16_t indent) std::ostream& RsGxsServerMsgUpdateItem::print(std::ostream& out, uint16_t indent)
@ -96,11 +107,6 @@ std::ostream& RsGxsServerMsgUpdateItem::print(std::ostream& out, uint16_t indent
} }
void RsGxsServerGrpUpdateItem::clear()
{
grpUpdateTS = 0;
}
std::ostream& RsGxsServerGrpUpdateItem::print(std::ostream& out, uint16_t indent) std::ostream& RsGxsServerGrpUpdateItem::print(std::ostream& out, uint16_t indent)
{ {
printRsItemBase(out, "RsGxsServerGrpUpdateItem", indent); printRsItemBase(out, "RsGxsServerGrpUpdateItem", indent);
@ -111,147 +117,128 @@ std::ostream& RsGxsServerGrpUpdateItem::print(std::ostream& out, uint16_t indent
return out; return out;
} }
/**********************************************************************************************/
/* SERIALISER */
/**********************************************************************************************/
bool RsGxsNetServiceItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const
uint32_t RsGxsUpdateSerialiser::size(RsItem* item)
{ {
RsGxsMsgUpdateItem* mui = NULL; tlvsize = serial_size() ;
RsGxsGrpUpdateItem* gui = NULL; offset = 0;
RsGxsServerGrpUpdateItem* gsui = NULL;
RsGxsServerMsgUpdateItem* msui = NULL;
if((mui = dynamic_cast<RsGxsMsgUpdateItem*>(item)) != NULL) if (pktsize < tlvsize)
{ return false; /* not enough space */
return sizeGxsMsgUpdate(mui);
}else if(( gui = dynamic_cast<RsGxsGrpUpdateItem*>(item)) != NULL){ pktsize = tlvsize;
return sizeGxsGrpUpdate(gui);
}else if((gsui = dynamic_cast<RsGxsServerGrpUpdateItem*>(item)) != NULL) if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize))
{ {
return sizeGxsServerGrpUpdate(gsui); std::cerr << "RsFileTransferItem::serialise_header(): ERROR. Not enough size!" << std::endl;
}else if((msui = dynamic_cast<RsGxsServerMsgUpdateItem*>(item)) != NULL) return false ;
{ }
return sizeGxsServerMsgUpdate(msui);
}else
{
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::size(): Could not find appropriate size function" std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl;
<< std::endl;
#endif #endif
return 0; offset += 8;
}
return true ;
} }
bool RsGxsUpdateSerialiser::serialise(RsItem* item, void* data,
uint32_t* size)
{
RsGxsMsgUpdateItem* mui;
RsGxsGrpUpdateItem* gui;
RsGxsServerGrpUpdateItem* gsui;
RsGxsServerMsgUpdateItem* msui;
if((mui = dynamic_cast<RsGxsMsgUpdateItem*>(item)) != NULL)
return serialiseGxsMsgUpdate(mui, data, size);
else if((gui = dynamic_cast<RsGxsGrpUpdateItem*>(item)) != NULL)
return serialiseGxsGrpUpdate(gui, data, size);
else if((msui = dynamic_cast<RsGxsServerMsgUpdateItem*>(item)) != NULL)
return serialiseGxsServerMsgUpdate(msui, data, size);
else if((gsui = dynamic_cast<RsGxsServerGrpUpdateItem*>(item)) != NULL)
return serialiseGxsServerGrpUpdate(gsui, data, size);
else
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialise() item does not caste to known type"
<< std::endl;
#endif
return false;
}
}
RsItem* RsGxsUpdateSerialiser::deserialise(void* data, uint32_t* size) RsItem* RsGxsUpdateSerialiser::deserialise(void* data, uint32_t* size)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialise()" << std::endl; std::cerr << "RsGxsUpdateSerialiser::deserialise()" << std::endl;
#endif #endif
/* get the type and size */ /* get the type and size */
uint32_t rstype = getRsItemId(data); uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)))
(SERVICE_TYPE != getRsItemService(rstype))) return NULL; /* wrong type */
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype)) switch(getRsItemSubType(rstype))
{ {
case RS_PKT_SUBTYPE_GXS_MSG_UPDATE: return deserialGxsMsgUpdate(data, size);
case RS_PKT_SUBTYPE_GXS_GRP_UPDATE: return deserialGxsGrpUpddate(data, size);
case RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE: return deserialGxsServerGrpUpddate(data, size);
case RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE: return deserialGxsServerMsgUpdate(data, size);
case RS_PKT_SUBTYPE_GXS_GRP_CONFIG: return deserialGxsGrpConfig(data, size);
case RS_PKT_SUBTYPE_GXS_MSG_UPDATE: default:
return deserialGxsMsgUpdate(data, size);
case RS_PKT_SUBTYPE_GXS_GRP_UPDATE:
return deserialGxsGrpUpddate(data, size);
case RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE:
return deserialGxsServerGrpUpddate(data, size);
case RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE:
return deserialGxsServerMsgUpdate(data, size);
default:
{ {
#ifdef RSSERIAL_DEBUG # ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialise() : data has no type" std::cerr << "RsGxsUpdateSerialiser::deserialise() : data has no type"
<< std::endl; << std::endl;
#endif # endif
return NULL; return NULL;
} }
} }
} }
uint32_t RsGxsUpdateSerialiser::sizeGxsGrpUpdate(RsGxsGrpUpdateItem* item) /**********************************************************************************************/
/* SERIAL_SIZE() */
/**********************************************************************************************/
uint32_t RsGxsGrpUpdateItem::serial_size() const
{ {
uint32_t s = 8; // header size uint32_t s = 8; // header size
s += item->peerID.serial_size(); s += peerID.serial_size();
s += 4; // mUpdateTS s += 4; // mUpdateTS
return s; return s;
} }
uint32_t RsGxsUpdateSerialiser::sizeGxsServerGrpUpdate(RsGxsServerGrpUpdateItem* /* item */) uint32_t RsGxsServerGrpUpdateItem::serial_size() const
{ {
uint32_t s = 8; // header size uint32_t s = 8; // header size
s += 4; // time stamp s += 4; // time stamp
return s; return s;
} }
bool RsGxsUpdateSerialiser::serialiseGxsGrpUpdate(RsGxsGrpUpdateItem* item, uint32_t RsGxsMsgUpdateItem::serial_size() const
void* data, uint32_t* size)
{ {
#ifdef RSSERIAL_DEBUG uint32_t s = 8; // header size
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsGrpUpdate()" << std::endl; s += peerID.serial_size() ;//GetTlvStringSize(item->peerId);
#endif
uint32_t tlvsize = sizeGxsGrpUpdate(item); s += msgUpdateInfos.size() * (4 + 4 + RsGxsGroupId::serial_size());
uint32_t offset = 0; s += 4; // number of map items
if(*size < tlvsize){ return s;
#ifdef RSSERIAL_DEBUG }
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsGrpUpdate() size do not match" << std::endl;
#endif
return false;
}
*size = tlvsize; uint32_t RsGxsServerMsgUpdateItem::serial_size() const
{
uint32_t s = 8; // header size
s += grpId.serial_size();
s += 4; // grp TS
return s;
}
uint32_t RsGxsGrpConfigItem::serial_size() const
{
uint32_t s = 8; // header size
s += grpId.serial_size();
s += 4; // msg_keep_delay
s += 4; // msg_send_delay
s += 4; // msg_req_delay
return s;
}
/**********************************************************************************************/
/* SERIALISE() */
/**********************************************************************************************/
bool RsGxsGrpUpdateItem::serialise(void* data, uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true; bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* skip the header */ ok &= peerID.serialise(data, size, offset) ;
offset += 8; ok &= setRawUInt32(data, size, &offset, grpUpdateTS);
/* RsGxsGrpUpdateItem */
ok &= item->peerID.serialise(data, *size, offset) ;
ok &= setRawUInt32(data, *size, &offset, item->grpUpdateTS);
if(offset != tlvsize){ if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
@ -260,45 +247,20 @@ bool RsGxsUpdateSerialiser::serialiseGxsGrpUpdate(RsGxsGrpUpdateItem* item,
ok = false; ok = false;
} }
#ifdef RSSERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsGrpUpdate() NOK" << std::endl;
}
#endif
return ok; return ok;
} }
bool RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate(RsGxsServerGrpUpdateItem* item, bool RsGxsServerGrpUpdateItem::serialise(void* data, uint32_t& size) const
void* data, uint32_t* size)
{ {
#ifdef RSSERIAL_DEBUG uint32_t tlvsize,offset=0;
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsServerGrpUpdate(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate() size do not match" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true; bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); if(!serialise_header(data,size,tlvsize,offset))
return false ;
/* skip the header */
offset += 8;
/* RsGxsServerGrpUpdateItem */ /* RsGxsServerGrpUpdateItem */
ok &= setRawUInt32(data, *size, &offset, item->grpUpdateTS); ok &= setRawUInt32(data, size, &offset, grpUpdateTS);
if(offset != tlvsize){ if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
@ -307,15 +269,153 @@ bool RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate(RsGxsServerGrpUpdateItem
ok = false; ok = false;
} }
#ifdef RSSERIAL_DEBUG return ok;
if (!ok) }
bool RsGxsMsgUpdateItem::serialise(void* data, uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= peerID.serialise(data, size, offset) ;
std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>::const_iterator cit(msgUpdateInfos.begin());
uint32_t numItems = msgUpdateInfos.size();
ok &= setRawUInt32(data, size, &offset, numItems);
for(; cit != msgUpdateInfos.end(); ++cit)
{ {
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerGrpUpdate() NOK" << std::endl; ok &= cit->first.serialise(data, size, offset);
ok &= setRawUInt32(data, size, &offset, cit->second.time_stamp);
ok &= setRawUInt32(data, size, &offset, cit->second.message_count);
} }
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate() FAIL Size Error! " << std::endl;
#endif #endif
ok = false;
}
return ok; return ok;
} }
bool RsGxsServerMsgUpdateItem::serialise( void* data, uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= grpId.serialise(data, size, offset) ;
ok &= setRawUInt32(data, size, &offset, msgUpdateTS);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
return ok;
}
bool RsGxsGrpConfigItem::serialise( void* data, uint32_t& size) const
{
uint32_t tlvsize,offset=0;
bool ok = true;
if(!serialise_header(data,size,tlvsize,offset))
return false ;
ok &= grpId.serialise(data, size, offset) ;
ok &= setRawUInt32(data, size, &offset, msg_keep_delay);
ok &= setRawUInt32(data, size, &offset, msg_send_delay);
ok &= setRawUInt32(data, size, &offset, msg_req_delay);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
return ok;
}
/**********************************************************************************************/
/* DESERIALISE() */
/**********************************************************************************************/
RsGxsGrpConfigItem* RsGxsUpdateSerialiser::deserialGxsGrpConfig(void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_GRP_CONFIG != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsGrpConfigItem* item = new RsGxsGrpConfigItem(getRsItemService(rstype));
/* skip the header */
offset += 8;
ok &= item->grpId.deserialise(data, *size, offset) ;
ok &= getRawUInt32(data, *size, &offset, &(item->msg_keep_delay));
ok &= getRawUInt32(data, *size, &offset, &(item->msg_send_delay));
ok &= getRawUInt32(data, *size, &offset, &(item->msg_req_delay));
if (offset != rssize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxxGrpUpdate() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsGrpUpdate() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsGrpUpddate(void* data, uint32_t* size) RsGxsGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsGrpUpddate(void* data, uint32_t* size)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
@ -381,8 +481,7 @@ RsGxsGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsGrpUpddate(void* data, uin
return item; return item;
} }
RsGxsServerGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerGrpUpddate(void* data, RsGxsServerGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerGrpUpddate(void* data, uint32_t* size)
uint32_t* size)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << std::endl; std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate()" << std::endl;
@ -394,9 +493,7 @@ RsGxsServerGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerGrpUpddate(voi
uint32_t offset = 0; uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE != getRsItemSubType(rstype)))
(SERVICE_TYPE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL wrong type" << std::endl; std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerGrpUpdate() FAIL wrong type" << std::endl;
@ -446,137 +543,9 @@ RsGxsServerGrpUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerGrpUpddate(voi
return item; return item;
} }
uint32_t RsGxsUpdateSerialiser::sizeGxsMsgUpdate(RsGxsMsgUpdateItem* item)
{
uint32_t s = 8; // header size
s += item->peerID.serial_size() ;//GetTlvStringSize(item->peerId);
s += item->msgUpdateInfos.size() * (4 + 4 + RsGxsGroupId::serial_size());
s += 4; // number of map items
return s;
}
uint32_t RsGxsUpdateSerialiser::sizeGxsServerMsgUpdate(RsGxsServerMsgUpdateItem* item)
{
uint32_t s = 8; // header size
s += item->grpId.serial_size();
s += 4; // grp TS
return s;
}
bool RsGxsUpdateSerialiser::serialiseGxsMsgUpdate(RsGxsMsgUpdateItem* item,
void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsMsgUpdate(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate() size do not match" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* RsGxsMsgUpdateItem */
ok &= item->peerID.serialise(data, *size, offset) ; RsGxsMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsMsgUpdate(void* data, uint32_t* size)
std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>::const_iterator cit(item->msgUpdateInfos.begin());
uint32_t numItems = item->msgUpdateInfos.size();
ok &= setRawUInt32(data, *size, &offset, numItems);
for(; cit != item->msgUpdateInfos.end(); ++cit)
{
ok &= cit->first.serialise(data, *size, offset);
ok &= setRawUInt32(data, *size, &offset, cit->second.time_stamp);
ok &= setRawUInt32(data, *size, &offset, cit->second.message_count);
}
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef RSSERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsMsgUpdate() NOK" << std::endl;
}
#endif
return ok;
}
bool RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate(RsGxsServerMsgUpdateItem* item,
void* data, uint32_t* size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsServerMsgUpdate(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() size do not match" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* RsNxsSyncm */
ok &= item->grpId.serialise(data, *size, offset) ;
ok &= setRawUInt32(data, *size, &offset, item->msgUpdateTS);
if(offset != tlvsize){
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef RSSERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsUpdateSerialiser::serialiseGxsServerMsgUpdate() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsMsgUpdate(void* data,
uint32_t* size)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate()" << std::endl; std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate()" << std::endl;
@ -588,9 +557,7 @@ RsGxsMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsMsgUpdate(void* data,
uint32_t offset = 0; uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_MSG_UPDATE != getRsItemSubType(rstype)))
(SERVICE_TYPE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXS_MSG_UPDATE != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL wrong type" << std::endl; std::cerr << "RsGxsUpdateSerialiser::deserialGxsMsgUpdate() FAIL wrong type" << std::endl;
@ -662,8 +629,7 @@ RsGxsMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsMsgUpdate(void* data,
return item; return item;
} }
RsGxsServerMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate(void* data, RsGxsServerMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate(void* data, uint32_t* size)
uint32_t* size)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate()" << std::endl; std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate()" << std::endl;
@ -675,9 +641,7 @@ RsGxsServerMsgUpdateItem* RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate(void
uint32_t offset = 0; uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE != getRsItemSubType(rstype)))
(SERVICE_TYPE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE != getRsItemSubType(rstype)))
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL wrong type" << std::endl; std::cerr << "RsGxsUpdateSerialiser::deserialGxsServerMsgUpdate() FAIL wrong type" << std::endl;

View File

@ -49,6 +49,23 @@ const uint8_t RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE = 0x04;
const uint8_t RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE = 0x08; const uint8_t RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE = 0x08;
const uint8_t RS_PKT_SUBTYPE_GXS_GRP_CONFIG = 0x09; const uint8_t RS_PKT_SUBTYPE_GXS_GRP_CONFIG = 0x09;
class RsGxsNetServiceItem: public RsItem
{
public:
RsGxsNetServiceItem(uint16_t serv_type,uint8_t subtype) : RsItem(RS_PKT_VERSION_SERVICE, serv_type, subtype) {}
virtual ~RsGxsNetServiceItem() {}
virtual bool serialise(void *data,uint32_t& size) const = 0 ;
virtual uint32_t serial_size() const = 0 ;
virtual void clear() = 0 ;
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0;
protected:
bool serialise_header(void *data, uint32_t& pktsize, uint32_t& tlvsize, uint32_t& offset) const;
};
class RsGxsGrpConfig class RsGxsGrpConfig
{ {
public: public:
@ -72,16 +89,18 @@ public:
time_t update_TS ; // last time the max visible count was updated. time_t update_TS ; // last time the max visible count was updated.
}; };
class RsGxsGrpConfigItem : public RsItem, public RsGxsGrpConfig class RsGxsGrpConfigItem : public RsGxsNetServiceItem, public RsGxsGrpConfig
{ {
public: public:
RsGxsGrpConfigItem(uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType, RS_PKT_SUBTYPE_GXS_GRP_CONFIG) {} RsGxsGrpConfigItem(uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_GRP_CONFIG) {}
RsGxsGrpConfigItem(const RsGxsGrpConfig& m,uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType, RS_PKT_SUBTYPE_GXS_GRP_CONFIG),RsGxsGrpConfig(m) {} RsGxsGrpConfigItem(const RsGxsGrpConfig& m,uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_GRP_CONFIG),RsGxsGrpConfig(m) {}
virtual ~RsGxsGrpConfigItem() {} virtual ~RsGxsGrpConfigItem() {}
virtual void clear() {} virtual void clear() {}
virtual std::ostream &print(std::ostream &out, uint16_t indent) { return out;} virtual std::ostream &print(std::ostream &out, uint16_t indent) { return out;}
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
}; };
class RsGxsGrpUpdate class RsGxsGrpUpdate
@ -93,16 +112,19 @@ public:
uint32_t grpUpdateTS; uint32_t grpUpdateTS;
}; };
class RsGxsGrpUpdateItem : public RsItem, public RsGxsGrpUpdate class RsGxsGrpUpdateItem : public RsGxsNetServiceItem, public RsGxsGrpUpdate
{ {
public: public:
RsGxsGrpUpdateItem(uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType, RS_PKT_SUBTYPE_GXS_GRP_UPDATE) {clear();} RsGxsGrpUpdateItem(uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_GRP_UPDATE) {clear();}
RsGxsGrpUpdateItem(const RsGxsGrpUpdate& u,uint16_t serv_type) : RsGxsGrpUpdate(u),RsItem(RS_PKT_VERSION_SERVICE, serv_type, RS_PKT_SUBTYPE_GXS_GRP_UPDATE) {clear();} RsGxsGrpUpdateItem(const RsGxsGrpUpdate& u,uint16_t serv_type) : RsGxsNetServiceItem(serv_type, RS_PKT_SUBTYPE_GXS_GRP_UPDATE), RsGxsGrpUpdate(u) {clear();}
virtual ~RsGxsGrpUpdateItem() {} virtual ~RsGxsGrpUpdateItem() {}
virtual void clear(); virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent); virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
}; };
class RsGxsServerGrpUpdate class RsGxsServerGrpUpdate
@ -113,16 +135,19 @@ public:
uint32_t grpUpdateTS; uint32_t grpUpdateTS;
}; };
class RsGxsServerGrpUpdateItem : public RsItem, public RsGxsServerGrpUpdate class RsGxsServerGrpUpdateItem : public RsGxsNetServiceItem, public RsGxsServerGrpUpdate
{ {
public: public:
RsGxsServerGrpUpdateItem(uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType, RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE) { clear();} RsGxsServerGrpUpdateItem(uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE) { clear();}
RsGxsServerGrpUpdateItem(const RsGxsServerGrpUpdate& u,uint16_t serv_type) : RsGxsServerGrpUpdate(u),RsItem(RS_PKT_VERSION_SERVICE, serv_type, RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE) {clear();} RsGxsServerGrpUpdateItem(const RsGxsServerGrpUpdate& u,uint16_t serv_type) : RsGxsNetServiceItem(serv_type, RS_PKT_SUBTYPE_GXS_SERVER_GRP_UPDATE), RsGxsServerGrpUpdate(u) {clear();}
virtual ~RsGxsServerGrpUpdateItem() {} virtual ~RsGxsServerGrpUpdateItem() {}
virtual void clear(); virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent); virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
}; };
class RsGxsMsgUpdate class RsGxsMsgUpdate
@ -140,16 +165,19 @@ public:
std::map<RsGxsGroupId, MsgUpdateInfo> msgUpdateInfos; std::map<RsGxsGroupId, MsgUpdateInfo> msgUpdateInfos;
}; };
class RsGxsMsgUpdateItem : public RsItem, public RsGxsMsgUpdate class RsGxsMsgUpdateItem : public RsGxsNetServiceItem, public RsGxsMsgUpdate
{ {
public: public:
RsGxsMsgUpdateItem(uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType, RS_PKT_SUBTYPE_GXS_MSG_UPDATE) { clear();} RsGxsMsgUpdateItem(uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_MSG_UPDATE) { clear();}
RsGxsMsgUpdateItem(const RsGxsMsgUpdate& m,uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType, RS_PKT_SUBTYPE_GXS_MSG_UPDATE), RsGxsMsgUpdate(m) { clear();} RsGxsMsgUpdateItem(const RsGxsMsgUpdate& m,uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_MSG_UPDATE), RsGxsMsgUpdate(m) { clear();}
virtual ~RsGxsMsgUpdateItem() {} virtual ~RsGxsMsgUpdateItem() {}
virtual void clear(); virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent); virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
}; };
class RsGxsServerMsgUpdate class RsGxsServerMsgUpdate
@ -161,15 +189,18 @@ public:
uint32_t msgUpdateTS; // local time stamp this group last received a new msg uint32_t msgUpdateTS; // local time stamp this group last received a new msg
}; };
class RsGxsServerMsgUpdateItem : public RsItem, public RsGxsServerMsgUpdate class RsGxsServerMsgUpdateItem : public RsGxsNetServiceItem, public RsGxsServerMsgUpdate
{ {
public: public:
RsGxsServerMsgUpdateItem(uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType, RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE) { clear();} RsGxsServerMsgUpdateItem(uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE) { clear();}
RsGxsServerMsgUpdateItem(const RsGxsServerMsgUpdate& m,uint16_t servType) : RsItem(RS_PKT_VERSION_SERVICE, servType, RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE),RsGxsServerMsgUpdate(m) { clear();} RsGxsServerMsgUpdateItem(const RsGxsServerMsgUpdate& m,uint16_t servType) : RsGxsNetServiceItem(servType, RS_PKT_SUBTYPE_GXS_SERVER_MSG_UPDATE),RsGxsServerMsgUpdate(m) { clear();}
virtual ~RsGxsServerMsgUpdateItem() {} virtual ~RsGxsServerMsgUpdateItem() {}
virtual void clear(); virtual void clear();
virtual std::ostream &print(std::ostream &out, uint16_t indent); virtual std::ostream &print(std::ostream &out, uint16_t indent);
virtual bool serialise(void *data,uint32_t& size) const ;
virtual uint32_t serial_size() const ;
}; };
@ -177,53 +208,44 @@ class RsGxsUpdateSerialiser : public RsSerialType
{ {
public: public:
RsGxsUpdateSerialiser(uint16_t servtype) : RsGxsUpdateSerialiser(uint16_t servtype) : RsSerialType(RS_PKT_VERSION_SERVICE, servtype), SERVICE_TYPE(servtype) {}
RsSerialType(RS_PKT_VERSION_SERVICE, servtype), SERVICE_TYPE(servtype) { return; }
virtual ~RsGxsUpdateSerialiser() { return; } virtual ~RsGxsUpdateSerialiser() {}
virtual uint32_t size(RsItem *item); virtual uint32_t size(RsItem *item)
virtual bool serialise(RsItem *item, void *data, uint32_t *size); {
virtual RsItem* deserialise(void *data, uint32_t *size); RsGxsNetServiceItem *gitem = dynamic_cast<RsGxsNetServiceItem *>(item);
if (!gitem)
return 0;
return gitem->serial_size() ;
}
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsNetServiceItem *gitem = dynamic_cast<RsGxsNetServiceItem *>(item);
if (!gitem)
return false;
return gitem->serialise(data,*size) ;
}
virtual RsItem* deserialise(void *data, uint32_t *size);
private: private:
RsGxsGrpConfigItem *deserialGxsGrpConfig(void *data, uint32_t *size);
RsGxsServerMsgUpdateItem *deserialGxsServerMsgUpdate(void *data, uint32_t *size);
RsGxsMsgUpdateItem *deserialGxsMsgUpdate(void *data, uint32_t *size);
RsGxsServerGrpUpdateItem *deserialGxsServerGrpUpddate(void *data, uint32_t *size);
RsGxsGrpUpdateItem *deserialGxsGrpUpddate(void *data, uint32_t *size);
bool checkItemHeader(void *data, uint32_t *size, uint16_t service_type,uint8_t subservice_type);
/* for RS_PKT_SUBTYPE_GRP_UPDATE_ITEM */ const uint16_t SERVICE_TYPE;
uint32_t sizeGxsGrpUpdate(RsGxsGrpUpdateItem* item);
bool serialiseGxsGrpUpdate(RsGxsGrpUpdateItem *item, void *data, uint32_t *size);
RsGxsGrpUpdateItem* deserialGxsGrpUpddate(void *data, uint32_t *size);
/* for RS_PKT_SUBTYPE_GRP_SERVER_UPDATE_ITEM */
uint32_t sizeGxsServerGrpUpdate(RsGxsServerGrpUpdateItem* item);
bool serialiseGxsServerGrpUpdate(RsGxsServerGrpUpdateItem *item, void *data, uint32_t *size);
RsGxsServerGrpUpdateItem* deserialGxsServerGrpUpddate(void *data, uint32_t *size);
/* for RS_PKT_SUBTYPE_GXS_MSG_UPDATE_ITEM */
uint32_t sizeGxsMsgUpdate(RsGxsMsgUpdateItem* item);
bool serialiseGxsMsgUpdate(RsGxsMsgUpdateItem *item, void *data, uint32_t *size);
RsGxsMsgUpdateItem* deserialGxsMsgUpdate(void *data, uint32_t *size);
/* for RS_PKT_SUBTYPE_GXS_SERVER_UPDATE_ITEM */
uint32_t sizeGxsServerMsgUpdate(RsGxsServerMsgUpdateItem* item);
bool serialiseGxsServerMsgUpdate(RsGxsServerMsgUpdateItem *item, void *data, uint32_t *size);
RsGxsServerMsgUpdateItem* deserialGxsServerMsgUpdate(void *data, uint32_t *size);
/* for RS_PKT_SUBTYPE_GXS_CONFIG */
uint32_t sizeGxsGrpConfig(RsGxsGrpConfigItem* item);
bool serialiseGxsGrpConfig(RsGxsGrpConfigItem *item, void *data, uint32_t *size);
RsGxsGrpConfigItem* deserialGxsGrpConfig(void *data, uint32_t *size);
private:
const uint16_t SERVICE_TYPE;
}; };
#endif /* RSGXSUPDATEITEMS_H_ */ #endif /* RSGXSUPDATEITEMS_H_ */