2012-10-21 15:45:35 -04:00
|
|
|
/*
|
|
|
|
* libretroshare/src/retroshare: rsgxsdataaccess.cc
|
|
|
|
*
|
|
|
|
* RetroShare C++ Interface.
|
|
|
|
*
|
2013-06-04 17:00:43 -04:00
|
|
|
* Copyright 2012-2013 by Robert Fernie, Christopher Evi-Parker
|
2012-10-21 15:45:35 -04:00
|
|
|
*
|
|
|
|
* 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-10-23 05:23:32 -04:00
|
|
|
#include <time.h>
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
#include "rsgxsdataaccess.h"
|
2014-07-20 07:21:06 -04:00
|
|
|
#include "retroshare/rsgxsflags.h"
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
// This bit will be filled out over time.
|
|
|
|
#define RS_TOKREQOPT_MSG_VERSIONS 0x0001 // MSGRELATED: Returns All MsgIds with OrigMsgId = MsgId.
|
|
|
|
#define RS_TOKREQOPT_MSG_ORIGMSG 0x0002 // MSGLIST: All Unique OrigMsgIds in a Group.
|
|
|
|
#define RS_TOKREQOPT_MSG_LATEST 0x0004 // MSGLIST: All Latest MsgIds in Group. MSGRELATED: Latest MsgIds for Input Msgs.
|
|
|
|
|
|
|
|
#define RS_TOKREQOPT_MSG_THREAD 0x0010 // MSGRELATED: All Msgs in Thread. MSGLIST: All Unique Thread Ids in Group.
|
|
|
|
#define RS_TOKREQOPT_MSG_PARENT 0x0020 // MSGRELATED: All Children Msgs.
|
|
|
|
|
|
|
|
#define RS_TOKREQOPT_MSG_AUTHOR 0x0040 // MSGLIST: Messages from this AuthorId
|
|
|
|
|
|
|
|
|
|
|
|
// Status Filtering... should it be a different Option Field.
|
|
|
|
#define RS_TOKREQOPT_GROUP_UPDATED 0x0100 // GROUPLIST: Groups that have been updated.
|
|
|
|
#define RS_TOKREQOPT_MSG_UPDATED 0x0200 // MSGLIST: Msg that have been updated from specified groups.
|
|
|
|
#define RS_TOKREQOPT_MSG_UPDATED 0x0200 // MSGLIST: Msg that have been updated from specified groups.
|
|
|
|
|
|
|
|
// Read Status.
|
|
|
|
#define RS_TOKREQOPT_READ 0x0001
|
|
|
|
#define RS_TOKREQOPT_UNREAD 0x0002
|
|
|
|
|
|
|
|
#define RS_TOKREQ_ANSTYPE_LIST 0x0001
|
|
|
|
#define RS_TOKREQ_ANSTYPE_SUMMARY 0x0002
|
|
|
|
#define RS_TOKREQ_ANSTYPE_DATA 0x0003
|
|
|
|
|
2014-05-04 08:48:42 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_FAILED = 0;
|
|
|
|
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_PENDING = 1;
|
|
|
|
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_PARTIAL = 2;
|
|
|
|
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_FINISHED_INCOMPLETE = 3;
|
|
|
|
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE = 4;
|
|
|
|
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_DONE = 5; // ONCE ALL DATA RETRIEVED.
|
2015-08-13 13:44:27 -04:00
|
|
|
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_CANCELLED = 6;
|
2014-05-04 08:48:42 -04:00
|
|
|
|
|
|
|
/***********
|
|
|
|
* #define DATA_DEBUG 1
|
|
|
|
**********/
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
RsGxsDataAccess::RsGxsDataAccess(RsGeneralDataService* ds)
|
|
|
|
: mDataStore(ds), mDataMutex("RsGxsDataAccess"), mNextToken(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts,
|
2014-03-17 16:56:06 -04:00
|
|
|
const std::list<RsGxsGroupId> &groupIds)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
if(groupIds.empty())
|
|
|
|
{
|
|
|
|
std::cerr << "Group Id list is empty" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GxsRequest* req = NULL;
|
|
|
|
uint32_t reqType = opts.mReqType;
|
|
|
|
|
|
|
|
if(reqType & GXS_REQUEST_TYPE_GROUP_META)
|
|
|
|
{
|
|
|
|
GroupMetaReq* gmr = new GroupMetaReq();
|
|
|
|
gmr->mGroupIds = groupIds;
|
|
|
|
req = gmr;
|
|
|
|
}
|
|
|
|
else if(reqType & GXS_REQUEST_TYPE_GROUP_DATA)
|
|
|
|
{
|
|
|
|
GroupDataReq* gdr = new GroupDataReq();
|
|
|
|
gdr->mGroupIds = groupIds;
|
|
|
|
req = gdr;
|
|
|
|
}
|
|
|
|
else if(reqType & GXS_REQUEST_TYPE_GROUP_IDS)
|
|
|
|
{
|
|
|
|
GroupIdReq* gir = new GroupIdReq();
|
|
|
|
gir->mGroupIds = groupIds;
|
|
|
|
req = gir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(req == NULL)
|
|
|
|
{
|
2012-11-01 20:45:50 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::requestGroupInfo() request type not recognised, type "
|
2012-10-21 15:45:35 -04:00
|
|
|
<< reqType << std::endl;
|
|
|
|
return false;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
generateToken(token);
|
2014-05-04 08:48:42 -04:00
|
|
|
|
|
|
|
#ifdef DATA_DEBUG
|
2012-11-01 20:45:50 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::requestGroupInfo() gets Token: " << token << std::endl;
|
2014-05-04 08:48:42 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setReq(req, token, ansType, opts);
|
|
|
|
storeRequest(req);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts)
|
|
|
|
{
|
|
|
|
|
|
|
|
GxsRequest* req = NULL;
|
|
|
|
uint32_t reqType = opts.mReqType;
|
|
|
|
|
|
|
|
if(reqType & GXS_REQUEST_TYPE_GROUP_META)
|
|
|
|
{
|
|
|
|
GroupMetaReq* gmr = new GroupMetaReq();
|
|
|
|
req = gmr;
|
|
|
|
}
|
|
|
|
else if(reqType & GXS_REQUEST_TYPE_GROUP_DATA)
|
|
|
|
{
|
|
|
|
GroupDataReq* gdr = new GroupDataReq();
|
|
|
|
req = gdr;
|
|
|
|
}
|
|
|
|
else if(reqType & GXS_REQUEST_TYPE_GROUP_IDS)
|
|
|
|
{
|
|
|
|
GroupIdReq* gir = new GroupIdReq();
|
|
|
|
req = gir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(req == NULL)
|
|
|
|
{
|
2012-11-01 20:45:50 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::requestGroupInfo() request type not recognised, type "
|
2012-10-21 15:45:35 -04:00
|
|
|
<< reqType << std::endl;
|
|
|
|
return false;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
generateToken(token);
|
2014-05-04 08:48:42 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-11-01 20:45:50 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::requestGroupInfo() gets Token: " << token << std::endl;
|
2014-05-04 08:48:42 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setReq(req, token, ansType, opts);
|
|
|
|
storeRequest(req);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RsGxsDataAccess::generateToken(uint32_t &token)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex); /****** LOCKED *****/
|
|
|
|
|
|
|
|
token = mNextToken++;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
|
|
|
|
const RsTokReqOptions &opts, const GxsMsgReq &msgIds)
|
|
|
|
{
|
|
|
|
|
|
|
|
GxsRequest* req = NULL;
|
|
|
|
uint32_t reqType = opts.mReqType;
|
|
|
|
|
|
|
|
// remove all empty grpId entries
|
|
|
|
GxsMsgReq::const_iterator mit = msgIds.begin();
|
|
|
|
std::vector<RsGxsGroupId> toRemove;
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; mit != msgIds.end(); ++mit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
if(mit->second.empty())
|
|
|
|
toRemove.push_back(mit->first);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<RsGxsGroupId>::const_iterator vit = toRemove.begin();
|
|
|
|
|
|
|
|
GxsMsgReq filteredMsgIds = msgIds;
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; vit != toRemove.end(); ++vit)
|
2012-10-21 15:45:35 -04:00
|
|
|
filteredMsgIds.erase(*vit);
|
|
|
|
|
|
|
|
if(reqType & GXS_REQUEST_TYPE_MSG_META)
|
|
|
|
{
|
|
|
|
MsgMetaReq* mmr = new MsgMetaReq();
|
|
|
|
mmr->mMsgIds = filteredMsgIds;
|
|
|
|
req = mmr;
|
|
|
|
|
|
|
|
}else if(reqType & GXS_REQUEST_TYPE_MSG_DATA)
|
|
|
|
{
|
|
|
|
MsgDataReq* mdr = new MsgDataReq();
|
|
|
|
mdr->mMsgIds = filteredMsgIds;
|
|
|
|
req = mdr;
|
|
|
|
|
|
|
|
}else if(reqType & GXS_REQUEST_TYPE_MSG_IDS)
|
|
|
|
{
|
|
|
|
MsgIdReq* mir = new MsgIdReq();
|
|
|
|
mir->mMsgIds = filteredMsgIds;
|
|
|
|
req = mir;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(req == NULL)
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsDataAccess::requestMsgInfo() request type not recognised, type "
|
|
|
|
<< reqType << std::endl;
|
|
|
|
return false;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
generateToken(token);
|
2014-05-04 08:48:42 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::requestMsgInfo() gets Token: " << token << std::endl;
|
2014-05-04 08:48:42 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setReq(req, token, ansType, opts);
|
|
|
|
storeRequest(req);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
|
|
|
|
const RsTokReqOptions &opts, const std::list<RsGxsGroupId>& grpIds)
|
|
|
|
{
|
|
|
|
GxsRequest* req = NULL;
|
|
|
|
uint32_t reqType = opts.mReqType;
|
|
|
|
|
|
|
|
std::list<RsGxsGroupId>::const_iterator lit = grpIds.begin();
|
|
|
|
|
|
|
|
if(reqType & GXS_REQUEST_TYPE_MSG_META)
|
|
|
|
{
|
|
|
|
MsgMetaReq* mmr = new MsgMetaReq();
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; lit != grpIds.end(); ++lit)
|
2012-10-21 15:45:35 -04:00
|
|
|
mmr->mMsgIds[*lit] = std::vector<RsGxsMessageId>();
|
|
|
|
|
|
|
|
req = mmr;
|
|
|
|
}else if(reqType & GXS_REQUEST_TYPE_MSG_DATA)
|
|
|
|
{
|
|
|
|
MsgDataReq* mdr = new MsgDataReq();
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; lit != grpIds.end(); ++lit)
|
2012-10-21 15:45:35 -04:00
|
|
|
mdr->mMsgIds[*lit] = std::vector<RsGxsMessageId>();
|
|
|
|
|
|
|
|
req = mdr;
|
|
|
|
}else if(reqType & GXS_REQUEST_TYPE_MSG_IDS)
|
|
|
|
{
|
|
|
|
MsgIdReq* mir = new MsgIdReq();
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; lit != grpIds.end(); ++lit)
|
2012-10-21 15:45:35 -04:00
|
|
|
mir->mMsgIds[*lit] = std::vector<RsGxsMessageId>();
|
|
|
|
|
|
|
|
req = mir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(req == NULL)
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsDataAccess::requestMsgInfo() request type not recognised, type "
|
|
|
|
<< reqType << std::endl;
|
|
|
|
return false;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
generateToken(token);
|
2014-05-04 08:48:42 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::requestMsgInfo() gets Token: " << token << std::endl;
|
2014-05-04 08:48:42 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setReq(req, token, ansType, opts);
|
|
|
|
storeRequest(req);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-23 10:07:52 -04:00
|
|
|
|
2014-07-16 17:40:57 -04:00
|
|
|
void RsGxsDataAccess::requestServiceStatistic(uint32_t& token)
|
2013-03-23 10:07:52 -04:00
|
|
|
{
|
2014-07-16 17:40:57 -04:00
|
|
|
ServiceStatisticRequest* req = new ServiceStatisticRequest();
|
2013-03-23 10:07:52 -04:00
|
|
|
|
2014-07-16 17:40:57 -04:00
|
|
|
generateToken(token);
|
|
|
|
|
2014-07-20 07:21:06 -04:00
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_SERVICE_STATS;
|
|
|
|
setReq(req, token, 0, opts);
|
2014-07-16 17:40:57 -04:00
|
|
|
storeRequest(req);
|
2013-03-23 10:07:52 -04:00
|
|
|
}
|
|
|
|
|
2014-07-16 17:40:57 -04:00
|
|
|
void RsGxsDataAccess::requestGroupStatistic(uint32_t& token, const RsGxsGroupId& grpId)
|
2013-03-23 10:07:52 -04:00
|
|
|
{
|
2014-07-16 17:40:57 -04:00
|
|
|
GroupStatisticRequest* req = new GroupStatisticRequest();
|
|
|
|
req->mGrpId = grpId;
|
2013-03-23 10:07:52 -04:00
|
|
|
|
2014-07-16 17:40:57 -04:00
|
|
|
generateToken(token);
|
|
|
|
|
2014-07-20 07:21:06 -04:00
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_STATS;
|
|
|
|
setReq(req, token, 0, opts);
|
2014-07-16 17:40:57 -04:00
|
|
|
storeRequest(req);
|
2013-03-23 10:07:52 -04:00
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool RsGxsDataAccess::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts,
|
2012-11-13 17:36:06 -05:00
|
|
|
const std::vector<RsGxsGrpMsgIdPair> &msgIds)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
MsgRelatedInfoReq* req = new MsgRelatedInfoReq();
|
2012-11-13 17:36:06 -05:00
|
|
|
req->mMsgIds = msgIds;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
generateToken(token);
|
|
|
|
|
|
|
|
setReq(req, token, ansType, opts);
|
|
|
|
storeRequest(req);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RsGxsDataAccess::setReq(GxsRequest* req, const uint32_t& token, const uint32_t& ansType, const RsTokReqOptions& opts) const
|
|
|
|
{
|
|
|
|
req->token = token;
|
|
|
|
req->ansType = ansType;
|
|
|
|
req->Options = opts;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
void RsGxsDataAccess::storeRequest(GxsRequest* req)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex); /****** LOCKED *****/
|
|
|
|
|
|
|
|
req->status = GXS_REQUEST_V2_STATUS_PENDING;
|
2012-12-15 19:43:15 -05:00
|
|
|
req->reqTime = time(NULL);
|
2012-10-21 15:45:35 -04:00
|
|
|
mRequests[req->token] = req;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t RsGxsDataAccess::requestStatus(uint32_t token)
|
|
|
|
{
|
|
|
|
uint32_t status;
|
|
|
|
uint32_t reqtype;
|
|
|
|
uint32_t anstype;
|
|
|
|
time_t ts;
|
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
// first check public tokens
|
|
|
|
if(mPublicToken.find(token) != mPublicToken.end())
|
|
|
|
return mPublicToken[token];
|
|
|
|
}
|
2014-11-26 15:33:29 -05:00
|
|
|
if(!checkRequestStatus(token, status, reqtype, anstype, ts))
|
|
|
|
return RsTokenService::GXS_REQUEST_V2_STATUS_FAILED ;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-08-13 13:44:27 -04:00
|
|
|
bool RsGxsDataAccess::cancelRequest(const uint32_t& token)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex); /****** LOCKED *****/
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2015-08-13 13:44:27 -04:00
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
if (!req)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2015-08-13 13:44:27 -04:00
|
|
|
req->status = GXS_REQUEST_V2_STATUS_CANCELLED;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2015-08-13 13:44:27 -04:00
|
|
|
return true;
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::clearRequest(const uint32_t& token)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex); /****** LOCKED *****/
|
|
|
|
|
|
|
|
std::map<uint32_t, GxsRequest*>::iterator it;
|
|
|
|
|
|
|
|
it = mRequests.find(token);
|
|
|
|
if (it == mRequests.end())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete it->second;
|
2015-08-13 13:44:27 -04:00
|
|
|
mRequests.erase(it);
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list<RsGxsGrpMetaData*>& groupInfo)
|
|
|
|
{
|
|
|
|
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
|
|
|
std::cerr << "RsGxsDataAccess::getGroupSummary() Unable to retrieve group summary" << std::endl;
|
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
|
|
|
GroupMetaReq* gmreq = dynamic_cast<GroupMetaReq*>(req);
|
|
|
|
|
|
|
|
if(gmreq)
|
|
|
|
{
|
|
|
|
groupInfo = gmreq->mGroupMetaData;
|
2015-01-25 18:22:58 -05:00
|
|
|
gmreq->mGroupMetaData.clear();
|
2012-10-21 15:45:35 -04:00
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getGroupData(const uint32_t& token, std::list<RsNxsGrp*>& grpData)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
|
|
|
std::cerr << "RsGxsDataAccess::getGroupData() Unable to retrieve group data" << std::endl;
|
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
|
|
|
GroupDataReq* gmreq = dynamic_cast<GroupDataReq*>(req);
|
|
|
|
|
|
|
|
if(gmreq)
|
|
|
|
{
|
|
|
|
grpData = gmreq->mGroupData;
|
2015-01-25 18:22:58 -05:00
|
|
|
gmreq->mGroupData.clear();
|
2012-10-21 15:45:35 -04:00
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getMsgData(const uint32_t& token, NxsMsgDataResult& msgData)
|
|
|
|
{
|
|
|
|
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgData() Unable to retrieve group data" << std::endl;
|
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
MsgDataReq* mdreq = dynamic_cast<MsgDataReq*>(req);
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
if(mdreq)
|
|
|
|
{
|
2012-11-13 17:36:06 -05:00
|
|
|
msgData = mdreq->mMsgData;
|
2015-01-25 18:22:58 -05:00
|
|
|
mdreq->mMsgData.clear();
|
2012-11-13 17:36:06 -05:00
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
bool RsGxsDataAccess::getMsgRelatedData(const uint32_t &token, NxsMsgRelatedDataResult &msgData)
|
|
|
|
{
|
|
|
|
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedData() Unable to retrieve group data" << std::endl;
|
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
|
|
|
MsgRelatedInfoReq* mrireq = dynamic_cast<MsgRelatedInfoReq*>(req);
|
|
|
|
|
|
|
|
if(req->Options.mReqType != GXS_REQUEST_TYPE_MSG_RELATED_DATA)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(mrireq)
|
|
|
|
{
|
|
|
|
msgData = mrireq->mMsgDataResult;
|
2015-01-25 18:22:58 -05:00
|
|
|
mrireq->mMsgDataResult.clear();
|
2012-11-13 17:36:06 -05:00
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedData() Req found, failed caste" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedData() Req not ready" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool RsGxsDataAccess::getMsgSummary(const uint32_t& token, GxsMsgMetaResult& msgInfo)
|
|
|
|
{
|
|
|
|
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgSummary() Unable to retrieve group data" << std::endl;
|
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
|
|
|
MsgMetaReq* mmreq = dynamic_cast<MsgMetaReq*>(req);
|
|
|
|
|
|
|
|
if(mmreq)
|
|
|
|
{
|
2012-11-13 17:36:06 -05:00
|
|
|
msgInfo = mmreq->mMsgMetaData;
|
2015-01-25 18:22:58 -05:00
|
|
|
mmreq->mMsgMetaData.clear();
|
2012-11-13 17:36:06 -05:00
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
bool RsGxsDataAccess::getMsgRelatedSummary(const uint32_t &token, MsgRelatedMetaResult &msgMeta)
|
|
|
|
{
|
|
|
|
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedSummary() Unable to retrieve message summary" << std::endl;
|
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
|
|
|
if(req->Options.mReqType != GXS_REQUEST_TYPE_MSG_RELATED_META)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MsgRelatedInfoReq* mrireq = dynamic_cast<MsgRelatedInfoReq*>(req);
|
|
|
|
|
|
|
|
if(mrireq)
|
|
|
|
{
|
|
|
|
msgMeta = mrireq->mMsgMetaResult;
|
2015-01-25 18:22:58 -05:00
|
|
|
mrireq->mMsgMetaResult.clear();
|
2012-11-13 17:36:06 -05:00
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedSummary() Req found, failed caste" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedSummary() Req not ready" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult &msgIds)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Unable to retrieve message data" << std::endl;
|
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
|
|
|
if(req->Options.mReqType != GXS_REQUEST_TYPE_MSG_RELATED_IDS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MsgRelatedInfoReq* mrireq = dynamic_cast<MsgRelatedInfoReq*>(req);
|
|
|
|
|
|
|
|
if(mrireq)
|
|
|
|
{
|
|
|
|
msgIds = mrireq->mMsgIdResult;
|
2015-01-25 18:22:58 -05:00
|
|
|
mrireq->mMsgIdResult.clear();
|
2012-11-13 17:36:06 -05:00
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Req found, failed caste" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Req not ready" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool RsGxsDataAccess::getMsgList(const uint32_t& token, GxsMsgIdResult& msgIds)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgList() Unable to retrieve msg Ids" << std::endl;
|
2012-10-21 15:45:35 -04:00
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
MsgIdReq* mireq = dynamic_cast<MsgIdReq*>(req);
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
if(mireq)
|
|
|
|
{
|
|
|
|
msgIds = mireq->mMsgIdResult;
|
2015-01-25 18:22:58 -05:00
|
|
|
mireq->mMsgIdResult.clear();
|
2012-10-21 15:45:35 -04:00
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getGroupList(const uint32_t& token, std::list<RsGxsGroupId>& groupIds)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
std::cerr << "RsGxsDataAccess::getGroupList() Unable to retrieve group Ids,"
|
2012-10-21 15:45:35 -04:00
|
|
|
"\nRequest does not exist" << std::endl;
|
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
|
|
|
GroupIdReq* gireq = dynamic_cast<GroupIdReq*>(req);
|
|
|
|
|
|
|
|
if(gireq)
|
|
|
|
{
|
|
|
|
groupIds = gireq->mGroupIdResult;
|
2015-01-25 18:22:58 -05:00
|
|
|
gireq->mGroupIdResult.clear();
|
2012-10-21 15:45:35 -04:00
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
GxsRequest* RsGxsDataAccess::locked_retrieveRequest(const uint32_t& token)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(mRequests.find(token) == mRequests.end()) return NULL;
|
|
|
|
|
|
|
|
GxsRequest* req = mRequests[token];
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2015-01-25 07:29:33 -05:00
|
|
|
#define MAX_REQUEST_AGE 120 // 2 minutes
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
void RsGxsDataAccess::processRequests()
|
|
|
|
{
|
|
|
|
std::list<uint32_t> toClear;
|
|
|
|
time_t now = time(NULL);
|
2015-08-13 13:44:27 -04:00
|
|
|
std::map<uint32_t, GxsRequest*>::iterator it;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex); /******* LOCKED *******/
|
|
|
|
|
2015-08-13 13:44:27 -04:00
|
|
|
// process status of the requests
|
|
|
|
for (it = mRequests.begin(); it != mRequests.end(); ++it)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
GxsRequest* req = it->second;
|
|
|
|
|
2015-08-13 13:44:27 -04:00
|
|
|
switch (req->status)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
2015-08-13 13:44:27 -04:00
|
|
|
case GXS_REQUEST_V2_STATUS_PENDING:
|
|
|
|
// process request later
|
|
|
|
break;
|
|
|
|
case GXS_REQUEST_V2_STATUS_PARTIAL:
|
|
|
|
// should not happen
|
|
|
|
req->status = GXS_REQUEST_V2_STATUS_COMPLETE;
|
|
|
|
break;
|
|
|
|
case GXS_REQUEST_V2_STATUS_DONE:
|
2014-05-04 08:48:42 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2015-08-13 13:44:27 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::processrequests() Clearing Done Request Token: " << req->token;
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << std::endl;
|
2014-05-04 08:48:42 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
toClear.push_back(req->token);
|
2015-08-13 13:44:27 -04:00
|
|
|
break;
|
|
|
|
case GXS_REQUEST_V2_STATUS_CANCELLED:
|
2014-05-04 08:48:42 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2015-08-13 13:44:27 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::processrequests() Clearing Cancelled Request Token: " << req->token;
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << std::endl;
|
2014-05-04 08:48:42 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
toClear.push_back(req->token);
|
2015-08-13 13:44:27 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (now - req->reqTime > MAX_REQUEST_AGE)
|
|
|
|
{
|
|
|
|
#ifdef DATA_DEBUG
|
|
|
|
std::cerr << "RsGxsDataAccess::processrequests() Clearing Old Request Token: " << req->token;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
toClear.push_back(req->token);
|
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // END OF MUTEX.
|
|
|
|
|
2015-08-13 13:44:27 -04:00
|
|
|
// clear requests
|
|
|
|
std::list<uint32_t>::iterator cit;
|
|
|
|
for (cit = toClear.begin(); cit != toClear.end(); ++cit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
clearRequest(*cit);
|
|
|
|
}
|
|
|
|
|
2015-08-13 13:44:27 -04:00
|
|
|
// process requests
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
GxsRequest* req = NULL;
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex); /******* LOCKED *******/
|
|
|
|
|
|
|
|
// get the first pending request
|
|
|
|
for (it = mRequests.begin(); it != mRequests.end(); ++it)
|
|
|
|
{
|
|
|
|
GxsRequest* reqCheck = it->second;
|
|
|
|
if (reqCheck->status == GXS_REQUEST_V2_STATUS_PENDING)
|
|
|
|
{
|
|
|
|
req = reqCheck;
|
|
|
|
req->status = GXS_REQUEST_V2_STATUS_PARTIAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // END OF MUTEX.
|
|
|
|
|
|
|
|
if (!req) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupMetaReq* gmr;
|
|
|
|
GroupDataReq* gdr;
|
|
|
|
GroupIdReq* gir;
|
|
|
|
|
|
|
|
MsgMetaReq* mmr;
|
|
|
|
MsgDataReq* mdr;
|
|
|
|
MsgIdReq* mir;
|
|
|
|
MsgRelatedInfoReq* mri;
|
|
|
|
GroupStatisticRequest* gsr;
|
|
|
|
ServiceStatisticRequest* ssr;
|
|
|
|
|
|
|
|
#ifdef DATA_DEBUG
|
|
|
|
std::cerr << "RsGxsDataAccess::processRequests() Processing Token: " << req->token << " Status: "
|
|
|
|
<< req->status << " ReqType: " << req->reqType << " Age: "
|
|
|
|
<< now - req->reqTime << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* PROCESS REQUEST! */
|
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
if((gmr = dynamic_cast<GroupMetaReq*>(req)) != NULL)
|
|
|
|
{
|
|
|
|
ok = getGroupSummary(gmr);
|
|
|
|
}
|
|
|
|
else if((gdr = dynamic_cast<GroupDataReq*>(req)) != NULL)
|
|
|
|
{
|
|
|
|
ok = getGroupData(gdr);
|
|
|
|
}
|
|
|
|
else if((gir = dynamic_cast<GroupIdReq*>(req)) != NULL)
|
|
|
|
{
|
|
|
|
ok = getGroupList(gir);
|
|
|
|
}
|
|
|
|
else if((mmr = dynamic_cast<MsgMetaReq*>(req)) != NULL)
|
|
|
|
{
|
|
|
|
ok = getMsgSummary(mmr);
|
|
|
|
}
|
|
|
|
else if((mdr = dynamic_cast<MsgDataReq*>(req)) != NULL)
|
|
|
|
{
|
|
|
|
ok = getMsgData(mdr);
|
|
|
|
}
|
|
|
|
else if((mir = dynamic_cast<MsgIdReq*>(req)) != NULL)
|
|
|
|
{
|
|
|
|
ok = getMsgList(mir);
|
|
|
|
}
|
|
|
|
else if((mri = dynamic_cast<MsgRelatedInfoReq*>(req)) != NULL)
|
|
|
|
{
|
|
|
|
ok = getMsgRelatedInfo(mri);
|
|
|
|
}
|
|
|
|
else if((gsr = dynamic_cast<GroupStatisticRequest*>(req)) != NULL)
|
|
|
|
{
|
|
|
|
ok = getGroupStatistic(gsr);
|
|
|
|
}
|
|
|
|
else if((ssr = dynamic_cast<ServiceStatisticRequest*>(req)) != NULL)
|
|
|
|
{
|
|
|
|
ok = getServiceStatistic(ssr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "RsGxsDataAccess::processRequests() Failed to process request, token: "
|
|
|
|
<< req->token << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex); /******* LOCKED *******/
|
|
|
|
if (req->status == GXS_REQUEST_V2_STATUS_PARTIAL)
|
|
|
|
{
|
|
|
|
req->status = ok ? GXS_REQUEST_V2_STATUS_COMPLETE : GXS_REQUEST_V2_STATUS_FAILED;
|
|
|
|
}
|
|
|
|
} // END OF MUTEX.
|
|
|
|
}
|
2014-07-16 17:40:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getGroupStatistic(const uint32_t &token, GxsGroupStatistic &grpStatistic)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
|
|
|
std::cerr << "RsGxsDataAccess::getGroupStatistic() Unable to retrieve grp stats" << std::endl;
|
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
|
|
|
GroupStatisticRequest* gsreq = dynamic_cast<GroupStatisticRequest*>(req);
|
|
|
|
|
|
|
|
if(gsreq)
|
|
|
|
{
|
|
|
|
grpStatistic = gsreq->mGroupStatistic;
|
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
std::cerr << "RsGxsDataAccess::getGroupStatistic() Req found, failed caste" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
std::cerr << "RsGxsDataAccess::getGroupStatistic() Req not ready" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getServiceStatistic(const uint32_t &token, GxsServiceStatistic &servStatistic)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req == NULL){
|
|
|
|
|
2014-07-20 07:21:06 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getServiceStatistic() Unable to retrieve service stats" << std::endl;
|
2014-07-16 17:40:57 -04:00
|
|
|
return false;
|
|
|
|
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
|
|
|
|
|
|
|
ServiceStatisticRequest* ssreq = dynamic_cast<ServiceStatisticRequest*>(req);
|
|
|
|
|
|
|
|
if(ssreq)
|
|
|
|
{
|
|
|
|
servStatistic = ssreq->mServiceStatistic;
|
|
|
|
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
std::cerr << "RsGxsDataAccess::getServiceStatistic() Req found, failed caste" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
std::cerr << "RsGxsDataAccess::getServiceStatistic() Req not ready" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getGroupData(GroupDataReq* req)
|
|
|
|
{
|
|
|
|
std::map<RsGxsGroupId, RsNxsGrp*> grpData;
|
2012-12-02 14:40:17 -05:00
|
|
|
std::list<RsGxsGroupId> grpIdsOut;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-12-02 14:40:17 -05:00
|
|
|
getGroupList(req->mGroupIds, req->Options, grpIdsOut);
|
|
|
|
|
|
|
|
if(grpIdsOut.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
std::list<RsGxsGroupId>::iterator lit = grpIdsOut.begin(),
|
|
|
|
lit_end = grpIdsOut.end();
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; lit != lit_end; ++lit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
grpData[*lit] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = mDataStore->retrieveNxsGrps(grpData, true, true);
|
|
|
|
|
|
|
|
std::map<RsGxsGroupId, RsNxsGrp*>::iterator mit = grpData.begin();
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; mit != grpData.end(); ++mit)
|
2012-10-21 15:45:35 -04:00
|
|
|
req->mGroupData.push_back(mit->second);
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getGroupSummary(GroupMetaReq* req)
|
|
|
|
{
|
|
|
|
|
|
|
|
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta;
|
|
|
|
|
2012-12-02 14:40:17 -05:00
|
|
|
std::list<RsGxsGroupId> grpIdsOut;
|
|
|
|
|
|
|
|
getGroupList(req->mGroupIds, req->Options, grpIdsOut);
|
|
|
|
|
|
|
|
if(grpIdsOut.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
std::list<RsGxsGroupId>::const_iterator lit = grpIdsOut.begin();
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; lit != grpIdsOut.end(); ++lit)
|
2012-10-21 15:45:35 -04:00
|
|
|
grpMeta[*lit] = NULL;
|
|
|
|
|
|
|
|
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
|
|
|
|
|
|
|
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.begin();
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; mit != grpMeta.end(); ++mit)
|
2012-10-21 15:45:35 -04:00
|
|
|
req->mGroupMetaData.push_back(mit->second);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getGroupList(GroupIdReq* req)
|
|
|
|
{
|
2012-12-02 14:40:17 -05:00
|
|
|
getGroupList(req->mGroupIds, req->Options, req->mGroupIdResult);
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-12-02 14:40:17 -05:00
|
|
|
return true;
|
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-12-02 14:40:17 -05:00
|
|
|
bool RsGxsDataAccess::getGroupList(const std::list<RsGxsGroupId>& grpIdsIn, const RsTokReqOptions& opts, std::list<RsGxsGroupId>& grpIdsOut)
|
|
|
|
{
|
|
|
|
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-12-02 14:40:17 -05:00
|
|
|
std::list<RsGxsGroupId>::const_iterator lit = grpIdsIn.begin();
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; lit != grpIdsIn.end(); ++lit)
|
2012-12-02 14:40:17 -05:00
|
|
|
grpMeta[*lit] = NULL;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-12-02 14:40:17 -05:00
|
|
|
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.begin();
|
2012-12-02 14:40:17 -05:00
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; mit != grpMeta.end(); ++mit)
|
2012-12-02 14:40:17 -05:00
|
|
|
{
|
|
|
|
grpIdsOut.push_back(mit->first);
|
|
|
|
}
|
|
|
|
|
|
|
|
filterGrpList(grpIdsOut, opts, grpMeta);
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
|
2012-12-02 14:40:17 -05:00
|
|
|
{
|
|
|
|
delete mit->second; // so wasteful!!
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getMsgData(MsgDataReq* req)
|
|
|
|
{
|
|
|
|
GxsMsgResult result;
|
|
|
|
|
|
|
|
GxsMsgReq msgIdOut;
|
|
|
|
|
|
|
|
// filter based on options
|
|
|
|
getMsgList(req->mMsgIds, req->Options, msgIdOut);
|
|
|
|
|
|
|
|
mDataStore->retrieveNxsMsgs(msgIdOut, result, true, true);
|
|
|
|
|
|
|
|
req->mMsgData = result;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getMsgSummary(MsgMetaReq* req)
|
|
|
|
{
|
|
|
|
GxsMsgMetaResult result;
|
|
|
|
|
|
|
|
GxsMsgReq msgIdOut;
|
|
|
|
|
|
|
|
// filter based on options
|
|
|
|
getMsgList(req->mMsgIds, req->Options, msgIdOut);
|
|
|
|
|
|
|
|
mDataStore->retrieveGxsMsgMetaData(msgIdOut, result);
|
|
|
|
req->mMsgMetaData = result;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getMsgList(const GxsMsgReq& msgIds, const RsTokReqOptions& opts, GxsMsgReq& msgIdsOut)
|
|
|
|
{
|
|
|
|
GxsMsgMetaResult result;
|
|
|
|
|
|
|
|
mDataStore->retrieveGxsMsgMetaData(msgIds, result);
|
|
|
|
|
|
|
|
/* CASEs this handles.
|
|
|
|
* Input is groupList + Flags.
|
|
|
|
* 1) No Flags => All Messages in those Groups.
|
|
|
|
*
|
|
|
|
*/
|
2015-06-16 15:11:07 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgList()";
|
|
|
|
std::cerr << std::endl;
|
2015-06-16 15:11:07 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
bool onlyOrigMsgs = false;
|
|
|
|
bool onlyLatestMsgs = false;
|
|
|
|
bool onlyThreadHeadMsgs = false;
|
|
|
|
|
|
|
|
// Can only choose one of these two.
|
|
|
|
if (opts.mOptions & RS_TOKREQOPT_MSG_ORIGMSG)
|
|
|
|
{
|
2015-06-16 15:11:07 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgList() MSG_ORIGMSG";
|
|
|
|
std::cerr << std::endl;
|
2015-06-16 15:11:07 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
onlyOrigMsgs = true;
|
|
|
|
}
|
|
|
|
else if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST)
|
|
|
|
{
|
2015-06-16 15:11:07 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgList() MSG_LATEST";
|
|
|
|
std::cerr << std::endl;
|
2015-06-16 15:11:07 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
onlyLatestMsgs = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.mOptions & RS_TOKREQOPT_MSG_THREAD)
|
|
|
|
{
|
2015-06-16 15:11:07 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgList() MSG_THREAD";
|
|
|
|
std::cerr << std::endl;
|
2015-06-16 15:11:07 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
onlyThreadHeadMsgs = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
GxsMsgMetaResult::iterator meta_it;
|
|
|
|
MsgMetaFilter metaFilter;
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(meta_it = result.begin(); meta_it != result.end(); ++meta_it)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
const RsGxsGroupId& grpId = meta_it->first;
|
|
|
|
|
|
|
|
metaFilter[grpId] = std::map<RsGxsMessageId, RsGxsMsgMetaData*>();
|
|
|
|
|
|
|
|
const std::vector<RsGxsMsgMetaData*>& metaV = meta_it->second;
|
|
|
|
if (onlyLatestMsgs) // THIS ONE IS HARD -> LOTS OF COMP.
|
|
|
|
{
|
|
|
|
std::vector<RsGxsMsgMetaData*>::const_iterator vit = metaV.begin();
|
|
|
|
|
|
|
|
// RUN THROUGH ALL MSGS... in map origId -> TS.
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsGxsMessageId, std::pair<RsGxsMessageId, time_t> > origMsgTs;
|
|
|
|
std::map<RsGxsMessageId, std::pair<RsGxsMessageId, time_t> >::iterator oit;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; vit != metaV.end(); ++vit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
RsGxsMsgMetaData* msgMeta = *vit;
|
|
|
|
|
|
|
|
/* if we are grabbing thread Head... then parentId == empty. */
|
|
|
|
if (onlyThreadHeadMsgs)
|
|
|
|
{
|
2014-03-17 16:56:06 -04:00
|
|
|
if (!(msgMeta->mParentId.isNull()))
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
oit = origMsgTs.find(msgMeta->mOrigMsgId);
|
|
|
|
bool addMsg = false;
|
|
|
|
if (oit == origMsgTs.end())
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgList() Found New OrigMsgId: ";
|
|
|
|
std::cerr << msgMeta->mOrigMsgId;
|
|
|
|
std::cerr << " MsgId: " << msgMeta->mMsgId;
|
|
|
|
std::cerr << " TS: " << msgMeta->mPublishTs;
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
addMsg = true;
|
|
|
|
}
|
|
|
|
// check timestamps.
|
|
|
|
else if (oit->second.second < msgMeta->mPublishTs)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgList() Found Later Msg. OrigMsgId: ";
|
|
|
|
std::cerr << msgMeta->mOrigMsgId;
|
|
|
|
std::cerr << " MsgId: " << msgMeta->mMsgId;
|
|
|
|
std::cerr << " TS: " << msgMeta->mPublishTs;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
addMsg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addMsg)
|
|
|
|
{
|
|
|
|
// add as latest. (overwriting if necessary)
|
|
|
|
origMsgTs[msgMeta->mOrigMsgId] = std::make_pair(msgMeta->mMsgId, msgMeta->mPublishTs);
|
|
|
|
metaFilter[grpId].insert(std::make_pair(msgMeta->mMsgId, msgMeta));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the discovered Latest Msgs.
|
2014-10-24 18:07:26 -04:00
|
|
|
for(oit = origMsgTs.begin(); oit != origMsgTs.end(); ++oit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
msgIdsOut[grpId].push_back(oit->second.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else // ALL OTHER CASES.
|
|
|
|
{
|
|
|
|
std::vector<RsGxsMsgMetaData*>::const_iterator vit = metaV.begin();
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; vit != metaV.end(); ++vit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
RsGxsMsgMetaData* msgMeta = *vit;
|
|
|
|
bool add = false;
|
|
|
|
|
|
|
|
/* if we are grabbing thread Head... then parentId == empty. */
|
|
|
|
if (onlyThreadHeadMsgs)
|
|
|
|
{
|
2014-03-17 16:56:06 -04:00
|
|
|
if (!(msgMeta->mParentId.isNull()))
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (onlyOrigMsgs)
|
|
|
|
{
|
|
|
|
if (msgMeta->mMsgId == msgMeta->mOrigMsgId)
|
|
|
|
{
|
|
|
|
add = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
add = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add)
|
|
|
|
{
|
|
|
|
msgIdsOut[grpId].push_back(msgMeta->mMsgId);
|
|
|
|
metaFilter[grpId].insert(std::make_pair(msgMeta->mMsgId, msgMeta));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filterMsgList(msgIdsOut, opts, metaFilter);
|
|
|
|
|
|
|
|
metaFilter.clear();
|
|
|
|
|
|
|
|
// delete meta data
|
|
|
|
cleanseMsgMetaMap(result);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
|
|
|
|
{
|
|
|
|
/* CASEs this handles.
|
|
|
|
* Input is msgList + Flags.
|
|
|
|
* 1) No Flags => return nothing
|
|
|
|
*/
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList()";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
const RsTokReqOptions& opts = req->Options;
|
|
|
|
|
|
|
|
bool onlyLatestMsgs = false;
|
|
|
|
bool onlyAllVersions = false;
|
|
|
|
bool onlyChildMsgs = false;
|
|
|
|
bool onlyThreadMsgs = false;
|
|
|
|
|
|
|
|
if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() MSG_LATEST";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
onlyLatestMsgs = true;
|
|
|
|
}
|
|
|
|
else if (opts.mOptions & RS_TOKREQOPT_MSG_VERSIONS)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() MSG_VERSIONS";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
onlyAllVersions = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.mOptions & RS_TOKREQOPT_MSG_PARENT)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() MSG_PARENTS";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
onlyChildMsgs = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.mOptions & RS_TOKREQOPT_MSG_THREAD)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() MSG_THREAD";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
onlyThreadMsgs = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onlyAllVersions && onlyChildMsgs)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() ERROR Incompatible FLAGS (VERSIONS & PARENT)";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onlyAllVersions && onlyThreadMsgs)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() ERROR Incompatible FLAGS (VERSIONS & THREAD)";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!onlyLatestMsgs) && onlyChildMsgs)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() ERROR Incompatible FLAGS (!LATEST & PARENT)";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!onlyLatestMsgs) && onlyThreadMsgs)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() ERROR Incompatible FLAGS (!LATEST & THREAD)";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onlyChildMsgs && onlyThreadMsgs)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() ERROR Incompatible FLAGS (PARENT & THREAD)";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* FALL BACK OPTION */
|
|
|
|
if ((!onlyLatestMsgs) && (!onlyAllVersions) && (!onlyChildMsgs) && (!onlyThreadMsgs))
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-10-21 15:45:35 -04:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() FALLBACK -> NO FLAGS -> SIMPLY RETURN nothing";
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
std::vector<RsGxsGrpMsgIdPair>::iterator vit_msgIds = req->mMsgIds.begin();
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; vit_msgIds != req->mMsgIds.end(); ++vit_msgIds)
|
2012-11-13 17:36:06 -05:00
|
|
|
{
|
|
|
|
MsgMetaFilter filterMap;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
const RsGxsGrpMsgIdPair& grpMsgIdPair = *vit_msgIds;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
// get meta data for all in group
|
|
|
|
GxsMsgMetaResult result;
|
|
|
|
GxsMsgReq msgIds;
|
|
|
|
msgIds.insert(std::make_pair(grpMsgIdPair.first, std::vector<RsGxsMessageId>()));
|
|
|
|
mDataStore->retrieveGxsMsgMetaData(msgIds, result);
|
|
|
|
std::vector<RsGxsMsgMetaData*>& metaV = result[grpMsgIdPair.first];
|
|
|
|
std::vector<RsGxsMsgMetaData*>::iterator vit_meta;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
// msg id to relate to
|
|
|
|
const RsGxsMessageId& msgId = grpMsgIdPair.second;
|
|
|
|
const RsGxsGroupId& grpId = grpMsgIdPair.first;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
std::vector<RsGxsMessageId> outMsgIds;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
RsGxsMsgMetaData* origMeta = NULL;
|
2014-10-24 18:07:26 -04:00
|
|
|
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
2012-11-13 17:36:06 -05:00
|
|
|
RsGxsMsgMetaData* meta = *vit_meta;
|
|
|
|
|
|
|
|
if(msgId == meta->mMsgId)
|
|
|
|
{
|
|
|
|
origMeta = meta;
|
|
|
|
break;
|
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
if(!origMeta)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-11-13 17:36:06 -05:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedInfo(): Cannot find meta of msgId (to relate to)!"
|
|
|
|
<< std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-11-13 17:36:06 -05:00
|
|
|
cleanseMsgMetaMap(result);
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
const RsGxsMessageId& origMsgId = origMeta->mOrigMsgId;
|
|
|
|
std::map<RsGxsMessageId, RsGxsMsgMetaData*>& metaMap = filterMap[grpId];
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
if (onlyLatestMsgs)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
2012-11-13 17:36:06 -05:00
|
|
|
if (onlyChildMsgs || onlyThreadMsgs)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
2012-11-13 17:36:06 -05:00
|
|
|
// RUN THROUGH ALL MSGS... in map origId -> TS.
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsGxsMessageId, std::pair<RsGxsMessageId, time_t> > origMsgTs;
|
|
|
|
std::map<RsGxsMessageId, std::pair<RsGxsMessageId, time_t> >::iterator oit;
|
2014-10-24 18:07:26 -04:00
|
|
|
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
2012-11-13 17:36:06 -05:00
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
RsGxsMsgMetaData* meta = *vit_meta;
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
// skip msgs that aren't children.
|
|
|
|
if (onlyChildMsgs)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
2012-11-13 17:36:06 -05:00
|
|
|
if (meta->mParentId != origMsgId)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
2012-11-13 17:36:06 -05:00
|
|
|
else /* onlyThreadMsgs */
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
2012-11-13 17:36:06 -05:00
|
|
|
if (meta->mThreadId != msgId)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
oit = origMsgTs.find(meta->mOrigMsgId);
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
bool addMsg = false;
|
|
|
|
if (oit == origMsgTs.end())
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-11-13 17:36:06 -05:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Found New OrigMsgId: ";
|
|
|
|
std::cerr << meta->mOrigMsgId;
|
|
|
|
std::cerr << " MsgId: " << meta->mMsgId;
|
|
|
|
std::cerr << " TS: " << meta->mPublishTs;
|
|
|
|
std::cerr << std::endl;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
addMsg = true;
|
|
|
|
}
|
|
|
|
// check timestamps.
|
|
|
|
else if (oit->second.second < meta->mPublishTs)
|
|
|
|
{
|
2014-09-16 15:53:23 -04:00
|
|
|
#ifdef DATA_DEBUG
|
2012-11-13 17:36:06 -05:00
|
|
|
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Found Later Msg. OrigMsgId: ";
|
|
|
|
std::cerr << meta->mOrigMsgId;
|
|
|
|
std::cerr << " MsgId: " << meta->mMsgId;
|
|
|
|
std::cerr << " TS: " << meta->mPublishTs;
|
2014-09-16 15:53:23 -04:00
|
|
|
#endif
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
addMsg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addMsg)
|
|
|
|
{
|
|
|
|
// add as latest. (overwriting if necessary)
|
|
|
|
origMsgTs[meta->mOrigMsgId] = std::make_pair(meta->mMsgId, meta->mPublishTs);
|
2012-11-17 13:45:14 -05:00
|
|
|
metaMap.insert(std::make_pair(meta->mMsgId, meta));
|
2012-11-13 17:36:06 -05:00
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
// Add the discovered Latest Msgs.
|
2014-10-24 18:07:26 -04:00
|
|
|
for(oit = origMsgTs.begin(); oit != origMsgTs.end(); ++oit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
2012-11-13 17:36:06 -05:00
|
|
|
outMsgIds.push_back(oit->second.first);
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
}
|
2012-11-13 17:36:06 -05:00
|
|
|
else
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
2012-11-13 17:36:06 -05:00
|
|
|
|
|
|
|
/* first guess is potentially better than Orig (can't be worse!) */
|
|
|
|
time_t latestTs = 0;
|
|
|
|
RsGxsMessageId latestMsgId;
|
|
|
|
RsGxsMsgMetaData* latestMeta;
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
2012-11-13 17:36:06 -05:00
|
|
|
{
|
|
|
|
RsGxsMsgMetaData* meta = *vit_meta;
|
|
|
|
|
|
|
|
if (meta->mOrigMsgId == origMsgId)
|
|
|
|
{
|
|
|
|
if (meta->mPublishTs > latestTs)
|
|
|
|
{
|
|
|
|
latestTs = meta->mPublishTs;
|
|
|
|
latestMsgId = meta->mMsgId;
|
|
|
|
latestMeta = meta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
outMsgIds.push_back(latestMsgId);
|
|
|
|
metaMap.insert(std::make_pair(latestMsgId, latestMeta));
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
}
|
2012-11-13 17:36:06 -05:00
|
|
|
else if (onlyAllVersions)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
2014-10-24 18:07:26 -04:00
|
|
|
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
RsGxsMsgMetaData* meta = *vit_meta;
|
|
|
|
|
|
|
|
if (meta->mOrigMsgId == origMsgId)
|
|
|
|
{
|
2012-11-13 17:36:06 -05:00
|
|
|
outMsgIds.push_back(meta->mMsgId);
|
|
|
|
metaMap.insert(std::make_pair(meta->mMsgId, meta));
|
2012-10-21 15:45:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
GxsMsgIdResult filteredOutMsgIds;
|
|
|
|
filteredOutMsgIds[grpId] = outMsgIds;
|
|
|
|
filterMsgList(filteredOutMsgIds, opts, filterMap);
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-17 13:45:14 -05:00
|
|
|
if(!filteredOutMsgIds[grpId].empty())
|
2012-11-13 17:36:06 -05:00
|
|
|
{
|
2012-11-15 18:09:56 -05:00
|
|
|
if(req->Options.mReqType == GXS_REQUEST_TYPE_MSG_RELATED_IDS)
|
|
|
|
{
|
|
|
|
req->mMsgIdResult[grpMsgIdPair] = filteredOutMsgIds[grpId];
|
|
|
|
}
|
|
|
|
else if(req->Options.mReqType == GXS_REQUEST_TYPE_MSG_RELATED_META)
|
|
|
|
{
|
|
|
|
GxsMsgMetaResult metaResult;
|
|
|
|
mDataStore->retrieveGxsMsgMetaData(filteredOutMsgIds, metaResult);
|
|
|
|
req->mMsgMetaResult[grpMsgIdPair] = metaResult[grpId];
|
|
|
|
}
|
|
|
|
else if(req->Options.mReqType == GXS_REQUEST_TYPE_MSG_RELATED_DATA)
|
|
|
|
{
|
|
|
|
GxsMsgResult msgResult;
|
|
|
|
mDataStore->retrieveNxsMsgs(filteredOutMsgIds, msgResult, false, true);
|
|
|
|
req->mMsgDataResult[grpMsgIdPair] = msgResult[grpId];
|
|
|
|
}
|
2012-11-13 17:36:06 -05:00
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
outMsgIds.clear();
|
|
|
|
filteredOutMsgIds.clear();
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2012-11-13 17:36:06 -05:00
|
|
|
cleanseMsgMetaMap(result);
|
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-19 04:00:06 -04:00
|
|
|
bool RsGxsDataAccess::getGroupStatistic(GroupStatisticRequest *req)
|
|
|
|
{
|
|
|
|
// filter based on options
|
|
|
|
GxsMsgIdResult metaReq;
|
|
|
|
metaReq[req->mGrpId] = std::vector<RsGxsMessageId>();
|
|
|
|
GxsMsgMetaResult metaResult;
|
|
|
|
mDataStore->retrieveGxsMsgMetaData(metaReq, metaResult);
|
|
|
|
|
|
|
|
std::vector<RsGxsMsgMetaData*>& msgMetaV = metaResult[req->mGrpId];
|
|
|
|
|
2014-07-20 15:35:33 -04:00
|
|
|
req->mGroupStatistic.mGrpId = req->mGrpId;
|
2014-07-19 04:00:06 -04:00
|
|
|
req->mGroupStatistic.mNumMsgs = msgMetaV.size();
|
|
|
|
req->mGroupStatistic.mTotalSizeOfMsgs = 0;
|
2014-09-24 19:57:47 -04:00
|
|
|
req->mGroupStatistic.mNumThreadMsgsNew = 0;
|
|
|
|
req->mGroupStatistic.mNumThreadMsgsUnread = 0;
|
|
|
|
req->mGroupStatistic.mNumChildMsgsNew = 0;
|
|
|
|
req->mGroupStatistic.mNumChildMsgsUnread = 0;
|
2014-07-20 15:35:33 -04:00
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(int i = 0; i < msgMetaV.size(); ++i)
|
2014-07-19 04:00:06 -04:00
|
|
|
{
|
|
|
|
RsGxsMsgMetaData* m = msgMetaV[i];
|
|
|
|
req->mGroupStatistic.mTotalSizeOfMsgs += m->mMsgSize + m->serial_size();
|
2014-07-20 15:35:33 -04:00
|
|
|
|
|
|
|
if (IS_MSG_NEW(m->mMsgStatus))
|
|
|
|
{
|
2014-09-24 19:57:47 -04:00
|
|
|
if (m->mParentId.isNull())
|
|
|
|
{
|
|
|
|
++req->mGroupStatistic.mNumThreadMsgsNew;
|
|
|
|
} else {
|
|
|
|
++req->mGroupStatistic.mNumChildMsgsNew;
|
|
|
|
}
|
2014-07-20 15:35:33 -04:00
|
|
|
}
|
|
|
|
if (IS_MSG_UNREAD(m->mMsgStatus))
|
|
|
|
{
|
2014-09-24 19:57:47 -04:00
|
|
|
if (m->mParentId.isNull())
|
|
|
|
{
|
|
|
|
++req->mGroupStatistic.mNumThreadMsgsUnread;
|
|
|
|
} else {
|
|
|
|
++req->mGroupStatistic.mNumChildMsgsUnread;
|
|
|
|
}
|
2014-07-20 15:35:33 -04:00
|
|
|
}
|
2014-07-19 04:00:06 -04:00
|
|
|
}
|
2014-07-19 04:29:56 -04:00
|
|
|
|
|
|
|
cleanseMsgMetaMap(metaResult);
|
2014-07-19 04:00:06 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// potentially very expensive!
|
|
|
|
bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req)
|
|
|
|
{
|
|
|
|
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta;
|
|
|
|
|
|
|
|
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
|
|
|
|
|
|
|
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.begin();
|
|
|
|
|
|
|
|
req->mServiceStatistic.mNumGrps = grpMeta.size();
|
2014-09-24 19:57:47 -04:00
|
|
|
req->mServiceStatistic.mNumMsgs = 0;
|
2014-07-19 04:00:06 -04:00
|
|
|
req->mServiceStatistic.mSizeOfGrps = 0;
|
|
|
|
req->mServiceStatistic.mSizeOfMsgs = 0;
|
2014-07-20 07:21:06 -04:00
|
|
|
req->mServiceStatistic.mNumGrpsSubscribed = 0;
|
2014-09-24 19:57:47 -04:00
|
|
|
req->mServiceStatistic.mNumThreadMsgsNew = 0;
|
|
|
|
req->mServiceStatistic.mNumThreadMsgsUnread = 0;
|
|
|
|
req->mServiceStatistic.mNumChildMsgsNew = 0;
|
|
|
|
req->mServiceStatistic.mNumChildMsgsUnread = 0;
|
2014-07-19 04:00:06 -04:00
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; mit != grpMeta.end(); ++mit)
|
2014-07-19 04:00:06 -04:00
|
|
|
{
|
|
|
|
RsGxsGrpMetaData* m = mit->second;
|
|
|
|
req->mServiceStatistic.mSizeOfGrps += m->mGrpSize + m->serial_size();
|
2014-09-24 19:57:47 -04:00
|
|
|
|
|
|
|
if (IS_GROUP_SUBSCRIBED(m->mSubscribeFlags))
|
|
|
|
{
|
|
|
|
++req->mServiceStatistic.mNumGrpsSubscribed;
|
|
|
|
|
|
|
|
GroupStatisticRequest gr;
|
|
|
|
gr.mGrpId = m->mGroupId;
|
|
|
|
getGroupStatistic(&gr);
|
|
|
|
|
|
|
|
req->mServiceStatistic.mNumMsgs += gr.mGroupStatistic.mNumMsgs;
|
|
|
|
req->mServiceStatistic.mSizeOfMsgs += gr.mGroupStatistic.mTotalSizeOfMsgs;
|
|
|
|
req->mServiceStatistic.mNumThreadMsgsNew += gr.mGroupStatistic.mNumThreadMsgsNew;
|
|
|
|
req->mServiceStatistic.mNumThreadMsgsUnread += gr.mGroupStatistic.mNumThreadMsgsUnread;
|
|
|
|
req->mServiceStatistic.mNumChildMsgsNew += gr.mGroupStatistic.mNumChildMsgsNew;
|
|
|
|
req->mServiceStatistic.mNumChildMsgsUnread += gr.mGroupStatistic.mNumChildMsgsUnread;
|
|
|
|
}
|
2014-07-20 07:21:06 -04:00
|
|
|
|
2014-07-19 04:29:56 -04:00
|
|
|
delete m;
|
2014-07-19 04:00:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
req->mServiceStatistic.mSizeStore = req->mServiceStatistic.mSizeOfGrps + req->mServiceStatistic.mSizeOfMsgs;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool RsGxsDataAccess::getMsgList(MsgIdReq* req)
|
|
|
|
{
|
|
|
|
|
|
|
|
GxsMsgMetaResult result;
|
|
|
|
|
|
|
|
mDataStore->retrieveGxsMsgMetaData(req->mMsgIds, result);
|
|
|
|
|
|
|
|
|
|
|
|
GxsMsgMetaResult::iterator mit = result.begin(), mit_end = result.end();
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; mit != mit_end; ++mit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
const RsGxsGroupId grpId = mit->first;
|
|
|
|
std::vector<RsGxsMsgMetaData*>& metaV = mit->second;
|
|
|
|
std::vector<RsGxsMsgMetaData*>::iterator vit = metaV.begin(),
|
|
|
|
vit_end = metaV.end();
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; vit != vit_end; ++vit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
RsGxsMsgMetaData* meta = *vit;
|
|
|
|
req->mMsgIdResult[grpId].push_back(meta->mMsgId);
|
|
|
|
delete meta; // discard meta data mem
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GxsMsgReq msgIdOut;
|
|
|
|
|
|
|
|
// filter based on options
|
|
|
|
getMsgList(req->mMsgIdResult, req->Options, msgIdOut);
|
|
|
|
req->mMsgIdResult = msgIdOut;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RsGxsDataAccess::cleanseMsgMetaMap(GxsMsgMetaResult& result)
|
|
|
|
{
|
|
|
|
GxsMsgMetaResult::iterator mit = result.begin();
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; mit !=result.end(); ++mit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
std::vector<RsGxsMsgMetaData*>& msgMetaV = mit->second;
|
|
|
|
std::vector<RsGxsMsgMetaData*>::iterator vit = msgMetaV.begin();
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; vit != msgMetaV.end(); ++vit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
delete *vit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RsGxsDataAccess::filterMsgList(GxsMsgIdResult& msgIds, const RsTokReqOptions& opts,
|
|
|
|
const MsgMetaFilter& msgMetas) const
|
|
|
|
{
|
|
|
|
|
|
|
|
GxsMsgIdResult::iterator mit = msgIds.begin();
|
2014-10-24 18:07:26 -04:00
|
|
|
for(;mit != msgIds.end(); ++mit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
MsgMetaFilter::const_iterator cit = msgMetas.find(mit->first);
|
|
|
|
|
|
|
|
if(cit == msgMetas.end())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::vector<RsGxsMessageId>& msgs = mit->second;
|
|
|
|
std::vector<RsGxsMessageId>::iterator vit = msgs.begin();
|
|
|
|
const std::map<RsGxsMessageId, RsGxsMsgMetaData*>& meta = cit->second;
|
|
|
|
std::map<RsGxsMessageId, RsGxsMsgMetaData*>::const_iterator cit2;
|
|
|
|
|
|
|
|
for(; vit != msgs.end();)
|
|
|
|
{
|
|
|
|
|
|
|
|
bool keep = false;
|
|
|
|
if( (cit2 = meta.find(*vit)) != meta.end() )
|
|
|
|
{
|
|
|
|
keep = checkMsgFilter(opts, cit2->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(keep)
|
|
|
|
{
|
2014-10-24 18:07:26 -04:00
|
|
|
++vit;
|
2012-10-21 15:45:35 -04:00
|
|
|
}else
|
|
|
|
{
|
|
|
|
vit = msgs.erase(vit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-02 14:40:17 -05:00
|
|
|
void RsGxsDataAccess::filterGrpList(std::list<RsGxsGroupId> &grpIds, const RsTokReqOptions &opts, const GrpMetaFilter &meta) const
|
|
|
|
{
|
|
|
|
std::list<RsGxsGroupId>::iterator lit = grpIds.begin();
|
|
|
|
|
|
|
|
for(; lit != grpIds.end(); )
|
|
|
|
{
|
|
|
|
GrpMetaFilter::const_iterator cit = meta.find(*lit);
|
|
|
|
|
|
|
|
bool keep = false;
|
|
|
|
|
|
|
|
if(cit != meta.end())
|
|
|
|
{
|
|
|
|
keep = checkGrpFilter(opts, cit->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(keep)
|
|
|
|
{
|
2014-10-24 18:07:26 -04:00
|
|
|
++lit;
|
2012-12-02 14:40:17 -05:00
|
|
|
}else
|
|
|
|
{
|
|
|
|
lit = grpIds.erase(lit);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
bool RsGxsDataAccess::checkRequestStatus(const uint32_t& token,
|
|
|
|
uint32_t& status, uint32_t& reqtype, uint32_t& anstype, time_t& ts)
|
|
|
|
{
|
|
|
|
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
2015-08-13 13:44:27 -04:00
|
|
|
if (req == NULL || req->status == GXS_REQUEST_V2_STATUS_CANCELLED)
|
2012-10-21 15:45:35 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-09-15 17:18:20 -04:00
|
|
|
bool RsGxsDataAccess::updateGroupData(RsNxsGrp* grp) {
|
2012-10-21 15:45:35 -04:00
|
|
|
|
2013-09-15 17:18:20 -04:00
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
|
|
|
|
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grpM;
|
|
|
|
grpM.insert(std::make_pair(grp, grp->metaData));
|
|
|
|
return mDataStore->updateGroup(grpM);
|
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; mit != mRequests.end(); ++mit)
|
2012-10-21 15:45:35 -04:00
|
|
|
{
|
|
|
|
tokens.push_back(mit->first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::locked_updateRequestStatus(const uint32_t& token,
|
|
|
|
const uint32_t& status)
|
|
|
|
{
|
|
|
|
|
|
|
|
GxsRequest* req = locked_retrieveRequest(token);
|
|
|
|
|
|
|
|
if(req)
|
|
|
|
req->status = status;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t RsGxsDataAccess::generatePublicToken()
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t token;
|
|
|
|
generateToken(token);
|
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
mPublicToken[token] = RsTokenService::GXS_REQUEST_V2_STATUS_PENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::updatePublicRequestStatus(const uint32_t& token,
|
|
|
|
const uint32_t& status)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
std::map<uint32_t, uint32_t>::iterator mit = mPublicToken.find(token);
|
|
|
|
|
|
|
|
if(mit != mPublicToken.end())
|
|
|
|
{
|
|
|
|
mit->second = status;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool RsGxsDataAccess::disposeOfPublicToken(const uint32_t& token)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mDataMutex);
|
|
|
|
std::map<uint32_t, uint32_t>::iterator mit = mPublicToken.find(token);
|
|
|
|
|
|
|
|
if(mit != mPublicToken.end())
|
|
|
|
{
|
|
|
|
mPublicToken.erase(mit);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-02 14:40:17 -05:00
|
|
|
bool RsGxsDataAccess::checkGrpFilter(const RsTokReqOptions &opts, const RsGxsGrpMetaData *meta) const
|
|
|
|
{
|
|
|
|
|
|
|
|
bool subscribeMatch = false;
|
|
|
|
|
|
|
|
if(opts.mSubscribeMask)
|
|
|
|
{
|
|
|
|
// Exact Flags match required.
|
|
|
|
if ((opts.mSubscribeMask & opts.mSubscribeFilter) == (opts.mSubscribeMask & meta->mSubscribeFlags))
|
|
|
|
{
|
|
|
|
subscribeMatch = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
subscribeMatch = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return subscribeMatch;
|
|
|
|
}
|
2012-10-21 15:45:35 -04:00
|
|
|
bool RsGxsDataAccess::checkMsgFilter(const RsTokReqOptions& opts, const RsGxsMsgMetaData* meta) const
|
|
|
|
{
|
|
|
|
bool statusMatch = false;
|
|
|
|
if (opts.mStatusMask)
|
|
|
|
{
|
|
|
|
// Exact Flags match required.
|
|
|
|
if ((opts.mStatusMask & opts.mStatusFilter) == (opts.mStatusMask & meta->mMsgStatus))
|
|
|
|
{
|
|
|
|
std::cerr << "checkMsgFilter() Accepting Msg as StatusMatches: ";
|
|
|
|
std::cerr << " Mask: " << opts.mStatusMask << " StatusFilter: " << opts.mStatusFilter;
|
|
|
|
std::cerr << " MsgStatus: " << meta->mMsgStatus << " MsgId: " << meta->mMsgId;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
statusMatch = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "checkMsgFilter() Dropping Msg due to !StatusMatch ";
|
|
|
|
std::cerr << " Mask: " << opts.mStatusMask << " StatusFilter: " << opts.mStatusFilter;
|
|
|
|
std::cerr << " MsgStatus: " << meta->mMsgStatus << " MsgId: " << meta->mMsgId;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// no status comparision,
|
|
|
|
statusMatch = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool flagMatch = false;
|
|
|
|
|
|
|
|
if(opts.mMsgFlagMask)
|
|
|
|
{
|
|
|
|
// Exact Flags match required.
|
|
|
|
if ((opts.mMsgFlagMask & opts.mMsgFlagFilter) == (opts.mMsgFlagMask & meta->mMsgFlags))
|
|
|
|
{
|
|
|
|
std::cerr << "checkMsgFilter() Accepting Msg as FlagMatches: ";
|
|
|
|
std::cerr << " Mask: " << opts.mMsgFlagMask << " FlagFilter: " << opts.mMsgFlagFilter;
|
|
|
|
std::cerr << " MsgFlag: " << meta->mMsgFlags << " MsgId: " << meta->mMsgId;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
flagMatch = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "checkMsgFilter() Dropping Msg due to !FlagMatch ";
|
|
|
|
std::cerr << " Mask: " << opts.mMsgFlagMask << " FlagFilter: " << opts.mMsgFlagFilter;
|
|
|
|
std::cerr << " MsgFlag: " << meta->mMsgFlags << " MsgId: " << meta->mMsgId;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
flagMatch = false;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
flagMatch = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return statusMatch && flagMatch;
|
|
|
|
}
|
|
|
|
|