mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-25 07:25:36 -04:00
Expose tokenservice methods trough GxsIfaceHelper
This commit is contained in:
parent
2f4b9b3e20
commit
d731b665db
17 changed files with 148 additions and 114 deletions
|
@ -105,8 +105,7 @@ class RsGxsChannels: public RsGxsIfaceHelper, public RsGxsCommentService
|
|||
{
|
||||
public:
|
||||
|
||||
explicit RsGxsChannels(RsGxsIface *gxs)
|
||||
:RsGxsIfaceHelper(gxs) {}
|
||||
explicit RsGxsChannels(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsGxsChannels() {}
|
||||
|
||||
/* Specific Service Data */
|
||||
|
|
|
@ -127,8 +127,8 @@ class RsGxsCircles: public RsGxsIfaceHelper
|
|||
{
|
||||
public:
|
||||
|
||||
RsGxsCircles(RsGxsIface *gxs) :RsGxsIfaceHelper(gxs) { return; }
|
||||
virtual ~RsGxsCircles() { return; }
|
||||
RsGxsCircles(RsGxsIface& gxs) :RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsGxsCircles() {}
|
||||
|
||||
/* External Interface (Cached stuff) */
|
||||
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details) = 0;
|
||||
|
|
|
@ -63,8 +63,7 @@ class RsGxsForums: public RsGxsIfaceHelper
|
|||
{
|
||||
public:
|
||||
|
||||
explicit RsGxsForums(RsGxsIface *gxs)
|
||||
:RsGxsIfaceHelper(gxs) {}
|
||||
explicit RsGxsForums(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsGxsForums() {}
|
||||
|
||||
/* Specific Service Data */
|
||||
|
|
|
@ -35,9 +35,8 @@
|
|||
/*!
|
||||
* Stores ids of changed gxs groups and messages. It is used to notify the GUI about changes.
|
||||
*/
|
||||
class RsGxsChanges
|
||||
struct RsGxsChanges
|
||||
{
|
||||
public:
|
||||
RsGxsChanges(): mService(0){}
|
||||
RsTokenService *mService;
|
||||
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > mMsgs;
|
||||
|
@ -49,13 +48,9 @@ public:
|
|||
/*!
|
||||
* All implementations must offer thread safety
|
||||
*/
|
||||
class RsGxsIface
|
||||
struct RsGxsIface
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~RsGxsIface(){};
|
||||
|
||||
public:
|
||||
virtual ~RsGxsIface() {}
|
||||
|
||||
/*!
|
||||
* Gxs services should call this for automatic handling of
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* RetroShare GXS. Convenience interface implementation
|
||||
*
|
||||
* Copyright 2012 by Christopher Evi-Parker
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
|
@ -29,26 +30,24 @@
|
|||
#include "retroshare/rsgxsiface.h"
|
||||
#include "retroshare/rsreputations.h"
|
||||
#include "rsgxsflags.h"
|
||||
#include "util/rsdeprecate.h"
|
||||
|
||||
/*!
|
||||
* The simple idea of this class is to implement the simple interface functions
|
||||
* of gen exchange.
|
||||
* This class provides convenience implementations of:
|
||||
* - Handle msg and group changes (client class must pass changes sent by RsGenExchange to it)
|
||||
* - subscription to groups
|
||||
* - retrieval of msgs and group ids and meta info
|
||||
* This class only make method of internal members visible tu upper level to
|
||||
* offer a more friendly API.
|
||||
* This is just a workaround to awkward GXS API design, do not take it as an
|
||||
* example for your coding.
|
||||
* To properly fix the API design many changes with the implied chain reactions
|
||||
* are necessary, so at this point this workaround seems acceptable.
|
||||
*/
|
||||
class RsGxsIfaceHelper
|
||||
struct RsGxsIfaceHelper
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param gxs handle to RsGenExchange instance of service (Usually the service class itself)
|
||||
*/
|
||||
RsGxsIfaceHelper(RsGxsIface* gxs)
|
||||
: mGxs(gxs)
|
||||
{}
|
||||
/*!
|
||||
* @param gxs handle to RsGenExchange instance of service (Usually the
|
||||
* service class itself)
|
||||
*/
|
||||
RsGxsIfaceHelper(RsGxsIface& gxs) :
|
||||
mGxs(gxs), mTokenService(*gxs.getTokenService()) {}
|
||||
|
||||
~RsGxsIfaceHelper(){}
|
||||
|
||||
|
@ -59,15 +58,7 @@ public:
|
|||
*/
|
||||
void receiveChanges(std::vector<RsGxsNotify *> &changes)
|
||||
{
|
||||
mGxs->receiveChanges(changes);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @return handle to token service for this GXS service
|
||||
*/
|
||||
RsTokenService* getTokenService()
|
||||
{
|
||||
return mGxs->getTokenService();
|
||||
mGxs.receiveChanges(changes);
|
||||
}
|
||||
|
||||
/* Generic Lists */
|
||||
|
@ -81,7 +72,7 @@ public:
|
|||
bool getGroupList(const uint32_t &token,
|
||||
std::list<RsGxsGroupId> &groupIds)
|
||||
{
|
||||
return mGxs->getGroupList(token, groupIds);
|
||||
return mGxs.getGroupList(token, groupIds);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -93,7 +84,7 @@ public:
|
|||
bool getMsgList(const uint32_t &token,
|
||||
GxsMsgIdResult& msgIds)
|
||||
{
|
||||
return mGxs->getMsgList(token, msgIds);
|
||||
return mGxs.getMsgList(token, msgIds);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -104,7 +95,7 @@ public:
|
|||
*/
|
||||
bool getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult &msgIds)
|
||||
{
|
||||
return mGxs->getMsgRelatedList(token, msgIds);
|
||||
return mGxs.getMsgRelatedList(token, msgIds);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -115,7 +106,7 @@ public:
|
|||
bool getGroupSummary(const uint32_t &token,
|
||||
std::list<RsGroupMetaData> &groupInfo)
|
||||
{
|
||||
return mGxs->getGroupMeta(token, groupInfo);
|
||||
return mGxs.getGroupMeta(token, groupInfo);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -126,7 +117,7 @@ public:
|
|||
bool getMsgSummary(const uint32_t &token,
|
||||
GxsMsgMetaMap &msgInfo)
|
||||
{
|
||||
return mGxs->getMsgMeta(token, msgInfo);
|
||||
return mGxs.getMsgMeta(token, msgInfo);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -136,7 +127,7 @@ public:
|
|||
*/
|
||||
bool getMsgRelatedSummary(const uint32_t &token, GxsMsgRelatedMetaMap &msgInfo)
|
||||
{
|
||||
return mGxs->getMsgRelatedMeta(token, msgInfo);
|
||||
return mGxs.getMsgRelatedMeta(token, msgInfo);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -147,7 +138,7 @@ public:
|
|||
*/
|
||||
bool subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe)
|
||||
{
|
||||
return mGxs->subscribeToGroup(token, grpId, subscribe);
|
||||
return mGxs.subscribeToGroup(token, grpId, subscribe);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -159,7 +150,7 @@ public:
|
|||
*/
|
||||
bool acknowledgeMsg(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
|
||||
{
|
||||
return mGxs->acknowledgeTokenMsg(token, msgId);
|
||||
return mGxs.acknowledgeTokenMsg(token, msgId);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -171,7 +162,7 @@ public:
|
|||
*/
|
||||
bool acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId)
|
||||
{
|
||||
return mGxs->acknowledgeTokenGrp(token, grpId);
|
||||
return mGxs.acknowledgeTokenGrp(token, grpId);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -182,7 +173,7 @@ public:
|
|||
*/
|
||||
bool getServiceStatistic(const uint32_t& token, GxsServiceStatistic& stats)
|
||||
{
|
||||
return mGxs->getServiceStatistic(token, stats);
|
||||
return mGxs.getServiceStatistic(token, stats);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -193,7 +184,7 @@ public:
|
|||
*/
|
||||
bool getGroupStatistic(const uint32_t& token, GxsGroupStatistic& stats)
|
||||
{
|
||||
return mGxs->getGroupStatistic(token, stats);
|
||||
return mGxs.getGroupStatistic(token, stats);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -206,7 +197,7 @@ public:
|
|||
*/
|
||||
void setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff)
|
||||
{
|
||||
return mGxs->setGroupReputationCutOff(token, grpId, CutOff);
|
||||
return mGxs.setGroupReputationCutOff(token, grpId, CutOff);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -214,36 +205,86 @@ public:
|
|||
*/
|
||||
uint32_t getDefaultStoragePeriod()
|
||||
{
|
||||
return mGxs->getDefaultStoragePeriod();
|
||||
return mGxs.getDefaultStoragePeriod();
|
||||
}
|
||||
uint32_t getStoragePeriod(const RsGxsGroupId& grpId)
|
||||
{
|
||||
return mGxs->getStoragePeriod(grpId);
|
||||
return mGxs.getStoragePeriod(grpId);
|
||||
}
|
||||
void setStoragePeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs)
|
||||
{
|
||||
mGxs->setStoragePeriod(grpId,age_in_secs);
|
||||
mGxs.setStoragePeriod(grpId,age_in_secs);
|
||||
}
|
||||
uint32_t getDefaultSyncPeriod()
|
||||
{
|
||||
return mGxs->getDefaultSyncPeriod();
|
||||
return mGxs.getDefaultSyncPeriod();
|
||||
}
|
||||
uint32_t getSyncPeriod(const RsGxsGroupId& grpId)
|
||||
{
|
||||
return mGxs->getSyncPeriod(grpId);
|
||||
return mGxs.getSyncPeriod(grpId);
|
||||
}
|
||||
void setSyncPeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs)
|
||||
{
|
||||
mGxs->setSyncPeriod(grpId,age_in_secs);
|
||||
mGxs.setSyncPeriod(grpId,age_in_secs);
|
||||
}
|
||||
|
||||
RsReputations::ReputationLevel minReputationForForwardingMessages(uint32_t group_sign_flags,uint32_t identity_flags)
|
||||
{
|
||||
return mGxs->minReputationForForwardingMessages(group_sign_flags,identity_flags);
|
||||
return mGxs.minReputationForForwardingMessages(group_sign_flags,identity_flags);
|
||||
}
|
||||
private:
|
||||
|
||||
RsGxsIface* mGxs;
|
||||
/// @see RsTokenService::requestGroupInfo
|
||||
bool requestGroupInfo( uint32_t& token, const RsTokReqOptions& opts,
|
||||
const std::list<RsGxsGroupId> &groupIds )
|
||||
{ return mTokenService.requestGroupInfo(token, 0, opts, groupIds); }
|
||||
|
||||
/// @see RsTokenService::requestGroupInfo
|
||||
bool requestGroupInfo(uint32_t& token, const RsTokReqOptions& opts)
|
||||
{ return mTokenService.requestGroupInfo(token, 0, opts); }
|
||||
|
||||
/// @see RsTokenService::requestMsgInfo
|
||||
bool requestMsgInfo( uint32_t& token,
|
||||
const RsTokReqOptions& opts, const GxsMsgReq& msgIds )
|
||||
{ return mTokenService.requestMsgInfo(token, 0, opts, msgIds); }
|
||||
|
||||
/// @see RsTokenService::requestMsgInfo
|
||||
bool requestMsgInfo(
|
||||
uint32_t& token, const RsTokReqOptions& opts,
|
||||
const std::list<RsGxsGroupId>& grpIds )
|
||||
{ return mTokenService.requestMsgInfo(token, 0, opts, grpIds); }
|
||||
|
||||
/// @see RsTokenService::requestMsgRelatedInfo
|
||||
bool requestMsgRelatedInfo(
|
||||
uint32_t& token, const RsTokReqOptions& opts,
|
||||
const std::vector<RsGxsGrpMsgIdPair>& msgIds )
|
||||
{ return mTokenService.requestMsgRelatedInfo(token, 0, opts, msgIds); }
|
||||
|
||||
/// @see RsTokenService::requestStatus
|
||||
RsTokenService::GxsRequestStatus requestStatus(uint32_t token)
|
||||
{ return mTokenService.requestStatus(token); }
|
||||
|
||||
/// @see RsTokenService::requestServiceStatistic
|
||||
void requestServiceStatistic(uint32_t& token)
|
||||
{ mTokenService.requestServiceStatistic(token); }
|
||||
|
||||
/// @see RsTokenService::requestGroupStatistic
|
||||
void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId)
|
||||
{ mTokenService.requestGroupStatistic(token, grpId); }
|
||||
|
||||
/// @see RsTokenService::cancelRequest
|
||||
bool cancelRequest(uint32_t token)
|
||||
{ return mTokenService.cancelRequest(token); }
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Token service methods are already exposed by this helper, so you should
|
||||
* not need to get token service pointer directly anymore.
|
||||
*/
|
||||
RS_DEPRECATED RsTokenService* getTokenService() { return &mTokenService; }
|
||||
|
||||
private:
|
||||
RsGxsIface& mGxs;
|
||||
RsTokenService& mTokenService;
|
||||
};
|
||||
|
||||
#endif // RSGXSIFACEIMPL_H
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
std::vector<RsGxsTransOutgoingRecord> outgoing_records;
|
||||
};
|
||||
|
||||
RsGxsTrans(RsGxsIface *gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
RsGxsTrans(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
|
||||
virtual ~RsGxsTrans() {}
|
||||
|
||||
|
|
|
@ -343,7 +343,7 @@ struct RsIdentityDetails : RsSerializable
|
|||
|
||||
struct RsIdentity : RsGxsIfaceHelper
|
||||
{
|
||||
explicit RsIdentity(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) {}
|
||||
explicit RsIdentity(RsGxsIface& gxs): RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsIdentity() {}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
|
|
@ -78,7 +78,7 @@ class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService
|
|||
//static const uint32_t FLAG_MSGTYPE_POST;
|
||||
//static const uint32_t FLAG_MSGTYPE_MASK;
|
||||
|
||||
explicit RsPosted(RsGxsIface* gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
explicit RsPosted(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsPosted() {}
|
||||
|
||||
/* Specific Service Data */
|
||||
|
|
|
@ -220,19 +220,14 @@ public:
|
|||
*/
|
||||
virtual void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId) = 0;
|
||||
|
||||
|
||||
/* Cancel Request */
|
||||
|
||||
/*!
|
||||
* If this function returns false, it may be that the request has completed
|
||||
* already. Useful for very expensive request. This is a blocking operation
|
||||
* @param token the token of the request to cancel
|
||||
* @return false if unusuccessful in cancelling request, true if successful
|
||||
*/
|
||||
virtual bool cancelRequest(const uint32_t &token) = 0;
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Cancel Request
|
||||
* If this function returns false, it may be that the request has completed
|
||||
* already. Useful for very expensive request.
|
||||
* @param token the token of the request to cancel
|
||||
* @return false if unusuccessful in cancelling request, true if successful
|
||||
*/
|
||||
virtual bool cancelRequest(const uint32_t &token) = 0;
|
||||
};
|
||||
|
||||
#endif // RSTOKENSERVICE_H
|
||||
|
|
|
@ -115,10 +115,10 @@ std::ostream &operator<<(std::ostream &out, const RsWikiComment &comment);
|
|||
|
||||
class RsWiki: public RsGxsIfaceHelper
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
RsWiki(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) { return; }
|
||||
virtual ~RsWiki() { return; }
|
||||
RsWiki(RsGxsIface& gxs): RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsWiki() {}
|
||||
|
||||
/* Specific Service Data */
|
||||
virtual bool getCollections(const uint32_t &token, std::vector<RsWikiCollection> &collections) = 0;
|
||||
|
|
|
@ -108,7 +108,7 @@ class RsWire: public RsGxsIfaceHelper
|
|||
{
|
||||
public:
|
||||
|
||||
explicit RsWire(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) {}
|
||||
explicit RsWire(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsWire() {}
|
||||
|
||||
/* Specific Service Data */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue