From 9c610a736da2f1caefcaead5762af23ccdb24e01 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Apr 2017 11:40:46 +0200 Subject: [PATCH] cleaned the hierarchy of serialization classes --- libretroshare/src/chat/rschatitems.cc | 28 +++--- libretroshare/src/chat/rschatitems.h | 30 +++--- .../src/file_sharing/rsfilelistitems.cc | 6 +- .../src/file_sharing/rsfilelistitems.h | 5 +- .../src/ft/ftturtlefiletransferitem.cc | 12 +-- .../src/ft/ftturtlefiletransferitem.h | 12 +-- libretroshare/src/grouter/grouteritems.cc | 40 ++++---- libretroshare/src/grouter/grouteritems.h | 18 ++-- .../src/gxstunnel/rsgxstunnelitems.h | 5 +- libretroshare/src/libretroshare.pro | 3 +- libretroshare/src/pqi/p3servicecontrol.cc | 1 + libretroshare/src/pqi/pqi.h | 3 +- libretroshare/src/pqi/pqiqos.cc | 4 + libretroshare/src/pqi/pqistore.cc | 1 + libretroshare/src/rsitems/rsbanlistitems.cc | 4 +- libretroshare/src/rsitems/rsbanlistitems.h | 6 +- libretroshare/src/rsitems/rsbwctrlitems.cc | 2 +- libretroshare/src/rsitems/rsbwctrlitems.h | 6 +- libretroshare/src/rsitems/rsconfigitems.cc | 19 ++-- libretroshare/src/rsitems/rsconfigitems.h | 18 ++-- .../src/rsitems/rsdiscovery2items.cc | 8 +- libretroshare/src/rsitems/rsdiscovery2items.h | 8 +- .../src/rsitems/rsfiletransferitems.cc | 12 +-- .../src/rsitems/rsfiletransferitems.h | 14 +-- .../src/rsitems/rsgxsreputationitems.cc | 10 +- .../src/rsitems/rsgxsreputationitems.h | 13 ++- libretroshare/src/rsitems/rshistoryitems.cc | 4 +- libretroshare/src/rsitems/rshistoryitems.h | 2 +- libretroshare/src/rsitems/rsitem.h | 90 ++++++++++++++++++ libretroshare/src/rsitems/rsmsgitems.cc | 18 ++-- libretroshare/src/rsitems/rsmsgitems.h | 18 ++-- libretroshare/src/rsitems/rsrttitems.cc | 6 +- libretroshare/src/rsitems/rsrttitems.h | 6 +- libretroshare/src/serialiser/rsgxsitems.h | 1 + .../src/serialiser/rsgxsrecognitems.h | 3 + .../src/serialiser/rsheartbeatitems.h | 2 + libretroshare/src/serialiser/rsnxsitems.h | 1 + libretroshare/src/serialiser/rsserial.cc | 5 +- libretroshare/src/serialiser/rsserial.h | 94 +------------------ .../src/serialiser/rsserviceinfoitems.h | 3 + .../src/serialiser/rsserviceserialiser.cc | 1 + libretroshare/src/serialiser/rsstatusitems.h | 3 +- .../src/serialization/rsserializer.cc | 12 ++- .../src/serialization/rsserializer.h | 35 +++++-- .../src/serialization/rstypeserializer.h | 84 +++++++---------- libretroshare/src/services/p3service.cc | 2 + libretroshare/src/turtle/rsturtleitem.cc | 12 +-- libretroshare/src/turtle/rsturtleitem.h | 18 ++-- 48 files changed, 382 insertions(+), 326 deletions(-) create mode 100644 libretroshare/src/rsitems/rsitem.h diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index 7aa0dd4f3..06bb063a7 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -62,7 +62,7 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) c } } -void RsChatMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ; RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ; @@ -80,7 +80,7 @@ RsChatAvatarItem::~RsChatAvatarItem() } } -void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, SerializeContext& ctx) +void RsChatLobbyBouncingObject::serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ; @@ -90,19 +90,19 @@ void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, Serialize RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; } -void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsChatMsgItem::serial_process(j,ctx) ; RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ; RsChatLobbyBouncingObject::serial_process(j,ctx) ; } -void RsChatLobbyListRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyListRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { // nothing to do. This is an empty item. } -template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& name) +template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& name) { RsTypeSerializer::serial_process(j,ctx,info.id,"info.id") ; @@ -112,12 +112,12 @@ template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,Serializ RsTypeSerializer::serial_process (j,ctx, info.flags,"info.flags") ; } -void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobbies,"lobbies") ; } -void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyEventItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,event_type,"event_type") ; RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,string1,"string1") ; @@ -125,24 +125,24 @@ void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContex RsChatLobbyBouncingObject::serial_process(j,ctx) ; } -void RsChatLobbyUnsubscribeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyUnsubscribeItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; } -void RsChatLobbyConnectChallengeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyConnectChallengeItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,challenge_code,"challenge_code") ; } -void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyInviteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx, lobby_id, "lobby_id") ; RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ; RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ; } -void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsPrivateChatMsgConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { uint32_t x=0 ; @@ -154,19 +154,19 @@ void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,Serialize RsTypeSerializer::serial_process(j,ctx, recvTime, "recvTime") ; } -void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,status_string,"status_string") ; } -void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatAvatarItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::TlvMemBlock_proxy b(image_data,image_size) ; RsTypeSerializer::serial_process(j,ctx,b,"image data") ; } -void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsChatLobbyConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_Id,"lobby_Id") ; RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 1766dbfec..06de87c7f 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -30,6 +30,8 @@ #include "serialization/rsserializer.h" #include "serialiser/rstlvkeys.h" #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" +#include "rsitems/rsitem.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" @@ -112,7 +114,7 @@ public: // derived from RsItem - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} uint32_t chatFlags; @@ -142,7 +144,7 @@ protected: // They are called by serial_size() and serialise() from children, but should not overload the serial_size() and // serialise() methods, otherwise the wrong method will be called when serialising from this top level class. - virtual void serial_process(RsItem::SerializeJob j, SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual uint32_t PacketId() const= 0; }; @@ -155,7 +157,7 @@ public: virtual ~RsChatLobbyMsgItem() {} virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; } - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ; + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); ChatLobbyMsgId parent_msg_id ; // Used for threaded chat. @@ -171,7 +173,7 @@ public: virtual ~RsChatLobbyEventItem() {} virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; } // - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // members. // @@ -189,7 +191,7 @@ class RsChatLobbyListRequestItem: public RsChatItem RsChatLobbyListRequestItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) {} virtual ~RsChatLobbyListRequestItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; struct VisibleChatLobbyInfo @@ -207,7 +209,7 @@ class RsChatLobbyListItem: public RsChatItem RsChatLobbyListItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) {} virtual ~RsChatLobbyListItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); std::vector lobbies ; }; @@ -219,7 +221,7 @@ class RsChatLobbyUnsubscribeItem: public RsChatItem virtual ~RsChatLobbyUnsubscribeItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint64_t lobby_id ; }; @@ -231,7 +233,7 @@ class RsChatLobbyConnectChallengeItem: public RsChatItem virtual ~RsChatLobbyConnectChallengeItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint64_t challenge_code ; }; @@ -242,7 +244,7 @@ class RsChatLobbyInviteItem: public RsChatItem RsChatLobbyInviteItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) {} virtual ~RsChatLobbyInviteItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); ChatLobbyId lobby_id ; std::string lobby_name ; @@ -262,7 +264,7 @@ class RsPrivateChatMsgConfigItem: public RsChatItem virtual ~RsPrivateChatMsgConfigItem() {} virtual void clear() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); /* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */ void set(RsChatMsgItem *ci, const RsPeerId &peerId, uint32_t confFlags); @@ -286,7 +288,7 @@ public: virtual void clear() { lobby_Id = 0; } - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint64_t lobby_Id; uint32_t flags ; @@ -301,7 +303,7 @@ class RsChatStatusItem: public RsChatItem virtual ~RsChatStatusItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t flags ; std::string status_string; @@ -315,7 +317,7 @@ class RsChatAvatarItem: public RsChatItem RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_AVATAR_ITEM) ;} virtual ~RsChatAvatarItem() ; - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t image_size ; // size of data in bytes unsigned char *image_data ; // image @@ -325,7 +327,7 @@ class RsChatSerialiser: public RsServiceSerializer { public: RsChatSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) - :RsServiceSerializer(RS_SERVICE_TYPE_CHAT,SerializeContext::FORMAT_BINARY,flags) {} + :RsServiceSerializer(RS_SERVICE_TYPE_CHAT,RsGenericSerializer::FORMAT_BINARY,flags) {} virtual RsItem *create_item(uint16_t service_id,uint8_t item_sub_id) const ; }; diff --git a/libretroshare/src/file_sharing/rsfilelistitems.cc b/libretroshare/src/file_sharing/rsfilelistitems.cc index 85a94488f..6934f29d2 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.cc +++ b/libretroshare/src/file_sharing/rsfilelistitems.cc @@ -24,16 +24,18 @@ */ #include "serialiser/rsbaseserial.h" +#include "serialization/rstypeserializer.h" + #include "file_sharing/rsfilelistitems.h" -void RsFileListsSyncRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsFileListsSyncRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ; RsTypeSerializer::serial_process(j,ctx,flags ,"flags") ; RsTypeSerializer::serial_process(j,ctx,last_known_recurs_modf_TS,"last_known_recurs_modf_TS") ; RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; } -void RsFileListsSyncResponseItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsFileListsSyncResponseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,entry_hash,"entry_hash") ; RsTypeSerializer::serial_process (j,ctx,checksum,"checksum") ; diff --git a/libretroshare/src/file_sharing/rsfilelistitems.h b/libretroshare/src/file_sharing/rsfilelistitems.h index 391d3dd88..8e45ef251 100644 --- a/libretroshare/src/file_sharing/rsfilelistitems.h +++ b/libretroshare/src/file_sharing/rsfilelistitems.h @@ -28,6 +28,7 @@ #include #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvitem.h" @@ -78,7 +79,7 @@ public: virtual void clear(){} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsFileHash entry_hash ; // hash of the directory to sync uint32_t flags; // used to say that it's a request or a response, say that the directory has been removed, ask for further update, etc. @@ -94,7 +95,7 @@ public: virtual void clear(); - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsFileHash entry_hash ; // hash of the directory to sync RsFileHash checksum ; // checksum of the bindary data, for checking diff --git a/libretroshare/src/ft/ftturtlefiletransferitem.cc b/libretroshare/src/ft/ftturtlefiletransferitem.cc index 5c343b7fa..3009fb87c 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.cc +++ b/libretroshare/src/ft/ftturtlefiletransferitem.cc @@ -32,37 +32,37 @@ #include -void RsTurtleFileMapRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleFileMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,direction,"direction") ; } -void RsTurtleFileMapItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleFileMapItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,direction,"direction") ; RsTypeSerializer::serial_process (j,ctx,compressed_map._map,"map") ; } -void RsTurtleChunkCrcRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleChunkCrcRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; } -void RsTurtleChunkCrcItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleChunkCrcItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; RsTypeSerializer::serial_process (j,ctx,check_sum,"check_sum") ; } -void RsTurtleFileRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleFileRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,chunk_offset,"chunk_offset") ; RsTypeSerializer::serial_process(j,ctx,chunk_size,"chunk_size") ; } -void RsTurtleFileDataItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleFileDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,chunk_offset,"chunk_offset") ; diff --git a/libretroshare/src/ft/ftturtlefiletransferitem.h b/libretroshare/src/ft/ftturtlefiletransferitem.h index fd8aada93..ce4a25217 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.h +++ b/libretroshare/src/ft/ftturtlefiletransferitem.h @@ -43,7 +43,7 @@ class RsTurtleFileRequestItem: public RsTurtleGenericTunnelItem void clear() {} protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem @@ -67,7 +67,7 @@ class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem uint32_t chunk_size ; // size of the file chunk void *chunk_data ; // actual data. - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem @@ -78,7 +78,7 @@ class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem virtual bool shouldStampTunnel() const { return false ; } void clear() {} - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem @@ -93,7 +93,7 @@ class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem // with the default file map for this source. void clear() { compressed_map._map.clear() ;} - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem @@ -107,7 +107,7 @@ class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem uint32_t chunk_number ; // id of the chunk to CRC. void clear() {} - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem @@ -122,5 +122,5 @@ class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem Sha1CheckSum check_sum ; void clear() { check_sum.clear() ;} - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; diff --git a/libretroshare/src/grouter/grouteritems.cc b/libretroshare/src/grouter/grouteritems.cc index c48dbc134..48da81548 100644 --- a/libretroshare/src/grouter/grouteritems.cc +++ b/libretroshare/src/grouter/grouteritems.cc @@ -3,6 +3,8 @@ #include "serialiser/rstlvbase.h" #include "grouteritems.h" +#include "serialization/rstypeserializer.h" + /**********************************************************************************************/ /* SERIALISER STUFF */ /**********************************************************************************************/ @@ -28,7 +30,7 @@ RsItem *RsGRouterSerialiser::create_item(uint16_t service_id,uint8_t subtype) co } } -void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterTransactionChunkItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,propagation_id,"propagation_id") ; RsTypeSerializer::serial_process(j,ctx,chunk_start ,"chunk_start") ; @@ -37,7 +39,7 @@ void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeConte // Hack for backward compatibility (the chunk size is not directly next to the chunk data) - if(j == RsItem::DESERIALIZE) + if(j == RsGenericSerializer::DESERIALIZE) { if(chunk_size > ctx.mSize || ctx.mOffset > ctx.mSize - chunk_size) // better than if(chunk_size + offset > size) { @@ -54,12 +56,12 @@ void RsGRouterTransactionChunkItem::serial_process(SerializeJob j,SerializeConte memcpy(chunk_data,&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_size) ; ctx.mOffset += chunk_size ; } - else if(j== RsItem::SERIALIZE) + else if(j== RsGenericSerializer::SERIALIZE) { memcpy(&((uint8_t*)ctx.mData)[ctx.mOffset],chunk_data,chunk_size) ; ctx.mOffset += chunk_size ; } - else if(j== RsItem::SIZE_ESTIMATE) + else if(j== RsGenericSerializer::SIZE_ESTIMATE) ctx.mOffset += chunk_size ; else std::cerr << " [Binary data] " << ", length=" << chunk_size << " data=" << RsUtil::BinToHex((uint8_t*)chunk_data,std::min(50u,chunk_size)) << ((chunk_size>50)?"...":"") << std::endl; @@ -112,7 +114,7 @@ RsGRouterTransactionChunkItem *RsGRouterSerialiser::deserialise_RsGRouterTransac } #endif -void RsGRouterTransactionAcknItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterTransactionAcknItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,propagation_id,"propagation_id") ; } @@ -140,7 +142,7 @@ RsGRouterTransactionAcknItem *RsGRouterSerialiser::deserialise_RsGRouterTransact } #endif -void RsGRouterGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,routing_id,"routing_id") ; RsTypeSerializer::serial_process (j,ctx,destination_key,"destination_key") ; @@ -157,7 +159,7 @@ void RsGRouterGenericDataItem::serial_process(SerializeJob j,SerializeContext& c RsTypeSerializer::serial_process(j,ctx,duplication_factor,"duplication_factor") ; RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; - if(j == RsItem::DESERIALIZE) // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more. + if(j == RsGenericSerializer::DESERIALIZE) // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more. { if(duplication_factor < 1) { @@ -242,7 +244,7 @@ RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataI } #endif -void RsGRouterSignedReceiptItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterSignedReceiptItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,routing_id,"routing_id") ; RsTypeSerializer::serial_process (j,ctx,flags,"flags") ; @@ -283,7 +285,7 @@ RsGRouterSignedReceiptItem *RsGRouterSerialiser::deserialise_RsGRouterSignedRece } #endif -void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterRoutingInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; RsTypeSerializer::serial_process(j,ctx,data_status,"data_status") ; @@ -304,7 +306,7 @@ void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& c // Hack for backward compatibility. Normally we should need a single commandline to serialise/deserialise a single item here. // But the full item is serialised, so we need the header. - if(j == RsItem::DESERIALIZE) + if(j == RsGenericSerializer::DESERIALIZE) { data_item = new RsGRouterGenericDataItem() ; @@ -321,7 +323,7 @@ void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& c else receipt_item = NULL ; } - else if(j == RsItem::SERIALIZE) + else if(j == RsGenericSerializer::SERIALIZE) { uint32_t remaining_size = ctx.mSize - ctx.mOffset; ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size) ; @@ -330,18 +332,18 @@ void RsGRouterRoutingInfoItem::serial_process(SerializeJob j,SerializeContext& c if(receipt_item != NULL) { remaining_size = ctx.mSize - ctx.mOffset; - ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(data_item,ctx.mData,&remaining_size); - ctx.mOffset += RsGRouterSerialiser().size(data_item) ; + ctx.mOk = ctx.mOk && RsGRouterSerialiser().serialise(receipt_item,ctx.mData,&remaining_size); + ctx.mOffset += RsGRouterSerialiser().size(receipt_item) ; } } - else if(j == RsItem::PRINT) + else if(j == RsGenericSerializer::PRINT) { std::cerr << " [Serialized data] " << std::endl; if(receipt_item != NULL) std::cerr << " [Receipt item ]" << std::endl; } - else if(j == RsItem::SIZE_ESTIMATE) + else if(j == RsGenericSerializer::SIZE_ESTIMATE) { ctx.mOffset += RsGRouterSerialiser().size(data_item) ; @@ -410,7 +412,7 @@ RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoI } #endif -void RsGRouterMatrixFriendListItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterMatrixFriendListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,reverse_friend_indices,"reverse_friend_indices") ; } @@ -443,7 +445,7 @@ RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixF } #endif -void RsGRouterMatrixTrackItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterMatrixTrackItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,provider_id,"provider_id") ; RsTypeSerializer::serial_process(j,ctx,message_id,"message_id") ; @@ -474,13 +476,13 @@ RsGRouterMatrixTrackItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixTrackI } #endif -void RsGRouterMatrixCluesItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsGRouterMatrixCluesItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,destination_key,"destination_key") ; RsTypeSerializer::serial_process(j,ctx,clues,"clues") ; } -template<> void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,RoutingMatrixHitEntry& s,const std::string& name) +template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,RoutingMatrixHitEntry& s,const std::string& name) { RsTypeSerializer::serial_process(j,ctx,s.friend_id,name+":friend_id") ; RsTypeSerializer::serial_process (j,ctx,s.weight,name+":weight") ; diff --git a/libretroshare/src/grouter/grouteritems.h b/libretroshare/src/grouter/grouteritems.h index 7c69d4718..505f35361 100644 --- a/libretroshare/src/grouter/grouteritems.h +++ b/libretroshare/src/grouter/grouteritems.h @@ -112,7 +112,7 @@ class RsGRouterGenericDataItem: public RsGRouterAbstractMsgItem, public RsGRoute data_bytes=NULL; } - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsGRouterGenericDataItem *duplicate() const ; @@ -130,7 +130,7 @@ class RsGRouterSignedReceiptItem: public RsGRouterAbstractMsgItem virtual ~RsGRouterSignedReceiptItem() {} virtual void clear() {} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsGRouterSignedReceiptItem *duplicate() const ; @@ -161,7 +161,7 @@ public: virtual ~RsGRouterTransactionChunkItem() { free(chunk_data) ; } virtual void clear() {} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual RsGRouterTransactionItem *duplicate() const { @@ -188,7 +188,7 @@ public: RsGRouterTransactionAcknItem() : RsGRouterTransactionItem(RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN) { setPriorityLevel(QOS_PRIORITY_RS_GROUTER) ; } virtual ~RsGRouterTransactionAcknItem() {} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} @@ -206,7 +206,7 @@ class RsGRouterMatrixCluesItem: public RsGRouterItem { setPriorityLevel(0) ; } // this item is never sent through the network virtual void clear() {} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // packet data // @@ -220,7 +220,7 @@ class RsGRouterMatrixTrackItem: public RsGRouterItem RsGRouterMatrixTrackItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_MATRIX_TRACK) { setPriorityLevel(0) ; } // this item is never sent through the network - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} @@ -236,7 +236,7 @@ class RsGRouterMatrixFriendListItem: public RsGRouterItem RsGRouterMatrixFriendListItem() : RsGRouterItem(RS_PKT_SUBTYPE_GROUTER_FRIENDS_LIST) { setPriorityLevel(0) ; } // this item is never sent through the network - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} // packet data @@ -252,7 +252,7 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo, virtual ~RsGRouterRoutingInfoItem() { clear() ; } - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() { @@ -271,7 +271,7 @@ class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo, class RsGRouterSerialiser: public RsServiceSerializer { public: - RsGRouterSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsServiceSerializer(RS_SERVICE_TYPE_GROUTER,SerializeContext::FORMAT_BINARY,flags) {} + RsGRouterSerialiser(SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsServiceSerializer(RS_SERVICE_TYPE_GROUTER,RsGenericSerializer::FORMAT_BINARY,flags) {} virtual RsItem *create_item(uint16_t service,uint8_t subtype) const ; }; diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.h b/libretroshare/src/gxstunnel/rsgxstunnelitems.h index ad049a753..4da26da0e 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.h +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.h @@ -27,9 +27,12 @@ #include +#include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" +#include "rsitems/rsitem.h" + #include "retroshare/rstypes.h" #include "serialiser/rstlvkeys.h" -#include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 8a633c1a7..287e6a4d7 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -452,7 +452,8 @@ HEADERS += grouter/groutercache.h \ grouter/groutertypes.h \ grouter/rsgrouterclient.h -HEADERS += rsitems/itempriorities.h \ +HEADERS += rsitems/rsitem.h \ + rsitems/itempriorities.h \ serialiser/rsbaseserial.h \ rsitems/rsfiletransferitems.h \ serialiser/rsserviceserialiser.h \ diff --git a/libretroshare/src/pqi/p3servicecontrol.cc b/libretroshare/src/pqi/p3servicecontrol.cc index f22cc44c0..0b3b1514e 100644 --- a/libretroshare/src/pqi/p3servicecontrol.cc +++ b/libretroshare/src/pqi/p3servicecontrol.cc @@ -27,6 +27,7 @@ #include "p3servicecontrol.h" #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" #include "serialiser/rsserial.h" #include "serialiser/rsbaseserial.h" #include "pqi/p3cfgmgr.h" diff --git a/libretroshare/src/pqi/pqi.h b/libretroshare/src/pqi/pqi.h index a7aa5854c..07cf00f9d 100644 --- a/libretroshare/src/pqi/pqi.h +++ b/libretroshare/src/pqi/pqi.h @@ -27,8 +27,7 @@ #ifndef PQI_TOP_HEADER #define PQI_TOP_HEADER -#include "serialiser/rsserial.h" - +#include "rsitems/rsitem.h" class P3Interface { diff --git a/libretroshare/src/pqi/pqiqos.cc b/libretroshare/src/pqi/pqiqos.cc index b2472c0b7..9fc62aa8c 100644 --- a/libretroshare/src/pqi/pqiqos.cc +++ b/libretroshare/src/pqi/pqiqos.cc @@ -11,7 +11,9 @@ const uint32_t pqiQoS::MAX_PACKET_COUNTER_VALUE = (1 << 24) ; pqiQoS::pqiQoS(uint32_t nb_levels,float alpha) : _item_queues(nb_levels),_alpha(alpha) { +#ifdef DEBUG assert(pow(alpha,nb_levels) < 1e+20) ; +#endif float c = 1.0f ; float inc = alpha ; @@ -110,7 +112,9 @@ void *pqiQoS::out_rsItem(uint32_t max_slice_size, uint32_t& size, bool& starts, if(last >= 0) { +#ifdef DEBUG assert(_nb_items > 0) ; +#endif // now chop a slice of this item diff --git a/libretroshare/src/pqi/pqistore.cc b/libretroshare/src/pqi/pqistore.cc index 4a962cf29..23201541a 100644 --- a/libretroshare/src/pqi/pqistore.cc +++ b/libretroshare/src/pqi/pqistore.cc @@ -40,6 +40,7 @@ * */ +#include "rsitems/rsitem.h" #include "pqi/pqistore.h" #include "serialiser/rsserial.h" #include diff --git a/libretroshare/src/rsitems/rsbanlistitems.cc b/libretroshare/src/rsitems/rsbanlistitems.cc index d597abcfd..85acfb96c 100644 --- a/libretroshare/src/rsitems/rsbanlistitems.cc +++ b/libretroshare/src/rsitems/rsbanlistitems.cc @@ -41,12 +41,12 @@ void RsBanListItem::clear() peerList.TlvClear(); } -void RsBanListItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsBanListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,peerList,"peerList") ; } -void RsBanListConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsBanListConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,type,"type") ; RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; diff --git a/libretroshare/src/rsitems/rsbanlistitems.h b/libretroshare/src/rsitems/rsbanlistitems.h index 3fce37956..836fe1b7e 100644 --- a/libretroshare/src/rsitems/rsbanlistitems.h +++ b/libretroshare/src/rsitems/rsbanlistitems.h @@ -29,6 +29,8 @@ #include #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" #include "serialiser/rstlvbanlist.h" #include "serialization/rsserializer.h" @@ -50,7 +52,7 @@ class RsBanListItem: public RsItem virtual ~RsBanListItem(){} virtual void clear(); - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvBanList peerList; }; @@ -64,7 +66,7 @@ public: virtual ~RsBanListConfigItem(){} virtual void clear() { banned_peers.TlvClear() ; } - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t type ; RsPeerId peerId ; diff --git a/libretroshare/src/rsitems/rsbwctrlitems.cc b/libretroshare/src/rsitems/rsbwctrlitems.cc index 747dbbbda..45c23d2c8 100644 --- a/libretroshare/src/rsitems/rsbwctrlitems.cc +++ b/libretroshare/src/rsitems/rsbwctrlitems.cc @@ -52,7 +52,7 @@ void RsBwCtrlAllowedItem::clear() allowedBw = 0; } -void RsBwCtrlAllowedItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsBwCtrlAllowedItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_UINT32_BW,allowedBw,"allowedBw") ; } diff --git a/libretroshare/src/rsitems/rsbwctrlitems.h b/libretroshare/src/rsitems/rsbwctrlitems.h index e21410b39..570e0d87b 100644 --- a/libretroshare/src/rsitems/rsbwctrlitems.h +++ b/libretroshare/src/rsitems/rsbwctrlitems.h @@ -28,9 +28,9 @@ #include +#include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" -#include "serialiser/rstlvbase.h" +#include "rsitems/itempriorities.h" #include "serialization/rsserializer.h" #include "serialization/rstypeserializer.h" @@ -51,7 +51,7 @@ public: virtual ~RsBwCtrlAllowedItem() {} virtual void clear(); - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t allowedBw; // Units are bytes/sec => 4Gb/s; }; diff --git a/libretroshare/src/rsitems/rsconfigitems.cc b/libretroshare/src/rsitems/rsconfigitems.cc index 4ba94a8bf..743e35871 100644 --- a/libretroshare/src/rsitems/rsconfigitems.cc +++ b/libretroshare/src/rsitems/rsconfigitems.cc @@ -28,6 +28,7 @@ #include "rsitems/rsconfigitems.h" #include "retroshare/rspeers.h" // Needed for RsGroupInfo. +#include "serialization/rstypeserializer.h" /*** * #define RSSERIAL_DEBUG 1 * #define RSSERIAL_ERROR_DEBUG 1 @@ -69,7 +70,7 @@ void RsFileTransfer::clear() } -void RsFileTransfer::serial_process(SerializeJob j,SerializeContext& ctx) +void RsFileTransfer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,file,"file") ; RsTypeSerializer::serial_process(j,ctx,allPeerIds,"allPeerIds") ; @@ -91,7 +92,7 @@ void RsFileTransfer::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process (j,ctx,compressed_chunk_map,"compressed_chunk_map") ; } -void RsFileConfigItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsFileConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,file,"file") ; RsTypeSerializer::serial_process (j,ctx,flags,"flags") ; @@ -111,7 +112,7 @@ RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_type,uint8_t item_su } } -void RsConfigKeyValueSet::serial_process(SerializeJob j,SerializeContext& ctx) +void RsConfigKeyValueSet::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tlvkvs,"tlvkvs") ; } @@ -156,7 +157,7 @@ void RsPeerNetItem::clear() domain_addr.clear(); domain_port = 0; } -void RsPeerNetItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsPeerNetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,peerId,"peerId") ; RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ; @@ -181,12 +182,12 @@ void RsPeerNetItem::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process(j,ctx,domain_port,"domain_port") ; } -void RsPeerBandwidthLimitsItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsPeerBandwidthLimitsItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,peers,"peers") ; } -void RsPeerStunItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsPeerStunItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,stunList,"stunList") ; } @@ -226,7 +227,7 @@ RsNodeGroupItem::RsNodeGroupItem(const RsGroupInfo& g) pgpList.ids = g.peerIds; } -void RsNodeGroupItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsNodeGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { uint32_t v=0 ; @@ -237,14 +238,14 @@ void RsNodeGroupItem::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process(j,ctx,pgpList,"pgpList") ; } -void RsPeerServicePermissionItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsPeerServicePermissionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { // We need to hack this because of backward compatibility. The correct way to do it would be: // // RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ; // RsTypeSerializer::serial_process(j,ctx,service_flags,"service_flags") ; - if(j == RsItem::DESERIALIZE) + if(j == RsGenericSerializer::DESERIALIZE) { uint32_t v=0 ; RsTypeSerializer::serial_process(j,ctx,v,"pgp_ids.size()") ; diff --git a/libretroshare/src/rsitems/rsconfigitems.h b/libretroshare/src/rsitems/rsconfigitems.h index 6ac90c212..bc4b9e824 100644 --- a/libretroshare/src/rsitems/rsconfigitems.h +++ b/libretroshare/src/rsitems/rsconfigitems.h @@ -29,6 +29,8 @@ #include #include +#include "rsitems/rsitem.h" + #include "retroshare/rstypes.h" #include "serialiser/rsserial.h" @@ -77,7 +79,7 @@ public: virtual ~RsPeerNetItem(){} virtual void clear(); - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); /* networking information */ RsPeerId peerId; /* Mandatory */ @@ -115,7 +117,7 @@ class RsPeerServicePermissionItem : public RsItem pgp_ids.clear() ; service_flags.clear() ; } - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); /* Mandatory */ @@ -132,7 +134,7 @@ class RsPeerBandwidthLimitsItem : public RsItem { peers.clear() ; } - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); /* Mandatory */ std::map peers ; @@ -172,7 +174,7 @@ public: explicit RsNodeGroupItem(const RsGroupInfo&) ; - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // /* set data from RsGroupInfo to RsPeerGroupItem */ // void set(RsGroupInfo &groupInfo); @@ -197,7 +199,7 @@ public: virtual ~RsPeerStunItem(){} virtual void clear() { stunList.TlvClear() ;} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvPeerIdSet stunList; /* Mandatory */ }; @@ -277,7 +279,7 @@ class RsFileTransfer: public RsItem virtual ~RsFileTransfer(){} virtual void clear(); - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvFileItem file; RsTlvPeerIdSet allPeerIds; @@ -331,7 +333,7 @@ public: virtual ~RsFileConfigItem() {} virtual void clear() { parent_groups.TlvClear(); } - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvFileItem file; uint32_t flags; @@ -359,7 +361,7 @@ public: virtual ~RsConfigKeyValueSet(){} virtual void clear() { tlvkvs.TlvClear();} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsTlvKeyValueSet tlvkvs; }; diff --git a/libretroshare/src/rsitems/rsdiscovery2items.cc b/libretroshare/src/rsitems/rsdiscovery2items.cc index 8e4175a9e..f9f19270c 100644 --- a/libretroshare/src/rsitems/rsdiscovery2items.cc +++ b/libretroshare/src/rsitems/rsdiscovery2items.cc @@ -73,7 +73,7 @@ void RsDiscPgpListItem::clear() pgpIdSet.TlvClear(); } -void RsDiscPgpListItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsDiscPgpListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mode,"mode") ; RsTypeSerializer::serial_process(j,ctx,pgpIdSet,"pgpIdSet") ; @@ -86,7 +86,7 @@ void RsDiscPgpCertItem::clear() } -void RsDiscPgpCertItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsDiscPgpCertItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,pgpId,"pgpId") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_PGPCERT,pgpCert,"pgpCert") ; @@ -121,7 +121,7 @@ void RsDiscContactItem::clear() extAddrList.TlvClear(); } -void RsDiscContactItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsDiscContactItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,pgpId,"pgpId"); RsTypeSerializer::serial_process (j,ctx,sslId,"sslId"); @@ -134,7 +134,7 @@ void RsDiscContactItem::serial_process(SerializeJob j,SerializeContext& ctx) // This is a hack. Normally we should have to different item types, in order to avoid this nonesense. - if(j == RsItem::DESERIALIZE) + if(j == RsGenericSerializer::DESERIALIZE) isHidden = ( GetTlvType( &(((uint8_t *) ctx.mData)[ctx.mOffset]) )==TLV_TYPE_STR_DOMADDR); if(isHidden) diff --git a/libretroshare/src/rsitems/rsdiscovery2items.h b/libretroshare/src/rsitems/rsdiscovery2items.h index 7610d534f..ce30a2928 100644 --- a/libretroshare/src/rsitems/rsdiscovery2items.h +++ b/libretroshare/src/rsitems/rsdiscovery2items.h @@ -32,6 +32,8 @@ #include "serialiser/rstlvidset.h" #include "serialiser/rstlvaddrs.h" #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" #include "serialization/rsserializer.h" @@ -65,7 +67,7 @@ public: virtual ~RsDiscPgpListItem(){} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); uint32_t mode; RsTlvPgpIdSet pgpIdSet; @@ -86,7 +88,7 @@ public: virtual ~RsDiscPgpCertItem(){} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); RsPgpId pgpId; std::string pgpCert; @@ -106,7 +108,7 @@ public: virtual ~RsDiscContactItem() {} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); RsPgpId pgpId; RsPeerId sslId; diff --git a/libretroshare/src/rsitems/rsfiletransferitems.cc b/libretroshare/src/rsitems/rsfiletransferitems.cc index acdadaff2..cd0ea088d 100644 --- a/libretroshare/src/rsitems/rsfiletransferitems.cc +++ b/libretroshare/src/rsitems/rsfiletransferitems.cc @@ -53,38 +53,38 @@ void RsFileTransferDataItem::clear() fd.TlvClear(); } -void RsFileTransferDataRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferDataRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,fileoffset,"fileoffset") ; RsTypeSerializer::serial_process (j,ctx,chunksize, "chunksize") ; RsTypeSerializer::serial_process(j,ctx,file, "file") ; } -void RsFileTransferDataItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,fd,"fd") ; } -void RsFileTransferChunkMapRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferChunkMapRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,is_client,"is_client") ; RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; } -void RsFileTransferChunkMapItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferChunkMapItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,is_client, "is_client") ; RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; RsTypeSerializer::serial_process (j,ctx,compressed_map,"compressed_map") ; } -void RsFileTransferSingleChunkCrcRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferSingleChunkCrcRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; } -void RsFileTransferSingleChunkCrcItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsFileTransferSingleChunkCrcItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,hash, "hash") ; RsTypeSerializer::serial_process(j,ctx,chunk_number,"chunk_number") ; diff --git a/libretroshare/src/rsitems/rsfiletransferitems.h b/libretroshare/src/rsitems/rsfiletransferitems.h index b51e74d53..b0ab0972a 100644 --- a/libretroshare/src/rsitems/rsfiletransferitems.h +++ b/libretroshare/src/rsitems/rsfiletransferitems.h @@ -30,7 +30,9 @@ #include "retroshare/rstypes.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvfileitem.h" +#include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" #include "serialization/rsserializer.h" @@ -70,7 +72,7 @@ class RsFileTransferDataRequestItem: public RsFileTransferItem virtual ~RsFileTransferDataRequestItem() {} virtual void clear(); - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // Private data part. // @@ -90,7 +92,7 @@ class RsFileTransferDataItem: public RsFileTransferItem } virtual ~RsFileTransferDataItem() { clear() ; } - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear(); @@ -109,7 +111,7 @@ class RsFileTransferChunkMapRequestItem: public RsFileTransferItem virtual ~RsFileTransferChunkMapRequestItem() {} virtual void clear() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); // Private data part. // @@ -127,7 +129,7 @@ class RsFileTransferChunkMapItem: public RsFileTransferItem } virtual ~RsFileTransferChunkMapItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} // Private data part. @@ -146,7 +148,7 @@ class RsFileTransferSingleChunkCrcRequestItem: public RsFileTransferItem } virtual ~RsFileTransferSingleChunkCrcRequestItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} // Private data part. @@ -164,7 +166,7 @@ class RsFileTransferSingleChunkCrcItem: public RsFileTransferItem } virtual ~RsFileTransferSingleChunkCrcItem() {} - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); virtual void clear() {} // Private data part. diff --git a/libretroshare/src/rsitems/rsgxsreputationitems.cc b/libretroshare/src/rsitems/rsgxsreputationitems.cc index 11e267654..1a50bf9dc 100644 --- a/libretroshare/src/rsitems/rsgxsreputationitems.cc +++ b/libretroshare/src/rsitems/rsgxsreputationitems.cc @@ -53,21 +53,21 @@ void RsGxsReputationBannedNodeSetItem::clear() mKnownIdentities.TlvClear(); } -void RsGxsReputationConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsGxsReputationConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,mPeerId,"mPeerId") ; RsTypeSerializer::serial_process(j,ctx,mLatestUpdate,"mLatestUpdate") ; RsTypeSerializer::serial_process(j,ctx,mLastQuery,"mLastQuery") ; } -void RsGxsReputationBannedNodeSetItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsGxsReputationBannedNodeSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,mPgpId,"mPgpId") ; RsTypeSerializer::serial_process (j,ctx,mLastActivityTS,"mLastActivityTS") ; RsTypeSerializer::serial_process(j,ctx,mKnownIdentities,"mKnownIdentities") ; } -void RsGxsReputationSetItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsGxsReputationSetItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,mGxsId,"mGxsId") ; RsTypeSerializer::serial_process(j,ctx,mOwnOpinion,"mOwnOpinion") ; @@ -78,12 +78,12 @@ void RsGxsReputationSetItem::serial_process(RsItem::SerializeJob j,SerializeCont RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ; } -void RsGxsReputationUpdateItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsGxsReputationUpdateItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mLatestUpdate,"mLatestUpdate") ; RsTypeSerializer::serial_process (j,ctx,mOpinions,"mOpinions") ; } -void RsGxsReputationRequestItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) +void RsGxsReputationRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mLastUpdate,"mLastUpdate") ; } diff --git a/libretroshare/src/rsitems/rsgxsreputationitems.h b/libretroshare/src/rsitems/rsgxsreputationitems.h index 1f30a5d65..7c841bd4e 100644 --- a/libretroshare/src/rsitems/rsgxsreputationitems.h +++ b/libretroshare/src/rsitems/rsgxsreputationitems.h @@ -29,6 +29,9 @@ #include #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" + #include "serialiser/rsserial.h" #include "serialiser/rstlvidset.h" #include "retroshare/rsgxsifacetypes.h" @@ -66,7 +69,7 @@ public: virtual ~RsGxsReputationConfigItem() {} virtual void clear() {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ; RsPeerId mPeerId; uint32_t mLatestUpdate; // timestamp they returned. @@ -110,7 +113,7 @@ public: virtual ~RsGxsReputationSetItem() {} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ; RsGxsId mGxsId; uint32_t mOwnOpinion; @@ -128,7 +131,7 @@ public: virtual ~RsGxsReputationBannedNodeSetItem() {} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ; RsPgpId mPgpId ; uint32_t mLastActivityTS ; @@ -143,7 +146,7 @@ public: virtual ~RsGxsReputationUpdateItem() {} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ; uint32_t mLatestUpdate; std::map mOpinions; // GxsId -> Opinion. @@ -157,7 +160,7 @@ public: virtual ~RsGxsReputationRequestItem() {} virtual void clear() {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) ; + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) ; uint32_t mLastUpdate; }; diff --git a/libretroshare/src/rsitems/rshistoryitems.cc b/libretroshare/src/rsitems/rshistoryitems.cc index eb50bf15e..38f2f0254 100644 --- a/libretroshare/src/rsitems/rshistoryitems.cc +++ b/libretroshare/src/rsitems/rshistoryitems.cc @@ -29,13 +29,15 @@ #include "serialiser/rsbaseserial.h" #include "serialiser/rstlvbase.h" +#include "serialization/rstypeserializer.h" + /*** #define RSSERIAL_DEBUG 1 ***/ #include -void RsHistoryMsgItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsHistoryMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { uint16_t version=0; diff --git a/libretroshare/src/rsitems/rshistoryitems.h b/libretroshare/src/rsitems/rshistoryitems.h index 27a387f60..56d12e559 100644 --- a/libretroshare/src/rsitems/rshistoryitems.h +++ b/libretroshare/src/rsitems/rshistoryitems.h @@ -42,7 +42,7 @@ public: virtual ~RsHistoryMsgItem() {} virtual void clear() {} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); RsPeerId chatPeerId; // empty for global chat bool incoming; diff --git a/libretroshare/src/rsitems/rsitem.h b/libretroshare/src/rsitems/rsitem.h new file mode 100644 index 000000000..f7f6dae54 --- /dev/null +++ b/libretroshare/src/rsitems/rsitem.h @@ -0,0 +1,90 @@ +#pragma once + +#include "util/smallobject.h" +#include "retroshare/rstypes.h" +#include "serialization/rsserializer.h" + +class RsItem: public RsMemoryManagement::SmallObject +{ + public: + RsItem(uint32_t t); + RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype); +#ifdef DO_STATISTICS + void *operator new(size_t s) ; + void operator delete(void *,size_t s) ; +#endif + + virtual ~RsItem(); + virtual void clear() = 0; + + virtual std::ostream &print(std::ostream &out, uint16_t /* indent */ = 0) + { + RsGenericSerializer::SerializeContext ctx(NULL,0,RsGenericSerializer::FORMAT_BINARY,RsGenericSerializer::SERIALIZATION_FLAG_NONE); + serial_process(RsGenericSerializer::PRINT,ctx) ; + return out; + } + + void print_string(std::string &out, uint16_t indent = 0); + + /* source / destination id */ + const RsPeerId& PeerId() const { return peerId; } + void PeerId(const RsPeerId& id) { peerId = id; } + + /* complete id */ + uint32_t PacketId() const; + + /* id parts */ + uint8_t PacketVersion(); + uint8_t PacketClass(); + uint8_t PacketType(); + uint8_t PacketSubType() const; + + /* For Service Packets */ + RsItem(uint8_t ver, uint16_t service, uint8_t subtype); + uint16_t PacketService() const; /* combined Packet class/type (mid 16bits) */ + void setPacketService(uint16_t service); + + inline uint8_t priority_level() const { return _priority_level ;} + inline void setPriorityLevel(uint8_t l) { _priority_level = l ;} + + /** + * @brief serialize this object to the given buffer + * @param Job to do: serialise or deserialize. + * @param data Chunk of memory were to dump the serialized data + * @param size Size of memory chunk + * @param offset Readed to determine at witch offset start writing data, + * written to inform caller were written data ends, the updated value + * is usually passed by the caller to serialize of another + * RsSerializable so it can write on the same chunk of memory just + * after where this RsSerializable has been serialized. + * @return true if serialization successed, false otherwise + */ + + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */) + { + std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! Class is " << typeid(*this).name() << std::endl; + } + + protected: + uint32_t type; + RsPeerId peerId; + uint8_t _priority_level ; +}; + +class RsRawItem: public RsItem +{ +public: + RsRawItem(uint32_t t, uint32_t size) : RsItem(t), len(size) + { data = rs_malloc(len); } + virtual ~RsRawItem() { free(data); } + + uint32_t getRawLength() { return len; } + void * getRawData() { return data; } + + virtual void clear() {} + virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + +private: + void *data; + uint32_t len; +}; diff --git a/libretroshare/src/rsitems/rsmsgitems.cc b/libretroshare/src/rsitems/rsmsgitems.cc index 8fd2f2c55..20c98ad1b 100644 --- a/libretroshare/src/rsitems/rsmsgitems.cc +++ b/libretroshare/src/rsitems/rsmsgitems.cc @@ -80,25 +80,25 @@ void RsMsgItem::clear() attachment.TlvClear(); } -void RsPublicMsgInviteConfigItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsPublicMsgInviteConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_SHA1,hash,"hash") ; RsTypeSerializer::serial_process(j,ctx,(uint32_t&)time_stamp,"time_stamp") ; } -void RsMsgTagType::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgTagType::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,text,"text") ; RsTypeSerializer::serial_process(j,ctx,rgb_color,"rgb_color") ; RsTypeSerializer::serial_process(j,ctx,tagId,"tagId") ; } -void RsMsgTags::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgTags::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,msgId,"msgId") ; #warning this is not the correct way to serialise here. We should directly call serial_process >() but for backward compatibility, we cannot - if(j == RsItem::DESERIALIZE) + if(j == RsGenericSerializer::DESERIALIZE) while(ctx.mOffset < ctx.mSize) { uint32_t n ; @@ -110,13 +110,13 @@ void RsMsgTags::serial_process(SerializeJob j,SerializeContext& ctx) RsTypeSerializer::serial_process(j,ctx,*it,"tagIds element") ; } -void RsMsgSrcId::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgSrcId::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,msgId,"msgId") ; RsTypeSerializer::serial_process (j,ctx,srcId,"srcId") ; } -void RsMsgGRouterMap::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgGRouterMap::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,ongoing_msgs,"ongoing_msgs") ; } @@ -128,18 +128,18 @@ void RsMsgGRouterMap::clear() return; } -void RsMsgDistantMessagesHashMap::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgDistantMessagesHashMap::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,hash_map,"hash_map") ; } -void RsMsgParentId::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgParentId::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,msgId,"msgId") ; RsTypeSerializer::serial_process(j,ctx,msgParentId,"msgParentId") ; } -void RsMsgItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,msgFlags,"msgFlags"); RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime"); diff --git a/libretroshare/src/rsitems/rsmsgitems.h b/libretroshare/src/rsitems/rsmsgitems.h index f0916352b..527c43fdf 100644 --- a/libretroshare/src/rsitems/rsmsgitems.h +++ b/libretroshare/src/rsitems/rsmsgitems.h @@ -101,7 +101,7 @@ class RsMsgItem: public RsMessageItem virtual ~RsMsgItem() {} virtual void clear(); - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); // ----------- Specific fields ------------- // @@ -130,7 +130,7 @@ class RsMsgTagType : public RsMessageItem public: RsMsgTagType() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAG_TYPE) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgTagType() {} virtual void clear(); @@ -148,7 +148,7 @@ public: RsMsgTags() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAGS) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgTags() {} virtual void clear(); @@ -164,7 +164,7 @@ class RsMsgSrcId : public RsMessageItem public: RsMsgSrcId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_SRC_TAG) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgSrcId() {} virtual void clear(){} @@ -180,7 +180,7 @@ class RsPublicMsgInviteConfigItem : public RsMessageItem public: RsPublicMsgInviteConfigItem() : RsMessageItem(RS_PKT_SUBTYPE_MSG_INVITE) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsPublicMsgInviteConfigItem() {} virtual void clear(); @@ -196,7 +196,7 @@ class RsMsgGRouterMap : public RsMessageItem public: RsMsgGRouterMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_GROUTER_MAP) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgGRouterMap() {} virtual void clear(); @@ -210,7 +210,7 @@ class RsMsgDistantMessagesHashMap : public RsMessageItem public: RsMsgDistantMessagesHashMap() : RsMessageItem(RS_PKT_SUBTYPE_MSG_DISTANT_MSG_MAP) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgDistantMessagesHashMap() {} virtual void clear() { hash_map.clear() ;} @@ -224,7 +224,7 @@ class RsMsgParentId : public RsMessageItem public: RsMsgParentId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_PARENT_TAG) {} - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */); + virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */); virtual ~RsMsgParentId() {} virtual void clear(){} @@ -239,7 +239,7 @@ class RsMsgSerialiser: public RsServiceSerializer { public: RsMsgSerialiser(SerializationFlags flags) - :RsServiceSerializer(RS_SERVICE_TYPE_MSG,SerializeContext::FORMAT_BINARY,flags){} + :RsServiceSerializer(RS_SERVICE_TYPE_MSG,RsGenericSerializer::FORMAT_BINARY,flags){} virtual ~RsMsgSerialiser() {} diff --git a/libretroshare/src/rsitems/rsrttitems.cc b/libretroshare/src/rsitems/rsrttitems.cc index ce2423dd4..2ab7292e5 100644 --- a/libretroshare/src/rsitems/rsrttitems.cc +++ b/libretroshare/src/rsitems/rsrttitems.cc @@ -32,6 +32,8 @@ #include +#include "serialization/rstypeserializer.h" + /*************************************************************************/ RsItem *RsRttSerialiser::create_item(uint16_t service,uint8_t type) const @@ -48,13 +50,13 @@ RsItem *RsRttSerialiser::create_item(uint16_t service,uint8_t type) const } } -void RsRttPingItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsRttPingItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mSeqNo,"mSeqNo") ; RsTypeSerializer::serial_process(j,ctx,mPingTS,"mPingTS") ; } -void RsRttPongItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsRttPongItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mSeqNo,"mSeqNo") ; RsTypeSerializer::serial_process(j,ctx,mPingTS,"mPingTS") ; diff --git a/libretroshare/src/rsitems/rsrttitems.h b/libretroshare/src/rsitems/rsrttitems.h index b3e5bdec2..8f635c3b9 100644 --- a/libretroshare/src/rsitems/rsrttitems.h +++ b/libretroshare/src/rsitems/rsrttitems.h @@ -28,7 +28,9 @@ #include +#include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" #include "serialiser/rsserial.h" #include "serialization/rsserializer.h" @@ -56,7 +58,7 @@ class RsRttPingItem: public RsRttItem virtual ~RsRttPingItem(){} virtual void clear(){} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t mSeqNo; uint64_t mPingTS; @@ -70,7 +72,7 @@ class RsRttPongItem: public RsRttItem virtual ~RsRttPongItem(){} virtual void clear(){} - virtual void serial_process(SerializeJob j,SerializeContext& ctx); + virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); uint32_t mSeqNo; uint64_t mPingTS; diff --git a/libretroshare/src/serialiser/rsgxsitems.h b/libretroshare/src/serialiser/rsgxsitems.h index ed6d3124d..74942d807 100644 --- a/libretroshare/src/serialiser/rsgxsitems.h +++ b/libretroshare/src/serialiser/rsgxsitems.h @@ -26,6 +26,7 @@ * */ +#include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" #include "serialiser/rsserial.h" //#include "serialiser/rstlvtypes.h" diff --git a/libretroshare/src/serialiser/rsgxsrecognitems.h b/libretroshare/src/serialiser/rsgxsrecognitems.h index 6d0ea0ae6..aab0e3974 100644 --- a/libretroshare/src/serialiser/rsgxsrecognitems.h +++ b/libretroshare/src/serialiser/rsgxsrecognitems.h @@ -28,7 +28,10 @@ #include +#include "rsitems/rsitem.h" #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" + #include "serialiser/rsserial.h" #include "serialiser/rstlvkeys.h" #include "serialiser/rstlvidset.h" diff --git a/libretroshare/src/serialiser/rsheartbeatitems.h b/libretroshare/src/serialiser/rsheartbeatitems.h index 5660ba373..3a9e6e95f 100644 --- a/libretroshare/src/serialiser/rsheartbeatitems.h +++ b/libretroshare/src/serialiser/rsheartbeatitems.h @@ -30,6 +30,8 @@ #include "serialiser/rsserial.h" #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" const uint8_t RS_PKT_SUBTYPE_HEARTBEAT_PULSE = 0x01; diff --git a/libretroshare/src/serialiser/rsnxsitems.h b/libretroshare/src/serialiser/rsnxsitems.h index 259c560a6..2f4886507 100644 --- a/libretroshare/src/serialiser/rsnxsitems.h +++ b/libretroshare/src/serialiser/rsnxsitems.h @@ -31,6 +31,7 @@ #include #include "rsitems/rsserviceids.h" +#include "rsitems/itempriorities.h" #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvitem.h" diff --git a/libretroshare/src/serialiser/rsserial.cc b/libretroshare/src/serialiser/rsserial.cc index 30fed530e..1436f92fa 100644 --- a/libretroshare/src/serialiser/rsserial.cc +++ b/libretroshare/src/serialiser/rsserial.cc @@ -25,11 +25,14 @@ */ #include "serialiser/rsbaseserial.h" -#include "serialiser/rsserial.h" + #include "util/rsthreads.h" #include "util/rsstring.h" #include "util/rsprint.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" + #include #include #include diff --git a/libretroshare/src/serialiser/rsserial.h b/libretroshare/src/serialiser/rsserial.h index 511eec1c3..248c0a3bc 100644 --- a/libretroshare/src/serialiser/rsserial.h +++ b/libretroshare/src/serialiser/rsserial.h @@ -34,9 +34,6 @@ #include #include -#include "util/rsmemory.h" -#include "retroshare/rstypes.h" - /******************************************************************* * This is the Top-Level serialiser/deserialise, * @@ -59,9 +56,6 @@ * 8 bits: SubType ******************************************************************/ -#include -#include "rsitems/itempriorities.h" - const uint8_t RS_PKT_VERSION1 = 0x01; const uint8_t RS_PKT_VERSION_SERVICE = 0x02; @@ -70,74 +64,7 @@ const uint8_t RS_PKT_CLASS_CONFIG = 0x02; const uint8_t RS_PKT_SUBTYPE_DEFAULT = 0x01; /* if only one subtype */ -class SerializeContext ; - -class RsItem: public RsMemoryManagement::SmallObject -{ - public: - RsItem(uint32_t t); - RsItem(uint8_t ver, uint8_t cls, uint8_t t, uint8_t subtype); -#ifdef DO_STATISTICS - void *operator new(size_t s) ; - void operator delete(void *,size_t s) ; -#endif - - virtual ~RsItem(); - virtual void clear() = 0; - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0) - { - std::cerr << "(EE) RsItem::print() called by an item using new serialization classes, but not derived! " << std::endl; -#warning This method should normally call serial_process(PRINT,ctx) - return out; - } - void print_string(std::string &out, uint16_t indent = 0); - - /* source / destination id */ - const RsPeerId& PeerId() const { return peerId; } - void PeerId(const RsPeerId& id) { peerId = id; } - - /* complete id */ - uint32_t PacketId() const; - - /* id parts */ - uint8_t PacketVersion(); - uint8_t PacketClass(); - uint8_t PacketType(); - uint8_t PacketSubType() const; - - /* For Service Packets */ - RsItem(uint8_t ver, uint16_t service, uint8_t subtype); - uint16_t PacketService() const; /* combined Packet class/type (mid 16bits) */ - void setPacketService(uint16_t service); - - inline uint8_t priority_level() const { return _priority_level ;} - inline void setPriorityLevel(uint8_t l) { _priority_level = l ;} - - /** - * @brief serialize this object to the given buffer - * @param Job to do: serialise or deserialize. - * @param data Chunk of memory were to dump the serialized data - * @param size Size of memory chunk - * @param offset Readed to determine at witch offset start writing data, - * written to inform caller were written data ends, the updated value - * is usually passed by the caller to serialize of another - * RsSerializable so it can write on the same chunk of memory just - * after where this RsSerializable has been serialized. - * @return true if serialization successed, false otherwise - */ - typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ; - - virtual void serial_process(SerializeJob /* j */,SerializeContext& /* ctx */) - { - std::cerr << "(EE) RsItem::serial_process() called by an item using new serialization classes, but not derived! " << std::endl; - } - - protected: - uint32_t type; - RsPeerId peerId; - uint8_t _priority_level ; -}; - +class RsItem ; class RsSerialType { @@ -201,23 +128,4 @@ std::ostream &printRsItemEnd(std::ostream &o, std::string n, uint16_t i); std::ostream &printIndent(std::ostream &out, uint16_t indent); /* Wrapper class for data that is serialised somewhere else */ -class RsRawItem: public RsItem -{ -public: - RsRawItem(uint32_t t, uint32_t size) : RsItem(t), len(size) - { data = rs_malloc(len); } - virtual ~RsRawItem() { free(data); } - - uint32_t getRawLength() { return len; } - void * getRawData() { return data; } - - virtual void clear() {} - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - -private: - void *data; - uint32_t len; -}; - - #endif /* RS_BASE_SERIALISER_H */ diff --git a/libretroshare/src/serialiser/rsserviceinfoitems.h b/libretroshare/src/serialiser/rsserviceinfoitems.h index 76b451cce..b4c9beabe 100644 --- a/libretroshare/src/serialiser/rsserviceinfoitems.h +++ b/libretroshare/src/serialiser/rsserviceinfoitems.h @@ -31,6 +31,9 @@ #include #include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" + #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rstlvgenericmap.h" diff --git a/libretroshare/src/serialiser/rsserviceserialiser.cc b/libretroshare/src/serialiser/rsserviceserialiser.cc index d99d03de1..0c953fec3 100644 --- a/libretroshare/src/serialiser/rsserviceserialiser.cc +++ b/libretroshare/src/serialiser/rsserviceserialiser.cc @@ -23,6 +23,7 @@ * */ +#include "rsitems/rsitem.h" #include "rsserviceserialiser.h" uint32_t RsServiceSerialiser::size(RsItem *i) diff --git a/libretroshare/src/serialiser/rsstatusitems.h b/libretroshare/src/serialiser/rsstatusitems.h index c6cc0c8b2..8ea99e04c 100644 --- a/libretroshare/src/serialiser/rsstatusitems.h +++ b/libretroshare/src/serialiser/rsstatusitems.h @@ -27,7 +27,8 @@ */ #include "rsitems/rsserviceids.h" -#include "serialiser/rsserial.h" +#include "rsitems/itempriorities.h" +#include "rsitems/rsitem.h" /**************************************************************************/ diff --git a/libretroshare/src/serialization/rsserializer.cc b/libretroshare/src/serialization/rsserializer.cc index 3ab5770aa..f9619e839 100644 --- a/libretroshare/src/serialization/rsserializer.cc +++ b/libretroshare/src/serialization/rsserializer.cc @@ -1,5 +1,7 @@ #include +#include "rsitems/rsitem.h" + #include "util/rsprint.h" #include "serialization/rsserializer.h" #include "serialization/rstypeserializer.h" @@ -31,7 +33,7 @@ RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size) SerializeContext ctx(const_cast(static_cast(data)),*size,mFormat,mFlags); ctx.mOffset = 8 ; - item->serial_process(RsItem::DESERIALIZE, ctx) ; + item->serial_process(RsGenericSerializer::DESERIALIZE, ctx) ; if(ctx.mSize != ctx.mOffset) { @@ -67,7 +69,7 @@ RsItem *RsConfigSerializer::deserialise(void *data, uint32_t *size) SerializeContext ctx(const_cast(static_cast(data)),*size,mFormat,mFlags); ctx.mOffset = 8 ; - item->serial_process(RsItem::DESERIALIZE, ctx) ; + item->serial_process(DESERIALIZE, ctx) ; if(ctx.mSize != ctx.mOffset) { @@ -105,7 +107,7 @@ bool RsGenericSerializer::serialise(RsItem *item,void *data,uint32_t *size) ctx.mSize = tlvsize; - item->serial_process(RsItem::SERIALIZE,ctx) ; + item->serial_process(RsGenericSerializer::SERIALIZE,ctx) ; if(ctx.mSize != ctx.mOffset) { @@ -123,7 +125,7 @@ uint32_t RsGenericSerializer::size(RsItem *item) ctx.mOffset = 0; else ctx.mOffset = 8 ; // header size - item->serial_process(RsItem::SIZE_ESTIMATE, ctx) ; + item->serial_process(SIZE_ESTIMATE, ctx) ; return ctx.mOffset ; } @@ -133,7 +135,7 @@ void RsGenericSerializer::print(RsItem *item) SerializeContext ctx(NULL,0,mFormat,mFlags); std::cerr << "***** RsItem class: \"" << typeid(*item).name() << "\" *****" << std::endl; - item->serial_process(RsItem::PRINT, ctx) ; + item->serial_process(PRINT, ctx) ; std::cerr << "******************************" << std::endl; } diff --git a/libretroshare/src/serialization/rsserializer.h b/libretroshare/src/serialization/rsserializer.h index 700b690f5..2bea8d23f 100644 --- a/libretroshare/src/serialization/rsserializer.h +++ b/libretroshare/src/serialization/rsserializer.h @@ -5,15 +5,34 @@ #include #include +#include "retroshare/rsflags.h" #include "serialiser/rsserial.h" -#include "serialization/rstypeserializer.h" + +class RsItem ; #define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : " class RsGenericSerializer: public RsSerialType { public: + typedef enum { SIZE_ESTIMATE = 0x01, SERIALIZE = 0x02, DESERIALIZE = 0x03, PRINT=0x04 } SerializeJob ; + typedef enum { FORMAT_BINARY = 0x01, FORMAT_JSON = 0x02 } SerializationFormat ; + class SerializeContext + { + public: + + + SerializeContext(uint8_t *data,uint32_t size,SerializationFormat format,SerializationFlags flags) + : mData(data),mSize(size),mOffset(0),mOk(true),mFormat(format),mFlags(flags) {} + + unsigned char *mData ; + uint32_t mSize ; + uint32_t mOffset ; + bool mOk ; + SerializationFormat mFormat ; + SerializationFlags mFlags ; + }; // These are convenience flags to be used by the items when processing the data. The names of the flags // are not very important. What matters is that the serial_process() method of each item correctly @@ -36,18 +55,18 @@ public: protected: RsGenericSerializer(uint8_t serial_class, uint8_t serial_type, - SerializeContext::SerializationFormat format, + SerializationFormat format, SerializationFlags flags ) : RsSerialType(RS_PKT_VERSION1,serial_class,serial_type), mFormat(format),mFlags(flags) {} RsGenericSerializer(uint16_t service, - SerializeContext::SerializationFormat format, + SerializationFormat format, SerializationFlags flags ) : RsSerialType(RS_PKT_VERSION_SERVICE,service), mFormat(format),mFlags(flags) {} - SerializeContext::SerializationFormat mFormat ; + SerializationFormat mFormat ; SerializationFlags mFlags ; }; @@ -56,8 +75,8 @@ class RsServiceSerializer: public RsGenericSerializer { public: RsServiceSerializer(uint16_t service_id, - SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, - SerializationFlags flags = SERIALIZATION_FLAG_NONE) + SerializationFormat format = FORMAT_BINARY, + SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsGenericSerializer(service_id,format,flags) {} @@ -74,8 +93,8 @@ class RsConfigSerializer: public RsGenericSerializer public: RsConfigSerializer(uint8_t config_class, uint8_t config_type, - SerializeContext::SerializationFormat format = SerializeContext::FORMAT_BINARY, - SerializationFlags flags = RsGenericSerializer::SERIALIZATION_FLAG_NONE) + SerializationFormat format = FORMAT_BINARY, + SerializationFlags flags = SERIALIZATION_FLAG_NONE) : RsGenericSerializer(config_class,config_type,format,flags) {} diff --git a/libretroshare/src/serialization/rstypeserializer.h b/libretroshare/src/serialization/rstypeserializer.h index 0693331b1..31da447f4 100644 --- a/libretroshare/src/serialization/rstypeserializer.h +++ b/libretroshare/src/serialization/rstypeserializer.h @@ -7,25 +7,7 @@ #include "retroshare/rsflags.h" #include "retroshare/rsids.h" -class SerializeContext -{ - public: - - enum SerializationFormat { - FORMAT_BINARY = 0x01 , - FORMAT_JSON = 0x02 - }; - - SerializeContext(uint8_t *data,uint32_t size,SerializationFormat format,SerializationFlags flags) - : mData(data),mSize(size),mOffset(0),mOk(true),mFormat(format),mFlags(flags) {} - - unsigned char *mData ; - uint32_t mSize ; - uint32_t mOffset ; - bool mOk ; - SerializationFormat mFormat ; - SerializationFlags mFlags ; -}; +#include "serialization/rsserializer.h" class RsTypeSerializer @@ -44,20 +26,20 @@ class RsTypeSerializer //=================================================================================================// template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,T& member,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: ctx.mOffset += serial_size(member) ; + case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += serial_size(member) ; break ; - case RsItem::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; + case RsGenericSerializer::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; break ; - case RsItem::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; + case RsGenericSerializer::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,member) ; break ; - case RsItem::PRINT: + case RsGenericSerializer::PRINT: print_data(member_name,member); break; default: @@ -71,20 +53,20 @@ class RsTypeSerializer //=================================================================================================// template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,uint16_t type_id,T& member,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,uint16_t type_id,T& member,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: ctx.mOffset += serial_size(type_id,member) ; + case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += serial_size(type_id,member) ; break ; - case RsItem::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; + case RsGenericSerializer::DESERIALIZE: ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; break ; - case RsItem::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; + case RsGenericSerializer::SERIALIZE: ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,type_id,member) ; break ; - case RsItem::PRINT: + case RsGenericSerializer::PRINT: print_data(member_name,type_id,member); break; default: @@ -97,11 +79,11 @@ class RsTypeSerializer //=================================================================================================// template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::map& v,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::map& v,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: + case RsGenericSerializer::SIZE_ESTIMATE: { ctx.mOffset += 4 ; for(typename std::map::iterator it(v.begin());it!=v.end();++it) @@ -112,7 +94,7 @@ class RsTypeSerializer } break ; - case RsItem::DESERIALIZE: + case RsGenericSerializer::DESERIALIZE: { uint32_t n=0 ; ctx.mOk = ctx.mOk && deserialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; @@ -130,7 +112,7 @@ class RsTypeSerializer } break ; - case RsItem::SERIALIZE: + case RsGenericSerializer::SERIALIZE: { uint32_t n=v.size(); ctx.mOk = ctx.mOk && serialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; @@ -143,12 +125,12 @@ class RsTypeSerializer } break ; - case RsItem::PRINT: + case RsGenericSerializer::PRINT: { if(v.empty()) - std::cerr << " Empty map"<< std::endl; + std::cerr << " Empty map \"" << member_name << "\"" << std::endl; else - std::cerr << " std::map of " << v.size() << " elements:" << std::endl; + std::cerr << " std::map of " << v.size() << " elements: \"" << member_name << "\"" << std::endl; for(typename std::map::iterator it(v.begin());it!=v.end();++it) { @@ -169,11 +151,11 @@ class RsTypeSerializer //=================================================================================================// template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::vector& v,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::vector& v,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: + case RsGenericSerializer::SIZE_ESTIMATE: { ctx.mOffset += 4 ; for(uint32_t i=0;i - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,std::list& v,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,std::list& v,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: + case RsGenericSerializer::SIZE_ESTIMATE: { ctx.mOffset += 4 ; for(typename std::list::iterator it(v.begin());it!=v.end();++it) @@ -235,7 +217,7 @@ class RsTypeSerializer } break ; - case RsItem::DESERIALIZE: + case RsGenericSerializer::DESERIALIZE: { uint32_t n=0 ; serial_process(j,ctx,n,"temporary size") ; @@ -248,7 +230,7 @@ class RsTypeSerializer } break ; - case RsItem::SERIALIZE: + case RsGenericSerializer::SERIALIZE: { uint32_t n=v.size(); serial_process(j,ctx,n,"temporary size") ; @@ -257,7 +239,7 @@ class RsTypeSerializer } break ; - case RsItem::PRINT: + case RsGenericSerializer::PRINT: { if(v.empty()) std::cerr << " Empty list"<< std::endl; @@ -275,14 +257,14 @@ class RsTypeSerializer //=================================================================================================// template - static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,t_RsFlags32& v,const std::string& member_name) + static void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,t_RsFlags32& v,const std::string& member_name) { switch(j) { - case RsItem::SIZE_ESTIMATE: ctx.mOffset += 4 ; + case RsGenericSerializer::SIZE_ESTIMATE: ctx.mOffset += 4 ; break ; - case RsItem::DESERIALIZE: + case RsGenericSerializer::DESERIALIZE: { uint32_t n=0 ; deserialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; @@ -290,14 +272,14 @@ class RsTypeSerializer } break ; - case RsItem::SERIALIZE: + case RsGenericSerializer::SERIALIZE: { uint32_t n=v.toUInt32() ; serialize(ctx.mData,ctx.mSize,ctx.mOffset,n) ; } break ; - case RsItem::PRINT: + case RsGenericSerializer::PRINT: std::cerr << " Flags of type " << std::hex << N << " : " << v.toUInt32() << std::endl; break ; } diff --git a/libretroshare/src/services/p3service.cc b/libretroshare/src/services/p3service.cc index 469247905..bb15831d7 100644 --- a/libretroshare/src/services/p3service.cc +++ b/libretroshare/src/services/p3service.cc @@ -23,6 +23,8 @@ * */ +#include "rsitems/itempriorities.h" + #include "pqi/pqi.h" #include "util/rsstring.h" #include "services/p3service.h" diff --git a/libretroshare/src/turtle/rsturtleitem.cc b/libretroshare/src/turtle/rsturtleitem.cc index 4d5f1a2fa..2455c98e5 100644 --- a/libretroshare/src/turtle/rsturtleitem.cc +++ b/libretroshare/src/turtle/rsturtleitem.cc @@ -48,14 +48,14 @@ RsItem *RsTurtleSerialiser::create_item(uint16_t service,uint8_t item_subtype) c return NULL ; } -void RsTurtleStringSearchRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleStringSearchRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_VALUE,match_string,"match_string") ; RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; } -void RsTurtleRegExpSearchRequestItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleRegExpSearchRequestItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process(j,ctx,depth,"depth") ; @@ -140,7 +140,7 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const RsRegul std::cerr << " [RegExpr ] " << n << ", tokens=" << expr._tokens.size() << " ints=" << expr._ints.size() << " strings=" << expr._strings.size() << std::endl; } -void RsTurtleSearchResultItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleSearchResultItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; @@ -193,7 +193,7 @@ template<> void RsTypeSerializer::print_data(const std::string& n, const TurtleF std::cerr << " [FileInfo ] " << n << " size=" << i.size << " hash=" << i.hash << ", name=" << i.name << std::endl; } -void RsTurtleOpenTunnelItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleOpenTunnelItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,file_hash ,"file_hash") ; RsTypeSerializer::serial_process(j,ctx,request_id ,"request_id") ; @@ -201,13 +201,13 @@ void RsTurtleOpenTunnelItem::serial_process(SerializeJob j,SerializeContext& ctx RsTypeSerializer::serial_process(j,ctx,depth ,"depth") ; } -void RsTurtleTunnelOkItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleTunnelOkItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id ,"tunnel_id") ; RsTypeSerializer::serial_process(j,ctx,request_id,"request_id") ; } -void RsTurtleGenericDataItem::serial_process(SerializeJob j,SerializeContext& ctx) +void RsTurtleGenericDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,tunnel_id ,"tunnel_id") ; diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index 9bc3fc4bf..8a8a1e49c 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -1,12 +1,16 @@ #pragma once +#include "rsitems/rsserviceids.h" +#include "rsitems/rsitem.h" +#include "rsitems/itempriorities.h" + #include "serialiser/rsserial.h" #include "serialiser/rstlvbase.h" #include "serialiser/rsbaseserial.h" + #include "retroshare/rsturtle.h" #include "retroshare/rsexpr.h" #include "retroshare/rstypes.h" -#include "rsitems/rsserviceids.h" #include "turtle/turtletypes.h" #include "serialization/rsserializer.h" @@ -58,7 +62,7 @@ class RsTurtleSearchResultItem: public RsTurtleItem void clear() { result.clear() ; } protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; @@ -87,7 +91,7 @@ class RsTurtleStringSearchRequestItem: public RsTurtleSearchRequestItem void clear() { match_string.clear() ; } protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem @@ -102,7 +106,7 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem void clear() { expr = RsRegularExpression::LinearizedExpression(); } protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; /***********************************************************************************/ @@ -121,7 +125,7 @@ class RsTurtleOpenTunnelItem: public RsTurtleItem void clear() { file_hash.clear() ;} protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; class RsTurtleTunnelOkItem: public RsTurtleItem @@ -134,7 +138,7 @@ class RsTurtleTunnelOkItem: public RsTurtleItem void clear() {} protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; /***********************************************************************************/ @@ -198,7 +202,7 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem data_size = 0; } protected: - void serial_process(SerializeJob j,SerializeContext& ctx); + void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx); }; /***********************************************************************************/