mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
moved rsgxschannel items to rsitems
This commit is contained in:
parent
69729ad7d2
commit
db645239cb
6 changed files with 177 additions and 579 deletions
173
libretroshare/src/rsitems/rsgxschannelitems.cc
Normal file
173
libretroshare/src/rsitems/rsgxschannelitems.cc
Normal file
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxschannelitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "rsgxschannelitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "serialization/rstypeserializer.h"
|
||||
|
||||
RsItem *RsGxsChannelSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_GXS_TYPE_CHANNELS)
|
||||
return NULL ;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM: return new RsGxsChannelGroupItem() ;
|
||||
case RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM: return new RsGxsChannelPostItem();
|
||||
default:
|
||||
return RsGxsCommentSerialiser::create_item(service_id,item_subtype) ;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsChannelGroupItem::clear()
|
||||
{
|
||||
mDescription.clear();
|
||||
mImage.TlvClear();
|
||||
}
|
||||
|
||||
bool RsGxsChannelGroupItem::fromChannelGroup(RsGxsChannelGroup &group, bool moveImage)
|
||||
{
|
||||
clear();
|
||||
meta = group.mMeta;
|
||||
mDescription = group.mDescription;
|
||||
|
||||
if (moveImage)
|
||||
{
|
||||
mImage.binData.bin_data = group.mImage.mData;
|
||||
mImage.binData.bin_len = group.mImage.mSize;
|
||||
group.mImage.shallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mImage.binData.setBinData(group.mImage.mData, group.mImage.mSize);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsGxsChannelGroupItem::toChannelGroup(RsGxsChannelGroup &group, bool moveImage)
|
||||
{
|
||||
group.mMeta = meta;
|
||||
group.mDescription = mDescription;
|
||||
if (moveImage)
|
||||
{
|
||||
group.mImage.take((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
|
||||
// mImage doesn't have a ShallowClear at the moment!
|
||||
mImage.binData.TlvShallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
group.mImage.copy((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RsGxsChannelGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_DESCR,mDescription,"mDescription") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mImage,"mImage") ;
|
||||
}
|
||||
|
||||
bool RsGxsChannelPostItem::fromChannelPost(RsGxsChannelPost &post, bool moveImage)
|
||||
{
|
||||
clear();
|
||||
meta = post.mMeta;
|
||||
mMsg = post.mMsg;
|
||||
|
||||
if (moveImage)
|
||||
{
|
||||
mThumbnail.binData.bin_data = post.mThumbnail.mData;
|
||||
mThumbnail.binData.bin_len = post.mThumbnail.mSize;
|
||||
post.mThumbnail.shallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mThumbnail.binData.setBinData(post.mThumbnail.mData, post.mThumbnail.mSize);
|
||||
}
|
||||
|
||||
std::list<RsGxsFile>::iterator fit;
|
||||
for(fit = post.mFiles.begin(); fit != post.mFiles.end(); ++fit)
|
||||
{
|
||||
RsTlvFileItem fi;
|
||||
fi.name = fit->mName;
|
||||
fi.filesize = fit->mSize;
|
||||
fi.hash = fit->mHash;
|
||||
mAttachment.items.push_back(fi);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsGxsChannelPostItem::toChannelPost(RsGxsChannelPost &post, bool moveImage)
|
||||
{
|
||||
post.mMeta = meta;
|
||||
post.mMsg = mMsg;
|
||||
if (moveImage)
|
||||
{
|
||||
post.mThumbnail.take((uint8_t *) mThumbnail.binData.bin_data, mThumbnail.binData.bin_len);
|
||||
// mThumbnail doesn't have a ShallowClear at the moment!
|
||||
mThumbnail.binData.TlvShallowClear();
|
||||
}
|
||||
else
|
||||
{
|
||||
post.mThumbnail.copy((uint8_t *) mThumbnail.binData.bin_data, mThumbnail.binData.bin_len);
|
||||
}
|
||||
|
||||
post.mCount = 0;
|
||||
post.mSize = 0;
|
||||
std::list<RsTlvFileItem>::iterator fit;
|
||||
for(fit = mAttachment.items.begin(); fit != mAttachment.items.end(); ++fit)
|
||||
{
|
||||
RsGxsFile fi;
|
||||
fi.mName = RsDirUtil::getTopDir(fit->name);
|
||||
fi.mSize = fit->filesize;
|
||||
fi.mHash = fit->hash;
|
||||
|
||||
post.mFiles.push_back(fi);
|
||||
post.mCount++;
|
||||
post.mSize += fi.mSize;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RsGxsChannelPostItem::clear()
|
||||
{
|
||||
mMsg.clear();
|
||||
mAttachment.TlvClear();
|
||||
mThumbnail.TlvClear();
|
||||
}
|
||||
|
||||
void RsGxsChannelPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,mMsg,"mMsg") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mAttachment,"mAttachment") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mThumbnail,"mThumbnail") ;
|
||||
}
|
97
libretroshare/src/rsitems/rsgxschannelitems.h
Normal file
97
libretroshare/src/rsitems/rsgxschannelitems.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsgxschannelitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 by Robert Fernie
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXS_CHANNEL_ITEMS_H
|
||||
#define RS_GXS_CHANNEL_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsgxscommentitems.h"
|
||||
#include "rsitems/rsgxsitems.h"
|
||||
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvimage.h"
|
||||
|
||||
#include "retroshare/rsgxschannels.h"
|
||||
|
||||
#include "serialization/rsserializer.h"
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM = 0x03;
|
||||
|
||||
class RsGxsChannelGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsChannelGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_CHANNELS, RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM) {}
|
||||
virtual ~RsGxsChannelGroupItem() {}
|
||||
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
// use conversion functions to transform:
|
||||
bool fromChannelGroup(RsGxsChannelGroup &group, bool moveImage);
|
||||
bool toChannelGroup(RsGxsChannelGroup &group, bool moveImage);
|
||||
|
||||
std::string mDescription;
|
||||
RsTlvImage mImage;
|
||||
};
|
||||
|
||||
class RsGxsChannelPostItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsChannelPostItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_CHANNELS, RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM) {}
|
||||
virtual ~RsGxsChannelPostItem() {}
|
||||
void clear();
|
||||
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
|
||||
|
||||
// Slightly unusual structure.
|
||||
// use conversion functions to transform:
|
||||
bool fromChannelPost(RsGxsChannelPost &post, bool moveImage);
|
||||
bool toChannelPost(RsGxsChannelPost &post, bool moveImage);
|
||||
|
||||
std::string mMsg;
|
||||
RsTlvFileSet mAttachment;
|
||||
RsTlvImage mThumbnail;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsChannelSerialiser : public RsGxsCommentSerialiser
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsChannelSerialiser() :RsGxsCommentSerialiser(RS_SERVICE_GXS_TYPE_CHANNELS) {}
|
||||
virtual ~RsGxsChannelSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_GXS_CHANNEL_ITEMS_H */
|
|
@ -29,8 +29,6 @@
|
|||
#include <map>
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
|
||||
|
@ -52,6 +50,7 @@ public:
|
|||
RsGxsComment mMsg;
|
||||
};
|
||||
|
||||
|
||||
class RsGxsVoteItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -28,9 +28,7 @@
|
|||
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
//#include "serialiser/rstlvtypes.h"
|
||||
//#include "serialiser/rstlvkeys.h"
|
||||
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue