mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-29 09:18:45 -04:00
Refactored GXS interface to remove exposure to RS internals (i.e. only reference types, declaration in retroshare folder)
To achieve this I created second interface RsGxsIface which RsGxsGenExchange derives from, and RsGxsIfaceImpl (renamed RsGxsIfaceHelper) now takes an instance of this instead so these interfaces don't exposed the RsGenExchange and its underlying types. The other stuff is simply definitions and type aliases required for the front-ends to work (RsGroupMeta, RsGroupId, etc) and I've moved gxs flags also. This is a good idea as it seem much more clear what's available to a GXS service (apart from RsGenExchange public methods). git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6166 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5ccfed1cf4
commit
50c75de73c
46 changed files with 573 additions and 536 deletions
|
@ -1,77 +0,0 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/gxs: gxscoreserver.cc
|
||||
*
|
||||
* General Data service, interface for RetroShare.
|
||||
*
|
||||
* Copyright 2011-2011 by Evi-Parker Christopher
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "gxscoreserver.h"
|
||||
|
||||
GxsCoreServer::GxsCoreServer()
|
||||
: mGxsMutex("GxsCoreServer")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GxsCoreServer::~GxsCoreServer()
|
||||
{
|
||||
|
||||
std::set<RsGxsService*>::iterator sit;
|
||||
|
||||
for(sit = mGxsServices.begin(); sit != mGxsServices.end(); sit++)
|
||||
delete *sit;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GxsCoreServer::run()
|
||||
{
|
||||
std::set<RsGxsService*>::iterator sit;
|
||||
|
||||
double timeDelta = 0.02;
|
||||
|
||||
while(isRunning())
|
||||
{
|
||||
for(sit = mGxsServices.begin(); sit != mGxsServices.end(); sit++)
|
||||
(*sit)->tick();
|
||||
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void GxsCoreServer::addService(RsGxsService* service)
|
||||
{
|
||||
mGxsServices.insert(service);
|
||||
}
|
||||
|
||||
bool GxsCoreServer::removeService(RsGxsService* service)
|
||||
{
|
||||
return (mGxsServices.erase(service) > 0);
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
#ifndef GXSCORESERVER_H_
|
||||
#define GXSCORESERVER_H_
|
||||
|
||||
/*
|
||||
* libretroshare/src/gxs: gxscoreserver.h
|
||||
*
|
||||
* General Data service, interface for RetroShare.
|
||||
*
|
||||
* Copyright 2011-2011 by Evi-Parker Christopher
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
#include "gxs/rsgxs.h"
|
||||
|
||||
class GxsCoreServer : public RsThread
|
||||
{
|
||||
public:
|
||||
GxsCoreServer();
|
||||
~GxsCoreServer();
|
||||
|
||||
void run();
|
||||
|
||||
void addService(RsGxsService* service);
|
||||
bool removeService(RsGxsService* service);
|
||||
|
||||
private:
|
||||
|
||||
std::set<RsGxsService*> mGxsServices;
|
||||
RsMutex mGxsMutex;
|
||||
};
|
||||
|
||||
#endif /* GXSCORESERVER_H_ */
|
|
@ -35,7 +35,7 @@
|
|||
#include "rsgenexchange.h"
|
||||
#include "gxssecurity.h"
|
||||
#include "util/contentvalue.h"
|
||||
#include "rsgxsflags.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include "rsgixs.h"
|
||||
|
||||
|
||||
|
@ -676,6 +676,96 @@ bool RsGenExchange::checkMsgAuthenFlag(const PrivacyBitPos& pos, const uint8_t&
|
|||
}
|
||||
}
|
||||
|
||||
void RsGenExchange::receiveChanges(std::vector<RsGxsNotify*>& changes)
|
||||
{
|
||||
RsStackMutex stack(mGenMtx);
|
||||
|
||||
std::vector<RsGxsNotify*>::iterator vit = changes.begin();
|
||||
|
||||
for(; vit != changes.end(); vit++)
|
||||
{
|
||||
RsGxsNotify* n = *vit;
|
||||
RsGxsGroupChange* gc;
|
||||
RsGxsMsgChange* mc;
|
||||
if((mc = dynamic_cast<RsGxsMsgChange*>(n)) != NULL)
|
||||
{
|
||||
mMsgChange.push_back(mc);
|
||||
}
|
||||
else if((gc = dynamic_cast<RsGxsGroupChange*>(n)) != NULL)
|
||||
{
|
||||
mGroupChange.push_back(gc);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete n;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RsGenExchange::msgsChanged(std::map<RsGxsGroupId,
|
||||
std::vector<RsGxsMessageId> >& msgs)
|
||||
{
|
||||
RsStackMutex stack(mGenMtx);
|
||||
|
||||
while(!mMsgChange.empty())
|
||||
{
|
||||
RsGxsMsgChange* mc = mMsgChange.back();
|
||||
msgs = mc->msgChangeMap;
|
||||
mMsgChange.pop_back();
|
||||
delete mc;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGenExchange::groupsChanged(std::list<RsGxsGroupId>& grpIds)
|
||||
{
|
||||
RsStackMutex stack(mGenMtx);
|
||||
|
||||
while(!mGroupChange.empty())
|
||||
{
|
||||
RsGxsGroupChange* gc = mGroupChange.back();
|
||||
std::list<RsGxsGroupId>& gList = gc->mGrpIdList;
|
||||
std::list<RsGxsGroupId>::iterator lit = gList.begin();
|
||||
for(; lit != gList.end(); lit++)
|
||||
grpIds.push_back(*lit);
|
||||
|
||||
mGroupChange.pop_back();
|
||||
delete gc;
|
||||
}
|
||||
}
|
||||
|
||||
bool RsGenExchange::subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe)
|
||||
{
|
||||
if(subscribe)
|
||||
setGroupSubscribeFlags(token, grpId, GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED, GXS_SERV::GROUP_SUBSCRIBE_MASK);
|
||||
else
|
||||
setGroupSubscribeFlags(token, grpId, 0, GXS_SERV::GROUP_SUBSCRIBE_MASK);
|
||||
|
||||
return true;
|
||||
}
|
||||
bool RsGenExchange::updated(bool willCallGrpChanged, bool willCallMsgChanged)
|
||||
{
|
||||
bool changed = false;
|
||||
{
|
||||
RsStackMutex stack(mGenMtx);
|
||||
|
||||
changed = (!mGroupChange.empty() || !mMsgChange.empty());
|
||||
}
|
||||
|
||||
if(!willCallGrpChanged)
|
||||
{
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
groupsChanged(grpIds);
|
||||
}
|
||||
|
||||
if(!willCallMsgChanged)
|
||||
{
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
|
||||
msgsChanged(msgs);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool RsGenExchange::getGroupList(const uint32_t &token, std::list<RsGxsGroupId> &groupIds)
|
||||
{
|
||||
return mDataAccess->getGroupList(token, groupIds);
|
||||
|
@ -1698,7 +1788,7 @@ void RsGenExchange::processRecvdGroups()
|
|||
if(!grpIds.empty())
|
||||
{
|
||||
RsGxsGroupChange* c = new RsGxsGroupChange();
|
||||
c->grpIdList = grpIds;
|
||||
c->mGrpIdList = grpIds;
|
||||
mNotifications.push_back(c);
|
||||
mDataStore->storeGroup(grps);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "rsgxs.h"
|
||||
#include "rsgds.h"
|
||||
#include "rsnxs.h"
|
||||
#include "retroshare/rsgxsiface.h"
|
||||
#include "rsgxsdataaccess.h"
|
||||
#include "rsnxsobserver.h"
|
||||
#include "retroshare/rsgxsservice.h"
|
||||
|
@ -40,8 +41,7 @@
|
|||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > GxsMsgDataMap;
|
||||
typedef std::map<RsGxsGroupId, RsGxsGrpItem*> GxsGroupDataMap;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMsgItem*> > GxsMsgRelatedDataMap;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsMsgMetaData> > GxsMsgRelatedMetaMap;
|
||||
|
||||
|
||||
/*!
|
||||
* This should form the parent class to \n
|
||||
|
@ -65,7 +65,7 @@ typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsMsgMetaData> > GxsMsgRelatedMe
|
|||
|
||||
class RsGixs;
|
||||
|
||||
class RsGenExchange : public RsGxsService, public RsNxsObserver, public RsThread
|
||||
class RsGenExchange : public RsNxsObserver, public RsThread, public RsGxsIface
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -112,7 +112,6 @@ public:
|
|||
*/
|
||||
virtual void service_tick() = 0;
|
||||
|
||||
|
||||
/*!
|
||||
*
|
||||
* @return handle to token service handle for making
|
||||
|
@ -190,8 +189,51 @@ public:
|
|||
bool getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMap& msgMeta);
|
||||
|
||||
|
||||
/*!
|
||||
* Gxs services should call this for automatic handling of
|
||||
* changes, send
|
||||
* @param changes
|
||||
*/
|
||||
virtual void receiveChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
/*!
|
||||
* Checks to see if a change has been received for
|
||||
* for a message or group
|
||||
* @param willCallGrpChanged if this is set to true, group changed function will return list
|
||||
* groups that have changed, if false, the group changed list is cleared
|
||||
* @param willCallMsgChanged if this is set to true, msgChanged function will return map
|
||||
* messages that have changed, if false, the message changed map is cleared
|
||||
* @return true if a change has occured for msg or group
|
||||
* @see groupsChanged
|
||||
* @see msgsChanged
|
||||
*/
|
||||
bool updated(bool willCallGrpChanged = false, bool willCallMsgChanged = false);
|
||||
|
||||
/*!
|
||||
* The groups changed. \n
|
||||
* class can reimplement to use to tailor
|
||||
* the group actually set for ui notification.
|
||||
* If receivedChanges is not passed RsGxsNotify changes
|
||||
* this function does nothing
|
||||
* @param grpIds returns list of grpIds that have changed
|
||||
* @see updated
|
||||
*/
|
||||
void groupsChanged(std::list<RsGxsGroupId>& grpIds);
|
||||
|
||||
/*!
|
||||
* The msg changed. \n
|
||||
* class can reimplement to use to tailor
|
||||
* the msg actually set for ui notification.
|
||||
* If receivedChanges is not passed RsGxsNotify changes
|
||||
* this function does nothing
|
||||
* @param msgs returns map of message ids that have changed
|
||||
* @see updated
|
||||
*/
|
||||
void msgsChanged(std::map<RsGxsGroupId,
|
||||
std::vector<RsGxsMessageId> >& msgs);
|
||||
|
||||
|
||||
bool subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe);
|
||||
protected:
|
||||
|
||||
/*!
|
||||
|
@ -563,6 +605,8 @@ private:
|
|||
private:
|
||||
|
||||
std::vector<RsGxsNotify*> mChanges;
|
||||
std::vector<RsGxsGroupChange*> mGroupChange;
|
||||
std::vector<RsGxsMsgChange*> mMsgChange;
|
||||
};
|
||||
|
||||
#endif // RSGENEXCHANGE_H
|
||||
|
|
|
@ -36,25 +36,8 @@
|
|||
|
||||
/* data types used throughout Gxs from netservice to genexchange */
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgReq;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgIdResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgMetaData*> > GxsMsgMetaResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > MsgMetaResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMsgMetaData*> > MsgRelatedMetaResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMessageId> > MsgRelatedIdResult;
|
||||
|
||||
|
||||
|
||||
class RsGxsService
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsService(){}
|
||||
virtual ~RsGxsService(){}
|
||||
|
||||
virtual void tick() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // RSGXS_H
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
|
||||
typedef std::string RsGxsGroupId;
|
||||
typedef std::string RsGxsMessageId;
|
||||
typedef std::pair<RsGxsGroupId, RsGxsMessageId> RsGxsGrpMsgIdPair;
|
||||
|
||||
class RsGroupMetaData;
|
||||
class RsMsgMetaData;
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
#ifndef RSGXSFLAGS_H
|
||||
#define RSGXSFLAGS_H
|
||||
|
||||
#include "inttypes.h"
|
||||
|
||||
/**
|
||||
* The GXS_SERV namespace serves a single point of reference for definining grp and msg flags
|
||||
* Declared and defined here are:
|
||||
* - privacy flags which define the level of privacy that can be given \n
|
||||
* to a group
|
||||
* - authentication types which defined types of authentication needed for a given message to
|
||||
* confirm its authenticity
|
||||
* - subscription flags: This used only locally by the peer to subscription status to a \n
|
||||
* a group
|
||||
* -
|
||||
*/
|
||||
namespace GXS_SERV {
|
||||
|
||||
|
||||
|
||||
/** START privacy **/
|
||||
|
||||
static const uint32_t FLAG_PRIVACY_MASK = 0x0000000f;
|
||||
|
||||
// pub key encrypted
|
||||
static const uint32_t FLAG_PRIVACY_PRIVATE = 0x00000001;
|
||||
|
||||
// publish private key needed to publish
|
||||
static const uint32_t FLAG_PRIVACY_RESTRICTED = 0x00000002;
|
||||
|
||||
// anyone can publish, publish key pair not needed
|
||||
static const uint32_t FLAG_PRIVACY_PUBLIC = 0x00000004;
|
||||
|
||||
/** END privacy **/
|
||||
|
||||
/** START authentication **/
|
||||
|
||||
static const uint32_t FLAG_AUTHEN_MASK = 0x000000f0;
|
||||
|
||||
// identity
|
||||
static const uint32_t FLAG_AUTHEN_IDENTITY = 0x000000010;
|
||||
|
||||
// publish key
|
||||
static const uint32_t FLAG_AUTHEN_PUBLISH = 0x000000020;
|
||||
|
||||
// admin key
|
||||
static const uint32_t FLAG_AUTHEN_ADMIN = 0x00000040;
|
||||
|
||||
// pgp sign identity
|
||||
static const uint32_t FLAG_AUTHEN_PGP_IDENTITY = 0x00000080;
|
||||
|
||||
/** END authentication **/
|
||||
|
||||
/** START msg authentication flags **/
|
||||
|
||||
static const uint8_t MSG_AUTHEN_MASK = 0x0f;
|
||||
|
||||
static const uint8_t MSG_AUTHEN_ROOT_PUBLISH_SIGN = 0x01;
|
||||
|
||||
static const uint8_t MSG_AUTHEN_CHILD_PUBLISH_SIGN = 0x02;
|
||||
|
||||
static const uint8_t MSG_AUTHEN_ROOT_AUTHOR_SIGN = 0x04;
|
||||
|
||||
static const uint8_t MSG_AUTHEN_CHILD_AUTHOR_SIGN = 0x08;
|
||||
|
||||
/** END msg authentication flags **/
|
||||
|
||||
/** START group options flag **/
|
||||
|
||||
static const uint8_t GRP_OPTION_AUTHEN_AUTHOR_SIGN = 0x01;
|
||||
|
||||
/** END group options flag **/
|
||||
|
||||
/** START Subscription Flags. (LOCAL) **/
|
||||
|
||||
static const uint32_t GROUP_SUBSCRIBE_ADMIN = 0x01;
|
||||
|
||||
static const uint32_t GROUP_SUBSCRIBE_PUBLISH = 0x02;
|
||||
|
||||
static const uint32_t GROUP_SUBSCRIBE_SUBSCRIBED = 0x04;
|
||||
|
||||
static const uint32_t GROUP_SUBSCRIBE_NOT_SUBSCRIBED = 0x08;
|
||||
|
||||
static const uint32_t GROUP_SUBSCRIBE_MASK = 0x0000000f;
|
||||
|
||||
/** END Subscription Flags. (LOCAL) **/
|
||||
|
||||
/** START GXS Msg status flags **/
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_UNPROCESSED = 0x000000100;
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_UNREAD = 0x00000200;
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_READ = 0x00000400;
|
||||
|
||||
/** END GXS Msg status flags **/
|
||||
|
||||
/** START GXS Grp status flags **/
|
||||
|
||||
static const uint32_t GXS_GRP_STATUS_UNPROCESSED = 0x000000100;
|
||||
|
||||
static const uint32_t GXS_GRP_STATUS_UNREAD = 0x00000200;
|
||||
|
||||
/** END GXS Grp status flags **/
|
||||
|
||||
}
|
||||
|
||||
|
||||
// GENERIC GXS MACROS
|
||||
#define IS_MSG_NEW(status) (status & GXS_SERV::GXS_MSG_STATUS_UNPROCESSED)
|
||||
#define IS_MSG_UNREAD(status) (status & GXS_SERV::GXS_MSG_STATUS_UNREAD)
|
||||
#define IS_GROUP_ADMIN(subscribeFlags) (subscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
|
||||
#define IS_GROUP_SUBSCRIBED(subscribeFlags) (subscribeFlags & (GXS_SERV::GROUP_SUBSCRIBE_ADMIN | GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED))
|
||||
|
||||
|
||||
|
||||
#endif // RSGXSFLAGS_H
|
|
@ -1,185 +0,0 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/gxs/rsgxsifaceimpl.cc: rsgxsifaceimpl.cc
|
||||
*
|
||||
* RetroShare GXS.
|
||||
*
|
||||
* Copyright 2012 by Christopher Evi-Parker
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "rsgxsifaceimpl.h"
|
||||
#include "gxs/rsgxs.h"
|
||||
#include "gxs/rsgxsflags.h"
|
||||
|
||||
RsGxsIfaceImpl::RsGxsIfaceImpl(RsGenExchange *gxs)
|
||||
: mGxsIfaceMutex("RsGxsIfaceImpl"), mGxs(gxs)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RsGxsIfaceImpl::groupsChanged(std::list<RsGxsGroupId> &grpIds)
|
||||
{
|
||||
RsStackMutex stack(mGxsIfaceMutex);
|
||||
|
||||
while(!mGroupChange.empty())
|
||||
{
|
||||
RsGxsGroupChange* gc = mGroupChange.back();
|
||||
std::list<RsGxsGroupId>& gList = gc->grpIdList;
|
||||
std::list<RsGxsGroupId>::iterator lit = gList.begin();
|
||||
for(; lit != gList.end(); lit++)
|
||||
grpIds.push_back(*lit);
|
||||
|
||||
mGroupChange.pop_back();
|
||||
delete gc;
|
||||
}
|
||||
}
|
||||
|
||||
bool RsGxsIfaceImpl::updated(bool willCallGrpChanged, bool willCallMsgChanged)
|
||||
{
|
||||
bool changed = false;
|
||||
{
|
||||
RsStackMutex stack(mGxsIfaceMutex);
|
||||
|
||||
changed = (!mGroupChange.empty() || !mMsgChange.empty());
|
||||
}
|
||||
|
||||
if(!willCallGrpChanged)
|
||||
{
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
groupsChanged(grpIds);
|
||||
}
|
||||
|
||||
if(!willCallMsgChanged)
|
||||
{
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
|
||||
msgsChanged(msgs);
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
void RsGxsIfaceImpl::msgsChanged(std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs)
|
||||
{
|
||||
RsStackMutex stack(mGxsIfaceMutex);
|
||||
|
||||
while(!mMsgChange.empty())
|
||||
{
|
||||
RsGxsMsgChange* mc = mMsgChange.back();
|
||||
msgs = mc->msgChangeMap;
|
||||
mMsgChange.pop_back();
|
||||
delete mc;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsIfaceImpl::receiveChanges(std::vector<RsGxsNotify *> &changes)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mGxsIfaceMutex);
|
||||
|
||||
std::vector<RsGxsNotify*>::iterator vit = changes.begin();
|
||||
|
||||
for(; vit != changes.end(); vit++)
|
||||
{
|
||||
RsGxsNotify* n = *vit;
|
||||
RsGxsGroupChange* gc;
|
||||
RsGxsMsgChange* mc;
|
||||
if((mc = dynamic_cast<RsGxsMsgChange*>(n)) != NULL)
|
||||
{
|
||||
mMsgChange.push_back(mc);
|
||||
}
|
||||
else if((gc = dynamic_cast<RsGxsGroupChange*>(n)) != NULL)
|
||||
{
|
||||
mGroupChange.push_back(gc);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RsTokenService* RsGxsIfaceImpl::getTokenService()
|
||||
{
|
||||
return mGxs->getTokenService();
|
||||
}
|
||||
|
||||
bool RsGxsIfaceImpl::getGroupList(const uint32_t &token,
|
||||
std::list<RsGxsGroupId> &groupIds)
|
||||
{
|
||||
|
||||
return mGxs->getGroupList(token, groupIds);
|
||||
}
|
||||
|
||||
bool RsGxsIfaceImpl::getMsgList(const uint32_t &token,
|
||||
GxsMsgIdResult& msgIds)
|
||||
{
|
||||
|
||||
return mGxs->getMsgList(token, msgIds);
|
||||
}
|
||||
|
||||
bool RsGxsIfaceImpl::getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult &msgIds)
|
||||
{
|
||||
return mGxs->getMsgRelatedList(token, msgIds);
|
||||
}
|
||||
|
||||
/* Generic Summary */
|
||||
bool RsGxsIfaceImpl::getGroupSummary(const uint32_t &token,
|
||||
std::list<RsGroupMetaData> &groupInfo)
|
||||
{
|
||||
|
||||
return mGxs->getGroupMeta(token, groupInfo);
|
||||
}
|
||||
|
||||
bool RsGxsIfaceImpl::getMsgSummary(const uint32_t &token,
|
||||
GxsMsgMetaMap &msgInfo)
|
||||
{
|
||||
|
||||
return mGxs->getMsgMeta(token, msgInfo);
|
||||
}
|
||||
|
||||
bool RsGxsIfaceImpl::getMsgrelatedSummary(const uint32_t &token, GxsMsgRelatedMetaMap &msgInfo)
|
||||
{
|
||||
return mGxs->getMsgRelatedMeta(token, msgInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsGxsIfaceImpl::subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe)
|
||||
{
|
||||
if(subscribe)
|
||||
mGxs->setGroupSubscribeFlags(token, grpId, GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED, GXS_SERV::GROUP_SUBSCRIBE_MASK);
|
||||
else
|
||||
mGxs->setGroupSubscribeFlags(token, grpId, 0, GXS_SERV::GROUP_SUBSCRIBE_MASK);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RsGxsIfaceImpl::acknowledgeMsg(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
|
||||
{
|
||||
|
||||
return mGxs->acknowledgeTokenMsg(token, msgId);
|
||||
}
|
||||
|
||||
bool RsGxsIfaceImpl::acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId)
|
||||
{
|
||||
return mGxs->acknowledgeTokenGrp(token, grpId);
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
#ifndef RSGXSIFACEIMPL_H
|
||||
#define RSGXSIFACEIMPL_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/gxs/: rsgxsifaceimpl.h
|
||||
*
|
||||
* RetroShare GXS. Convenience interface implementation
|
||||
*
|
||||
* Copyright 2012 by Christopher Evi-Parker
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gxs/rsgenexchange.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
|
||||
*/
|
||||
class RsGxsIfaceImpl
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param gxs handle to RsGenExchange instance of service (Usually the service class itself)
|
||||
*/
|
||||
RsGxsIfaceImpl(RsGenExchange* gxs);
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* Gxs services should call this for automatic handling of
|
||||
* changes, send
|
||||
* @param changes
|
||||
*/
|
||||
void receiveChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Checks to see if a change has been received for
|
||||
* for a message or group
|
||||
* @param willCallGrpChanged if this is set to true, group changed function will return list
|
||||
* groups that have changed, if false, the group changed list is cleared
|
||||
* @param willCallMsgChanged if this is set to true, msgChanged function will return map
|
||||
* messages that have changed, if false, the message changed map is cleared
|
||||
* @return true if a change has occured for msg or group
|
||||
* @see groupsChanged
|
||||
* @see msgsChanged
|
||||
*/
|
||||
virtual bool updated(bool willCallGrpChanged = false, bool willCallMsgChanged = false);
|
||||
|
||||
/*!
|
||||
* The groups changed. \n
|
||||
* class can reimplement to use to tailor
|
||||
* the group actually set for ui notification.
|
||||
* If receivedChanges is not passed RsGxsNotify changes
|
||||
* this function does nothing
|
||||
* @param grpIds returns list of grpIds that have changed
|
||||
* @see updated
|
||||
*/
|
||||
virtual void groupsChanged(std::list<RsGxsGroupId>& grpIds);
|
||||
|
||||
/*!
|
||||
* The msg changed. \n
|
||||
* class can reimplement to use to tailor
|
||||
* the msg actually set for ui notification.
|
||||
* If receivedChanges is not passed RsGxsNotify changes
|
||||
* this function does nothing
|
||||
* @param msgs returns map of message ids that have changed
|
||||
* @see updated
|
||||
*/
|
||||
virtual void msgsChanged(std::map<RsGxsGroupId,
|
||||
std::vector<RsGxsMessageId> >& msgs);
|
||||
|
||||
/*!
|
||||
* @return handle to token service for this GXS service
|
||||
*/
|
||||
RsTokenService* getTokenService();
|
||||
|
||||
/* Generic Lists */
|
||||
|
||||
/*!
|
||||
* Retrieve list of group ids associated to a request token
|
||||
* @param token token to be redeemed for this request
|
||||
* @param groupIds the ids return for given request token
|
||||
* @return false if request token is invalid, check token status for error report
|
||||
*/
|
||||
bool getGroupList(const uint32_t &token,
|
||||
std::list<RsGxsGroupId> &groupIds);
|
||||
|
||||
/*!
|
||||
* Retrieves list of msg ids associated to a request token
|
||||
* @param token token to be redeemed for this request
|
||||
* @param msgIds the ids return for given request token
|
||||
* @return false if request token is invalid, check token status for error report
|
||||
*/
|
||||
bool getMsgList(const uint32_t &token,
|
||||
GxsMsgIdResult& msgIds);
|
||||
|
||||
/*!
|
||||
* Retrieves list of msg related ids associated to a request token
|
||||
* @param token token to be redeemed for this request
|
||||
* @param msgIds the ids return for given request token
|
||||
* @return false if request token is invalid, check token status for error report
|
||||
*/
|
||||
bool getMsgRelatedList(const uint32_t &token,
|
||||
MsgRelatedIdResult& msgIds);
|
||||
|
||||
/*!
|
||||
* @param token token to be redeemed for group summary request
|
||||
* @param groupInfo the ids returned for given request token
|
||||
* @return false if request token is invalid, check token status for error report
|
||||
*/
|
||||
bool getGroupSummary(const uint32_t &token,
|
||||
std::list<RsGroupMetaData> &groupInfo);
|
||||
|
||||
/*!
|
||||
* @param token token to be redeemed for message summary request
|
||||
* @param msgInfo the message metadata returned for given request token
|
||||
* @return false if request token is invalid, check token status for error report
|
||||
*/
|
||||
bool getMsgSummary(const uint32_t &token,
|
||||
GxsMsgMetaMap &msgInfo);
|
||||
|
||||
/*!
|
||||
* @param token token to be redeemed for message related summary request
|
||||
* @param msgInfo the message metadata returned for given request token
|
||||
* @return false if request token is invalid, check token status for error report
|
||||
*/
|
||||
bool getMsgrelatedSummary(const uint32_t &token,
|
||||
GxsMsgRelatedMetaMap &msgInfo);
|
||||
|
||||
/*!
|
||||
* subscribes to group, and returns token which can be used
|
||||
* to be acknowledged to get group Id
|
||||
* @param token token to redeem for acknowledgement
|
||||
* @param grpId the id of the group to subscribe to
|
||||
*/
|
||||
virtual bool subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe);
|
||||
|
||||
/*!
|
||||
* This allows the client service to acknowledge that their msgs has
|
||||
* been created/modified and retrieve the create/modified msg ids
|
||||
* @param token the token related to modification/create request
|
||||
* @param msgIds map of grpid->msgIds of message created/modified
|
||||
* @return true if token exists false otherwise
|
||||
*/
|
||||
bool acknowledgeMsg(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId);
|
||||
|
||||
/*!
|
||||
* This allows the client service to acknowledge that their grps has
|
||||
* been created/modified and retrieve the create/modified grp ids
|
||||
* @param token the token related to modification/create request
|
||||
* @param msgIds vector of ids of groups created/modified
|
||||
* @return true if token exists false otherwise
|
||||
*/
|
||||
bool acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
RsGenExchange* mGxs;
|
||||
|
||||
std::vector<RsGxsGroupChange*> mGroupChange;
|
||||
std::vector<RsGxsMsgChange*> mMsgChange;
|
||||
|
||||
RsMutex mGxsIfaceMutex;
|
||||
};
|
||||
|
||||
#endif // RSGXSIFACEIMPL_H
|
|
@ -28,7 +28,7 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "rsgxsnetservice.h"
|
||||
#include "rsgxsflags.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
|
||||
/**
|
||||
* #define NXS_NET_DEBUG 1
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include "serialiser/rsgxsitems.h"
|
||||
#include "gxs/rsgxs.h"
|
||||
//#include "gxs/rsgxs.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
#define GXS_REQUEST_TYPE_GROUP_DATA 0x00010000
|
||||
#define GXS_REQUEST_TYPE_GROUP_META 0x00020000
|
||||
|
@ -66,8 +66,6 @@
|
|||
#define RS_TOKREQ_ANSTYPE_ACK 0x0004
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* This class provides useful generic support for GXS style services.
|
||||
* I expect much of this will be incorporated into the base GXS.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue