mirror of
				https://github.com/RetroShare/RetroShare.git
				synced 2025-11-03 15:29:02 -05:00 
			
		
		
		
	cache stuff does not compile. just saving lots of coding i've done.
Completed most of the coding for first new cache service, need to fix compile errors and test. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5330 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
		
							parent
							
								
									b2c74a045f
								
							
						
					
					
						commit
						d50ecd145f
					
				
					 20 changed files with 775 additions and 263 deletions
				
			
		
							
								
								
									
										56
									
								
								libretroshare/src/gxs/gxscoreserver.cc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								libretroshare/src/gxs/gxscoreserver.cc
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,56 @@
 | 
			
		|||
/*
 | 
			
		||||
 * gxscoreserver.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: 24 Jul 2012
 | 
			
		||||
 *      Author: crispy
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "gxscoreserver.h"
 | 
			
		||||
 | 
			
		||||
GxsCoreServer::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.2;
 | 
			
		||||
 | 
			
		||||
	while(isRunning())
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
#ifndef WINDOWS_SYS
 | 
			
		||||
        usleep((int) (timeDelta * 1000000));
 | 
			
		||||
#else
 | 
			
		||||
        Sleep((int) (timeDelta * 1000));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
		for(sit = mGxsServices.begin(); sit != mGxsServices.end(); sit++)
 | 
			
		||||
				(*sit)->tick();
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void GxsCoreServer::addService(RsGxsService* service)
 | 
			
		||||
{
 | 
			
		||||
	mGxsServices.insert(service);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool GxsCoreServer::removeService(RsGxsService* service)
 | 
			
		||||
{
 | 
			
		||||
	return (mGxsServices.erase(service) > 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										30
									
								
								libretroshare/src/gxs/gxscoreserver.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								libretroshare/src/gxs/gxscoreserver.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,30 @@
 | 
			
		|||
/*
 | 
			
		||||
 * gxscoreserver.h
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: 24 Jul 2012
 | 
			
		||||
 *      Author: crispy
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef GXSCORESERVER_H_
 | 
			
		||||
#define GXSCORESERVER_H_
 | 
			
		||||
 | 
			
		||||
#include "util/rsthreads.h"
 | 
			
		||||
#include "gxs/rsgxs.h"
 | 
			
		||||
 | 
			
		||||
class GxsCoreServer : RsThread {
 | 
			
		||||
public:
 | 
			
		||||
	GxsCoreServer();
 | 
			
		||||
	~GxsCoreServer();
 | 
			
		||||
 | 
			
		||||
	void run();
 | 
			
		||||
 | 
			
		||||
	void addService(RsGxsService* service);
 | 
			
		||||
	bool removeService(RsGxsService* service);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
	std::set<RsGxsService*> mGxsServices;
 | 
			
		||||
	RsMutex mGxsMutex;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif /* GXSCORESERVER_H_ */
 | 
			
		||||
| 
						 | 
				
			
			@ -460,7 +460,7 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    // finish transaction
 | 
			
		||||
    return mDb->execSQL("COMMIT;");;
 | 
			
		||||
    return mDb->execSQL("COMMIT;");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -542,7 +542,7 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
 | 
			
		|||
    return mDb->execSQL("COMMIT;");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool cache){
 | 
			
		||||
int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool withMeta, bool cache){
 | 
			
		||||
 | 
			
		||||
	if(grp.empty()){
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -552,7 +552,7 @@ int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool
 | 
			
		|||
		{
 | 
			
		||||
			std::vector<RsNxsGrp*> grps;
 | 
			
		||||
 | 
			
		||||
			retrieveGroups(c, grps);
 | 
			
		||||
			retrieveGroups(c, grps, withMeta);
 | 
			
		||||
			std::vector<RsNxsGrp*>::iterator vit = grps.begin();
 | 
			
		||||
 | 
			
		||||
			for(; vit != grps.end(); vit++)
 | 
			
		||||
| 
						 | 
				
			
			@ -593,7 +593,7 @@ int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool
 | 
			
		|||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RsDataService::retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps){
 | 
			
		||||
void RsDataService::retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps, bool withMeta){
 | 
			
		||||
 | 
			
		||||
    if(c){
 | 
			
		||||
        bool valid = c->moveToFirst();
 | 
			
		||||
| 
						 | 
				
			
			@ -604,6 +604,12 @@ void RsDataService::retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps)
 | 
			
		|||
            // only add the latest grp info
 | 
			
		||||
            if(g)
 | 
			
		||||
            {
 | 
			
		||||
            	RsGxsGrpMetaData* meta;
 | 
			
		||||
 | 
			
		||||
            	if(withMeta)
 | 
			
		||||
            		meta = getGrpMeta(*c);
 | 
			
		||||
 | 
			
		||||
            	if(meta) g->metaData = meta;
 | 
			
		||||
                grps.push_back(g);
 | 
			
		||||
            }
 | 
			
		||||
            valid = c->moveToNext();
 | 
			
		||||
| 
						 | 
				
			
			@ -738,7 +744,7 @@ int RsDataService::resetDataStore()
 | 
			
		|||
 | 
			
		||||
    std::map<std::string, RsNxsGrp*> grps;
 | 
			
		||||
 | 
			
		||||
    retrieveNxsGrps(grps, false);
 | 
			
		||||
    retrieveNxsGrps(grps, false, false);
 | 
			
		||||
    std::map<std::string, RsNxsGrp*>::iterator mit
 | 
			
		||||
            = grps.begin();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,15 +2,15 @@
 | 
			
		|||
#define RSDATASERVICE_H
 | 
			
		||||
 | 
			
		||||
#include "gxs/rsgds.h"
 | 
			
		||||
 | 
			
		||||
#include "util/retrodb.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class RsDataService : public RsGeneralDataService
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    RsDataService(const std::string& serviceDir, const std::string& dbName, uint16_t serviceType, RsGxsSearchModule* mod = NULL);
 | 
			
		||||
    virtual ~RsDataService();
 | 
			
		||||
    virtual ~RsDataService() ;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     * Retrieves all msgs
 | 
			
		||||
| 
						 | 
				
			
			@ -25,10 +25,11 @@ public:
 | 
			
		|||
     * Retrieves groups, if empty, retrieves all grps, if map is not empty
 | 
			
		||||
     * only retrieve entries, if entry cannot be found, it is removed from map
 | 
			
		||||
     * @param grp retrieved groups
 | 
			
		||||
     * @param withMeta this initialise the metaData member of the nxsgroups retrieved
 | 
			
		||||
     * @param cache whether to store retrieval in mem for faster later retrieval
 | 
			
		||||
     * @return error code
 | 
			
		||||
     */
 | 
			
		||||
    int retrieveNxsGrps(std::map<std::string, RsNxsGrp*>& grp, bool cache);
 | 
			
		||||
    int retrieveNxsGrps(std::map<std::string, RsNxsGrp*>& grp, bool withMeta, bool cache);
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     * Retrieves meta data of all groups stored (most current versions only)
 | 
			
		||||
| 
						 | 
				
			
			@ -120,7 +121,7 @@ private:
 | 
			
		|||
	 * @param c cursor to result set
 | 
			
		||||
	 * @param msgs messages retrieved from cursor are stored here
 | 
			
		||||
	 */
 | 
			
		||||
	void retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& msgs);
 | 
			
		||||
	void retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps, bool withMeta = false);
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     * extracts a msg meta item from a cursor at its
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,10 +46,18 @@ public:
 | 
			
		|||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * This allows modification of local
 | 
			
		||||
 * meta data items of a message
 | 
			
		||||
 */
 | 
			
		||||
class MsgLocMetaData {
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * This allows modification of local
 | 
			
		||||
 * meta data items of a group
 | 
			
		||||
 */
 | 
			
		||||
class GrpLocMetaData {
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -99,10 +107,11 @@ public:
 | 
			
		|||
    /*!
 | 
			
		||||
     * Retrieves all groups stored
 | 
			
		||||
     * @param grp retrieved groups
 | 
			
		||||
     * @param withMeta this initialises the meta handles nxs grps
 | 
			
		||||
     * @param cache whether to store retrieval in mem for faster later retrieval
 | 
			
		||||
     * @return error code
 | 
			
		||||
     */
 | 
			
		||||
    virtual int retrieveNxsGrps(std::map<RsGxsGroupId, RsNxsGrp*>& grp, bool cache) = 0;
 | 
			
		||||
    virtual int retrieveNxsGrps(std::map<RsGxsGroupId, RsNxsGrp*>& grp, bool withMeta, bool cache) = 0;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     * Retrieves meta data of all groups stored (most current versions only)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,8 @@
 | 
			
		|||
#include "rsgenexchange.h"
 | 
			
		||||
 | 
			
		||||
RsGenExchange::RsGenExchange(RsGeneralDataService *gds,
 | 
			
		||||
                             RsNetworkExchangeService *ns, RsSerialType *serviceSerialiser)
 | 
			
		||||
: mReqMtx("GenExchange"), mDataStore(gds), mNetService(ns), mSerialiser(serviceSerialiser)
 | 
			
		||||
                             RsNetworkExchangeService *ns, RsSerialType *serviceSerialiser, uint16_t servType)
 | 
			
		||||
: mGenMtx("GenExchange"), mDataStore(gds), mNetService(ns), mSerialiser(serviceSerialiser), mServType(servType)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    mDataAccess = new RsGxsDataAccess(gds);
 | 
			
		||||
| 
						 | 
				
			
			@ -11,8 +11,7 @@ RsGenExchange::RsGenExchange(RsGeneralDataService *gds,
 | 
			
		|||
 | 
			
		||||
RsGenExchange::~RsGenExchange()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    // need to destruct in a certain order
 | 
			
		||||
    // need to destruct in a certain order (prob a bad thing!)
 | 
			
		||||
    delete mNetService;
 | 
			
		||||
 | 
			
		||||
    delete mDataAccess;
 | 
			
		||||
| 
						 | 
				
			
			@ -27,12 +26,18 @@ RsGenExchange::~RsGenExchange()
 | 
			
		|||
void RsGenExchange::tick()
 | 
			
		||||
{
 | 
			
		||||
	mDataAccess->processRequests();
 | 
			
		||||
 | 
			
		||||
	publishGrps();
 | 
			
		||||
 | 
			
		||||
	publishMsgs();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool RsGenExchange::getGroupList(const uint32_t &token, std::list<RsGxsGroupId> &groupIds)
 | 
			
		||||
{
 | 
			
		||||
	return mDataAccess->getGroupList(token, groupIds);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool RsGenExchange::getMsgList(const uint32_t &token,
 | 
			
		||||
| 
						 | 
				
			
			@ -45,9 +50,16 @@ bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaDat
 | 
			
		|||
{
 | 
			
		||||
	std::list<RsGxsGrpMetaData*> metaL;
 | 
			
		||||
	bool ok = mDataAccess->getGroupSummary(token, metaL);
 | 
			
		||||
	groupInfo = metaL;
 | 
			
		||||
 | 
			
		||||
	std::list<RsGroupMetaData*>::iterator cit = metaL;
 | 
			
		||||
	std::list<RsGxsGrpMetaData*>::iterator lit = metaL.begin();
 | 
			
		||||
 | 
			
		||||
	for(; lit != metaL.end(); lit++)
 | 
			
		||||
	{
 | 
			
		||||
		RsGroupMetaData m = *(*lit);
 | 
			
		||||
		groupInfo.push_back(m);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	std::list<RsGxsGrpMetaData*>::iterator cit = metaL;
 | 
			
		||||
	for(; cit != metaL.end(); cit++)
 | 
			
		||||
		delete *cit;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -92,7 +104,7 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem
 | 
			
		|||
	{
 | 
			
		||||
		for(; lit != nxsGrps.end(); lit++)
 | 
			
		||||
		{
 | 
			
		||||
			RsTlvBinaryData& data = *lit->grp;
 | 
			
		||||
			RsTlvBinaryData& data = (*lit)->grp;
 | 
			
		||||
			RsItem* item = mSerialiser->deserialise(data.bin_data, &data.bin_len);
 | 
			
		||||
			RsGxsGrpItem* gItem = dynamic_cast<RsGxsGrpItem*>(item);
 | 
			
		||||
			grpItem.push_back(gItem);
 | 
			
		||||
| 
						 | 
				
			
			@ -114,7 +126,7 @@ bool RsGenExchange::getMsgData(const uint32_t &token,
 | 
			
		|||
		for(; mit != msgResult.end(); mit++)
 | 
			
		||||
		{
 | 
			
		||||
			std::vector<RsGxsMsgItem*> gxsMsgItems;
 | 
			
		||||
			RsGxsGroupId& grpId = mit->first;
 | 
			
		||||
			const RsGxsGroupId& grpId = mit->first;
 | 
			
		||||
			std::vector<RsNxsMsg*>& nxsMsgsV = mit->second;
 | 
			
		||||
			std::vector<RsNxsMsg*>::iterator vit
 | 
			
		||||
			= nxsMsgsV.begin();
 | 
			
		||||
| 
						 | 
				
			
			@ -134,50 +146,6 @@ bool RsGenExchange::getMsgData(const uint32_t &token,
 | 
			
		|||
    return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RsGenExchange::operator =(std::list<RsGroupMetaData>& lMeta, std::list<RsGxsGrpMetaData*>& rGxsMeta)
 | 
			
		||||
{
 | 
			
		||||
	std::list<RsGxsGrpMetaData*>::const_iterator cit = rGxsMeta.begin();
 | 
			
		||||
 | 
			
		||||
	for(; cit != rGxsMeta.end(); cit++)
 | 
			
		||||
	{
 | 
			
		||||
		const RsGxsGrpMetaData*& gxm = *cit;
 | 
			
		||||
		RsGroupMetaData gm;
 | 
			
		||||
		gm.mAuthorId = gxm->mAuthorId;
 | 
			
		||||
		gm.mGroupFlags = gxm->mGroupFlags;
 | 
			
		||||
		gm.mGroupId = gxm->mGroupId;
 | 
			
		||||
		gm.mGroupStatus = gxm->mGroupStatus;
 | 
			
		||||
		gm.mLastPost = gxm->mLastPost;
 | 
			
		||||
		gm.mMsgCount = gxm->mMsgCount;
 | 
			
		||||
		gm.mPop = gxm->mPop;
 | 
			
		||||
		gm.mPublishTs = gxm->mPublishTs;
 | 
			
		||||
		gm.mSubscribeFlags = gxm->mSubscribeFlags;
 | 
			
		||||
		gm.mGroupName = gxm->mGroupName;
 | 
			
		||||
		lMeta.push_back(gm);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RsGenExchange::operator =(std::vector<RsMsgMetaData>& lMeta, std::vector<RsGxsMsgMetaData*>& rGxsMeta)
 | 
			
		||||
{
 | 
			
		||||
	std::vector<RsMsgMetaData*>::const_iterator vit = rGxsMeta.begin();
 | 
			
		||||
 | 
			
		||||
	for(; vit != rGxsMeta.end(); vit++)
 | 
			
		||||
	{
 | 
			
		||||
		const RsGxsMsgMetaData*& mxm = *vit;
 | 
			
		||||
		RsMsgMetaData mm;
 | 
			
		||||
		mm.mAuthorId = mxm->mAuthorId;
 | 
			
		||||
		mm.mChildTs = mxm->mChildTs;
 | 
			
		||||
		mm.mGroupId = mxm->mGroupId;
 | 
			
		||||
		mm.mMsgFlags = mxm->mMsgFlags;
 | 
			
		||||
		mm.mMsgId = mxm->mMsgId;
 | 
			
		||||
		mm.mMsgName = mxm->mMsgName;
 | 
			
		||||
		mm.mMsgStatus = mxm->mMsgStatus;
 | 
			
		||||
		mm.mOrigMsgId = mxm->mOrigMsgId;
 | 
			
		||||
		mm.mParentId = mxm->mParentId;
 | 
			
		||||
		mm.mPublishTs = mxm->mPublishTs;
 | 
			
		||||
		mm.mThreadId = mxm->mThreadId;
 | 
			
		||||
		lMeta.push_back(mm);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
RsTokenService* RsGenExchange::getTokenService()
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -209,11 +177,113 @@ void RsGenExchange::notifyNewMessages(std::vector<RsNxsMsg *> messages)
 | 
			
		|||
bool RsGenExchange::publishGroup(RsGxsGrpItem *grpItem)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	RsStackMutex stack(mGenMtx);
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
	mGrpsToPublish.push_back(grpItem);
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool RsGenExchange::publishMsg(RsGxsMsgItem *msgItem)
 | 
			
		||||
{
 | 
			
		||||
    return false;
 | 
			
		||||
 | 
			
		||||
	RsStackMutex stack(mGenMtx);
 | 
			
		||||
 | 
			
		||||
	mMsgsToPublish.push_back(msgItem);
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void RsGenExchange::publishMsgs()
 | 
			
		||||
{
 | 
			
		||||
	RsStackMutex stack(mGenMtx);
 | 
			
		||||
 | 
			
		||||
	std::vector<RsGxsMsgItem*>::iterator vit = mMsgsToPublish.begin();
 | 
			
		||||
 | 
			
		||||
	for(; vit != mMsgsToPublish.end(); )
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
		RsNxsMsg* msg = new RsNxsMsg(mServType);
 | 
			
		||||
		RsGxsMsgItem* msgItem = *vit;
 | 
			
		||||
		uint32_t size = mSerialiser->size(msgItem);
 | 
			
		||||
		char mData[size];
 | 
			
		||||
		bool ok = mSerialiser->serialise(msgItem, mData, &size);
 | 
			
		||||
 | 
			
		||||
		if(ok)
 | 
			
		||||
		{
 | 
			
		||||
			msg->metaData = new RsGxsMsgMetaData();
 | 
			
		||||
			ok = mDataAccess->addMsgData(msg);
 | 
			
		||||
 | 
			
		||||
			if(ok)
 | 
			
		||||
			{
 | 
			
		||||
				RsGxsMsgChange* mc = new RsGxsMsgChange();
 | 
			
		||||
				mNotifications.push_back(mc);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(!ok)
 | 
			
		||||
		{
 | 
			
		||||
#ifdef GEN_EXCH_DEBUG
 | 
			
		||||
			std::cerr << "RsGenExchange::publishMsgs() failed to publish msg " << std::endl;
 | 
			
		||||
#endif
 | 
			
		||||
			delete msg;
 | 
			
		||||
			continue;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		delete msgItem;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RsGenExchange::publishGrps()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	RsStackMutex stack(mGenMtx);
 | 
			
		||||
 | 
			
		||||
	std::vector<RsGxsGrpItem*>::iterator vit = mGrpsToPublish.begin();
 | 
			
		||||
 | 
			
		||||
	for(; vit != mGrpsToPublish.end();)
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
		RsNxsGrp* grp = new RsNxsGrp(mServType);
 | 
			
		||||
		RsGxsGrpItem* grpItem = *vit;
 | 
			
		||||
		uint32_t size = mSerialiser->size(grpItem);
 | 
			
		||||
 | 
			
		||||
		char gData[size];
 | 
			
		||||
		bool ok = mSerialiser->serialise(grpItem, gData, &size);
 | 
			
		||||
 | 
			
		||||
		if(ok)
 | 
			
		||||
		{
 | 
			
		||||
			grp->metaData = new RsGxsGrpMetaData();
 | 
			
		||||
			ok = mDataAccess->addGroupData(grp);
 | 
			
		||||
			RsGxsGroupChange* gc = RsGxsGroupChange();
 | 
			
		||||
			mNotifications.push_back(gc);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(!ok)
 | 
			
		||||
		{
 | 
			
		||||
 | 
			
		||||
#ifdef GEN_EXCH_DEBUG
 | 
			
		||||
			std::cerr << "RsGenExchange::publishGrps() failed to publish grp " << std::endl;
 | 
			
		||||
#endif
 | 
			
		||||
			delete grp;
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		delete grpItem;
 | 
			
		||||
 | 
			
		||||
		vit = mGrpsToPublish.erase(vit);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
void RsGenExchange::processRecvdData() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void RsGenExchange::processRecvdMessages() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void RsGenExchange::processRecvdGroups() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,7 +39,6 @@ typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > GxsMsgDataMap;
 | 
			
		|||
typedef std::map<RsGxsGroupId, RsGxsGrpItem*> GxsGroupDataMap;
 | 
			
		||||
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * This should form the parent class to \n
 | 
			
		||||
 * all gxs services. This provides access to service's msg/grp data \n
 | 
			
		||||
| 
						 | 
				
			
			@ -71,7 +70,7 @@ public:
 | 
			
		|||
     * @param serviceSerialiser The users service needs this \n
 | 
			
		||||
     *        in order for gen exchange to deal with its data types
 | 
			
		||||
     */
 | 
			
		||||
    RsGenExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns, RsSerialType* serviceSerialiser);
 | 
			
		||||
    RsGenExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns, RsSerialType* serviceSerialiser, uint16_t mServType);
 | 
			
		||||
 | 
			
		||||
    virtual ~RsGenExchange();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -160,6 +159,7 @@ protected:
 | 
			
		|||
     * Enables publication of a group item
 | 
			
		||||
     * If the item exists already this is simply versioned
 | 
			
		||||
     * This will induce a related change message
 | 
			
		||||
     * Ownership of item passes to this rsgenexchange
 | 
			
		||||
     * @param grpItem
 | 
			
		||||
     * @param
 | 
			
		||||
     */
 | 
			
		||||
| 
						 | 
				
			
			@ -169,6 +169,7 @@ protected:
 | 
			
		|||
     * Enables publication of a message item
 | 
			
		||||
     * If the item exists already this is simply versioned
 | 
			
		||||
     * This will induce a related a change message
 | 
			
		||||
     * Ownership of item passes to this rsgenexchange
 | 
			
		||||
     * @param msgItem
 | 
			
		||||
     * @return false if msg creation failed.
 | 
			
		||||
     */
 | 
			
		||||
| 
						 | 
				
			
			@ -188,12 +189,9 @@ protected:
 | 
			
		|||
     * instigate client to retrieve new content from the system
 | 
			
		||||
     * @param changes the changes that have occured to data held by this service
 | 
			
		||||
     */
 | 
			
		||||
    virtual void notifyChanges(std::vector<RsGxsChange*>& changes) = 0;
 | 
			
		||||
    virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) = 0;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    void operator=(std::list<RsGroupMetaData>& lMeta, std::list<RsGxsGrpMetaData*>& rGxsMeta);
 | 
			
		||||
    void operator=(std::vector<RsMsgMetaData>& lMeta, std::vector<RsGxsMsgMetaData*>& rGxsMeta);
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    void processRecvdData();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -201,10 +199,13 @@ private:
 | 
			
		|||
 | 
			
		||||
    void processRecvdGroups();
 | 
			
		||||
 | 
			
		||||
    void publishGrps();
 | 
			
		||||
 | 
			
		||||
    void publishMsgs();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    RsMutex mReqMtx;
 | 
			
		||||
    std::map<uint32_t, gxsRequest> mRequests;
 | 
			
		||||
    RsMutex mGenMtx;
 | 
			
		||||
    RsGxsDataAccess* mDataAccess;
 | 
			
		||||
    RsGeneralDataService* mDataStore;
 | 
			
		||||
    RsNetworkExchangeService *mNetService;
 | 
			
		||||
| 
						 | 
				
			
			@ -213,6 +214,14 @@ private:
 | 
			
		|||
    std::vector<RsNxsMsg*> mReceivedMsgs;
 | 
			
		||||
    std::vector<RsNxsGrp*> mReceivedGrps;
 | 
			
		||||
 | 
			
		||||
    std::vector<RsGxsGrpItem*> mGrpsToPublish;
 | 
			
		||||
    std::vector<RsGxsMsgItem*> mMsgsToPublish;
 | 
			
		||||
 | 
			
		||||
    std::vector<RsGxsNotify*> mNotifications;
 | 
			
		||||
 | 
			
		||||
    /// service type
 | 
			
		||||
    uint16_t mServType;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -219,3 +219,34 @@ bool RsGxsMsgMetaData::deserialise(void *data, uint32_t *size)
 | 
			
		|||
 | 
			
		||||
    return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RsGxsGrpMetaData::operator =(const RsGroupMetaData& rMeta)
 | 
			
		||||
{
 | 
			
		||||
	this->mAuthorId = rMeta.mAuthorId;
 | 
			
		||||
	this->mGroupFlags = rMeta.mGroupFlags;
 | 
			
		||||
	this->mGroupId = rMeta.mGroupId;
 | 
			
		||||
	this->mGroupStatus = rMeta.mGroupStatus ;
 | 
			
		||||
	this->mLastPost = rMeta.mLastPost;
 | 
			
		||||
	this->mMsgCount = rMeta.mMsgCount ;
 | 
			
		||||
	this->mPop = rMeta.mPop;
 | 
			
		||||
	this->mPublishTs = rMeta.mPublishTs;
 | 
			
		||||
	this->mSubscribeFlags = rMeta.mSubscribeFlags;
 | 
			
		||||
	this->mGroupName = rMeta.mGroupName;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RsGxsMsgMetaData::operator =(const RsMsgMetaData& rMeta)
 | 
			
		||||
{
 | 
			
		||||
	this->mAuthorId = rMeta.mAuthorId;
 | 
			
		||||
	this->mChildTs = rMeta.mChildTs ;
 | 
			
		||||
	this->mGroupId = rMeta.mGroupId;
 | 
			
		||||
	this->mMsgFlags = rMeta.mMsgFlags ;
 | 
			
		||||
	this->mMsgId = rMeta.mMsgId ;
 | 
			
		||||
	this->mMsgName = rMeta.mMsgName;
 | 
			
		||||
	this->mMsgStatus = rMeta.mMsgStatus;
 | 
			
		||||
	this->mOrigMsgId = rMeta.mOrigMsgId;
 | 
			
		||||
	this->mParentId = rMeta.mParentId ;
 | 
			
		||||
	this->mPublishTs = rMeta.mPublishTs ;
 | 
			
		||||
	this->mThreadId = rMeta.mThreadId;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,11 +7,14 @@
 | 
			
		|||
#include "serialiser/rstlvbase.h"
 | 
			
		||||
#include "serialiser/rstlvtypes.h"
 | 
			
		||||
#include "serialiser/rstlvkeys.h"
 | 
			
		||||
#include "serialiser/rsgxsitems.h"
 | 
			
		||||
 | 
			
		||||
typedef std::string RsGxsGroupId;
 | 
			
		||||
typedef std::string RsGxsMessageId;
 | 
			
		||||
typedef std::pair<RsGxsGroupId, RsGxsMessageId> RsGxsGrpMsgIdPair;
 | 
			
		||||
 | 
			
		||||
class RsGroupMetaData;
 | 
			
		||||
class RsMsgMetaData;
 | 
			
		||||
 | 
			
		||||
class RsGxsGrpMetaData
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -22,7 +25,7 @@ public:
 | 
			
		|||
    bool serialise(void* data, uint32_t &pktsize);
 | 
			
		||||
    uint32_t serial_size();
 | 
			
		||||
    void clear();
 | 
			
		||||
 | 
			
		||||
    void operator =(const RsGroupMetaData& rMeta);
 | 
			
		||||
 | 
			
		||||
    RsGxsGroupId mGroupId;
 | 
			
		||||
    RsGxsGroupId mOrigGrpId;
 | 
			
		||||
| 
						 | 
				
			
			@ -62,6 +65,7 @@ public:
 | 
			
		|||
    bool serialise(void* data, uint32_t *size);
 | 
			
		||||
    uint32_t serial_size();
 | 
			
		||||
    void clear();
 | 
			
		||||
    void operator =(const RsMsgMetaData& rMeta);
 | 
			
		||||
 | 
			
		||||
    RsGxsGroupId mGroupId;
 | 
			
		||||
    RsGxsMessageId mMsgId;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,6 +51,13 @@
 | 
			
		|||
#define RS_TOKREQ_ANSTYPE_SUMMARY	0x0002
 | 
			
		||||
#define RS_TOKREQ_ANSTYPE_DATA		0x0003
 | 
			
		||||
 | 
			
		||||
	const uint8_t RsGxsDataAccess::GXS_REQUEST_STATUS_FAILED = 0;
 | 
			
		||||
	const uint8_t RsGxsDataAccess::GXS_REQUEST_STATUS_PENDING = 1;
 | 
			
		||||
	const uint8_t RsGxsDataAccess::GXS_REQUEST_STATUS_PARTIAL = 2;
 | 
			
		||||
	const uint8_t RsGxsDataAccess::GXS_REQUEST_STATUS_FINISHED_INCOMPLETE = 3;
 | 
			
		||||
	const uint8_t RsGxsDataAccess::GXS_REQUEST_STATUS_COMPLETE = 4;
 | 
			
		||||
	const uint8_t RsGxsDataAccess::GXS_REQUEST_STATUS_DONE = 5;			 // ONCE ALL DATA RETRIEVED.
 | 
			
		||||
 | 
			
		||||
RsGxsDataAccess::RsGxsDataAccess(RsGeneralDataService* ds)
 | 
			
		||||
 : mDataStore(ds)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -187,7 +194,6 @@ bool RsGxsDataAccess::requestSetMessageStatus(uint32_t& token, const RsGxsGrpMsg
 | 
			
		|||
		uint32_t statusMask)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	generateToken(token);
 | 
			
		||||
 | 
			
		||||
	MessageSetFlagReq* req = new MessageSetFlagReq();
 | 
			
		||||
| 
						 | 
				
			
			@ -231,6 +237,8 @@ uint32_t RsGxsDataAccess::requestStatus(uint32_t token)
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool RsGxsDataAccess::cancelRequest(const uint32_t& token)
 | 
			
		||||
{
 | 
			
		||||
	return clearRequest(token);
 | 
			
		||||
| 
						 | 
				
			
			@ -263,17 +271,21 @@ bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list<RsGxsGrpM
 | 
			
		|||
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getGroupSummary() Unable to retrieve group summary" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}else{
 | 
			
		||||
	}else  if(req->token == GXS_REQUEST_STATUS_COMPLETE){
 | 
			
		||||
 | 
			
		||||
		GroupMetaReq* gmreq = dynamic_cast<GroupMetaReq*>(req);
 | 
			
		||||
 | 
			
		||||
		if(gmreq)
 | 
			
		||||
		{
 | 
			
		||||
			groupInfo = gmreq->mGroupMetaData;
 | 
			
		||||
			updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
 | 
			
		||||
		}else{
 | 
			
		||||
			std::cerr << "RsGxsDataAccess::getGroupSummary() Req found, failed caste" << std::endl;
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
	}else{
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getGroupSummary() Req not ready" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -288,17 +300,21 @@ bool RsGxsDataAccess::getGroupData(const uint32_t& token, std::list<RsNxsGrp*>&
 | 
			
		|||
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getGroupData() Unable to retrieve group data" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}else{
 | 
			
		||||
	}else  if(req->token == GXS_REQUEST_STATUS_COMPLETE){
 | 
			
		||||
 | 
			
		||||
		GroupDataReq* gmreq = dynamic_cast<GroupMetaReq*>(req);
 | 
			
		||||
 | 
			
		||||
		if(gmreq)
 | 
			
		||||
		{
 | 
			
		||||
			grpData = gmreq->mGroupData;
 | 
			
		||||
			updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
 | 
			
		||||
		}else{
 | 
			
		||||
			std::cerr << "RsGxsDataAccess::getGroupData() Req found, failed caste" << std::endl;
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
	}else{
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getGroupData() Req not ready" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -312,17 +328,21 @@ bool RsGxsDataAccess::getMsgData(const uint32_t& token, NxsMsgDataResult& msgDat
 | 
			
		|||
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getMsgData() Unable to retrieve group data" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}else{
 | 
			
		||||
	}else if(req->token == GXS_REQUEST_STATUS_COMPLETE){
 | 
			
		||||
 | 
			
		||||
		MsgDataReq* mdreq = dynamic_cast<GroupMetaReq*>(req);
 | 
			
		||||
 | 
			
		||||
		if(mdreq)
 | 
			
		||||
		{
 | 
			
		||||
		 msgData = mdreq->mMsgData;
 | 
			
		||||
		 updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
 | 
			
		||||
		}else{
 | 
			
		||||
			std::cerr << "RsGxsDataAccess::getMsgData() Req found, failed caste" << std::endl;
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
	}else{
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getMsgData() Req not ready" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -336,18 +356,22 @@ bool RsGxsDataAccess::getMsgSummary(const uint32_t& token, GxsMsgMetaResult& msg
 | 
			
		|||
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getMsgSummary() Unable to retrieve group data" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}else{
 | 
			
		||||
	}else  if(req->token == GXS_REQUEST_STATUS_COMPLETE){
 | 
			
		||||
 | 
			
		||||
		MsgMetaReq* mmreq = dynamic_cast<GroupMetaReq*>(req);
 | 
			
		||||
 | 
			
		||||
		if(mmreq)
 | 
			
		||||
		{
 | 
			
		||||
		 msgInfo = mmreq->mMsgMetaData;
 | 
			
		||||
		 updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
 | 
			
		||||
 | 
			
		||||
		}else{
 | 
			
		||||
			std::cerr << "RsGxsDataAccess::getMsgSummary() Req found, failed caste" << std::endl;
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
	}else{
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getMsgSummary() Req not ready" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -361,18 +385,22 @@ bool RsGxsDataAccess::getMsgList(const uint32_t& token, GxsMsgIdResult& msgIds)
 | 
			
		|||
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getMsgList() Unable to retrieve group data" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}else{
 | 
			
		||||
	}else  if(req->token == GXS_REQUEST_STATUS_COMPLETE){
 | 
			
		||||
 | 
			
		||||
		MsgIdReq* mireq = dynamic_cast<GroupMetaReq*>(req);
 | 
			
		||||
 | 
			
		||||
		if(mireq)
 | 
			
		||||
		{
 | 
			
		||||
		 msgIds = mireq->mMsgIdResult;
 | 
			
		||||
		 updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
 | 
			
		||||
 | 
			
		||||
		}else{
 | 
			
		||||
			std::cerr << "RsGxsDataAccess::getMsgList() Req found, failed caste" << std::endl;
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
	}else{
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getMsgList() Req not ready" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -384,20 +412,25 @@ bool RsGxsDataAccess::getGroupList(const uint32_t& token, std::list<RsGxsGroupId
 | 
			
		|||
 | 
			
		||||
	if(req == NULL){
 | 
			
		||||
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getGroupList() Unable to retrieve group data" << std::endl;
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getGroupList() Unable to retrieve group data,"
 | 
			
		||||
				"\nRequest does not exist" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}else{
 | 
			
		||||
	}else if(req->token == GXS_REQUEST_STATUS_COMPLETE){
 | 
			
		||||
 | 
			
		||||
		GroupIdReq* gireq = dynamic_cast<GroupMetaReq*>(req);
 | 
			
		||||
 | 
			
		||||
		if(gireq)
 | 
			
		||||
		{
 | 
			
		||||
		 groupIds = gireq->mGroupIdResult;
 | 
			
		||||
		 updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
 | 
			
		||||
 | 
			
		||||
		}else{
 | 
			
		||||
			std::cerr << "RsGxsDataAccess::getGroupList() Req found, failed caste" << std::endl;
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
	}else{
 | 
			
		||||
		std::cerr << "RsGxsDataAccess::getGroupList() Req not ready" << std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -520,7 +553,7 @@ bool RsGxsDataAccess::getGroupData(GroupDataReq* req)
 | 
			
		|||
{
 | 
			
		||||
 | 
			
		||||
	std::map<RsGxsGroupId, RsNxsGrp*> grpData;
 | 
			
		||||
	mDataStore->retrieveNxsGrps(grpData, true);
 | 
			
		||||
	mDataStore->retrieveNxsGrps(grpData, true, true);
 | 
			
		||||
 | 
			
		||||
	std::map<RsGxsGroupId, RsNxsGrp*>::iterator mit = grpData.begin();
 | 
			
		||||
	for(; mit != grpData.end(); mit++)
 | 
			
		||||
| 
						 | 
				
			
			@ -805,6 +838,59 @@ void RsGxsDataAccess::filterMsgList(GxsMsgIdResult& msgIds, const RsTokReqOption
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool RsGxsDataAccess::checkRequestStatus(const uint32_t& token,
 | 
			
		||||
		uint32_t& status, uint32_t& reqtype, uint32_t& anstype, time_t& ts)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	GxsRequest* req = retrieveRequest(token);
 | 
			
		||||
 | 
			
		||||
	RsStackMutex stack(mDataMutex);
 | 
			
		||||
 | 
			
		||||
	if(!req)
 | 
			
		||||
		return false;
 | 
			
		||||
 | 
			
		||||
	anstype = req->ansType;
 | 
			
		||||
	reqtype = req->reqType;
 | 
			
		||||
	status = req->status;
 | 
			
		||||
	ts = req->reqTime;
 | 
			
		||||
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool RsGxsDataAccess::addGroupData(RsNxsGrp* grp) {
 | 
			
		||||
 | 
			
		||||
	RsStackMutex stack(mDataMutex);
 | 
			
		||||
 | 
			
		||||
	std::map<RsNxsGrp*, RsGxsGrpMetaData*> grpM;
 | 
			
		||||
	grpM.insert(std::make_pair(grp, grp->metaData));
 | 
			
		||||
	return mDataStore->storeGroup(grpM);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool RsGxsDataAccess::addMsgData(RsNxsMsg* msg) {
 | 
			
		||||
 | 
			
		||||
	RsStackMutex stack(mDataMutex);
 | 
			
		||||
 | 
			
		||||
	std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgM;
 | 
			
		||||
	msgM.insert(std::make_pair(msg, msg->metaData));
 | 
			
		||||
	return mDataStore->storeMessage(msgM);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void RsGxsDataAccess::tokenList(std::list<uint32_t>& tokens) {
 | 
			
		||||
 | 
			
		||||
	RsStackMutex stack(mDataMutex);
 | 
			
		||||
 | 
			
		||||
	std::map<uint32_t, GxsRequest*>::iterator mit = mRequests.begin();
 | 
			
		||||
 | 
			
		||||
	for(; mit != mRequests.end(); mit++)
 | 
			
		||||
	{
 | 
			
		||||
		tokens.push_back(mit->first);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool RsGxsDataAccess::checkMsgFilter(const RsTokReqOptions& opts, const RsGxsMsgMetaData* meta) const
 | 
			
		||||
{
 | 
			
		||||
	bool statusMatch = false;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -106,7 +106,22 @@ public:
 | 
			
		|||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     * This adds a groups to the gxs data base, this is a blocking call
 | 
			
		||||
     * Responsibility for grp still lies with callee \n
 | 
			
		||||
     * If function returns successfully DataAccess can be queried for grp
 | 
			
		||||
     * @param grp the group to add, responsibility grp passed lies with callee
 | 
			
		||||
     * @return false if group cound not be added
 | 
			
		||||
     */
 | 
			
		||||
    bool addGroupData(RsNxsGrp* grp);
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     * This adds a group to the gxs data base, this is a blocking call \n
 | 
			
		||||
     * Responsibility for msg still lies with callee \n
 | 
			
		||||
     * If function returns successfully DataAccess can be queried for msg
 | 
			
		||||
     * @param msg the msg to add
 | 
			
		||||
     * @return false if msg could not be added, true otherwise
 | 
			
		||||
     */
 | 
			
		||||
    bool addMsgData(RsNxsMsg* msg);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
| 
						 | 
				
			
			@ -202,43 +217,30 @@ private:
 | 
			
		|||
    bool clearRequest(const uint32_t &token);
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     *
 | 
			
		||||
     * @param token
 | 
			
		||||
     * @param status
 | 
			
		||||
     * Updates the status flag of a request
 | 
			
		||||
     * @param token the token value of the request to set
 | 
			
		||||
     * @param status the status to set
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    bool updateRequestStatus(const uint32_t &token, const uint32_t &status);
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     *
 | 
			
		||||
     * @param token
 | 
			
		||||
     * @param status
 | 
			
		||||
     * @param reqtype
 | 
			
		||||
     * @param anstype
 | 
			
		||||
     * @param ts
 | 
			
		||||
     * @return
 | 
			
		||||
     * Use to query the status and other values of a given token
 | 
			
		||||
     * @param token the toke of the request to check for
 | 
			
		||||
     * @param status set to current status of request
 | 
			
		||||
     * @param reqtype set to request type of request
 | 
			
		||||
     * @param anstype set to to anstype of request
 | 
			
		||||
     * @param ts time stamp
 | 
			
		||||
     * @return false if token does not exist, true otherwise
 | 
			
		||||
     */
 | 
			
		||||
    bool checkRequestStatus(const uint32_t &token, uint32_t &status, uint32_t &reqtype, uint32_t &anstype, time_t &ts);
 | 
			
		||||
 | 
			
		||||
            // special ones for testing (not in final design)
 | 
			
		||||
    /*!
 | 
			
		||||
     *
 | 
			
		||||
     * @param tokens
 | 
			
		||||
     * @return
 | 
			
		||||
     * Get list of active tokens of this token service
 | 
			
		||||
     * @param tokens sets to list of token contained in this tokenservice
 | 
			
		||||
     */
 | 
			
		||||
    bool tokenList(std::list<uint32_t> &tokens);
 | 
			
		||||
    bool popRequestInList(const uint32_t &token, std::string &id);
 | 
			
		||||
    bool popRequestOutList(const uint32_t &token, std::string &id);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    virtual bool getGroupList(uint32_t &token, const RsTokReqOptions &opts,
 | 
			
		||||
                              const std::list<std::string> &groupIds, std::list<std::string> &outGroupIds);
 | 
			
		||||
 | 
			
		||||
    virtual bool getMsgList(uint32_t &token, const RsTokReqOptions &opts,
 | 
			
		||||
                            const std::list<std::string> &groupIds, std::list<std::string> &outMsgIds);
 | 
			
		||||
 | 
			
		||||
    virtual bool getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts,
 | 
			
		||||
                                   const std::list<std::string> &msgIds, std::list<std::string> &outMsgIds);
 | 
			
		||||
    void tokenList(std::list<uint32_t> &tokens);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
| 
						 | 
				
			
			@ -299,11 +301,11 @@ private:
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     * This applies the options to the meta to find out if the message satisfies
 | 
			
		||||
     * This applies the options to the meta to find out if the given message satisfies
 | 
			
		||||
     * them
 | 
			
		||||
     * @param opts options containing filters to check
 | 
			
		||||
     * @param meta meta containing currently defined options for msg
 | 
			
		||||
     * @return true if msg meta passed all options
 | 
			
		||||
     * @return true if msg meta passes all options
 | 
			
		||||
     */
 | 
			
		||||
    bool checkMsgFilter(const RsTokReqOptions& opts, const RsGxsMsgMetaData* meta) const;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -858,7 +858,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
 | 
			
		|||
		grps[item->grpId] = NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	mDataStore->retrieveNxsGrps(grps, false);
 | 
			
		||||
	mDataStore->retrieveNxsGrps(grps, false, false);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	NxsTransaction* newTr = new NxsTransaction();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,13 +37,6 @@ typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgIdResult;
 | 
			
		|||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgMetaData*> > GxsMsgMetaResult;
 | 
			
		||||
typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > NxsMsgDataResult;
 | 
			
		||||
 | 
			
		||||
#define GXS_REQUEST_STATUS_FAILED		0
 | 
			
		||||
#define GXS_REQUEST_STATUS_PENDING		1
 | 
			
		||||
#define GXS_REQUEST_STATUS_PARTIAL		2
 | 
			
		||||
#define GXS_REQUEST_STATUS_FINISHED_INCOMPLETE	3
 | 
			
		||||
#define GXS_REQUEST_STATUS_COMPLETE		4
 | 
			
		||||
#define GXS_REQUEST_STATUS_DONE			5 // ONCE ALL DATA RETRIEVED.
 | 
			
		||||
 | 
			
		||||
#define GXS_REQUEST_TYPE_GROUP_DATA			0x00010000
 | 
			
		||||
#define GXS_REQUEST_TYPE_GROUP_META			0x00020000
 | 
			
		||||
#define GXS_REQUEST_TYPE_GROUP_IDS			0x00040000
 | 
			
		||||
| 
						 | 
				
			
			@ -89,6 +82,15 @@ time_t   mAfter;
 | 
			
		|||
class RsTokenService
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
	static const uint8_t GXS_REQUEST_STATUS_FAILED;
 | 
			
		||||
	static const uint8_t GXS_REQUEST_STATUS_PENDING;
 | 
			
		||||
	static const uint8_t GXS_REQUEST_STATUS_PARTIAL;
 | 
			
		||||
	static const uint8_t GXS_REQUEST_STATUS_FINISHED_INCOMPLETE;
 | 
			
		||||
	static const uint8_t GXS_REQUEST_STATUS_COMPLETE;
 | 
			
		||||
	static const uint8_t GXS_REQUEST_STATUS_DONE;			 // ONCE ALL DATA RETRIEVED.
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    RsTokenService()  { return; }
 | 
			
		||||
| 
						 | 
				
			
			@ -98,20 +100,20 @@ public:
 | 
			
		|||
 | 
			
		||||
    /*!
 | 
			
		||||
     * Use this to request group related information
 | 
			
		||||
     * @param token
 | 
			
		||||
     * @param token The token returned for the request, store this value to pool for request completion
 | 
			
		||||
     * @param ansType The type of result (e.g. group data, meta, ids)
 | 
			
		||||
     * @param opts
 | 
			
		||||
     * @param opts Additional option that affect outcome of request. Please see specific services, for valid values
 | 
			
		||||
     * @param groupIds group id to request info for. Leave empty to get info on all groups,
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    virtual bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<RsGxsGroupId> &groupIds) = 0;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     *
 | 
			
		||||
     * @param token
 | 
			
		||||
     * @param ansType
 | 
			
		||||
     * @param opts
 | 
			
		||||
     * @param groupIds
 | 
			
		||||
     * Use this to get msg related information, store this value to pole for request completion
 | 
			
		||||
     * @param token The token returned for the request
 | 
			
		||||
     * @param ansType The type of result wanted
 | 
			
		||||
     * @param opts Additional option that affect outcome of request. Please see specific services, for valid values
 | 
			
		||||
     * @param groupIds The ids of the groups to get, second entry of map empty to query for all msgs
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    virtual bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const GxsMsgReq& msgIds) = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -129,11 +131,11 @@ public:
 | 
			
		|||
    		const uint32_t status, const uint32_t statusMask) = 0;
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     *
 | 
			
		||||
     * @param token
 | 
			
		||||
     * @param grpId
 | 
			
		||||
     * @param status
 | 
			
		||||
     * @param statusMask
 | 
			
		||||
     * Set the status of a group given by group Id
 | 
			
		||||
     * @param token The token returned for this request
 | 
			
		||||
     * @param grpId The Id of the group to apply status change to
 | 
			
		||||
     * @param status The status to apply
 | 
			
		||||
     * @param statusMask The status mask (target particular type of status)
 | 
			
		||||
     * @return true if request made successfully, false otherwise
 | 
			
		||||
     */
 | 
			
		||||
    virtual bool requestSetGroupStatus(uint32_t &token, const RsGxsGroupId &grpId, const uint32_t status,
 | 
			
		||||
| 
						 | 
				
			
			@ -152,10 +154,14 @@ public:
 | 
			
		|||
    	// (FUTURE WORK).
 | 
			
		||||
    //virtual bool groupRestoreKeys(const std::string &groupId) = 0;
 | 
			
		||||
    //virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers) = 0;
 | 
			
		||||
 | 
			
		||||
        /* Poll */
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     * Request the status of ongoing request. This is a blocking operation!
 | 
			
		||||
     * Request the status of ongoing request.
 | 
			
		||||
     * Please use this for polling as much cheaper
 | 
			
		||||
     * than polling the specific service as they might
 | 
			
		||||
     * not return intermediate status information
 | 
			
		||||
     * @param token value of token to check status for
 | 
			
		||||
     * @return the current status of request
 | 
			
		||||
     */
 | 
			
		||||
| 
						 | 
				
			
			@ -166,8 +172,8 @@ public:
 | 
			
		|||
    /*!
 | 
			
		||||
     * 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
 | 
			
		||||
     * @return false if unusuccessful, true if successful
 | 
			
		||||
     * @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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -158,117 +158,118 @@ class RsPhotoAlbum
 | 
			
		|||
std::ostream &operator<<(std::ostream &out, const RsPhotoPhoto &photo);
 | 
			
		||||
std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album);
 | 
			
		||||
 | 
			
		||||
typedef std::map<std::string, std::vector<RsPhotoPhoto> > PhotoResult;
 | 
			
		||||
typedef std::map<std::string, std::vector<RsMsgMetaData> > MsgMetaResult;
 | 
			
		||||
typedef std::map<RsGxsGroupId, std::vector<RsPhotoPhoto> > PhotoResult;
 | 
			
		||||
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > MsgMetaResult;
 | 
			
		||||
 | 
			
		||||
class RsPhotoV2
 | 
			
		||||
{
 | 
			
		||||
        public:
 | 
			
		||||
 | 
			
		||||
        RsPhotoV2()  { return; }
 | 
			
		||||
virtual ~RsPhotoV2() { return; }
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * Use to enquire if groups or msgs have changed
 | 
			
		||||
 * @return true if msgs or groups have changed
 | 
			
		||||
 */
 | 
			
		||||
virtual bool updated() = 0;
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 *
 | 
			
		||||
 * @param grpIds
 | 
			
		||||
 */
 | 
			
		||||
virtual void groupsChanged(std::list<std::string>& grpIds) = 0;
 | 
			
		||||
	RsPhotoV2()  { return; }
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 *
 | 
			
		||||
 * @param msgs
 | 
			
		||||
 */
 | 
			
		||||
virtual void msgsChanged(std::map<std::string,
 | 
			
		||||
                         std::vector<std::string> >& msgs) = 0;
 | 
			
		||||
	virtual ~RsPhotoV2() { return; }
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * To acquire a handle to token service handler
 | 
			
		||||
 * needed to make requests to the service
 | 
			
		||||
 * @return handle to token service for this gxs service
 | 
			
		||||
 */
 | 
			
		||||
virtual RsTokenService* getTokenService() = 0;
 | 
			
		||||
	/*!
 | 
			
		||||
	 * Use to enquire if groups or msgs have changed
 | 
			
		||||
	 * Poll regularly, particularly after a photo submission
 | 
			
		||||
	 * @return true if msgs or groups have changed
 | 
			
		||||
	 */
 | 
			
		||||
	virtual bool updated() = 0;
 | 
			
		||||
 | 
			
		||||
/* Generic Lists */
 | 
			
		||||
	/*!
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param grpIds
 | 
			
		||||
	 */
 | 
			
		||||
	virtual void groupsChanged(std::list<RsGroupId>& grpIds) = 0;
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 *
 | 
			
		||||
 * @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
 | 
			
		||||
 */
 | 
			
		||||
virtual bool getGroupList(const uint32_t &token,
 | 
			
		||||
                          std::list<std::string> &groupIds) = 0;
 | 
			
		||||
	/*!
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param msgs
 | 
			
		||||
	 */
 | 
			
		||||
	virtual void msgsChanged(GxsMsgIdResult& msgs) = 0;
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * @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
 | 
			
		||||
 */
 | 
			
		||||
virtual bool getMsgList(const uint32_t &token,
 | 
			
		||||
                        std::map<std::string, std::vector<std::string> > &msgIds) = 0;
 | 
			
		||||
	/*!
 | 
			
		||||
	 * To acquire a handle to token service handler
 | 
			
		||||
	 * needed to make requests to the service
 | 
			
		||||
	 * @return handle to token service for this gxs service
 | 
			
		||||
	 */
 | 
			
		||||
	virtual RsTokenService* getTokenService() = 0;
 | 
			
		||||
 | 
			
		||||
/* Generic Summary */
 | 
			
		||||
	/* Generic Lists */
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * @param token token to be redeemed for this request
 | 
			
		||||
 * @param groupInfo the ids returned for given request token
 | 
			
		||||
 * @return false if request token is invalid, check token status for error report
 | 
			
		||||
 */
 | 
			
		||||
virtual bool getGroupSummary(const uint32_t &token,
 | 
			
		||||
                             std::list<RsGroupMetaData> &groupInfo) = 0;
 | 
			
		||||
	/*!
 | 
			
		||||
	 *
 | 
			
		||||
	 * @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
 | 
			
		||||
	 */
 | 
			
		||||
	virtual bool getGroupList(const uint32_t &token,
 | 
			
		||||
							  std::list<RsGroupId> &groupIds) = 0;
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * @param token token to be redeemed for this request
 | 
			
		||||
 * @param msgInfo the message metadata returned for given request token
 | 
			
		||||
 * @return false if request token is invalid, check token status for error report
 | 
			
		||||
 */
 | 
			
		||||
virtual bool getMsgSummary(const uint32_t &token,
 | 
			
		||||
                           MsgMetaResult &msgInfo) = 0;
 | 
			
		||||
	/*!
 | 
			
		||||
	 * @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
 | 
			
		||||
	 */
 | 
			
		||||
	virtual bool getMsgList(const uint32_t &token,
 | 
			
		||||
							GxsMsgIdResult &msgIds) = 0;
 | 
			
		||||
 | 
			
		||||
        /* Specific Service Data */
 | 
			
		||||
	/* Generic Summary */
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * @param token token to be redeemed for this request
 | 
			
		||||
 * @param album the album returned for given request token
 | 
			
		||||
 * @return false if request token is invalid, check token status for error report
 | 
			
		||||
 */
 | 
			
		||||
virtual bool getAlbum(const uint32_t &token, RsPhotoAlbum &album) = 0;
 | 
			
		||||
	/*!
 | 
			
		||||
	 * @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
 | 
			
		||||
	 */
 | 
			
		||||
	virtual bool getGroupSummary(const uint32_t &token,
 | 
			
		||||
								 std::list<RsGroupMetaData> &groupInfo) = 0;
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * @param token token to be redeemed for this request
 | 
			
		||||
 * @param photo the photo returned for given request token
 | 
			
		||||
 * @return false if request token is invalid, check token status for error report
 | 
			
		||||
 */
 | 
			
		||||
virtual bool getPhoto(const uint32_t &token,
 | 
			
		||||
                      PhotoResult &photo) = 0;
 | 
			
		||||
	/*!
 | 
			
		||||
	 * @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
 | 
			
		||||
	 */
 | 
			
		||||
	virtual bool getMsgSummary(const uint32_t &token,
 | 
			
		||||
							   MsgMetaResult &msgInfo) = 0;
 | 
			
		||||
 | 
			
		||||
/* details are updated in album - to choose Album ID, and storage path */
 | 
			
		||||
			/* Specific Service Data */
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * @param album
 | 
			
		||||
 * @param isNew
 | 
			
		||||
 * @return false if submission failed
 | 
			
		||||
 */
 | 
			
		||||
virtual bool submitAlbumDetails(RsPhotoAlbum &album, bool isNew) = 0;
 | 
			
		||||
	/*!
 | 
			
		||||
	 * @param token token to be redeemed for album request
 | 
			
		||||
	 * @param album the album returned for given request token
 | 
			
		||||
	 * @return false if request token is invalid, check token status for error report
 | 
			
		||||
	 */
 | 
			
		||||
	virtual bool getAlbum(const uint32_t &token, std::vector<RsPhotoAlbum> &album) = 0;
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * @param photo photo to submit
 | 
			
		||||
 * @param isNew whether photo is new
 | 
			
		||||
 * @param
 | 
			
		||||
 */
 | 
			
		||||
virtual bool submitPhoto(RsPhotoPhoto &photo, bool isNew) = 0;
 | 
			
		||||
	/*!
 | 
			
		||||
	 * @param token token to be redeemed for photo request
 | 
			
		||||
	 * @param photo the photo returned for given request token
 | 
			
		||||
	 * @return false if request token is invalid, check token status for error report
 | 
			
		||||
	 */
 | 
			
		||||
	virtual bool getPhoto(const uint32_t &token,
 | 
			
		||||
						  PhotoResult &photo) = 0;
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
 * @param grpId the id of the group to subscribe to
 | 
			
		||||
 * @param subsribe set to true to subscribe
 | 
			
		||||
 */
 | 
			
		||||
virtual bool subscribeToAlbum(const std::string grpId, bool subscribe) = 0;
 | 
			
		||||
	/* details are updated in album - to choose Album ID, and storage path */
 | 
			
		||||
 | 
			
		||||
	/*!
 | 
			
		||||
	 * This RsGenExchange service will be alerted to this album as \n
 | 
			
		||||
	 * a new album. Do not keep the submitted album as representative, wait for
 | 
			
		||||
	 * notification telling of successful submission
 | 
			
		||||
	 * @param album The album to be submitted
 | 
			
		||||
	 * @return false if submission failed
 | 
			
		||||
	 */
 | 
			
		||||
	virtual bool submitAlbumDetails(RsPhotoAlbum &album) = 0;
 | 
			
		||||
 | 
			
		||||
	/*!
 | 
			
		||||
	 * This RsGenExchange service will be alerted to this photo as \n
 | 
			
		||||
	 * a new photo. Do not keep the submitted photo as representative, wait for new photo
 | 
			
		||||
	 * returned
 | 
			
		||||
	 * @param photo photo to submit
 | 
			
		||||
	 * @return
 | 
			
		||||
	 */
 | 
			
		||||
	virtual bool submitPhoto(RsPhotoPhoto &photo) = 0;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										40
									
								
								libretroshare/src/serialiser/rsgxsitems.cc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								libretroshare/src/serialiser/rsgxsitems.cc
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,40 @@
 | 
			
		|||
/*
 | 
			
		||||
 * rsgxsitems.cc
 | 
			
		||||
 *
 | 
			
		||||
 *  Created on: 26 Jul 2012
 | 
			
		||||
 *      Author: crispy
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "rsgxsitems.h"
 | 
			
		||||
#include "gxs/rsgxsdata.h"
 | 
			
		||||
 | 
			
		||||
	void RsMsgMetaData::operator =(const RsGxsMsgMetaData& rGxsMeta)
 | 
			
		||||
	{
 | 
			
		||||
		this->mAuthorId = rGxsMeta.mAuthorId;
 | 
			
		||||
		this->mChildTs = rGxsMeta.mChildTs;
 | 
			
		||||
		this->mGroupId = rGxsMeta.mGroupId;
 | 
			
		||||
		this->mMsgFlags = rGxsMeta.mMsgFlags;
 | 
			
		||||
		this->mMsgId = rGxsMeta.mMsgId;
 | 
			
		||||
		this->mMsgName = rGxsMeta.mMsgName;
 | 
			
		||||
		this->mMsgStatus = rGxsMeta.mMsgStatus;
 | 
			
		||||
		this->mOrigMsgId = rGxsMeta.mOrigMsgId;
 | 
			
		||||
		this->mParentId = rGxsMeta.mParentId;
 | 
			
		||||
		this->mPublishTs = rGxsMeta.mPublishTs;
 | 
			
		||||
		this->mThreadId = rGxsMeta.mThreadId;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	void RsGroupMetaData::operator =(const RsGxsGrpMetaData& rGxsMeta)
 | 
			
		||||
	{
 | 
			
		||||
		this->mAuthorId = rGxsMeta.mAuthorId;
 | 
			
		||||
		this->mGroupFlags = rGxsMeta.mGroupFlags;
 | 
			
		||||
		this->mGroupId = rGxsMeta.mGroupId;
 | 
			
		||||
		this->mGroupStatus = rGxsMeta.mGroupStatus;
 | 
			
		||||
		this->mLastPost = rGxsMeta.mLastPost;
 | 
			
		||||
		this->mMsgCount = rGxsMeta.mMsgCount;
 | 
			
		||||
		this->mPop = rGxsMeta.mPop;
 | 
			
		||||
		this->mPublishTs = rGxsMeta.mPublishTs;
 | 
			
		||||
		this->mSubscribeFlags = rGxsMeta.mSubscribeFlags;
 | 
			
		||||
		this->mGroupName = rGxsMeta.mGroupName;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -32,35 +32,8 @@
 | 
			
		|||
#include "serialiser/rstlvtypes.h"
 | 
			
		||||
#include "serialiser/rstlvkeys.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class RsGxsGrpItem : public RsItem
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    RsGxsGrpItem() : RsItem(0) { return; }
 | 
			
		||||
    virtual ~RsGxsGrpItem(){}
 | 
			
		||||
 | 
			
		||||
    // must be serialised
 | 
			
		||||
    std::string mAuthorId;
 | 
			
		||||
    std::string mGrpId;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class RsGxsMsgItem : public RsItem
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    RsGxsMsgItem() : RsItem(0) { return; }
 | 
			
		||||
    virtual ~RsGxsMsgItem(){}
 | 
			
		||||
 | 
			
		||||
    // must be serialised
 | 
			
		||||
    std::string mAuthorId;
 | 
			
		||||
    std::string mMsgId;
 | 
			
		||||
    std::string mGrpId;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class RsGxsGrpMetaData;
 | 
			
		||||
class RsGxsMsgMetaData;
 | 
			
		||||
 | 
			
		||||
class RsGroupMetaData
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -79,6 +52,20 @@ class RsGroupMetaData
 | 
			
		|||
                //mPublishTs = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    	void operator =(const RsGxsGrpMetaData& rGxsMeta);
 | 
			
		||||
//    	{
 | 
			
		||||
//    		this->mAuthorId = rGxsMeta.mAuthorId;
 | 
			
		||||
//    		this->mGroupFlags = rGxsMeta.mGroupFlags;
 | 
			
		||||
//    		this->mGroupId = rGxsMeta.mGroupId;
 | 
			
		||||
//    		this->mGroupStatus = rGxsMeta.mGroupStatus;
 | 
			
		||||
//    		this->mLastPost = rGxsMeta.mLastPost;
 | 
			
		||||
//    		this->mMsgCount = rGxsMeta.mMsgCount;
 | 
			
		||||
//    		this->mPop = rGxsMeta.mPop;
 | 
			
		||||
//    		this->mPublishTs = rGxsMeta.mPublishTs;
 | 
			
		||||
//    		this->mSubscribeFlags = rGxsMeta.mSubscribeFlags;
 | 
			
		||||
//    		this->mGroupName = rGxsMeta.mGroupName;
 | 
			
		||||
//    	}
 | 
			
		||||
 | 
			
		||||
        std::string mGroupId;
 | 
			
		||||
        std::string mGroupName;
 | 
			
		||||
        uint32_t    mGroupFlags;
 | 
			
		||||
| 
						 | 
				
			
			@ -113,6 +100,9 @@ class RsMsgMetaData
 | 
			
		|||
                mChildTs = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void operator =(const RsGxsMsgMetaData& rGxsMeta);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        std::string mGroupId;
 | 
			
		||||
        std::string mMsgId;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -135,5 +125,31 @@ class RsMsgMetaData
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class RsGxsGrpItem : public RsItem
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    RsGxsGrpItem() : RsItem(0) { return; }
 | 
			
		||||
    virtual ~RsGxsGrpItem(){}
 | 
			
		||||
 | 
			
		||||
    RsGroupMetaData meta;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class RsGxsMsgItem : public RsItem
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    RsGxsMsgItem() : RsItem(0) { return; }
 | 
			
		||||
    virtual ~RsGxsMsgItem(){}
 | 
			
		||||
 | 
			
		||||
    RsMsgMetaData meta;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // RSGXSITEMS_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -184,8 +184,9 @@ class RsNxsGrp : public RsNxsItem
 | 
			
		|||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    RsNxsGrp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP), grp(servtype), meta(servtype) { clear(); return; }
 | 
			
		||||
 | 
			
		||||
    RsNxsGrp(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_GRP), grp(servtype), meta(servtype),
 | 
			
		||||
    metaData(NULL) { clear(); return; }
 | 
			
		||||
    virtual ~RsNxsGrp() { if(metaData) delete metaData; }
 | 
			
		||||
 | 
			
		||||
    virtual void clear();
 | 
			
		||||
    virtual std::ostream &print(std::ostream &out, uint16_t indent);
 | 
			
		||||
| 
						 | 
				
			
			@ -278,6 +279,8 @@ public:
 | 
			
		|||
     */
 | 
			
		||||
    RsTlvBinaryData msg;
 | 
			
		||||
 | 
			
		||||
    RsGxsMsgMetaData* metaData;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*!
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,13 +39,15 @@
 | 
			
		|||
class RsGxsPhotoAlbumItem : public RsGxsGrpItem
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	RsGxsPhotoAlbumItem() {}
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
	RsGxsPhotoAlbumItem() {}
 | 
			
		||||
	RsPhotoAlbum album;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class RsGxsPhotoPhotoItem : public RsGxsMsgItem
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
	RsGxsPhotoPhotoItem() {}
 | 
			
		||||
	RsPhotoPhoto photo;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,142 @@
 | 
			
		|||
#include "serialiser/rsphotov2items.h"
 | 
			
		||||
 | 
			
		||||
p3PhotoServiceV2::p3PhotoServiceV2(RsGeneralDataService* gds, RsNetworkExchangeService* nes)
 | 
			
		||||
	: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser())
 | 
			
		||||
	: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser(), RS_SERVICE_TYPE_PHOTO)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool p3PhotoServiceV2::updated()
 | 
			
		||||
{
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void p3PhotoServiceV2::groupsChanged(std::list<std::string>& grpIds) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void p3PhotoServiceV2::msgsChanged(
 | 
			
		||||
		std::map<std::string, std::vector<std::string> >& msgs)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
RsTokenService* p3PhotoServiceV2::getTokenService() {
 | 
			
		||||
 | 
			
		||||
	return RsGenExchange::getTokenService();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool p3PhotoServiceV2::getGroupList(const uint32_t& token,
 | 
			
		||||
		std::list<std::string>& groupIds)
 | 
			
		||||
{
 | 
			
		||||
	return RsGenExchange::getGroupList(token, groupIds);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool p3PhotoServiceV2::getMsgList(const uint32_t& token,
 | 
			
		||||
		GxsMsgIdResult& msgIds)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	return RsGenExchange::getMsgList(token, msgIds);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool p3PhotoServiceV2::getGroupSummary(const uint32_t& token,
 | 
			
		||||
		std::list<RsGroupMetaData>& groupInfo)
 | 
			
		||||
{
 | 
			
		||||
	return RsGenExchange::getGroupMeta(token, groupInfo);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool p3PhotoServiceV2::getMsgSummary(const uint32_t& token,
 | 
			
		||||
		MsgMetaResult& msgInfo)
 | 
			
		||||
{
 | 
			
		||||
	return RsGenExchange::getMsgMeta(token, msgInfo);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool p3PhotoServiceV2::getAlbum(const uint32_t& token, std::vector<RsPhotoAlbum>& albums)
 | 
			
		||||
{
 | 
			
		||||
	std::vector<RsGxsGrpItem*> grpData;
 | 
			
		||||
	bool ok = RsGenExchange::getGroupData(token, grpData);
 | 
			
		||||
 | 
			
		||||
	if(ok)
 | 
			
		||||
	{
 | 
			
		||||
		std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
 | 
			
		||||
 | 
			
		||||
		for(; vit != grpData.end(); vit++)
 | 
			
		||||
		{
 | 
			
		||||
			RsGxsGrpItem* item = *vit;
 | 
			
		||||
			RsPhotoAlbum album = *item;
 | 
			
		||||
			albums.push_back(album);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool p3PhotoServiceV2::getPhoto(const uint32_t& token, PhotoResult& photo)
 | 
			
		||||
{
 | 
			
		||||
	GxsMsgDataMap msgData;
 | 
			
		||||
	bool ok = RsGenExchange::getMsgData(token, msgData);
 | 
			
		||||
 | 
			
		||||
	if(ok)
 | 
			
		||||
	{
 | 
			
		||||
		GxsMsgDataMap::iterator mit = msgData.begin();
 | 
			
		||||
 | 
			
		||||
		for(; mit != msgData.end();  mit++)
 | 
			
		||||
		{
 | 
			
		||||
			RsGxsGroupId grpId = mit->first;
 | 
			
		||||
			std::vector<RsGxsMsgItem*>& msgItems = mit->second;
 | 
			
		||||
			std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
 | 
			
		||||
 | 
			
		||||
			for(; vit != msgItems.end(); vit++)
 | 
			
		||||
			{
 | 
			
		||||
				RsGxsPhotoPhotoItem* item = dynamic_cast<RsGxsPhotoPhotoItem*>(*vit);
 | 
			
		||||
 | 
			
		||||
				if(item)
 | 
			
		||||
				{
 | 
			
		||||
					RsPhotoPhoto photo = *item;
 | 
			
		||||
					photo[grpId] = photo;
 | 
			
		||||
					delete item;
 | 
			
		||||
				}else
 | 
			
		||||
				{
 | 
			
		||||
					delete *vit;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool p3PhotoServiceV2::submitAlbumDetails(RsPhotoAlbum& album)
 | 
			
		||||
{
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void p3PhotoServiceV2::operator =(RsPhoto& lPhotos,
 | 
			
		||||
		const RsGxsPhotoPhotoItem& rPhoto)
 | 
			
		||||
{
 | 
			
		||||
	lPhotos = rPhoto.photo;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void p3PhotoServiceV2::operator =(RsPhotoAlbum& lAlbum,
 | 
			
		||||
		const RsGxsPhotoAlbumItem& rAlbum)
 | 
			
		||||
{
 | 
			
		||||
	lAlbum = rAlbum.album;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool p3PhotoServiceV2::submitPhoto(RsPhotoPhoto& photo)
 | 
			
		||||
{
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,6 +38,9 @@ public:
 | 
			
		|||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    bool updated();
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
| 
						 | 
				
			
			@ -55,7 +58,7 @@ public:
 | 
			
		|||
    bool getGroupList(const uint32_t &token,
 | 
			
		||||
                              std::list<std::string> &groupIds);
 | 
			
		||||
    bool getMsgList(const uint32_t &token,
 | 
			
		||||
                            std::list<std::string> &msgIds);
 | 
			
		||||
                            GxsMsgIdResult& msgIds);
 | 
			
		||||
 | 
			
		||||
    /* Generic Summary */
 | 
			
		||||
    bool getGroupSummary(const uint32_t &token,
 | 
			
		||||
| 
						 | 
				
			
			@ -65,18 +68,20 @@ public:
 | 
			
		|||
                               MsgMetaResult &msgInfo);
 | 
			
		||||
 | 
			
		||||
    /* Specific Service Data */
 | 
			
		||||
    bool getAlbum(const uint32_t &token, RsPhotoAlbum &album);
 | 
			
		||||
    bool getPhoto(const uint32_t &token, PhotoResult &photo);
 | 
			
		||||
    bool getAlbum(const uint32_t &token, std::vector<RsPhotoAlbum> &albums);
 | 
			
		||||
    bool getPhoto(const uint32_t &token, PhotoResult &photos);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    void operator=(RsPhoto& lPhotos, const RsGxsPhotoPhotoItem& rPhoto);
 | 
			
		||||
    void operator=(RsPhotoAlbum& lAlbum, const RsGxsPhotoAlbumItem& rAlbum);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    /** Modifications **/
 | 
			
		||||
 | 
			
		||||
    bool submitAlbumDetails(RsPhotoAlbum &album, bool isNew);
 | 
			
		||||
    bool submitPhoto(RsPhotoPhoto &photo, bool isNew);
 | 
			
		||||
    bool subscribeToAlbum(const std::string& grpId, bool subscribe);
 | 
			
		||||
    bool submitAlbumDetails(RsPhotoAlbum &album);
 | 
			
		||||
    bool submitPhoto(RsPhotoPhoto &photo);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // P3PHOTOSERVICEV2_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue