mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-13 03:22:34 -04:00
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:
parent
4b9087b60d
commit
123d4a630b
16 changed files with 1927 additions and 2179 deletions
|
@ -48,10 +48,9 @@ class RsGxsChannelGroup
|
||||||
public:
|
public:
|
||||||
RsGroupMetaData mMeta;
|
RsGroupMetaData mMeta;
|
||||||
std::string mDescription;
|
std::string mDescription;
|
||||||
|
RsGxsImage mImage;
|
||||||
|
|
||||||
//RsGxsImage mChanImage;
|
|
||||||
bool mAutoDownload;
|
bool mAutoDownload;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsGxsChannelPost
|
class RsGxsChannelPost
|
||||||
|
@ -60,15 +59,14 @@ class RsGxsChannelPost
|
||||||
RsMsgMetaData mMeta;
|
RsMsgMetaData mMeta;
|
||||||
std::string mMsg; // UTF8 encoded.
|
std::string mMsg; // UTF8 encoded.
|
||||||
|
|
||||||
//std::list<RsGxsFile> mFiles;
|
std::list<RsGxsFile> mFiles;
|
||||||
uint32_t mCount; // auto calced.
|
uint32_t mCount; // auto calced.
|
||||||
uint64_t mSize; // 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 RsGxsChannelGroup &group);
|
||||||
std::ostream &operator<<(std::ostream &out, const RsGxsChannelPost &post);
|
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 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 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 setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,23 @@ class RsGxsFile
|
||||||
class RsGxsImage
|
class RsGxsImage
|
||||||
{
|
{
|
||||||
public:
|
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;
|
uint8_t *mData;
|
||||||
uint32_t mSize;
|
uint32_t mSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define GXS_VOTE_DOWN 0x0001
|
#define GXS_VOTE_DOWN 0x0001
|
||||||
#define GXS_VOTE_UP 0x0002
|
#define GXS_VOTE_UP 0x0002
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#ifndef RSPOSTED_H
|
#ifndef RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H
|
||||||
#define RSPOSTED_H
|
#define RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* libretroshare/src/retroshare: rsposted.h
|
* libretroshare/src/retroshare: rsposted.h
|
||||||
|
@ -11,7 +10,7 @@
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* 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,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
@ -30,22 +29,26 @@
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#include "retroshare/rstokenservice.h"
|
#include "retroshare/rstokenservice.h"
|
||||||
#include "retroshare/rsgxsifacehelper.h"
|
#include "retroshare/rsgxsifacehelper.h"
|
||||||
|
#include "retroshare/rsgxscommon.h"
|
||||||
|
|
||||||
|
/* The Main Interface Class - for information about your Posted */
|
||||||
class RsPosted;
|
class RsPosted;
|
||||||
extern RsPosted *rsPosted;
|
extern RsPosted *rsPosted;
|
||||||
|
|
||||||
/* The Main Interface Class - for information about your Peers */
|
class RsPostedPost;
|
||||||
|
|
||||||
class RsPostedGroup
|
class RsPostedGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsGroupMetaData mMeta;
|
RsPostedGroup() { return; }
|
||||||
std::string mDescription;
|
|
||||||
RsPostedGroup() { return; }
|
RsGroupMetaData mMeta;
|
||||||
|
std::string mDescription;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//#define RSPOSTED_MSGTYPE_POST 0x0001
|
//#define RSPOSTED_MSGTYPE_POST 0x0001
|
||||||
//#define RSPOSTED_MSGTYPE_VOTE 0x0002
|
//#define RSPOSTED_MSGTYPE_VOTE 0x0002
|
||||||
//#define RSPOSTED_MSGTYPE_COMMENT 0x0004
|
//#define RSPOSTED_MSGTYPE_COMMENT 0x0004
|
||||||
|
@ -61,127 +64,99 @@ class RsPostedGroup
|
||||||
#define RSPOSTED_VIEWMODE_HOT 3
|
#define RSPOSTED_VIEWMODE_HOT 3
|
||||||
#define RSPOSTED_VIEWMODE_COMMENTS 4
|
#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 RsPostedGroup &group);
|
||||||
std::ostream &operator<<(std::ostream &out, const RsPostedPost &post);
|
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, public RsGxsCommentService
|
||||||
class RsPosted : public RsGxsIfaceHelper
|
|
||||||
{
|
{
|
||||||
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_POST;
|
||||||
static const uint32_t FLAG_MSGTYPE_VOTE;
|
static const uint32_t FLAG_MSGTYPE_MASK;
|
||||||
static const uint32_t FLAG_MSGTYPE_COMMENT;
|
|
||||||
static const uint32_t FLAG_MSGTYPE_MASK;
|
|
||||||
|
|
||||||
|
RsPosted(RsGxsIface* gxs) : RsGxsIfaceHelper(gxs) { return; }
|
||||||
RsPosted(RsGxsIface* gxs) : RsGxsIfaceHelper(gxs) { return; }
|
|
||||||
virtual ~RsPosted() { return; }
|
virtual ~RsPosted() { return; }
|
||||||
|
|
||||||
/* Specific Service Data */
|
/* Specific Service Data */
|
||||||
|
|
||||||
virtual bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group) = 0;
|
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups) = 0;
|
||||||
virtual bool getPost(const uint32_t &token, PostedPostResult &post) = 0;
|
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||||
virtual bool getComment(const uint32_t &token, PostedCommentResult &comment) = 0;
|
virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||||
virtual bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult& comments) = 0;
|
|
||||||
virtual bool getPostRanking(const uint32_t& token, RsPostedPostRanking& ranking) = 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.
|
virtual bool getPostRanking(const uint32_t &token, std::vector<RsPostedPost> &msgs) = 0;
|
||||||
/*!
|
|
||||||
* 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
|
//virtual bool getPostRanking(const uint32_t& token, std::vector<RsPostedPost> &ranking) = 0;
|
||||||
* @param token
|
|
||||||
* @param rType type of ranking to collect
|
/* From RsGxsCommentService */
|
||||||
* @param msgId message id of post as groupid-messageid pair
|
//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 requestCommentRankings(uint32_t &token, const RankType& rType, const RsGxsGrpMsgIdPair& msgId) = 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
|
class RsPostedPost
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsPostedPost()
|
RsPostedPost()
|
||||||
{
|
{
|
||||||
mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_POST;
|
mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_POST;
|
||||||
mMeta.mServiceString = " 0 0 0";
|
mUpVotes = 0;
|
||||||
return;
|
mDownVotes = 0;
|
||||||
}
|
mComments = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RsMsgMetaData mMeta;
|
RsMsgMetaData mMeta;
|
||||||
std::string mLink;
|
std::string mLink;
|
||||||
std::string mNotes;
|
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
|
#endif // RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H
|
||||||
{
|
|
||||||
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
|
|
||||||
|
|
|
@ -2370,11 +2370,11 @@ int RsServer::StartupRetroShare()
|
||||||
RsGeneralDataService* posted_ds = new RsDataService(currGxsDir + "/", "posted_db",
|
RsGeneralDataService* posted_ds = new RsDataService(currGxsDir + "/", "posted_db",
|
||||||
RS_SERVICE_GXSV1_TYPE_POSTED);
|
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
|
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
|
// create GXS photo service
|
||||||
RsGxsNetService* posted_ns = new RsGxsNetService(
|
RsGxsNetService* posted_ns = new RsGxsNetService(
|
||||||
|
|
|
@ -122,7 +122,8 @@ RsItem* RsGxsChannelSerialiser::deserialise(void* data, uint32_t* size)
|
||||||
|
|
||||||
void RsGxsChannelGroupItem::clear()
|
void RsGxsChannelGroupItem::clear()
|
||||||
{
|
{
|
||||||
mGroup.mDescription.clear();
|
mDescription.clear();
|
||||||
|
mImage.TlvClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& RsGxsChannelGroupItem::print(std::ostream& out, uint16_t indent)
|
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;
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
printIndent(out, int_Indent);
|
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);
|
printRsItemEnd(out ,"RsGxsChannelGroupItem", indent);
|
||||||
return out;
|
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)
|
uint32_t RsGxsChannelSerialiser::sizeGxsChannelGroupItem(RsGxsChannelGroupItem *item)
|
||||||
{
|
{
|
||||||
|
|
||||||
const RsGxsChannelGroup& group = item->mGroup;
|
|
||||||
uint32_t s = 8; // header
|
uint32_t s = 8; // header
|
||||||
|
|
||||||
s += GetTlvStringSize(group.mDescription);
|
s += GetTlvStringSize(item->mDescription);
|
||||||
|
s += item->mImage.TlvSize();
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +219,8 @@ bool RsGxsChannelSerialiser::serialiseGxsChannelGroupItem(RsGxsChannelGroupItem
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
|
||||||
/* GxsChannelGroupItem */
|
/* 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)
|
if(offset != tlvsize)
|
||||||
{
|
{
|
||||||
|
@ -237,7 +280,8 @@ RsGxsChannelGroupItem* RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem(vo
|
||||||
/* skip the header */
|
/* skip the header */
|
||||||
offset += 8;
|
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)
|
if (offset != rssize)
|
||||||
{
|
{
|
||||||
|
@ -270,7 +314,9 @@ RsGxsChannelGroupItem* RsGxsChannelSerialiser::deserialiseGxsChannelGroupItem(vo
|
||||||
|
|
||||||
void RsGxsChannelPostItem::clear()
|
void RsGxsChannelPostItem::clear()
|
||||||
{
|
{
|
||||||
mMsg.mMsg.clear();
|
mMsg.clear();
|
||||||
|
mAttachment.TlvClear();
|
||||||
|
mThumbnail.TlvClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& RsGxsChannelPostItem::print(std::ostream& out, uint16_t indent)
|
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;
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
printIndent(out, int_Indent);
|
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);
|
printRsItemEnd(out ,"RsGxsChannelPostItem", indent);
|
||||||
return out;
|
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)
|
uint32_t RsGxsChannelSerialiser::sizeGxsChannelPostItem(RsGxsChannelPostItem *item)
|
||||||
{
|
{
|
||||||
|
|
||||||
const RsGxsChannelPost& msg = item->mMsg;
|
|
||||||
uint32_t s = 8; // header
|
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;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -325,7 +441,9 @@ bool RsGxsChannelSerialiser::serialiseGxsChannelPostItem(RsGxsChannelPostItem *i
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
|
||||||
/* GxsChannelPostItem */
|
/* 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)
|
if(offset != tlvsize)
|
||||||
{
|
{
|
||||||
|
@ -385,7 +503,9 @@ RsGxsChannelPostItem* RsGxsChannelSerialiser::deserialiseGxsChannelPostItem(void
|
||||||
/* skip the header */
|
/* skip the header */
|
||||||
offset += 8;
|
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)
|
if (offset != rssize)
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
#include "rsgxsitems.h"
|
#include "rsgxsitems.h"
|
||||||
#include "retroshare/rsgxschannels.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_GROUP_ITEM = 0x02;
|
||||||
const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM = 0x03;
|
const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM = 0x03;
|
||||||
|
|
||||||
|
@ -52,8 +54,12 @@ public:
|
||||||
void clear();
|
void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
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
|
class RsGxsChannelPostItem : public RsGxsMsgItem
|
||||||
|
@ -66,7 +72,14 @@ public:
|
||||||
void clear();
|
void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
*
|
*
|
||||||
* RetroShare Serialiser.
|
* 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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* 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,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
@ -31,627 +31,363 @@
|
||||||
|
|
||||||
uint32_t RsGxsPostedSerialiser::size(RsItem *item)
|
uint32_t RsGxsPostedSerialiser::size(RsItem *item)
|
||||||
{
|
{
|
||||||
RsGxsPostedPostItem* ppItem = NULL;
|
#ifdef POSTED_DEBUG
|
||||||
RsGxsPostedCommentItem* pcItem = NULL;
|
std::cerr << "RsGxsPostedSerialiser::size()" << std::endl;
|
||||||
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;
|
|
||||||
#endif
|
#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)
|
bool RsGxsPostedSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||||
{
|
{
|
||||||
|
#ifdef POSTED_DEBUG
|
||||||
RsGxsPostedPostItem* ppItem = NULL;
|
std::cerr << "RsGxsPostedSerialiser::serialise()" << std::endl;
|
||||||
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;
|
|
||||||
#endif
|
#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)
|
RsItem* RsGxsPostedSerialiser::deserialise(void *data, uint32_t *size)
|
||||||
{
|
{
|
||||||
#ifdef RSSERIAL_DEBUG
|
#ifdef POSTED_DEBUG
|
||||||
std::cerr << "RsGxsPostedSerialiser::deserialise()" << std::endl;
|
std::cerr << "RsGxsPostedSerialiser::deserialise()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/* get the type and size */
|
/* get the type and size */
|
||||||
uint32_t rstype = getRsItemId(data);
|
uint32_t rstype = getRsItemId(data);
|
||||||
|
|
||||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)))
|
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)))
|
||||||
{
|
{
|
||||||
return NULL; /* wrong type */
|
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:
|
case RS_PKT_SUBTYPE_POSTED_GRP_ITEM:
|
||||||
return deserialiseGxsPostedCommentItem(data, size);
|
return deserialiseGxsPostedGroupItem(data, size);
|
||||||
case RS_PKT_SUBTYPE_POSTED_GRP_ITEM:
|
break;
|
||||||
return deserialiseGxsPostedGroupItem(data, size);
|
case RS_PKT_SUBTYPE_POSTED_POST_ITEM:
|
||||||
case RS_PKT_SUBTYPE_POSTED_POST_ITEM:
|
return deserialiseGxsPostedPostItem(data, size);
|
||||||
return deserialiseGxsPostedPostItem(data, size);
|
break;
|
||||||
case RS_PKT_SUBTYPE_POSTED_VOTE_ITEM:
|
default:
|
||||||
return deserialiseGxsPostedVoteItem(data, size);
|
return RsGxsCommentSerialiser::deserialise(data, size);
|
||||||
default:
|
break;
|
||||||
{
|
}
|
||||||
#ifdef RS_SSERIAL_DEBUG
|
return NULL;
|
||||||
std::cerr << "RsGxsPostedSerialiser::deserialise(): subtype could not be dealt with"
|
|
||||||
<< std::endl;
|
|
||||||
#endif
|
|
||||||
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)
|
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.mLink);
|
||||||
s += GetTlvStringSize(p.mNotes);
|
s += GetTlvStringSize(p.mNotes);
|
||||||
|
|
||||||
return s;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsGxsPostedSerialiser::serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size)
|
bool RsGxsPostedSerialiser::serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
#ifdef POSTED_DEBUG
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()" << std::endl;
|
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32_t tlvsize = sizeGxsPostedPostItem(item);
|
uint32_t tlvsize = sizeGxsPostedPostItem(item);
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
|
|
||||||
if(*size < tlvsize){
|
if(*size < tlvsize){
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() Size too small" << std::endl;
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem()()" << std::endl;
|
return false;
|
||||||
#endif
|
}
|
||||||
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 */
|
/* skip the header */
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
|
||||||
/* GxsPhotoAlbumItem */
|
/* RsPostedPost */
|
||||||
|
|
||||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mPost.mLink);
|
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.mNotes);
|
||||||
|
|
||||||
if(offset != tlvsize)
|
if(offset != tlvsize)
|
||||||
{
|
{
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() FAIL Size Error! " << std::endl;
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() FAIL Size Error! " << std::endl;
|
ok = false;
|
||||||
#endif
|
}
|
||||||
ok = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
#ifdef POSTED_DEBUG
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() NOK" << std::endl;
|
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedPostItem() NOK" << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
#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){
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedCommentItem()" << std::endl;
|
(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
|
#endif
|
||||||
return false;
|
delete item;
|
||||||
}
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
*size = tlvsize;
|
return item;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsGxsPostedSerialiser::serialiseGxsPostedVoteItem(RsGxsPostedVoteItem* item, void* data, uint32_t *size)
|
|
||||||
|
/*****************************************************************************************/
|
||||||
|
/*****************************************************************************************/
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
|
void RsGxsPostedGroupItem::clear()
|
||||||
{
|
{
|
||||||
|
mGroup.mDescription.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
std::ostream & RsGxsPostedGroupItem::print(std::ostream &out, uint16_t indent)
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem()" << std::endl;
|
{
|
||||||
#endif
|
printRsItemBase(out, "RsGxsPostedGroupItem", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
uint32_t tlvsize = sizeGxsPostedVoteItem(item);
|
printIndent(out, int_Indent);
|
||||||
uint32_t offset = 0;
|
out << "Description: " << mGroup.mDescription << std::endl;
|
||||||
|
|
||||||
if(*size < tlvsize){
|
printRsItemEnd(out ,"RsGxsPostedGroupItem", indent);
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
return out;
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedVoteItem()" << std::endl;
|
}
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
*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 */
|
return s;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsGxsPostedSerialiser::serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size)
|
bool RsGxsPostedSerialiser::serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
#ifdef POSTED_DEBUG
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
|
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32_t tlvsize = sizeGxsPostedGroupItem(item);
|
uint32_t tlvsize = sizeGxsPostedGroupItem(item);
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
|
|
||||||
if(*size < tlvsize){
|
if(*size < tlvsize){
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
#ifdef POSTED_DEBUG
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
|
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem()" << std::endl;
|
||||||
#endif
|
#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 */
|
/* skip the header */
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
|
||||||
/* GxsPhotoAlbumItem */
|
/* PostedGroupItem */
|
||||||
|
ok &= SetTlvString(data, tlvsize, &offset, 1, item->mGroup.mDescription);
|
||||||
|
|
||||||
if(offset != tlvsize)
|
|
||||||
{
|
if(offset != tlvsize)
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
{
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() FAIL Size Error! " << std::endl;
|
#ifdef POSTED_DEBUG
|
||||||
|
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() FAIL Size Error! " << std::endl;
|
||||||
#endif
|
#endif
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
#ifdef POSTED_DEBUG
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() NOK" << std::endl;
|
std::cerr << "RsGxsPostedSerialiser::serialiseGxsPostedGroupItem() NOK" << std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
#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)
|
RsGxsPostedGroupItem* RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem(void *data, uint32_t *size)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
#ifdef POSTED_DEBUG
|
||||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem()" << std::endl;
|
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/* get the type and size */
|
/* get the type and size */
|
||||||
uint32_t rstype = getRsItemId(data);
|
uint32_t rstype = getRsItemId(data);
|
||||||
uint32_t rssize = getRsItemSize(data);
|
uint32_t rssize = getRsItemSize(data);
|
||||||
|
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
|
|
||||||
|
|
||||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||||
(RS_PKT_SUBTYPE_POSTED_VOTE_ITEM != getRsItemSubType(rstype)))
|
(RS_PKT_SUBTYPE_POSTED_GRP_ITEM != getRsItemSubType(rstype)))
|
||||||
{
|
{
|
||||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedGroupItem() FAIL wrong type" << std::endl;
|
||||||
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
|
#endif
|
||||||
return NULL; /* wrong type */
|
delete item;
|
||||||
}
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (*size < rssize) /* check size */
|
return item;
|
||||||
{
|
|
||||||
#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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,98 +5,64 @@
|
||||||
#include "serialiser/rsserial.h"
|
#include "serialiser/rsserial.h"
|
||||||
#include "serialiser/rstlvtypes.h"
|
#include "serialiser/rstlvtypes.h"
|
||||||
|
|
||||||
|
#include "serialiser/rsgxscommentitems.h"
|
||||||
|
|
||||||
#include "rsgxsitems.h"
|
#include "rsgxsitems.h"
|
||||||
#include "retroshare/rsposted.h"
|
#include "retroshare/rsposted.h"
|
||||||
|
|
||||||
const uint8_t RS_PKT_SUBTYPE_POSTED_GRP_ITEM = 0x02;
|
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_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
|
class RsGxsPostedGroupItem : public RsGxsGrpItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
RsGxsPostedGroupItem() : RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_POSTED,
|
||||||
RS_PKT_SUBTYPE_POSTED_GRP_ITEM)
|
RS_PKT_SUBTYPE_POSTED_GRP_ITEM) { return; }
|
||||||
{ return; }
|
virtual ~RsGxsPostedGroupItem() { return; }
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
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:
|
public:
|
||||||
|
|
||||||
RsGxsPostedSerialiser()
|
RsGxsPostedSerialiser()
|
||||||
: RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_PHOTO)
|
:RsGxsCommentSerialiser(RS_SERVICE_GXSV1_TYPE_POSTED)
|
||||||
{ return; }
|
{ return; }
|
||||||
|
|
||||||
virtual ~RsGxsPostedSerialiser() { return; }
|
virtual ~RsGxsPostedSerialiser() { return; }
|
||||||
|
|
||||||
uint32_t size(RsItem *item);
|
uint32_t size(RsItem *item);
|
||||||
bool serialise(RsItem *item, void *data, uint32_t *size);
|
bool serialise(RsItem *item, void *data, uint32_t *size);
|
||||||
RsItem* deserialise(void *data, uint32_t *size);
|
RsItem* deserialise(void *data, uint32_t *size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
uint32_t sizeGxsPostedPostItem(RsGxsPostedPostItem* item);
|
uint32_t sizeGxsPostedGroupItem(RsGxsPostedGroupItem* item);
|
||||||
bool serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size);
|
bool serialiseGxsPostedGroupItem(RsGxsPostedGroupItem* item, void* data, uint32_t *size);
|
||||||
RsGxsPostedPostItem* deserialiseGxsPostedPostItem(void *data, uint32_t *size);
|
RsGxsPostedGroupItem* deserialiseGxsPostedGroupItem(void *data, uint32_t *size);
|
||||||
|
|
||||||
uint32_t sizeGxsPostedCommentItem(RsGxsPostedCommentItem* item);
|
uint32_t sizeGxsPostedPostItem(RsGxsPostedPostItem* item);
|
||||||
bool serialiseGxsPostedCommentItem(RsGxsPostedCommentItem* item, void* data, uint32_t *size);
|
bool serialiseGxsPostedPostItem(RsGxsPostedPostItem* item, void* data, uint32_t *size);
|
||||||
RsGxsPostedCommentItem* deserialiseGxsPostedCommentItem(void *data, uint32_t *size);
|
RsGxsPostedPostItem* deserialiseGxsPostedPostItem(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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,12 @@
|
||||||
RsGxsChannels *rsGxsChannels = NULL;
|
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.
|
#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)
|
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.
|
// For Dummy Msgs.
|
||||||
mGenActive = false;
|
mGenActive = false;
|
||||||
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXSV1_TYPE_CHANNELS);
|
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);
|
// Test Data disabled in repo.
|
||||||
|
//RsTickEvent::schedule_in(CHANNEL_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +90,44 @@ uint32_t p3GxsChannels::channelsAuthenPolicy()
|
||||||
|
|
||||||
void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
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);
|
RsGxsIfaceHelper::receiveChanges(changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +140,9 @@ void p3GxsChannels::service_tick()
|
||||||
|
|
||||||
bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannelGroup> &groups)
|
bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannelGroup> &groups)
|
||||||
{
|
{
|
||||||
|
std::cerr << "p3GxsChannels::getGroupData()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
std::vector<RsGxsGrpItem*> grpData;
|
std::vector<RsGxsGrpItem*> grpData;
|
||||||
bool ok = RsGenExchange::getGroupData(token, 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++)
|
for(; vit != grpData.end(); vit++)
|
||||||
{
|
{
|
||||||
RsGxsChannelGroupItem* item = dynamic_cast<RsGxsChannelGroupItem*>(*vit);
|
RsGxsChannelGroupItem* item = dynamic_cast<RsGxsChannelGroupItem*>(*vit);
|
||||||
RsGxsChannelGroup grp = item->mGroup;
|
if (item)
|
||||||
item->mGroup.mMeta = item->meta;
|
{
|
||||||
grp.mMeta = item->mGroup.mMeta;
|
RsGxsChannelGroup grp;
|
||||||
delete item;
|
item->toChannelGroup(grp, true);
|
||||||
groups.push_back(grp);
|
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;
|
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)
|
bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &msgs)
|
||||||
{
|
{
|
||||||
|
std::cerr << "p3GxsChannels::getPostData()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
GxsMsgDataMap msgData;
|
GxsMsgDataMap msgData;
|
||||||
bool ok = RsGenExchange::getMsgData(token, msgData);
|
bool ok = RsGenExchange::getMsgData(token, msgData);
|
||||||
|
|
||||||
|
@ -144,8 +205,8 @@ bool p3GxsChannels::getPostData(const uint32_t &token, std::vector<RsGxsChannelP
|
||||||
|
|
||||||
if(item)
|
if(item)
|
||||||
{
|
{
|
||||||
RsGxsChannelPost msg = item->mMsg;
|
RsGxsChannelPost msg;
|
||||||
msg.mMeta = item->meta;
|
item->toChannelPost(msg, true);
|
||||||
msgs.push_back(msg);
|
msgs.push_back(msg);
|
||||||
delete item;
|
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;
|
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)
|
bool p3GxsChannels::getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost> &msgs)
|
||||||
{
|
{
|
||||||
|
std::cerr << "p3GxsChannels::getRelatedPosts()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
GxsMsgRelatedDataMap msgData;
|
GxsMsgRelatedDataMap msgData;
|
||||||
bool ok = RsGenExchange::getMsgRelatedData(token, msgData);
|
bool ok = RsGenExchange::getMsgRelatedData(token, msgData);
|
||||||
|
|
||||||
|
@ -182,8 +251,8 @@ bool p3GxsChannels::getRelatedPosts(const uint32_t &token, std::vector<RsGxsChan
|
||||||
|
|
||||||
if(item)
|
if(item)
|
||||||
{
|
{
|
||||||
RsGxsChannelPost msg = item->mMsg;
|
RsGxsChannelPost msg;
|
||||||
msg.mMeta = item->meta;
|
item->toChannelPost(msg, true);
|
||||||
msgs.push_back(msg);
|
msgs.push_back(msg);
|
||||||
delete item;
|
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;
|
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)
|
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;
|
std::cerr << "p3GxsChannels::createGroup()" << std::endl;
|
||||||
|
|
||||||
RsGxsChannelGroupItem* grpItem = new RsGxsChannelGroupItem();
|
RsGxsChannelGroupItem* grpItem = new RsGxsChannelGroupItem();
|
||||||
grpItem->mGroup = group;
|
grpItem->fromChannelGroup(group, true);
|
||||||
grpItem->meta = group.mMeta;
|
|
||||||
|
|
||||||
RsGenExchange::publishGroup(token, grpItem);
|
RsGenExchange::publishGroup(token, grpItem);
|
||||||
return true;
|
return true;
|
||||||
|
@ -221,30 +702,13 @@ bool p3GxsChannels::createPost(uint32_t &token, RsGxsChannelPost &msg)
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
RsGxsChannelPostItem* msgItem = new RsGxsChannelPostItem();
|
RsGxsChannelPostItem* msgItem = new RsGxsChannelPostItem();
|
||||||
msgItem->mMsg = msg;
|
msgItem->fromChannelPost(msg, true);
|
||||||
msgItem->meta = msg.mMeta;
|
|
||||||
|
|
||||||
RsGenExchange::publishMsg(token, msgItem);
|
RsGenExchange::publishMsg(token, msgItem);
|
||||||
return true;
|
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);
|
rsIdentity->getOwnIds(ownIds);
|
||||||
|
|
||||||
uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32());
|
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++);
|
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++);
|
||||||
|
|
||||||
if (it != ownIds.end())
|
if (it != ownIds.end())
|
||||||
|
@ -497,6 +961,9 @@ void p3GxsChannels::handle_event(uint32_t event_type, const std::string &elabel)
|
||||||
generateDummyData();
|
generateDummyData();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CHANNEL_PROCESS:
|
||||||
|
request_AllSubscribedGroups();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* error */
|
/* error */
|
||||||
std::cerr << "p3GxsChannels::handle_event() Unknown Event Type: " << event_type;
|
std::cerr << "p3GxsChannels::handle_event() Unknown Event Type: " << event_type;
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "retroshare/rsgxschannels.h"
|
#include "retroshare/rsgxschannels.h"
|
||||||
#include "services/p3gxscommon.h"
|
#include "services/p3gxscommon.h"
|
||||||
#include "gxs/rsgenexchange.h"
|
#include "gxs/rsgenexchange.h"
|
||||||
|
#include "gxs/gxstokenqueue.h"
|
||||||
|
|
||||||
#include "util/rstickevent.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,
|
class p3GxsChannels: public RsGenExchange, public RsGxsChannels,
|
||||||
|
public GxsTokenQueue,
|
||||||
public RsTickEvent /* only needed for testing - remove after */
|
public RsTickEvent /* only needed for testing - remove after */
|
||||||
{
|
{
|
||||||
public:
|
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 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 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 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 createGroup(uint32_t &token, RsGxsChannelGroup &group);
|
||||||
virtual bool createPost(uint32_t &token, RsGxsChannelPost &post);
|
virtual bool createPost(uint32_t &token, RsGxsChannelPost &post);
|
||||||
|
|
||||||
|
virtual void setChannelAutoDownload(uint32_t&, const RsGxsGroupId&, bool);
|
||||||
|
|
||||||
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
|
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
|
||||||
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
|
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);
|
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:
|
private:
|
||||||
|
|
||||||
static uint32_t channelsAuthenPolicy();
|
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,
|
// DUMMY DATA,
|
||||||
virtual bool generateDummyData();
|
virtual bool generateDummyData();
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "serialiser/rsgxscommentitems.h"
|
#include "serialiser/rsgxscommentitems.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
RsGxsComment::RsGxsComment()
|
RsGxsComment::RsGxsComment()
|
||||||
|
@ -37,6 +38,8 @@ RsGxsComment::RsGxsComment()
|
||||||
score = 0;
|
score = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/********************************************************************************/
|
||||||
|
|
||||||
RsGxsImage::RsGxsImage()
|
RsGxsImage::RsGxsImage()
|
||||||
{
|
{
|
||||||
mData = NULL;
|
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()
|
RsGxsFile::RsGxsFile()
|
||||||
{
|
{
|
||||||
mSize = 0;
|
mSize = 0;
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
* 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 "retroshare/rsgxscommon.h"
|
||||||
#include "gxs/rsgenexchange.h"
|
#include "gxs/rsgenexchange.h"
|
||||||
|
@ -56,4 +58,5 @@ class p3GxsCommentService
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -56,11 +56,8 @@ p3GxsForums::p3GxsForums(RsGeneralDataService *gds, RsNetworkExchangeService *ne
|
||||||
// For Dummy Msgs.
|
// For Dummy Msgs.
|
||||||
mGenActive = false;
|
mGenActive = false;
|
||||||
|
|
||||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
// Test Data disabled in Repo.
|
||||||
|
//RsTickEvent::schedule_in(FORUM_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
|
||||||
RsTickEvent::schedule_in(FORUM_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,175 +1,153 @@
|
||||||
#ifndef P3POSTED_H
|
/*
|
||||||
#define P3POSTED_H
|
* libretroshare/src/services: p3posted.h
|
||||||
|
*
|
||||||
#include <map>
|
* GxsChannel interface for RetroShare.
|
||||||
|
*
|
||||||
#include "retroshare/rsposted.h"
|
* Copyright 2012-2013 by Robert Fernie.
|
||||||
#include "gxs/rsgenexchange.h"
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
class GxsPostedPostRanking
|
* License Version 2.1 as published by the Free Software Foundation.
|
||||||
{
|
*
|
||||||
public:
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
uint32_t pubToken;
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
uint32_t reqToken;
|
* Library General Public License for more details.
|
||||||
RsPosted::RankType rType;
|
*
|
||||||
RsGxsGroupId grpId;
|
* You should have received a copy of the GNU Library General Public
|
||||||
RsPostedPostRanking rankingResult;
|
* License along with this library; if not, write to the Free Software
|
||||||
};
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
class GxsPostedCommentRanking
|
*
|
||||||
{
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
public:
|
*
|
||||||
|
*/
|
||||||
uint32_t pubToken;
|
|
||||||
uint32_t reqToken;
|
#ifndef P3_POSTED_SERVICE_HEADER
|
||||||
RsPosted::RankType rType;
|
#define P3_POSTED_SERVICE_HEADER
|
||||||
RsGxsGrpMsgIdPair msgId;
|
|
||||||
PostedRanking result;
|
|
||||||
};
|
#include "retroshare/rsposted.h"
|
||||||
|
#include "services/p3gxscommon.h"
|
||||||
class PostedScore {
|
#include "gxs/rsgenexchange.h"
|
||||||
public:
|
|
||||||
|
#include "util/rstickevent.h"
|
||||||
PostedScore() : upVotes(0), downVotes(0), commentCount(0), date(0) {}
|
|
||||||
uint32_t upVotes, downVotes;
|
#include <map>
|
||||||
uint32_t commentCount;
|
#include <string>
|
||||||
time_t date;
|
|
||||||
RsGxsMessageId msgId;
|
/*
|
||||||
};
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class p3Posted: public RsGenExchange, public RsPosted,
|
||||||
class p3Posted : public RsGenExchange, public RsPosted
|
public RsTickEvent /* only needed for testing - remove after */
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
|
|
||||||
|
p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
|
||||||
protected:
|
|
||||||
|
virtual void service_tick();
|
||||||
/*!
|
|
||||||
* This confirms this class as an abstract one that \n
|
protected:
|
||||||
* should not be instantiated \n
|
|
||||||
* The deriving class should implement this function \n
|
|
||||||
* as it is called by the backend GXS system to \n
|
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||||
* update client of changes which should \n
|
|
||||||
* instigate client to retrieve new content from the system
|
// Overloaded from RsTickEvent.
|
||||||
* @param changes the changes that have occured to data held by this service
|
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||||
*/
|
|
||||||
void notifyChanges(std::vector<RsGxsNotify*>& changes) ;
|
public:
|
||||||
|
|
||||||
void service_tick();
|
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups);
|
||||||
|
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts);
|
||||||
public:
|
|
||||||
|
virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts);
|
||||||
void generateTopics();
|
|
||||||
/*!
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
* Exists solely for testing
|
|
||||||
*/
|
// SPECIAL REQUEST.
|
||||||
void generatePosts();
|
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);
|
||||||
* Exists solely for testing
|
|
||||||
* Generates random votes to existing posts
|
|
||||||
* in the system
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
*/
|
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
|
||||||
void generateVotesAndComments();
|
|
||||||
|
//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
|
||||||
public:
|
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
|
||||||
|
|
||||||
bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group);
|
//virtual bool groupRestoreKeys(const std::string &groupId);
|
||||||
bool getPost(const uint32_t &token, PostedPostResult& posts) ;
|
//virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
|
||||||
bool getComment(const uint32_t &token, PostedCommentResult& comments) ;
|
|
||||||
bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult &comments);
|
virtual bool createGroup(uint32_t &token, RsPostedGroup &group);
|
||||||
bool getPostRanking(const uint32_t &token, RsPostedPostRanking &ranking);
|
virtual bool createPost(uint32_t &token, RsPostedPost &post);
|
||||||
|
|
||||||
bool submitGroup(uint32_t &token, RsPostedGroup &group);
|
|
||||||
bool submitPost(uint32_t &token, RsPostedPost &post);
|
|
||||||
bool submitVote(uint32_t &token, RsPostedVote &vote);
|
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
|
||||||
bool submitComment(uint32_t &token, RsPostedComment &comment) ;
|
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
|
||||||
// Special Ranking Request.
|
{
|
||||||
bool requestPostRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId);
|
return mCommentService->getGxsCommentData(token, msgs);
|
||||||
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;
|
virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &msgs)
|
||||||
|
{
|
||||||
private:
|
return mCommentService->getGxsRelatedComments(token, msgs);
|
||||||
|
}
|
||||||
/* Functions for processing rankings */
|
|
||||||
|
virtual bool createComment(uint32_t &token, RsGxsComment &msg)
|
||||||
void processRankings();
|
{
|
||||||
void processPostRanks();
|
return mCommentService->createGxsComment(token, msg);
|
||||||
void processCommentRanks();
|
}
|
||||||
void discardCalc(const uint32_t& token);
|
|
||||||
bool completePostedPostCalc(GxsPostedPostRanking* gpp);
|
virtual bool createVote(uint32_t &token, RsGxsVote &msg)
|
||||||
void completePostedCommentRanking(GxsPostedCommentRanking* gpc);
|
{
|
||||||
|
return mCommentService->createGxsVote(token, msg);
|
||||||
bool storeScores(std::string& serviceString, uint32_t& upVotes, uint32_t downVotes, uint32_t nComments) const;
|
}
|
||||||
|
|
||||||
// for posts
|
virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
|
||||||
void calcPostedPostRank(const std::vector<RsMsgMetaData>, PostedRanking& ranking, bool com(const PostedScore& i, const PostedScore &j)) const;
|
{
|
||||||
|
return acknowledgeMsg(token, msgId);
|
||||||
// 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;
|
private:
|
||||||
|
|
||||||
/* Functions for maintaing vote counts in meta data */
|
static uint32_t postedAuthenPolicy();
|
||||||
|
|
||||||
/*!
|
|
||||||
* Update votes should only be called when a vote comes in
|
// DUMMY DATA,
|
||||||
* Several phases to calculating votes.
|
virtual bool generateDummyData();
|
||||||
* First get all messages for groups which you are subscribed
|
|
||||||
* Then for these messages get all the votes accorded to them
|
std::string genRandomId();
|
||||||
* Then do the calculation and update messages
|
|
||||||
* Also stores updates for messages which have new scores
|
void dummy_tick();
|
||||||
*/
|
|
||||||
void updateVotes();
|
bool generatePost(uint32_t &token, const RsGxsGroupId &grpId);
|
||||||
bool updateRequestGroups();
|
bool generateComment(uint32_t &token, const RsGxsGroupId &grpId,
|
||||||
bool updateRequestMessages();
|
const RsGxsMessageId &parentId, const RsGxsMessageId &threadId);
|
||||||
bool updateRequestVotesComments();
|
bool generateGroup(uint32_t &token, std::string groupName);
|
||||||
bool updateCompleteVotes();
|
|
||||||
bool updateCompleteComments();
|
class PostedDummyRef
|
||||||
|
{
|
||||||
/*!
|
public:
|
||||||
* The aim of this is create notifications
|
PostedDummyRef() { return; }
|
||||||
* for the UI of changes to a post if their vote
|
PostedDummyRef(const RsGxsGroupId &grpId, const RsGxsMessageId &threadId, const RsGxsMessageId &msgId)
|
||||||
* or comment count has changed
|
:mGroupId(grpId), mThreadId(threadId), mMsgId(msgId) { return; }
|
||||||
*/
|
|
||||||
bool updateComplete();
|
RsGxsGroupId mGroupId;
|
||||||
|
RsGxsMessageId mThreadId;
|
||||||
|
RsGxsMessageId mMsgId;
|
||||||
private:
|
};
|
||||||
|
|
||||||
// for calculating ranks
|
uint32_t mGenToken;
|
||||||
std::vector<GxsPostedPostRanking*> mPendingPostRanks;
|
bool mGenActive;
|
||||||
std::vector<GxsPostedPostRanking*> mCompletionPostRanks;
|
int mGenCount;
|
||||||
std::map<uint32_t, RsPostedPostRanking> mCompletePostRanks;
|
std::vector<PostedDummyRef> mGenRefs;
|
||||||
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCommentRanks;
|
RsGxsMessageId mGenThreadId;
|
||||||
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCalculationCommentRanks;
|
|
||||||
|
p3GxsCommentService *mCommentService;
|
||||||
// for maintaining vote counts in msg meta
|
};
|
||||||
uint32_t mUpdateRequestGroup, mUpdateRequestMessages, mUpdateRequestComments, mUpdateRequestVotes;
|
|
||||||
bool mPostUpdate;
|
#endif
|
||||||
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
|
|
||||||
|
|
|
@ -35,11 +35,6 @@
|
||||||
|
|
||||||
RsWiki *rsWiki = NULL;
|
RsWiki *rsWiki = NULL;
|
||||||
|
|
||||||
/**
|
|
||||||
* #define WIKI_GEN_DUMMY_DATA 1
|
|
||||||
**/
|
|
||||||
|
|
||||||
#define WIKI_GEN_DUMMY_DATA 1
|
|
||||||
|
|
||||||
#define WIKI_EVENT_DUMMYTICK 0x0001
|
#define WIKI_EVENT_DUMMYTICK 0x0001
|
||||||
#define WIKI_EVENT_DUMMYSTART 0x0002
|
#define WIKI_EVENT_DUMMYSTART 0x0002
|
||||||
|
@ -56,11 +51,8 @@ p3Wiki::p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs
|
||||||
mImprovActive = false;
|
mImprovActive = false;
|
||||||
mMarkdownActive = false;
|
mMarkdownActive = false;
|
||||||
|
|
||||||
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
|
// TestData disabled in Repo.
|
||||||
#ifdef WIKI_GEN_DUMMY_DATA
|
//RsTickEvent::schedule_in(WIKI_EVENT_DUMMYSTART, DUMMYSTART_PERIOD);
|
||||||
RsTickEvent::schedule_in(WIKI_EVENT_DUMMYSTART, DUMMYSTART_PERIOD);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue