Expose tokenservice methods trough GxsIfaceHelper

This commit is contained in:
Gioacchino Mazzurco 2018-06-25 10:44:39 +02:00
parent 2f4b9b3e20
commit d731b665db
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
17 changed files with 148 additions and 114 deletions

View File

@ -85,7 +85,7 @@ struct MsgSizeCount
* @see GxsTransClient::receiveGxsTransMail(...),
* @see GxsTransClient::notifyGxsTransSendStatus(...).
*/
class p3GxsTrans : public RsGenExchange, public GxsTokenQueue, public p3Config, public RsGxsTrans
struct p3GxsTrans : RsGenExchange, GxsTokenQueue, p3Config, RsGxsTrans
{
public:
p3GxsTrans( RsGeneralDataService* gds, RsNetworkExchangeService* nes,
@ -94,17 +94,16 @@ public:
RS_SERVICE_TYPE_GXS_TRANS, &identities,
AuthenPolicy()),
GxsTokenQueue(this),
RsGxsTrans(this),
RsGxsTrans(static_cast<RsGxsIface&>(*this)),
// always check 30 secs after start)
mLastMsgCleanup(time(NULL) - MAX_DELAY_BETWEEN_CLEANUPS + 30),
mIdService(identities),
mServClientsMutex("p3GxsTrans client services map mutex"),
mOutgoingMutex("p3GxsTrans outgoing queue map mutex"),
mIngoingMutex("p3GxsTrans ingoing queue map mutex"),
mCleanupThread(nullptr),
mPerUserStatsMutex("p3GxsTrans user stats mutex"),
mDataMutex("p3GxsTrans data mutex")
{
mLastMsgCleanup = time(NULL) - MAX_DELAY_BETWEEN_CLEANUPS + 30; // always check 30 secs after start
mCleanupThread = NULL ;
}
mDataMutex("p3GxsTrans data mutex") {}
virtual ~p3GxsTrans();

View File

@ -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 */

View File

@ -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;

View File

@ -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 */

View File

@ -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

View File

@ -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)
* @param gxs handle to RsGenExchange instance of service (Usually the
* service class itself)
*/
RsGxsIfaceHelper(RsGxsIface* gxs)
: mGxs(gxs)
{}
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

View File

@ -91,7 +91,7 @@ public:
std::vector<RsGxsTransOutgoingRecord> outgoing_records;
};
RsGxsTrans(RsGxsIface *gxs) : RsGxsIfaceHelper(gxs) {}
RsGxsTrans(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
virtual ~RsGxsTrans() {}

View File

@ -343,7 +343,7 @@ struct RsIdentityDetails : RsSerializable
struct RsIdentity : RsGxsIfaceHelper
{
explicit RsIdentity(RsGxsIface *gxs): RsGxsIfaceHelper(gxs) {}
explicit RsIdentity(RsGxsIface& gxs): RsGxsIfaceHelper(gxs) {}
virtual ~RsIdentity() {}
/********************************************************************************************/

View File

@ -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 */

View File

@ -220,19 +220,14 @@ public:
*/
virtual void requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId) = 0;
/* Cancel Request */
/*!
* @brief 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
* 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

View File

@ -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;

View File

@ -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 */

View File

@ -68,8 +68,12 @@ RsGxsChannels *rsGxsChannels = NULL;
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3GxsChannels::p3GxsChannels(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs)
: RsGenExchange(gds, nes, new RsGxsChannelSerialiser(), RS_SERVICE_GXS_TYPE_CHANNELS, gixs, channelsAuthenPolicy()), RsGxsChannels(this), GxsTokenQueue(this)
p3GxsChannels::p3GxsChannels(
RsGeneralDataService *gds, RsNetworkExchangeService *nes,
RsGixs* gixs ) :
RsGenExchange( gds, nes, new RsGxsChannelSerialiser(),
RS_SERVICE_GXS_TYPE_CHANNELS, gixs, channelsAuthenPolicy() ),
RsGxsChannels(static_cast<RsGxsIface&>(*this)), GxsTokenQueue(this)
{
// For Dummy Msgs.
mGenActive = false;

View File

@ -111,16 +111,16 @@ RsGxsCircles *rsGxsCircles = NULL;
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3GxsCircles::p3GxsCircles(RsGeneralDataService *gds, RsNetworkExchangeService *nes,
p3IdService *identities, PgpAuxUtils *pgpUtils)
: RsGxsCircleExchange(gds, nes, new RsGxsCircleSerialiser(),
RS_SERVICE_GXS_TYPE_GXSCIRCLE, identities, circleAuthenPolicy()),
RsGxsCircles(this), GxsTokenQueue(this), RsTickEvent(),
mIdentities(identities),
mPgpUtils(pgpUtils),
p3GxsCircles::p3GxsCircles(
RsGeneralDataService *gds, RsNetworkExchangeService *nes,
p3IdService *identities, PgpAuxUtils *pgpUtils) :
RsGxsCircleExchange(
gds, nes, new RsGxsCircleSerialiser(), RS_SERVICE_GXS_TYPE_GXSCIRCLE,
identities, circleAuthenPolicy() ),
RsGxsCircles(static_cast<RsGxsIface&>(*this)), GxsTokenQueue(this),
RsTickEvent(), mIdentities(identities), mPgpUtils(pgpUtils),
mCircleMtx("p3GxsCircles"),
mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache")
mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache" )
{
// Kick off Cache Testing, + Others.
//RsTickEvent::schedule_in(CIRCLE_EVENT_CACHETEST, CACHETEST_PERIOD);

View File

@ -55,7 +55,8 @@ p3GxsForums::p3GxsForums( RsGeneralDataService *gds,
RsNetworkExchangeService *nes, RsGixs* gixs ) :
RsGenExchange( gds, nes, new RsGxsForumSerialiser(),
RS_SERVICE_GXS_TYPE_FORUMS, gixs, forumsAuthenPolicy()),
RsGxsForums(this), mGenToken(0), mGenActive(false), mGenCount(0)
RsGxsForums(static_cast<RsGxsIface&>(*this)), mGenToken(0),
mGenActive(false), mGenCount(0)
{
// Test Data disabled in Repo.
//RsTickEvent::schedule_in(FORUM_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);

View File

@ -156,12 +156,14 @@ RsIdentity *rsIdentity = NULL;
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *nes, PgpAuxUtils *pgpUtils)
: RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXS_TYPE_GXSID, idAuthenPolicy()),
RsIdentity(this), GxsTokenQueue(this), RsTickEvent(),
mKeyCache(GXSID_MAX_CACHE_SIZE, "GxsIdKeyCache"),
mIdMtx("p3IdService"), mNes(nes),
mPgpUtils(pgpUtils)
p3IdService::p3IdService(
RsGeneralDataService *gds, RsNetworkExchangeService *nes,
PgpAuxUtils *pgpUtils ) :
RsGxsIdExchange( gds, nes, new RsGxsIdSerialiser(),
RS_SERVICE_GXS_TYPE_GXSID, idAuthenPolicy() ),
RsIdentity(static_cast<RsGxsIface&>(*this)), GxsTokenQueue(this),
RsTickEvent(), mKeyCache(GXSID_MAX_CACHE_SIZE, "GxsIdKeyCache"),
mIdMtx("p3IdService"), mNes(nes), mPgpUtils(pgpUtils)
{
mBgSchedule_Mode = 0;
mBgSchedule_Active = false;

View File

@ -40,13 +40,12 @@ RsPosted *rsPosted = NULL;
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3Posted::p3Posted(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs)
:p3PostBase(gds, nes, gixs, new RsGxsPostedSerialiser(), RS_SERVICE_GXS_TYPE_POSTED),
RsPosted(this)
{
return;
}
p3Posted::p3Posted(
RsGeneralDataService *gds, RsNetworkExchangeService *nes,
RsGixs* gixs ) :
p3PostBase( gds, nes, gixs, new RsGxsPostedSerialiser(),
RS_SERVICE_GXS_TYPE_POSTED ),
RsPosted(static_cast<RsGxsIface&>(*this)) {}
const std::string GXS_POSTED_APP_NAME = "gxsposted";
const uint16_t GXS_POSTED_APP_MAJOR_VERSION = 1;