mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-25 15:35:49 -04:00
Complete GxsChannels JSON API with blocking methods
RsGxsIfaceHelper::requestStatus expose it to JSON API Implemented RsGxsIfaceHelper::waitToken to wait for GXS operations RsItem::serial_process fix doxygen warning as it's a comment not documentation RsTypeSerializer add JSON conversion methods for double [de]serialization not implemented yet RsTypeSerializer_PRIVATE_{FROM,TO}_JSON_ARRAY fix doxygen warning as it's a comment not documentation make GxsChannels::ExtraFileHash a bit more reasonable jsonapi-generator fix unused variable warning if there is no input or output paramethers jsonapi-generator fix generation for inerithed jsonapi methods Convert to RsSerializable some Gxs structs for the JSON API
This commit is contained in:
parent
d731b665db
commit
15f39129f1
13 changed files with 316 additions and 82 deletions
|
@ -108,29 +108,83 @@ public:
|
|||
explicit RsGxsChannels(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsGxsChannels() {}
|
||||
|
||||
/* Specific Service Data */
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsChannelGroup> &groups) = 0;
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &posts, std::vector<RsGxsComment> &cmts) = 0;
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &posts) = 0;
|
||||
//Not currently used
|
||||
//virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost> &posts) = 0;
|
||||
|
||||
/* From RsGxsCommentService */
|
||||
//virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
|
||||
//virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
|
||||
//virtual bool createComment(uint32_t &token, RsGxsComment &comment) = 0;
|
||||
//virtual bool createVote(uint32_t &token, RsGxsVote &vote) = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
|
||||
|
||||
virtual bool setChannelAutoDownload(const RsGxsGroupId &groupId, bool enabled) = 0;
|
||||
virtual bool getChannelAutoDownload(const RsGxsGroupId &groupid, bool& enabled) = 0;
|
||||
|
||||
virtual bool setChannelDownloadDirectory(const RsGxsGroupId &groupId, const std::string& directory)=0;
|
||||
/**
|
||||
* @brief Get channels summaries list. Blocking API.
|
||||
* @jsonapi{development}
|
||||
* @param[out] channels list where to store the channels
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getChannelsSummaries(std::list<RsGroupMetaData>& channels) = 0;
|
||||
|
||||
/**
|
||||
* Get download directory for the given channel
|
||||
* @brief Get channels information (description, thumbnail...).
|
||||
* Blocking API.
|
||||
* @jsonapi{development}
|
||||
* @param[in] chanIds ids of the channels of which to get the informations
|
||||
* @param[out] channelsInfo storage for the channels informations
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getChannelsInfo(
|
||||
const std::list<RsGxsGroupId>& chanIds,
|
||||
std::vector<RsGxsChannelGroup>& channelsInfo ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get content of specified channels. Blocking API
|
||||
* @jsonapi{development}
|
||||
* @param[in] chanIds id of the channels of which the content is requested
|
||||
* @param[out] posts storage for the posts
|
||||
* @param[out] comments storage for the comments
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getChannelsContent(
|
||||
const std::list<RsGxsGroupId>& chanIds,
|
||||
std::vector<RsGxsChannelPost>& posts,
|
||||
std::vector<RsGxsComment>& comments ) = 0;
|
||||
|
||||
/* Specific Service Data
|
||||
* TODO: change the orrible const uint32_t &token to uint32_t token
|
||||
* TODO: create a new typedef for token so code is easier to read
|
||||
*/
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsChannelGroup> &groups) = 0;
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &posts, std::vector<RsGxsComment> &cmts) = 0;
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &posts) = 0;
|
||||
|
||||
|
||||
virtual void setMessageReadStatus(
|
||||
uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
|
||||
|
||||
/**
|
||||
* @brief Enable or disable auto-download for given channel
|
||||
* @jsonapi{development}
|
||||
* @param[in] groupId channel id
|
||||
* @param[in] enable true to enable, false to disable
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool setChannelAutoDownload(
|
||||
const RsGxsGroupId &groupId, bool enable) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get auto-download option value for given channel
|
||||
* @jsonapi{development}
|
||||
* @param[in] groupId channel id
|
||||
* @param[in] enabled storage for the auto-download option value
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual bool getChannelAutoDownload(
|
||||
const RsGxsGroupId &groupId, bool& enabled) = 0;
|
||||
|
||||
/**
|
||||
* @brief Set download directory for the given channel
|
||||
* @jsonapi{development}
|
||||
* @param[in] channelId id of the channel
|
||||
* @param[in] directory path
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool setChannelDownloadDirectory(
|
||||
const RsGxsGroupId& channelId, const std::string& directory) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get download directory for the given channel
|
||||
* @jsonapi{development}
|
||||
* @param[in] channelId id of the channel
|
||||
* @param[out] directory reference to string where to store the path
|
||||
|
@ -139,13 +193,16 @@ virtual bool setChannelDownloadDirectory(const RsGxsGroupId &groupId, const std:
|
|||
virtual bool getChannelDownloadDirectory( const RsGxsGroupId& channelId,
|
||||
std::string& directory ) = 0;
|
||||
|
||||
//virtual void setChannelAutoDownload(uint32_t& token, const RsGxsGroupId& groupId, bool autoDownload) = 0;
|
||||
|
||||
//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
|
||||
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
|
||||
|
||||
//virtual bool groupRestoreKeys(const std::string &groupId);
|
||||
virtual bool groupShareKeys(const RsGxsGroupId &groupId, std::set<RsPeerId>& peers)=0;
|
||||
/**
|
||||
* @brief Share channel publishing key
|
||||
* This can be used to authorize other peers to post on the channel
|
||||
* @jsonapi{development}
|
||||
* param[in] groupId Channel id
|
||||
* param[in] peers peers to which share the key
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool groupShareKeys(
|
||||
const RsGxsGroupId& groupId, const std::set<RsPeerId>& peers ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Request subscription to a group.
|
||||
|
@ -197,11 +254,22 @@ virtual bool setChannelDownloadDirectory(const RsGxsGroupId &groupId, const std:
|
|||
*/
|
||||
virtual bool updateGroup(uint32_t& token, RsGxsChannelGroup& group) = 0;
|
||||
|
||||
// File Interface
|
||||
virtual bool ExtraFileHash(const std::string &path, std::string filename) = 0;
|
||||
virtual bool ExtraFileRemove(const RsFileHash &hash) = 0;
|
||||
/**
|
||||
* @brief Share extra file
|
||||
* Can be used to share extra file attached to a channel post
|
||||
* @jsonapi{development}
|
||||
* @param[in] path file path
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool ExtraFileHash(const std::string& path) = 0;
|
||||
|
||||
/**
|
||||
* @brief Remove extra file from shared files
|
||||
* @jsonapi{development}
|
||||
* @param[in] hash hash of the file to remove
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool ExtraFileRemove(const RsFileHash& hash) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -94,17 +94,23 @@ namespace GXS_SERV {
|
|||
|
||||
|
||||
|
||||
class RsGxsVote
|
||||
struct RsGxsVote : RsSerializable
|
||||
{
|
||||
public:
|
||||
RsGxsVote();
|
||||
RsMsgMetaData mMeta;
|
||||
uint32_t mVoteType;
|
||||
|
||||
/// @see RsSerializable
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
{
|
||||
RS_SERIAL_PROCESS(mMeta);
|
||||
RS_SERIAL_PROCESS(mVoteType);
|
||||
}
|
||||
};
|
||||
|
||||
class RsGxsComment
|
||||
struct RsGxsComment : RsSerializable
|
||||
{
|
||||
public:
|
||||
RsGxsComment();
|
||||
RsMsgMetaData mMeta;
|
||||
std::string mComment;
|
||||
|
@ -119,6 +125,19 @@ class RsGxsComment
|
|||
// This is filled in if detailed Comment Data is called.
|
||||
std::list<RsGxsVote> mVotes;
|
||||
|
||||
/// @see RsSerializable
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
{
|
||||
RS_SERIAL_PROCESS(mMeta);
|
||||
RS_SERIAL_PROCESS(mComment);
|
||||
RS_SERIAL_PROCESS(mUpVotes);
|
||||
RS_SERIAL_PROCESS(mDownVotes);
|
||||
RS_SERIAL_PROCESS(mScore);
|
||||
RS_SERIAL_PROCESS(mOwnVote);
|
||||
RS_SERIAL_PROCESS(mVotes);
|
||||
}
|
||||
|
||||
const std::ostream &print(std::ostream &out, std::string indent = "", std::string varName = "") const {
|
||||
out << indent << varName << " of RsGxsComment Values ###################" << std::endl;
|
||||
mMeta.print(out, indent + " ", "mMeta");
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "retroshare/rsgxsiface.h"
|
||||
#include "retroshare/rsreputations.h"
|
||||
#include "rsgxsflags.h"
|
||||
|
@ -259,7 +262,10 @@ struct RsGxsIfaceHelper
|
|||
const std::vector<RsGxsGrpMsgIdPair>& msgIds )
|
||||
{ return mTokenService.requestMsgRelatedInfo(token, 0, opts, msgIds); }
|
||||
|
||||
/// @see RsTokenService::requestStatus
|
||||
/**
|
||||
* @jsonapi{development}
|
||||
* @param[in] token
|
||||
*/
|
||||
RsTokenService::GxsRequestStatus requestStatus(uint32_t token)
|
||||
{ return mTokenService.requestStatus(token); }
|
||||
|
||||
|
@ -282,6 +288,28 @@ struct RsGxsIfaceHelper
|
|||
*/
|
||||
RS_DEPRECATED RsTokenService* getTokenService() { return &mTokenService; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Block caller while request is being processed.
|
||||
* Useful for blocking API implementation.
|
||||
* @param[in] token token associated to the request caller is waiting for
|
||||
* @param[in] maxWait maximum waiting time in milliseconds
|
||||
*/
|
||||
RsTokenService::GxsRequestStatus waitToken(
|
||||
uint32_t token,
|
||||
std::chrono::milliseconds maxWait = std::chrono::milliseconds(500) )
|
||||
{
|
||||
auto timeout = std::chrono::steady_clock::now() + maxWait;
|
||||
auto st = requestStatus(token);
|
||||
while( !(st == RsTokenService::FAILED || st >= RsTokenService::COMPLETE)
|
||||
&& std::chrono::steady_clock::now() < timeout )
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2));
|
||||
st = requestStatus(token);
|
||||
}
|
||||
return st;
|
||||
}
|
||||
|
||||
private:
|
||||
RsGxsIface& mGxs;
|
||||
RsTokenService& mTokenService;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue