Major commit of progress on new GxsServices (Channels and Posted). These are not complete yet!

- Reorganisation of p3posted, stripped out lots of previous stuff.
 - Converted p3posted to use GxsComment system.
 - Disabled much of the DummyData - switch it on manually when testing.
 - Added Basics of ChannelPost processing for AutoDownload. (incomplete).
 - Added GxsCommon backend for RsGxsImage and RsGxsFile.
 - Completed Serialiser for GxsChannels.




git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6207 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2013-03-11 20:40:28 +00:00
parent 4b9087b60d
commit 123d4a630b
16 changed files with 1927 additions and 2179 deletions

View File

@ -48,10 +48,9 @@ class RsGxsChannelGroup
public:
RsGroupMetaData mMeta;
std::string mDescription;
RsGxsImage mImage;
//RsGxsImage mChanImage;
bool mAutoDownload;
};
class RsGxsChannelPost
@ -60,15 +59,14 @@ class RsGxsChannelPost
RsMsgMetaData mMeta;
std::string mMsg; // UTF8 encoded.
//std::list<RsGxsFile> mFiles;
std::list<RsGxsFile> mFiles;
uint32_t mCount; // auto calced.
uint64_t mSize; // auto calced.
//RsGxsImage mThumbnail;
RsGxsImage mThumbnail;
};
//typedef std::map<RsGxsGroupId, std::vector<RsGxsChannelMsg> > GxsChannelMsgResult;
std::ostream &operator<<(std::ostream &out, const RsGxsChannelGroup &group);
std::ostream &operator<<(std::ostream &out, const RsGxsChannelPost &post);
@ -95,6 +93,8 @@ virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost
//////////////////////////////////////////////////////////////////////////////
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
virtual void setChannelAutoDownload(uint32_t& token, const RsGxsGroupId& groupId, bool autoDownload) = 0;
//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);

View File

@ -45,11 +45,23 @@ class RsGxsFile
class RsGxsImage
{
public:
RsGxsImage();
RsGxsImage();
~RsGxsImage();
//NB: Must make sure that we always use methods - to be consistent about malloc/free for this data.
static uint8_t *allocate(uint32_t size);
static void release(void *data);
void take(uint8_t *data, uint32_t size); // Copies Pointer.
void copy(uint8_t *data, uint32_t size); // Allocates and Copies.
void clear(); // Frees.
void shallowClear(); // Clears Pointer.
uint8_t *mData;
uint32_t mSize;
};
#define GXS_VOTE_DOWN 0x0001
#define GXS_VOTE_UP 0x0002

View File

@ -1,6 +1,5 @@
#ifndef RSPOSTED_H
#define RSPOSTED_H
#ifndef RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H
#define RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H
/*
* libretroshare/src/retroshare: rsposted.h
@ -11,7 +10,7 @@
*
* 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.
* 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
@ -30,22 +29,26 @@
#include <inttypes.h>
#include <string>
#include <list>
#include "retroshare/rstokenservice.h"
#include "retroshare/rsgxsifacehelper.h"
#include "retroshare/rsgxscommon.h"
/* The Main Interface Class - for information about your Posted */
class RsPosted;
extern RsPosted *rsPosted;
/* The Main Interface Class - for information about your Peers */
class RsPostedPost;
class RsPostedGroup
{
public:
RsGroupMetaData mMeta;
std::string mDescription;
RsPostedGroup() { return; }
public:
RsPostedGroup() { return; }
RsGroupMetaData mMeta;
std::string mDescription;
};
//#define RSPOSTED_MSGTYPE_POST 0x0001
//#define RSPOSTED_MSGTYPE_VOTE 0x0002
//#define RSPOSTED_MSGTYPE_COMMENT 0x0004
@ -61,127 +64,99 @@ class RsPostedGroup
#define RSPOSTED_VIEWMODE_HOT 3
#define RSPOSTED_VIEWMODE_COMMENTS 4
class RsPostedPost;
class RsPostedComment;
class RsPostedVote;
class RsPostedPostRanking;
typedef std::map<RsGxsGroupId, std::vector<RsPostedPost> > PostedPostResult;
typedef std::map<RsGxsGroupId, std::vector<RsPostedComment> > PostedCommentResult;
typedef std::map<RsGxsGroupId, std::vector<RsPostedVote> > PostedVoteResult;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsPostedComment> > PostedRelatedCommentResult;
typedef std::pair<RsGxsGroupId, int32_t> GroupRank;
typedef std::map<uint32_t, RsGxsMessageId> PostedRanking;
std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
std::ostream &operator<<(std::ostream &out, const RsPostedPost &post);
std::ostream &operator<<(std::ostream &out, const RsPostedVote &vote);
std::ostream &operator<<(std::ostream &out, const RsPostedComment &comment);
class RsPosted : public RsGxsIfaceHelper
class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService
{
public:
public:
enum RankType {TopRankType, HotRankType, NewRankType };
enum RankType {TopRankType, HotRankType, NewRankType };
static const uint32_t FLAG_MSGTYPE_POST;
static const uint32_t FLAG_MSGTYPE_VOTE;
static const uint32_t FLAG_MSGTYPE_COMMENT;
static const uint32_t FLAG_MSGTYPE_MASK;
static const uint32_t FLAG_MSGTYPE_POST;
static const uint32_t FLAG_MSGTYPE_MASK;
RsPosted(RsGxsIface* gxs) : RsGxsIfaceHelper(gxs) { return; }
RsPosted(RsGxsIface* gxs) : RsGxsIfaceHelper(gxs) { return; }
virtual ~RsPosted() { return; }
/* Specific Service Data */
/* Specific Service Data */
virtual bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group) = 0;
virtual bool getPost(const uint32_t &token, PostedPostResult &post) = 0;
virtual bool getComment(const uint32_t &token, PostedCommentResult &comment) = 0;
virtual bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult& comments) = 0;
virtual bool getPostRanking(const uint32_t& token, RsPostedPostRanking& ranking) = 0;
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups) = 0;
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
virtual bool submitGroup(uint32_t &token, RsPostedGroup &group) = 0;
virtual bool submitPost(uint32_t &token, RsPostedPost &post) = 0;
virtual bool submitVote(uint32_t &token, RsPostedVote &vote) = 0;
virtual bool submitComment(uint32_t &token, RsPostedComment &comment) = 0;
virtual bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t& downVotes, uint32_t& nComments) const = 0;
// SPECIAL RANKING FNS.
virtual bool requestPostRankings(uint32_t &token, const RankType &rType, uint32_t count, uint32_t page_no, const RsGxsGroupId &groupId) = 0;
// Special Ranking Request.
/*!
* Makes request for posts of a topic
* @param token
* @param rType
* @param groupId
*/
virtual bool requestPostRankings(uint32_t &token, const RankType& rType, const RsGxsGroupId& groupId) = 0;
virtual bool getPostRanking(const uint32_t &token, std::vector<RsPostedPost> &msgs) = 0;
/*!
* Makes request for ranking of comments for a post
* @param token
* @param rType type of ranking to collect
* @param msgId message id of post as groupid-messageid pair
*/
virtual bool requestCommentRankings(uint32_t &token, const RankType& rType, const RsGxsGrpMsgIdPair& msgId) = 0;
//virtual bool getPostRanking(const uint32_t& token, std::vector<RsPostedPost> &ranking) = 0;
/* From RsGxsCommentService */
//virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
//virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
//virtual bool createComment(uint32_t &token, RsGxsComment &comment) = 0;
//virtual bool createVote(uint32_t &token, RsGxsVote &vote) = 0;
//////////////////////////////////////////////////////////////////////////////
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
virtual bool createGroup(uint32_t &token, RsPostedGroup &group) = 0;
virtual bool createPost(uint32_t &token, RsPostedPost &post) = 0;
//virtual bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t& downVotes, uint32_t& nComments) const = 0;
// Special Ranking Request.
/*!
* Makes request for posts of a topic
* @param token
* @param rType
* @param groupId
*/
//virtual bool requestPostRankings(uint32_t &token, const RankType& rType, const RsGxsGroupId& groupId) = 0;
/*!
* Makes request for ranking of comments for a post
* @param token
* @param rType type of ranking to collect
* @param msgId message id of post as groupid-messageid pair
*/
//virtual bool requestCommentRankings(uint32_t &token, const RankType& rType, const RsGxsGrpMsgIdPair& msgId) = 0;
};
class RsPostedPost
{
public:
RsPostedPost()
{
mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_POST;
mMeta.mServiceString = " 0 0 0";
return;
}
public:
RsPostedPost()
{
mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_POST;
mUpVotes = 0;
mDownVotes = 0;
mComments = 0;
return;
}
RsMsgMetaData mMeta;
std::string mLink;
std::string mNotes;
RsMsgMetaData mMeta;
std::string mLink;
std::string mNotes;
// Calculated.
uint32_t mUpVotes;
uint32_t mDownVotes;
uint32_t mComments;
// and Calculated Scores:???
double mHotScore;
double mTopScore;
double mNewScore;
};
class RsGxsPostedVoteItem;
class RsPostedVote
{
public:
RsPostedVote(const RsGxsPostedVoteItem&);
RsPostedVote()
{
mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_VOTE;
return;
}
uint8_t mDirection;
RsMsgMetaData mMeta;
};
class RsGxsPostedCommentItem;
class RsPostedComment
{
public:
RsPostedComment()
{
mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_COMMENT;
return;
}
RsPostedComment(const RsGxsPostedCommentItem& );
std::string mComment;
RsMsgMetaData mMeta;
};
class RsPostedPostRanking
{
public:
RsGxsGroupId grpId;
PostedRanking ranking;
RsPosted::RankType rType;
};
#endif // RSPOSTED_H
#endif // RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H

View File

@ -2370,11 +2370,11 @@ int RsServer::StartupRetroShare()
RsGeneralDataService* posted_ds = new RsDataService(currGxsDir + "/", "posted_db",
RS_SERVICE_GXSV1_TYPE_POSTED);
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
//#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
posted_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
#endif
//#endif
mPosted = new p3Posted(posted_ds, NULL);
mPosted = new p3Posted(posted_ds, NULL, mGxsIdService);
// create GXS photo service
RsGxsNetService* posted_ns = new RsGxsNetService(

View File

@ -122,7 +122,8 @@ RsItem* RsGxsChannelSerialiser::deserialise(void* data, uint32_t* size)
void RsGxsChannelGroupItem::clear()
{
mGroup.mDescription.clear();
mDescription.clear();
mImage.TlvClear();
}
std::ostream& RsGxsChannelGroupItem::print(std::ostream& out, uint16_t indent)
@ -131,20 +132,61 @@ std::ostream& RsGxsChannelGroupItem::print(std::ostream& out, uint16_t indent)
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Description: " << mGroup.mDescription << std::endl;
out << "Description: " << mDescription << std::endl;
out << "Image: " << std::endl;
mImage.print(out, int_Indent);
printRsItemEnd(out ,"RsGxsChannelGroupItem", indent);
return out;
}
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.TlvShallowClear();
}
else
{
group.mImage.copy((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
}
return true;
}
uint32_t RsGxsChannelSerialiser::sizeGxsChannelGroupItem(RsGxsChannelGroupItem *item)
{
const RsGxsChannelGroup& group = item->mGroup;
uint32_t s = 8; // header
s += GetTlvStringSize(group.mDescription);
s += GetTlvStringSize(item->mDescription);
s += item->mImage.TlvSize();
return s;
}
@ -177,7 +219,8 @@ bool RsGxsChannelSerialiser::serialiseGxsChannelGroupItem(RsGxsChannelGroupItem
offset += 8;
/* GxsChannelGroupItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mGroup.mDescription);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mDescription);
item->mImage.SetTlv(data, tlvsize, &offset);
if(offset != tlvsize)
{
@ -237,7 +280,8 @@ RsGxsChannelGroupItem* RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem(vo
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mGroup.mDescription);
ok &= GetTlvString(data, rssize, &offset, 1, item->mDescription);
item->mImage.GetTlv(data, rssize, &offset);
if (offset != rssize)
{
@ -270,7 +314,9 @@ RsGxsChannelGroupItem* RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem(vo
void RsGxsChannelPostItem::clear()
{
mMsg.mMsg.clear();
mMsg.clear();
mAttachment.TlvClear();
mThumbnail.TlvClear();
}
std::ostream& RsGxsChannelPostItem::print(std::ostream& out, uint16_t indent)
@ -279,20 +325,90 @@ std::ostream& RsGxsChannelPostItem::print(std::ostream& out, uint16_t indent)
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Msg: " << mMsg.mMsg << std::endl;
out << "Msg: " << mMsg << std::endl;
out << "Attachment: " << std::endl;
mAttachment.print(out, int_Indent);
out << "Thumbnail: " << std::endl;
mThumbnail.print(out, int_Indent);
printRsItemEnd(out ,"RsGxsChannelPostItem", indent);
return out;
}
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.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;
fi.mPath = fit->path;
post.mFiles.push_back(fi);
post.mCount++;
post.mSize += fi.mSize;
}
return true;
}
uint32_t RsGxsChannelSerialiser::sizeGxsChannelPostItem(RsGxsChannelPostItem *item)
{
const RsGxsChannelPost& msg = item->mMsg;
uint32_t s = 8; // header
s += GetTlvStringSize(msg.mMsg); // mMsg.
s += GetTlvStringSize(item->mMsg); // mMsg.
s += item->mAttachment.TlvSize();
s += item->mThumbnail.TlvSize();
return s;
}
@ -325,7 +441,9 @@ bool RsGxsChannelSerialiser::serialiseGxsChannelPostItem(RsGxsChannelPostItem *i
offset += 8;
/* GxsChannelPostItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg.mMsg);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg);
item->mAttachment.SetTlv(data, tlvsize, &offset);
item->mThumbnail.SetTlv(data, tlvsize, &offset);
if(offset != tlvsize)
{
@ -385,7 +503,9 @@ RsGxsChannelPostItem* RsGxsChannelSerialiser::deserialiseGxsChannelPostItem(void
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg.mMsg);
ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg);
item->mAttachment.GetTlv(data, rssize, &offset);
item->mThumbnail.GetTlv(data, rssize, &offset);
if (offset != rssize)
{

View File

@ -37,6 +37,8 @@
#include "rsgxsitems.h"
#include "retroshare/rsgxschannels.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;
@ -52,8 +54,12 @@ public:
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
// use conversion functions to transform:
bool fromChannelGroup(RsGxsChannelGroup &group, bool moveImage);
bool toChannelGroup(RsGxsChannelGroup &group, bool moveImage);
RsGxsChannelGroup mGroup;
std::string mDescription;
RsTlvImage mImage;
};
class RsGxsChannelPostItem : public RsGxsMsgItem
@ -66,7 +72,14 @@ public:
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsChannelPost mMsg;
// 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;
};

View File

@ -4,11 +4,11 @@
*
* RetroShare Serialiser.
*
* Copyright 2012 by Christopher Evi-Parker
* Copyright 2012-2013 by Robert Fernie, Christopher Evi-Parker
*
* 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.
* 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
@ -31,627 +31,363 @@
uint32_t RsGxsPostedSerialiser::size(RsItem *item)
{
RsGxsPostedPostItem* ppItem = NULL;
RsGxsPostedCommentItem* pcItem = NULL;
RsGxsPostedVoteItem* pvItem = NULL;
RsGxsPostedGroupItem* pgItem = NULL;
if((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
{
return sizeGxsPostedPostItem(ppItem);
}
else if((pcItem = dynamic_cast<RsGxsPostedCommentItem*>(item)) != NULL)
{
return sizeGxsPostedCommentItem(pcItem);
}else if((pvItem = dynamic_cast<RsGxsPostedVoteItem*>(item)) != NULL)
{
return sizeGxsPostedVoteItem(pvItem);
}else if((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
{
return sizeGxsPostedGroupItem(pgItem);
}
else
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::size() Failed" << std::endl;
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::size()" << std::endl;
#endif
return NULL;
}
RsGxsPostedGroupItem* pgItem = NULL;
RsGxsPostedPostItem* ppItem = NULL;
if ((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
{
return sizeGxsPostedGroupItem(pgItem);
}
else if ((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
{
return sizeGxsPostedPostItem(ppItem);
}
else
{
return RsGxsCommentSerialiser::size(item);
}
return NULL;
}
bool RsGxsPostedSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsPostedPostItem* ppItem = NULL;
RsGxsPostedCommentItem* pcItem = NULL;
RsGxsPostedVoteItem* pvItem = NULL;
RsGxsPostedGroupItem* pgItem = NULL;
if((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
{
return serialiseGxsPostedPostItem(ppItem, data, size);
}
else if((pcItem = dynamic_cast<RsGxsPostedCommentItem*>(item)) != NULL)
{
return serialiseGxsPostedCommentItem(pcItem, data, size);
}else if((pvItem = dynamic_cast<RsGxsPostedVoteItem*>(item)) != NULL)
{
return serialiseGxsPostedVoteItem(pvItem, data, size);
}else if((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
{
return serialiseGxsPostedGroupItem(pgItem, data, size);
}
else
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialise() FAILED" << std::endl;
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialise()" << std::endl;
#endif
return false;
}
RsGxsPostedPostItem* ppItem = NULL;
RsGxsPostedGroupItem* pgItem = NULL;
if ((pgItem = dynamic_cast<RsGxsPostedGroupItem*>(item)) != NULL)
{
return serialiseGxsPostedGroupItem(pgItem, data, size);
}
else if ((ppItem = dynamic_cast<RsGxsPostedPostItem*>(item)) != NULL)
{
return serialiseGxsPostedPostItem(ppItem, data, size);
}
else
{
return RsGxsCommentSerialiser::serialise(item, data, size);
}
return false;
}
RsItem* RsGxsPostedSerialiser::deserialise(void *data, uint32_t *size)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialise()" << std::endl;
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)))
{
std::cerr << "RsGxsPostedSerialiser::deserialise() ERROR Wrong Type";
std::cerr << std::endl;
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM:
return deserialiseGxsPostedCommentItem(data, size);
case RS_PKT_SUBTYPE_POSTED_GRP_ITEM:
return deserialiseGxsPostedGroupItem(data, size);
case RS_PKT_SUBTYPE_POSTED_POST_ITEM:
return deserialiseGxsPostedPostItem(data, size);
case RS_PKT_SUBTYPE_POSTED_VOTE_ITEM:
return deserialiseGxsPostedVoteItem(data, size);
default:
{
#ifdef RS_SSERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialise(): subtype could not be dealt with"
<< std::endl;
#endif
break;
}
}
return NULL;
case RS_PKT_SUBTYPE_POSTED_GRP_ITEM:
return deserialiseGxsPostedGroupItem(data, size);
break;
case RS_PKT_SUBTYPE_POSTED_POST_ITEM:
return deserialiseGxsPostedPostItem(data, size);
break;
default:
return RsGxsCommentSerialiser::deserialise(data, size);
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsPostedPostItem::clear()
{
mPost.mLink.clear();
mPost.mNotes.clear();
}
std::ostream & RsGxsPostedPostItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsGxsPostedPostItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Link: " << mPost.mLink << std::endl;
printIndent(out, int_Indent);
out << "Notes: " << mPost.mNotes << std::endl;
printRsItemEnd(out ,"RsGxsPostedPostItem", indent);
return out;
}
uint32_t RsGxsPostedSerialiser::sizeGxsPostedPostItem(RsGxsPostedPostItem* item)
{
RsPostedPost& p = item->mPost;
RsPostedPost& p = item->mPost;
uint32_t s = 8;
uint32_t s = 8;
s += GetTlvStringSize(p.mLink);
s += GetTlvStringSize(p.mNotes);
s += GetTlvStringSize(p.mLink);
s += GetTlvStringSize(p.mNotes);
return s;
}
uint32_t RsGxsPostedSerialiser::sizeGxsPostedCommentItem(RsGxsPostedCommentItem* item)
{
RsPostedComment& c = item->mComment;
uint32_t s = 8;
s += GetTlvStringSize(c.mComment);
return s;
}
uint32_t RsGxsPostedSerialiser::sizeGxsPostedVoteItem(RsGxsPostedVoteItem* item)
{
RsPostedVote& v = item->mVote;
uint32_t s = 8;
s += 1; // for vote direction
return s;
}
uint32_t RsGxsPostedSerialiser::sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item)
{
RsPostedGroup& g = item->mGroup;
uint32_t s = 8;
return s;
return s;
}
bool RsGxsPostedSerialiser::serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()" << std::endl;
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsPostedPostItem(item);
uint32_t offset = 0;
uint32_t tlvsize = sizeGxsPostedPostItem(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()()" << std::endl;
#endif
return false;
}
if(*size < tlvsize){
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() Size too small" << std::endl;
return false;
}
*size = tlvsize;
*size = tlvsize;
bool ok = true;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
/* RsPostedPost */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mLink);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mNotes);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mLink);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mNotes);
if(offset != tlvsize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
if(offset != tlvsize)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() FAIL Size Error! " << std::endl;
ok = false;
}
#ifdef GXS_POSTED_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() NOK" << std::endl;
}
#ifdef POSTED_DEBUG
if (!ok)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() NOK" << std::endl;
}
#endif
return ok;
return ok;
}
bool RsGxsPostedSerialiser::serialiseGxsPostedCommentItem(RsGxsPostedCommentItem* item, void* data, uint32_t *size)
RsGxsPostedPostItem* RsGxsPostedSerialiser::deserialiseGxsPostedPostItem(void *data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()" << std::endl;
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t tlvsize = sizeGxsPostedCommentItem(item);
uint32_t offset = 0;
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()" << std::endl;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_POSTED_POST_ITEM != getRsItemSubType(rstype)))
{
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong type" << std::endl;
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong size" << std::endl;
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPostedPostItem* item = new RsGxsPostedPostItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mLink);
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mNotes);
if (offset != rssize)
{
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL size mismatch" << std::endl;
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() NOK" << std::endl;
#endif
return false;
}
delete item;
return NULL;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mComment.mComment);
if(offset != tlvsize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_POSTED_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()() NOK" << std::endl;
}
#endif
return ok;
return item;
}
bool RsGxsPostedSerialiser::serialiseGxsPostedVoteItem(RsGxsPostedVoteItem* item, void* data, uint32_t *size)
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsPostedGroupItem::clear()
{
mGroup.mDescription.clear();
return;
}
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem()" << std::endl;
#endif
std::ostream & RsGxsPostedGroupItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsGxsPostedGroupItem", indent);
uint16_t int_Indent = indent + 2;
uint32_t tlvsize = sizeGxsPostedVoteItem(item);
uint32_t offset = 0;
printIndent(out, int_Indent);
out << "Description: " << mGroup.mDescription << std::endl;
if(*size < tlvsize){
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem()" << std::endl;
#endif
return false;
}
printRsItemEnd(out ,"RsGxsPostedGroupItem", indent);
return out;
}
*size = tlvsize;
bool ok = true;
uint32_t RsGxsPostedSerialiser::sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item)
{
RsPostedGroup& g = item->mGroup;
uint32_t s = 8; // header
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
s += GetTlvStringSize(g.mDescription);
/* skip the header */
offset += 8;
ok &= setRawUInt8(data, tlvsize, &offset, item->mVote.mDirection);
if(offset != tlvsize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef GXS_POSTED_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem() NOK" << std::endl;
}
#endif
return ok;
return s;
}
bool RsGxsPostedSerialiser::serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsPostedGroupItem(item);
uint32_t offset = 0;
uint32_t tlvsize = sizeGxsPostedGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize){
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
if(*size < tlvsize){
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
#endif
return false;
}
return false;
}
*size = tlvsize;
*size = tlvsize;
bool ok = true;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* skip the header */
offset += 8;
/* GxsPhotoAlbumItem */
/* PostedGroupItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mGroup.mDescription);
if(offset != tlvsize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() FAIL Size Error! " << std::endl;
if(offset != tlvsize)
{
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
ok = false;
}
#ifdef GXS_POSTED_SERIAL_DEBUG
if (!ok)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() NOK" << std::endl;
}
#ifdef POSTED_DEBUG
if (!ok)
{
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() NOK" << std::endl;
}
#endif
return ok;
return ok;
}
RsGxsPostedPostItem* RsGxsPostedSerialiser::deserialiseGxsPostedPostItem(void *data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_POSTED_POST_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPostedPostItem* item = new RsGxsPostedPostItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mLink);
ok &= GetTlvString(data, rssize, &offset, 1, item->mPost.mNotes);
if (offset != rssize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedPostItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsPostedCommentItem* RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem(void *data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPostedCommentItem* item = new RsGxsPostedCommentItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mComment.mComment);
if (offset != rssize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsPostedVoteItem* RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem(void *data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_POSTED_VOTE_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPostedVoteItem* item = new RsGxsPostedVoteItem();
/* skip the header */
offset += 8;
ok &= getRawUInt8(data, rssize, &offset, &(item->mVote.mDirection));
if (offset != rssize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedVoteItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
RsGxsPostedGroupItem* RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem(void *data, uint32_t *size)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem()" << std::endl;
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_POSTED_VOTE_ITEM != getRsItemSubType(rstype)))
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong type" << std::endl;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_POSTED_GRP_ITEM != getRsItemSubType(rstype)))
{
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong type" << std::endl;
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong size" << std::endl;
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPostedGroupItem* item = new RsGxsPostedGroupItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->mGroup.mDescription);
if (offset != rssize)
{
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL size mismatch" << std::endl;
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef POSTED_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() NOK" << std::endl;
#endif
return NULL; /* wrong type */
}
delete item;
return NULL;
}
if (*size < rssize) /* check size */
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsPostedGroupItem* item = new RsGxsPostedGroupItem();
/* skip the header */
offset += 8;
if (offset != rssize)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef GXS_POSTED_SERIAL_DEBUG
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
return item;
}
void RsGxsPostedPostItem::clear()
{
}
std::ostream & RsGxsPostedPostItem::print(std::ostream &out, uint16_t indent)
{
return out;
}
void RsGxsPostedVoteItem::clear()
{
return;
}
std::ostream & RsGxsPostedVoteItem::print(std::ostream &out, uint16_t indent)
{
return out;
}
void RsGxsPostedCommentItem::clear()
{
return;
}
std::ostream & RsGxsPostedCommentItem::print(std::ostream &out, uint16_t indent)
{
return out;
}
void RsGxsPostedGroupItem::clear()
{
return;
}
std::ostream & RsGxsPostedGroupItem::print(std::ostream &out, uint16_t indent)
{
return out;
}

View File

@ -5,98 +5,64 @@
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "serialiser/rsgxscommentitems.h"
#include "rsgxsitems.h"
#include "retroshare/rsposted.h"
const uint8_t RS_PKT_SUBTYPE_POSTED_GRP_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_POSTED_POST_ITEM = 0x03;
const uint8_t RS_PKT_SUBTYPE_POSTED_VOTE_ITEM = 0x04;
const uint8_t RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM = 0x05;
class RsGxsPostedPostItem : public RsGxsMsgItem
{
public:
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
RS_PKT_SUBTYPE_POSTED_POST_ITEM)
{return ; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPostedPost mPost;
};
class RsGxsPostedVoteItem : public RsGxsMsgItem
{
public:
RsGxsPostedVoteItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
RS_PKT_SUBTYPE_POSTED_VOTE_ITEM)
{return ;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPostedVote mVote;
};
class RsGxsPostedCommentItem : public RsGxsMsgItem
{
public:
RsGxsPostedCommentItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM)
{ return; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPostedComment mComment;
};
class RsGxsPostedGroupItem : public RsGxsGrpItem
{
public:
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_POSTED,
RS_PKT_SUBTYPE_POSTED_GRP_ITEM)
{ return; }
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_POSTED,
RS_PKT_SUBTYPE_POSTED_GRP_ITEM) { return; }
virtual ~RsGxsPostedGroupItem() { return; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPostedGroup mGroup;
RsPostedGroup mGroup;
};
class RsGxsPostedSerialiser : public RsSerialType
class RsGxsPostedPostItem : public RsGxsMsgItem
{
public:
RsGxsPostedPostItem() : RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_POSTED,
RS_PKT_SUBTYPE_POSTED_POST_ITEM) {return ; }
virtual ~RsGxsPostedPostItem() { return; }
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsPostedPost mPost;
};
class RsGxsPostedSerialiser : public RsGxsCommentSerialiser
{
public:
RsGxsPostedSerialiser()
: RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_PHOTO)
{ return; }
RsGxsPostedSerialiser()
:RsGxsCommentSerialiser(RS_SERVICE_GXSV1_TYPE_POSTED)
{ return; }
virtual ~RsGxsPostedSerialiser() { return; }
virtual ~RsGxsPostedSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise(RsItem *item, void *data, uint32_t *size);
RsItem* deserialise(void *data, uint32_t *size);
uint32_t size(RsItem *item);
bool serialise(RsItem *item, void *data, uint32_t *size);
RsItem* deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsPostedPostItem(RsGxsPostedPostItem* item);
bool serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size);
RsGxsPostedPostItem* deserialiseGxsPostedPostItem(void *data, uint32_t *size);
uint32_t sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item);
bool serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size);
RsGxsPostedGroupItem* deserialiseGxsPostedGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsPostedCommentItem(RsGxsPostedCommentItem* item);
bool serialiseGxsPostedCommentItem(RsGxsPostedCommentItem* item, void* data, uint32_t *size);
RsGxsPostedCommentItem* deserialiseGxsPostedCommentItem(void *data, uint32_t *size);
uint32_t sizeGxsPostedVoteItem(RsGxsPostedVoteItem* item);
bool serialiseGxsPostedVoteItem(RsGxsPostedVoteItem* item, void* data, uint32_t *size);
RsGxsPostedVoteItem* deserialiseGxsPostedVoteItem(void *data, uint32_t *size);
uint32_t sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item);
bool serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size);
RsGxsPostedGroupItem* deserialiseGxsPostedGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsPostedPostItem(RsGxsPostedPostItem* item);
bool serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size);
RsGxsPostedPostItem* deserialiseGxsPostedPostItem(void *data, uint32_t *size);
};

View File

@ -44,7 +44,12 @@
RsGxsChannels *rsGxsChannels = NULL;
#define CHANNEL_TESTEVENT_DUMMYDATA 0x0001
#define GXSCHANNELS_SUBSCRIBED_META 1
#define GXSCHANNELS_UNPROCESSED_SPECIFIC 2
#define GXSCHANNELS_UNPROCESSED_GENERIC 3
#define CHANNEL_PROCESS 0x0001
#define CHANNEL_TESTEVENT_DUMMYDATA 0x0002
#define DUMMYDATA_PERIOD 60 // long enough for some RsIdentities to be generated.
/********************************************************************************/
@ -52,17 +57,16 @@ RsGxsChannels *rsGxsChannels = NULL;
/********************************************************************************/
p3GxsChannels::p3GxsChannels(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs)
: RsGenExchange(gds, nes, new RsGxsChannelSerialiser(), RS_SERVICE_GXSV1_TYPE_CHANNELS, gixs, channelsAuthenPolicy()), RsGxsChannels(this)
: RsGenExchange(gds, nes, new RsGxsChannelSerialiser(), RS_SERVICE_GXSV1_TYPE_CHANNELS, gixs, channelsAuthenPolicy()), RsGxsChannels(this), GxsTokenQueue(this)
{
// For Dummy Msgs.
mGenActive = false;
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXSV1_TYPE_CHANNELS);
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
RsTickEvent::schedule_in(CHANNEL_PROCESS, 0);
RsTickEvent::schedule_in(CHANNEL_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
#endif
// Test Data disabled in repo.
//RsTickEvent::schedule_in(CHANNEL_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
}
@ -86,6 +90,44 @@ uint32_t p3GxsChannels::channelsAuthenPolicy()
void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
{
std::cerr << "p3GxsChannels::notifyChanges()";
std::cerr << std::endl;
/* iterate through and grab any new messages */
std::list<RsGxsGroupId> unprocessedGroups;
std::vector<RsGxsNotify *>::iterator it;
for(it = changes.begin(); it != changes.end(); it++)
{
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
if (msgChange)
{
std::cerr << "p3GxsChannels::notifyChanges() Found Message Change Notification";
std::cerr << std::endl;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
for(mit = msgChangeMap.begin(); mit != msgChangeMap.end(); mit++)
{
std::cerr << "p3GxsChannels::notifyChanges() Msgs for Group: " << mit->first;
std::cerr << std::endl;
if (autoDownloadEnabled(mit->first))
{
std::cerr << "p3GxsChannels::notifyChanges() AutoDownload for Group: " << mit->first;
std::cerr << std::endl;
/* problem is most of these will be comments and votes,
* should make it occasional - every 5mins / 10minutes TODO */
unprocessedGroups.push_back(mit->first);
}
}
}
}
request_SpecificSubscribedGroups(unprocessedGroups);
RsGxsIfaceHelper::receiveChanges(changes);
}
@ -98,6 +140,9 @@ void p3GxsChannels::service_tick()
bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannelGroup> &groups)
{
std::cerr << "p3GxsChannels::getGroupData()";
std::cerr << std::endl;
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
@ -108,13 +153,26 @@ bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannel
for(; vit != grpData.end(); vit++)
{
RsGxsChannelGroupItem* item = dynamic_cast<RsGxsChannelGroupItem*>(*vit);
RsGxsChannelGroup grp = item->mGroup;
item->mGroup.mMeta = item->meta;
grp.mMeta = item->mGroup.mMeta;
delete item;
groups.push_back(grp);
if (item)
{
RsGxsChannelGroup grp;
item->toChannelGroup(grp, true);
delete item;
groups.push_back(grp);
}
else
{
std::cerr << "p3GxsChannels::getGroupData() ERROR in decode";
std::cerr << std::endl;
}
}
}
else
{
std::cerr << "p3GxsChannels::getGroupData() ERROR in request";
std::cerr << std::endl;
}
return ok;
}
@ -125,6 +183,9 @@ bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannel
bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &msgs)
{
std::cerr << "p3GxsChannels::getPostData()";
std::cerr << std::endl;
GxsMsgDataMap msgData;
bool ok = RsGenExchange::getMsgData(token, msgData);
@ -144,8 +205,8 @@ bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelP
if(item)
{
RsGxsChannelPost msg = item->mMsg;
msg.mMeta = item->meta;
RsGxsChannelPost msg;
item->toChannelPost(msg, true);
msgs.push_back(msg);
delete item;
}
@ -157,6 +218,11 @@ bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelP
}
}
}
else
{
std::cerr << "p3GxsChannels::getPostData() ERROR in request";
std::cerr << std::endl;
}
return ok;
}
@ -164,6 +230,9 @@ bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelP
bool p3GxsChannels::getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost> &msgs)
{
std::cerr << "p3GxsChannels::getRelatedPosts()";
std::cerr << std::endl;
GxsMsgRelatedDataMap msgData;
bool ok = RsGenExchange::getMsgRelatedData(token, msgData);
@ -182,8 +251,8 @@ bool p3GxsChannels::getRelatedPosts(const uint32_t &token, std::vector<RsGxsChan
if(item)
{
RsGxsChannelPost msg = item->mMsg;
msg.mMeta = item->meta;
RsGxsChannelPost msg;
item->toChannelPost(msg, true);
msgs.push_back(msg);
delete item;
}
@ -195,11 +264,424 @@ bool p3GxsChannels::getRelatedPosts(const uint32_t &token, std::vector<RsGxsChan
}
}
}
else
{
std::cerr << "p3GxsChannels::getRelatedPosts() ERROR in request";
std::cerr << std::endl;
}
return ok;
}
/********************************************************************************************/
/********************************************************************************************/
void p3GxsChannels::setChannelAutoDownload(uint32_t&, const RsGxsGroupId&, bool)
{
std::cerr << "p3GxsChannels::setChannelAutoDownload() TODO";
std::cerr << std::endl;
return;
}
void p3GxsChannels::request_AllSubscribedGroups()
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::request_SubscribedGroups()";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
uint32_t token = 0;
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts);
GxsTokenQueue::queueRequest(token, GXSCHANNELS_SUBSCRIBED_META);
}
void p3GxsChannels::request_SpecificSubscribedGroups(const std::list<RsGxsGroupId> &groups)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::request_SpecificSubscribedGroups()";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
uint32_t token = 0;
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts, groups);
GxsTokenQueue::queueRequest(token, GXSCHANNELS_SUBSCRIBED_META);
}
void p3GxsChannels::load_SubscribedGroups(const uint32_t &token)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::load_SubscribedGroups()";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
std::list<RsGroupMetaData> groups;
std::list<RsGxsGroupId> groupList;
getGroupMeta(token, groups);
std::list<RsGroupMetaData>::iterator it;
for(it = groups.begin(); it != groups.end(); it++)
{
if (it->mSubscribeFlags &
(GXS_SERV::GROUP_SUBSCRIBE_ADMIN |
GXS_SERV::GROUP_SUBSCRIBE_PUBLISH |
GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED ))
{
std::cerr << "p3GxsChannels::load_SubscribedGroups() updating Subscribed Group: " << it->mGroupId;
std::cerr << std::endl;
updateSubscribedGroup(*it);
if (autoDownloadEnabled(it->mGroupId))
{
std::cerr << "p3GxsChannels::load_SubscribedGroups() remembering AutoDownload Group: " << it->mGroupId;
std::cerr << std::endl;
groupList.push_back(it->mGroupId);
}
}
else
{
std::cerr << "p3GxsChannels::load_SubscribedGroups() clearing unsubscribed Group: " << it->mGroupId;
std::cerr << std::endl;
clearUnsubscribedGroup(it->mGroupId);
}
}
/* Query for UNPROCESSED POSTS from checkGroupList */
request_GroupUnprocessedPosts(groupList);
}
void p3GxsChannels::updateSubscribedGroup(const RsGroupMetaData &group)
{
std::cerr << "p3GxsChannels::updateSubscribedGroup() id: " << group.mGroupId;
std::cerr << std::endl;
mSubscribedGroups[group.mGroupId] = group;
}
void p3GxsChannels::clearUnsubscribedGroup(const RsGxsGroupId &id)
{
std::cerr << "p3GxsChannels::clearUnsubscribedGroup() id: " << id;
std::cerr << std::endl;
//std::map<RsGxsGroupId, RsGrpMetaData> mSubscribedGroups;
std::map<RsGxsGroupId, RsGroupMetaData>::iterator it;
it = mSubscribedGroups.find(id);
if (it != mSubscribedGroups.end())
{
mSubscribedGroups.erase(it);
}
}
void p3GxsChannels::subscribeToGroup(const RsGxsGroupId &groupId, bool subscribe)
{
std::cerr << "p3GxsChannels::subscribedToGroup() id: " << groupId << " subscribe: " << subscribe;
std::cerr << std::endl;
std::list<RsGxsGroupId> groups;
groups.push_back(groupId);
// Call down to do the real work.
uint32_t token;
RsGenExchange::subscribeToGroup(token, groupId, subscribe);
// reload Group afterwards.
request_SpecificSubscribedGroups(groups);
}
void p3GxsChannels::request_SpecificUnprocessedPosts(std::list<std::pair<RsGxsGroupId, RsGxsMessageId> > &ids)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::request_SpecificUnprocessedPosts()";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token = 0;
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts);
GxsTokenQueue::queueRequest(token, GXSCHANNELS_UNPROCESSED_SPECIFIC);
}
void p3GxsChannels::request_GroupUnprocessedPosts(const std::list<RsGxsGroupId> &grouplist)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::request_GroupUnprocessedPosts()";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token = 0;
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts);
GxsTokenQueue::queueRequest(token, GXSCHANNELS_UNPROCESSED_GENERIC);
}
void p3GxsChannels::load_SpecificUnprocessedPosts(const uint32_t &token)
{
std::vector<RsGxsChannelPost> posts;
if (!getRelatedPosts(token, posts))
{
std::cerr << "p3GxsChannels::load_GroupUnprocessedPosts ERROR";
return;
}
std::vector<RsGxsChannelPost>::iterator it;
for(it = posts.begin(); it != posts.end(); it++)
{
/* autodownload the files */
handleUnprocessedPost(*it);
}
}
void p3GxsChannels::load_GroupUnprocessedPosts(const uint32_t &token)
{
std::vector<RsGxsChannelPost> posts;
if (!getPostData(token, posts))
{
std::cerr << "p3GxsChannels::load_GroupUnprocessedPosts ERROR";
return;
}
std::vector<RsGxsChannelPost>::iterator it;
for(it = posts.begin(); it != posts.end(); it++)
{
handleUnprocessedPost(*it);
}
}
void p3GxsChannels::handleUnprocessedPost(const RsGxsChannelPost &msg)
{
std::cerr << "p3GxsChannels::handleUnprocessedPost() GroupId: " << msg.mMeta.mGroupId << " MsgId: " << msg.mMeta.mMsgId;
std::cerr << std::endl;
/* check that autodownload is set */
if (autoDownloadEnabled(msg.mMeta.mGroupId))
{
std::cerr << "p3GxsChannels::handleUnprocessedPost() AutoDownload Enabled ... handling";
std::cerr << std::endl;
/* check the date is not too old */
/* start download */
std::cerr << "p3GxsChannels::handleUnprocessedPost() START DOWNLOAD (TODO)";
std::cerr << std::endl;
/* mark as processed */
uint32_t token;
RsGxsGrpMsgIdPair msgId(msg.mMeta.mGroupId, msg.mMeta.mMsgId);
setMessageProcessedStatus(token, msgId, true);
}
else
{
std::cerr << "p3GxsChannels::handleUnprocessedPost() AutoDownload Disabled ... skipping";
std::cerr << std::endl;
}
}
// Overloaded from GxsTokenQueue for Request callbacks.
void p3GxsChannels::handleResponse(uint32_t token, uint32_t req_type)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::handleResponse(" << token << "," << req_type << ")";
std::cerr << std::endl;
#endif // GXSCHANNELS_DEBUG
// stuff.
switch(req_type)
{
case GXSCHANNELS_SUBSCRIBED_META:
load_SubscribedGroups(token);
break;
case GXSCHANNELS_UNPROCESSED_SPECIFIC:
load_SpecificUnprocessedPosts(token);
break;
case GXSCHANNELS_UNPROCESSED_GENERIC:
load_SpecificUnprocessedPosts(token);
break;
default:
/* error */
std::cerr << "p3GxsService::handleResponse() Unknown Request Type: " << req_type;
std::cerr << std::endl;
break;
}
}
/********************************************************************************************/
/********************************************************************************************/
bool p3GxsChannels::autoDownloadEnabled(const RsGxsGroupId &id)
{
std::cerr << "p3GxsChannels::autoDownloadEnabled(" << id << ")";
std::cerr << std::endl;
std::map<RsGxsGroupId, RsGroupMetaData>::iterator it;
it = mSubscribedGroups.find(id);
if (it != mSubscribedGroups.end())
{
std::cerr << "p3GxsChannels::autoDownloadEnabled() No Entry";
std::cerr << std::endl;
return false;
}
/* extract from ServiceString */
SSGxsChannelGroup ss;
ss.load(it->second.mServiceString);
return ss.mAutoDownload;
}
#define RSGXSCHANNEL_MAX_SERVICE_STRING 128
bool SSGxsChannelGroup::load(const std::string &input)
{
char line[RSGXSCHANNEL_MAX_SERVICE_STRING];
int download_val;
mAutoDownload = false;
if (1 == sscanf(input.c_str(), "D:%d", &download_val))
{
if (download_val == 1)
{
mAutoDownload = true;
}
}
return true;
}
std::string SSGxsChannelGroup::save() const
{
std::string output;
if (mAutoDownload)
{
output += "D:1";
}
else
{
output += "D:0";
}
return output;
}
bool p3GxsChannels::setAutoDownload(const RsGxsGroupId &groupId, bool enabled)
{
std::cerr << "p3GxsChannels::setAutoDownload() id: " << groupId << " enabled: " << enabled;
std::cerr << std::endl;
std::map<RsGxsGroupId, RsGroupMetaData>::iterator it;
it = mSubscribedGroups.find(groupId);
if (it != mSubscribedGroups.end())
{
std::cerr << "p3GxsChannels::setAutoDownload() Missing Group";
std::cerr << std::endl;
return false;
}
/* extract from ServiceString */
SSGxsChannelGroup ss;
ss.load(it->second.mServiceString);
if (enabled == ss.mAutoDownload)
{
/* it should be okay! */
std::cerr << "p3GxsChannels::setAutoDownload() WARNING setting looks okay already";
std::cerr << std::endl;
}
/* we are just going to set it anyway. */
ss.mAutoDownload = enabled;
std::string serviceString = ss.save();
uint32_t token;
RsGenExchange::setGroupServiceString(token, groupId, serviceString);
/* now reload it */
std::list<RsGxsGroupId> groups;
groups.push_back(groupId);
request_SpecificSubscribedGroups(groups);
return true;
}
/********************************************************************************************/
/********************************************************************************************/
void p3GxsChannels::setMessageProcessedStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool processed)
{
std::cerr << "p3GxsChannels::setMessageProcessedStatus()";
std::cerr << std::endl;
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
uint32_t status = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
if (processed)
{
status = 0;
}
setMsgStatusFlags(token, msgId, status, mask);
}
void p3GxsChannels::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read)
{
std::cerr << "p3GxsChannels::setMessageReadStatus()";
std::cerr << std::endl;
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_UNREAD;
uint32_t status = GXS_SERV::GXS_MSG_STATUS_UNREAD;
if (read)
{
status = 0;
}
setMsgStatusFlags(token, msgId, status, mask);
}
/********************************************************************************************/
/********************************************************************************************/
bool p3GxsChannels::createGroup(uint32_t &token, RsGxsChannelGroup &group)
@ -207,8 +689,7 @@ bool p3GxsChannels::createGroup(uint32_t &token, RsGxsChannelGroup &group)
std::cerr << "p3GxsChannels::createGroup()" << std::endl;
RsGxsChannelGroupItem* grpItem = new RsGxsChannelGroupItem();
grpItem->mGroup = group;
grpItem->meta = group.mMeta;
grpItem->fromChannelGroup(group, true);
RsGenExchange::publishGroup(token, grpItem);
return true;
@ -221,30 +702,13 @@ bool p3GxsChannels::createPost(uint32_t &token, RsGxsChannelPost &msg)
std::cerr << std::endl;
RsGxsChannelPostItem* msgItem = new RsGxsChannelPostItem();
msgItem->mMsg = msg;
msgItem->meta = msg.mMeta;
msgItem->fromChannelPost(msg, true);
RsGenExchange::publishMsg(token, msgItem);
return true;
}
/********************************************************************************************/
/********************************************************************************************/
void p3GxsChannels::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read)
{
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_UNREAD | GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
uint32_t status = GXS_SERV::GXS_MSG_STATUS_UNREAD;
if (read)
{
status = 0;
}
setMsgStatusFlags(token, msgId, status, mask);
}
/********************************************************************************************/
/********************************************************************************************/
@ -451,7 +915,7 @@ bool p3GxsChannels::generateComment(uint32_t &token, const RsGxsGroupId &grpId,
rsIdentity->getOwnIds(ownIds);
uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32());
int i = 0;
uint32_t i = 0;
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++);
if (it != ownIds.end())
@ -497,6 +961,9 @@ void p3GxsChannels::handle_event(uint32_t event_type, const std::string &elabel)
generateDummyData();
break;
case CHANNEL_PROCESS:
request_AllSubscribedGroups();
default:
/* error */
std::cerr << "p3GxsChannels::handle_event() Unknown Event Type: " << event_type;

View File

@ -30,6 +30,7 @@
#include "retroshare/rsgxschannels.h"
#include "services/p3gxscommon.h"
#include "gxs/rsgenexchange.h"
#include "gxs/gxstokenqueue.h"
#include "util/rstickevent.h"
@ -40,7 +41,20 @@
*
*/
class SSGxsChannelGroup
{
public:
bool load(const std::string &input);
std::string save() const;
bool mAutoDownload;
};
class p3GxsChannels: public RsGenExchange, public RsGxsChannels,
public GxsTokenQueue,
public RsTickEvent /* only needed for testing - remove after */
{
public:
@ -65,7 +79,6 @@ virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &p
virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost> &posts);
//////////////////////////////////////////////////////////////////////////////
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
@ -76,7 +89,7 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
virtual bool createGroup(uint32_t &token, RsGxsChannelGroup &group);
virtual bool createPost(uint32_t &token, RsGxsChannelPost &post);
virtual void setChannelAutoDownload(uint32_t&, const RsGxsGroupId&, bool);
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
@ -104,10 +117,46 @@ virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, R
return acknowledgeMsg(token, msgId);
}
// Overloaded from RsGxsIface.
virtual void subscribeToGroup(const RsGxsGroupId &groupId, bool subscribe);
// Set Statuses.
virtual void setMessageProcessedStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool processed);
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
protected:
// Overloaded from GxsTokenQueue for Request callbacks.
virtual void handleResponse(uint32_t token, uint32_t req_type);
private:
static uint32_t channelsAuthenPolicy();
// Handle Processing.
void request_AllSubscribedGroups();
void request_SpecificSubscribedGroups(const std::list<RsGxsGroupId> &groups);
void load_SubscribedGroups(const uint32_t &token);
void request_SpecificUnprocessedPosts(std::list<std::pair<RsGxsGroupId, RsGxsMessageId> > &ids);
void load_SpecificUnprocessedPosts(const uint32_t &token);
void request_GroupUnprocessedPosts(const std::list<RsGxsGroupId> &grouplist);
void load_GroupUnprocessedPosts(const uint32_t &token);
void handleUnprocessedPost(const RsGxsChannelPost &msg);
// Local Cache of Subscribed Groups. and AutoDownload Flag.
void updateSubscribedGroup(const RsGroupMetaData &group);
void clearUnsubscribedGroup(const RsGxsGroupId &id);
bool autoDownloadEnabled(const RsGxsGroupId &id);
bool setAutoDownload(const RsGxsGroupId &groupId, bool enabled);
std::map<RsGxsGroupId, RsGroupMetaData> mSubscribedGroups;
// DUMMY DATA,
virtual bool generateDummyData();

View File

@ -28,6 +28,7 @@
#include "serialiser/rsgxscommentitems.h"
#include <stdio.h>
#include <stdlib.h>
RsGxsComment::RsGxsComment()
@ -37,6 +38,8 @@ RsGxsComment::RsGxsComment()
score = 0;
}
/********************************************************************************/
RsGxsImage::RsGxsImage()
{
mData = NULL;
@ -44,6 +47,64 @@ RsGxsImage::RsGxsImage()
}
RsGxsImage::~RsGxsImage()
{
clear();
}
void RsGxsImage::take(uint8_t *data, uint32_t size)
{
// Copies Pointer.
clear();
mData = data;
mSize = size;
}
// NB Must make sure that we always use malloc/free for this data.
uint8_t *RsGxsImage::allocate(uint32_t size)
{
return (uint8_t *) malloc(size);
}
void RsGxsImage::release(void *data)
{
free(data);
}
void RsGxsImage::copy(uint8_t *data, uint32_t size)
{
// Allocates and Copies.
clear();
if (data && size)
{
mData = allocate(size);
memcpy(mData, data, size);
mSize = size;
}
}
void RsGxsImage::clear()
{
// Frees.
if (mData)
{
release(mData);
}
mData = NULL;
mSize = 0;
}
void RsGxsImage::shallowClear()
{
// Clears Pointer.
mData = NULL;
mSize = 0;
}
/********************************************************************************/
RsGxsFile::RsGxsFile()
{
mSize = 0;

View File

@ -22,6 +22,8 @@
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef P3_GXSCOMMON_SERVICE_HEADER
#define P3_GXSCOMMON_SERVICE_HEADER
#include "retroshare/rsgxscommon.h"
#include "gxs/rsgenexchange.h"
@ -56,4 +58,5 @@ class p3GxsCommentService
};
#endif

View File

@ -56,11 +56,8 @@ p3GxsForums::p3GxsForums(RsGeneralDataService *gds, RsNetworkExchangeService *ne
// For Dummy Msgs.
mGenActive = false;
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
RsTickEvent::schedule_in(FORUM_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
#endif
// Test Data disabled in Repo.
//RsTickEvent::schedule_in(FORUM_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,175 +1,153 @@
#ifndef P3POSTED_H
#define P3POSTED_H
#include <map>
#include "retroshare/rsposted.h"
#include "gxs/rsgenexchange.h"
class GxsPostedPostRanking
{
public:
uint32_t pubToken;
uint32_t reqToken;
RsPosted::RankType rType;
RsGxsGroupId grpId;
RsPostedPostRanking rankingResult;
};
class GxsPostedCommentRanking
{
public:
uint32_t pubToken;
uint32_t reqToken;
RsPosted::RankType rType;
RsGxsGrpMsgIdPair msgId;
PostedRanking result;
};
class PostedScore {
public:
PostedScore() : upVotes(0), downVotes(0), commentCount(0), date(0) {}
uint32_t upVotes, downVotes;
uint32_t commentCount;
time_t date;
RsGxsMessageId msgId;
};
class p3Posted : public RsGenExchange, public RsPosted
{
public:
p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
protected:
/*!
* This confirms this class as an abstract one that \n
* should not be instantiated \n
* The deriving class should implement this function \n
* as it is called by the backend GXS system to \n
* update client of changes which should \n
* instigate client to retrieve new content from the system
* @param changes the changes that have occured to data held by this service
*/
void notifyChanges(std::vector<RsGxsNotify*>& changes) ;
void service_tick();
public:
void generateTopics();
/*!
* Exists solely for testing
*/
void generatePosts();
/*!
* Exists solely for testing
* Generates random votes to existing posts
* in the system
*/
void generateVotesAndComments();
public:
bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group);
bool getPost(const uint32_t &token, PostedPostResult& posts) ;
bool getComment(const uint32_t &token, PostedCommentResult& comments) ;
bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult &comments);
bool getPostRanking(const uint32_t &token, RsPostedPostRanking &ranking);
bool submitGroup(uint32_t &token, RsPostedGroup &group);
bool submitPost(uint32_t &token, RsPostedPost &post);
bool submitVote(uint32_t &token, RsPostedVote &vote);
bool submitComment(uint32_t &token, RsPostedComment &comment) ;
// Special Ranking Request.
bool requestPostRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId);
bool requestCommentRankings(uint32_t &token, const RankType &rType, const RsGxsGrpMsgIdPair &msgId);
bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t& downVotes, uint32_t& nComments) const;
private:
/* Functions for processing rankings */
void processRankings();
void processPostRanks();
void processCommentRanks();
void discardCalc(const uint32_t& token);
bool completePostedPostCalc(GxsPostedPostRanking* gpp);
void completePostedCommentRanking(GxsPostedCommentRanking* gpc);
bool storeScores(std::string& serviceString, uint32_t& upVotes, uint32_t downVotes, uint32_t nComments) const;
// for posts
void calcPostedPostRank(const std::vector<RsMsgMetaData>, PostedRanking& ranking, bool com(const PostedScore& i, const PostedScore &j)) const;
// for comments
void calcPostedCommentsRank(const std::map<RsGxsMessageId, std::vector<RsGxsMessageId> >& msgBranches, std::map<RsGxsMessageId, RsMsgMetaData>& msgMetas,
PostedRanking& ranking, bool com(const PostedScore& i, const PostedScore &j)) const;
/* Functions for maintaing vote counts in meta data */
/*!
* Update votes should only be called when a vote comes in
* Several phases to calculating votes.
* First get all messages for groups which you are subscribed
* Then for these messages get all the votes accorded to them
* Then do the calculation and update messages
* Also stores updates for messages which have new scores
*/
void updateVotes();
bool updateRequestGroups();
bool updateRequestMessages();
bool updateRequestVotesComments();
bool updateCompleteVotes();
bool updateCompleteComments();
/*!
* The aim of this is create notifications
* for the UI of changes to a post if their vote
* or comment count has changed
*/
bool updateComplete();
private:
// for calculating ranks
std::vector<GxsPostedPostRanking*> mPendingPostRanks;
std::vector<GxsPostedPostRanking*> mCompletionPostRanks;
std::map<uint32_t, RsPostedPostRanking> mCompletePostRanks;
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCommentRanks;
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCalculationCommentRanks;
// for maintaining vote counts in msg meta
uint32_t mUpdateRequestGroup, mUpdateRequestMessages, mUpdateRequestComments, mUpdateRequestVotes;
bool mPostUpdate;
uint32_t mUpdatePhase;
std::vector<RsGxsGrpMsgIdPair> mMsgsPendingUpdate;
time_t mLastUpdate;
GxsMsgMetaMap mMsgMetaUpdate;
std::map<RsGxsGrpMsgIdPair, PostedScore > mMsgCounts;
std::vector<uint32_t> mChangeTokens;
RsTokenService* mTokenService;
RsMutex mPostedMutex;
// for data generation
bool mGeneratingPosts, mGeneratingTopics,
mRequestPhase1, mRequestPhase2, mRequestPhase3, mGenerateVotesAndComments;
std::vector<uint32_t> mTokens;
uint32_t mToken;
std::list<RsGxsGroupId> mGrpIds;
};
#endif // P3POSTED_H
/*
* libretroshare/src/services: p3posted.h
*
* GxsChannel interface for RetroShare.
*
* Copyright 2012-2013 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".
*
*/
#ifndef P3_POSTED_SERVICE_HEADER
#define P3_POSTED_SERVICE_HEADER
#include "retroshare/rsposted.h"
#include "services/p3gxscommon.h"
#include "gxs/rsgenexchange.h"
#include "util/rstickevent.h"
#include <map>
#include <string>
/*
*
*/
class p3Posted: public RsGenExchange, public RsPosted,
public RsTickEvent /* only needed for testing - remove after */
{
public:
p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
virtual void service_tick();
protected:
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
// Overloaded from RsTickEvent.
virtual void handle_event(uint32_t event_type, const std::string &elabel);
public:
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups);
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts);
virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts);
//////////////////////////////////////////////////////////////////////////////
// SPECIAL REQUEST.
virtual bool requestPostRankings(uint32_t &token, const RankType &rType, uint32_t count, uint32_t page_no, const RsGxsGroupId &groupId);
virtual bool getPostRanking(const uint32_t &token, std::vector<RsPostedPost> &msgs);
//////////////////////////////////////////////////////////////////////////////
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
//virtual bool groupRestoreKeys(const std::string &groupId);
//virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
virtual bool createGroup(uint32_t &token, RsPostedGroup &group);
virtual bool createPost(uint32_t &token, RsPostedPost &post);
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsCommentData(token, msgs);
}
virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsRelatedComments(token, msgs);
}
virtual bool createComment(uint32_t &token, RsGxsComment &msg)
{
return mCommentService->createGxsComment(token, msg);
}
virtual bool createVote(uint32_t &token, RsGxsVote &msg)
{
return mCommentService->createGxsVote(token, msg);
}
virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
return acknowledgeMsg(token, msgId);
}
private:
static uint32_t postedAuthenPolicy();
// DUMMY DATA,
virtual bool generateDummyData();
std::string genRandomId();
void dummy_tick();
bool generatePost(uint32_t &token, const RsGxsGroupId &grpId);
bool generateComment(uint32_t &token, const RsGxsGroupId &grpId,
const RsGxsMessageId &parentId, const RsGxsMessageId &threadId);
bool generateGroup(uint32_t &token, std::string groupName);
class PostedDummyRef
{
public:
PostedDummyRef() { return; }
PostedDummyRef(const RsGxsGroupId &grpId, const RsGxsMessageId &threadId, const RsGxsMessageId &msgId)
:mGroupId(grpId), mThreadId(threadId), mMsgId(msgId) { return; }
RsGxsGroupId mGroupId;
RsGxsMessageId mThreadId;
RsGxsMessageId mMsgId;
};
uint32_t mGenToken;
bool mGenActive;
int mGenCount;
std::vector<PostedDummyRef> mGenRefs;
RsGxsMessageId mGenThreadId;
p3GxsCommentService *mCommentService;
};
#endif

View File

@ -35,11 +35,6 @@
RsWiki *rsWiki = NULL;
/**
* #define WIKI_GEN_DUMMY_DATA 1
**/
#define WIKI_GEN_DUMMY_DATA 1
#define WIKI_EVENT_DUMMYTICK 0x0001
#define WIKI_EVENT_DUMMYSTART 0x0002
@ -56,11 +51,8 @@ p3Wiki::p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs
mImprovActive = false;
mMarkdownActive = false;
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
#ifdef WIKI_GEN_DUMMY_DATA
RsTickEvent::schedule_in(WIKI_EVENT_DUMMYSTART, DUMMYSTART_PERIOD);
#endif
#endif
// TestData disabled in Repo.
//RsTickEvent::schedule_in(WIKI_EVENT_DUMMYSTART, DUMMYSTART_PERIOD);
}