diff --git a/libretroshare/src/serialiser/rsserviceinfoitems.cc b/libretroshare/src/serialiser/rsserviceinfoitems.cc index 8efc0eb87..a538273de 100644 --- a/libretroshare/src/serialiser/rsserviceinfoitems.cc +++ b/libretroshare/src/serialiser/rsserviceinfoitems.cc @@ -25,6 +25,7 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rsserviceinfoitems.h" +#include "serialization/rstypeserializer.h" /*** #define RSSERIAL_DEBUG 1 @@ -35,8 +36,7 @@ /*************************************************************************/ /***** RsServiceInfo ****/ -template<> -std::ostream &RsTlvParamRef::print(std::ostream &out, uint16_t /*indent*/) const +template<> std::ostream& RsTlvParamRef::print(std::ostream &out, uint16_t /*indent*/) const { out << "RsServiceInfo: " << mParam.mServiceType << " name " << mParam.mServiceName; out << std::endl; @@ -138,38 +138,19 @@ template class RsTlvParamRef; /*************************************************************************/ -RsServiceInfoListItem::~RsServiceInfoListItem() -{ - return; -} - void RsServiceInfoListItem::clear() { mServiceInfo.clear(); } -std::ostream &RsServiceInfoListItem::print(std::ostream &out, uint16_t indent) +void RsServiceInfoListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { - printRsItemBase(out, "RsServiceInfoListItem", indent); - uint16_t int_Indent = indent + 2; RsTlvServiceInfoMapRef map(mServiceInfo); - map.print(out, int_Indent); - out << std::endl; - printRsItemEnd(out, "RsServiceInfoListItem", indent); - return out; -} - - -uint32_t RsServiceInfoSerialiser::sizeInfo(RsServiceInfoListItem *item) -{ - uint32_t s = 8; /* header */ - RsTlvServiceInfoMapRef map(item->mServiceInfo); - s += map.TlvSize(); - - return s; + RsTypeSerializer::serial_process(j,ctx,map,"map") ; } +#ifdef TO_REMOVE /* serialise the data to the buffer */ bool RsServiceInfoSerialiser::serialiseInfo(RsServiceInfoListItem *item, void *data, uint32_t *pktsize) { @@ -291,7 +272,14 @@ uint32_t RsServiceInfoSerialiser::sizePermissions(RsServiceInfoPermissionsIte return s; } +#endif +void RsServiceInfoPermissionsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) +{ + RsTypeSerializer::serial_process(j,ctx,allowedBw,"allowedBw") ; +} + +#ifdef TO_REMOVE /* serialise the data to the buffer */ bool RsServiceInfoSerialiser::serialisePermissions(RsServiceInfoPermissionsItem *item, void *data, uint32_t *pktsize) { @@ -440,6 +428,21 @@ RsItem *RsServiceInfoSerialiser::deserialise(void *data, uint32_t *pktsize) } /*************************************************************************/ +#endif + +RsItem *RsServiceInfoSerialiser::create_item(uint16_t service, uint8_t item_sub_id) const +{ + if(service != RS_SERVICE_TYPE_SERVICEINFO) + return NULL ; + + switch(item_sub_id) + { + case RS_PKT_SUBTYPE_SERVICELIST_ITEM: return new RsServiceInfoListItem() ; + case RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM: return new RsServiceInfoPermissionsItem() ; + default: + return NULL ; + } +} diff --git a/libretroshare/src/serialiser/rsserviceinfoitems.h b/libretroshare/src/serialiser/rsserviceinfoitems.h index b4c9beabe..04a524331 100644 --- a/libretroshare/src/serialiser/rsserviceinfoitems.h +++ b/libretroshare/src/serialiser/rsserviceinfoitems.h @@ -34,8 +34,6 @@ #include "rsitems/rsitem.h" #include "rsitems/itempriorities.h" -#include "serialiser/rsserial.h" -#include "serialiser/rstlvbase.h" #include "serialiser/rstlvgenericmap.h" #include "retroshare/rsservicecontrol.h" @@ -63,72 +61,47 @@ public: } }; - - class RsServiceInfoListItem: public RsItem { public: - RsServiceInfoListItem() - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO, - RS_PKT_SUBTYPE_SERVICELIST_ITEM) + RsServiceInfoListItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO, RS_PKT_SUBTYPE_SERVICELIST_ITEM) { setPriorityLevel(QOS_PRIORITY_RS_SERVICE_INFO_ITEM); return; } -virtual ~RsServiceInfoListItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual ~RsServiceInfoListItem(){} + virtual void clear(); - std::map mServiceInfo; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); + + std::map mServiceInfo; }; - class RsServiceInfoPermissionsItem: public RsItem { public: - RsServiceInfoPermissionsItem() - :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO, - RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM) + RsServiceInfoPermissionsItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO, RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM) { setPriorityLevel(QOS_PRIORITY_RS_SERVICE_INFO_ITEM); return; } -virtual ~RsServiceInfoPermissionsItem(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); + virtual ~RsServiceInfoPermissionsItem(){} + virtual void clear(){} + + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t allowedBw; // Units are bytes/sec => 4Gb/s; - }; - -class RsServiceInfoSerialiser: public RsSerialType +class RsServiceInfoSerialiser: public RsServiceSerializer { public: - RsServiceInfoSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO) - { return; } -virtual ~RsServiceInfoSerialiser() - { return; } + RsServiceInfoSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_SERVICEINFO) {} + virtual ~RsServiceInfoSerialiser() {} -virtual uint32_t size(RsItem *); -virtual bool serialise (RsItem *item, void *data, uint32_t *size); -virtual RsItem * deserialise(void *data, uint32_t *size); - - private: - -virtual uint32_t sizeInfo(RsServiceInfoListItem *); -virtual bool serialiseInfo(RsServiceInfoListItem *item, void *data, uint32_t *size); -virtual RsServiceInfoListItem *deserialiseInfo(void *data, uint32_t *size); - - -virtual uint32_t sizePermissions(RsServiceInfoPermissionsItem *); -virtual bool serialisePermissions(RsServiceInfoPermissionsItem *item, void *data, uint32_t *size); -virtual RsServiceInfoPermissionsItem *deserialisePermissions(void *data, uint32_t *size); - - + virtual RsItem *create_item(uint16_t /* service */, uint8_t /* item_sub_id */) const; }; /**************************************************************************/ diff --git a/libretroshare/src/serialiser/rstlvgenericmap.inl b/libretroshare/src/serialiser/rstlvgenericmap.inl index 87e0d8b04..540ee5d2e 100644 --- a/libretroshare/src/serialiser/rstlvgenericmap.inl +++ b/libretroshare/src/serialiser/rstlvgenericmap.inl @@ -24,6 +24,7 @@ * */ +#include "serialiser/rstlvbase.h" // Must be different - as this is inline in headers. //#define TLV_GENERICMAP_DEBUG 1