begun in ernest implementing data access (RsTokenService) interface for gui

added request processing and generalised request base class (switch to casts)
msg request now have grpId option
ci code not part of build


git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5310 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-07-17 21:27:43 +00:00
parent 52a911329e
commit 90c1aa4903
5 changed files with 610 additions and 36 deletions

View File

@ -10,22 +10,7 @@
#include "retroshare/rsgxsservice.h" #include "retroshare/rsgxsservice.h"
#include "serialiser/rsnxsitems.h" #include "serialiser/rsnxsitems.h"
class gxsRequest
{
public:
uint32_t token;
uint32_t reqTime;
uint32_t ansType;
uint32_t reqType;
RsTokReqOptions Options;
uint32_t status;
std::list<std::string> inList;
std::list<std::string> outList;
//std::map<std::string, void *> readyData;
};
/*! /*!
* This should form the parent class to \n * This should form the parent class to \n
@ -63,6 +48,8 @@ public:
virtual ~RsGenExchange(); virtual ~RsGenExchange();
/** S: Observer implementation **/
/*! /*!
* @param messages messages are deleted after function returns * @param messages messages are deleted after function returns
*/ */
@ -73,6 +60,7 @@ public:
*/ */
void notifyNewGroups(std::vector<RsNxsGrp*>& groups); void notifyNewGroups(std::vector<RsNxsGrp*>& groups);
/** E: Observer implementation **/
/*! /*!
* This is called by Gxs service runner * This is called by Gxs service runner

View File

@ -0,0 +1,395 @@
#include "rsgxsdataaccess.h"
#include "retroshare/rsidentity.h"
RsGxsDataAccess::RsGxsDataAccess(RsGeneralDataService* ds)
: mDataStore(ds)
{
}
bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts,
const std::list<std::string> &groupIds)
{
return true;
}
bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
const RsTokReqOptions &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "RsGxsDataAccess::requestMsgInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds);
return true;
}
bool RsGxsDataAccess::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions& opts,
const GxsMsgReq &msgIds)
{
generateToken(token);
std::cerr << "RsGxsDataAccess::requestMsgRelatedInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
bool RsGxsDataAccess::requestGroupSubscribe(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::string &grpId)
{
generateToken(token);
std::cerr << "RsGxsDataAccess::requestGroupSubscribe() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, grpId);
return false;
}
bool RsGxsDataAccess::storeRequest(const uint32_t &token, const uint32_t &ansType, const RsTokReqOptions &opts, const uint32_t &type, const std::list<std::string> &ids)
{
RsStackMutex stack(mDataMutex); /****** LOCKED *****/
GxsRequest* req;
req.token = token;
req.reqTime = time(NULL);
req.reqType = type;
req.ansType = ansType;
req.Options = opts;
req.status = GXS_REQUEST_STATUS_PENDING;
req.inList = ids;
mRequests[token] = req;
return true;
}
uint32_t RsGxsDataAccess::requestStatus(uint32_t token)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
return status;
}
bool RsGxsDataAccess::cancelRequest(const uint32_t& token)
{
return clearRequest(token);
}
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;
}
mRequests.erase(it);
return true;
}
bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list<RsGxsGrpMetaData*>& groupInfo)
{
GxsRequest* req = retrieveRequest(token);
if(req == NULL){
std::cerr << "RsGxsDataAccess::getGroupSummary() Unable to retrieve group summary" << std::endl;
return false;
}else{
GroupMetaReq* gmreq = dynamic_cast<GroupMetaReq*>(req);
if(gmreq)
{
groupInfo = gmreq->mGroupMetaData;
}else{
std::cerr << "RsGxsDataAccess::getGroupSummary() Req found, failed caste" << std::endl;
return false;
}
}
return true;
}
bool RsGxsDataAccess::getGroupData(const uint32_t& token, std::list<RsNxsGrp*>& grpData)
{
GxsRequest* req = retrieveRequest(token);
if(req == NULL){
std::cerr << "RsGxsDataAccess::getGroupData() Unable to retrieve group data" << std::endl;
return false;
}else{
GroupDataReq* gmreq = dynamic_cast<GroupMetaReq*>(req);
if(gmreq)
{
grpData = gmreq->mGroupData;
}else{
std::cerr << "RsGxsDataAccess::getGroupData() Req found, failed caste" << std::endl;
return false;
}
}
return true;
}
bool RsGxsDataAccess::getMsgData(const uint32_t& token, GxsMsgDataResult& msgData)
{
GxsRequest* req = retrieveRequest(token);
if(req == NULL){
std::cerr << "RsGxsDataAccess::getMsgData() Unable to retrieve group data" << std::endl;
return false;
}else{
MsgDataReq* mdreq = dynamic_cast<GroupMetaReq*>(req);
if(mdreq)
{
msgData = mdreq->mMsgData;
}else{
std::cerr << "RsGxsDataAccess::getMsgData() Req found, failed caste" << std::endl;
return false;
}
}
return true;
}
bool RsGxsDataAccess::getMsgSummary(const uint32_t& token, GxsMsgMetaResult& msgInfo)
{
GxsRequest* req = retrieveRequest(token);
if(req == NULL){
std::cerr << "RsGxsDataAccess::getMsgSummary() Unable to retrieve group data" << std::endl;
return false;
}else{
MsgMetaReq* mmreq = dynamic_cast<GroupMetaReq*>(req);
if(mmreq)
{
msgInfo = mmreq->mMsgMetaData;
}else{
std::cerr << "RsGxsDataAccess::getMsgSummary() Req found, failed caste" << std::endl;
return false;
}
}
return true;
}
bool RsGxsDataAccess::getMsgList(const uint32_t& token, GxsMsgIdResult& msgIds)
{
GxsRequest* req = retrieveRequest(token);
if(req == NULL){
std::cerr << "RsGxsDataAccess::getMsgList() Unable to retrieve group data" << std::endl;
return false;
}else{
MsgIdReq* mireq = dynamic_cast<GroupMetaReq*>(req);
if(mireq)
{
msgIds = mireq->mMsgIdResult;
}else{
std::cerr << "RsGxsDataAccess::getMsgList() Req found, failed caste" << std::endl;
return false;
}
}
return true;
}
bool RsGxsDataAccess::getGroupList(const uint32_t& token, std::list<std::string>& groupIds)
{
GxsRequest* req = retrieveRequest(token);
if(req == NULL){
std::cerr << "RsGxsDataAccess::getGroupList() Unable to retrieve group data" << std::endl;
return false;
}else{
GroupIdReq* gireq = dynamic_cast<GroupMetaReq*>(req);
if(gireq)
{
groupIds = gireq->mGroupIdResult;
}else{
std::cerr << "RsGxsDataAccess::getGroupList() Req found, failed caste" << std::endl;
return false;
}
}
return true;
}
GxsRequest* RsGxsDataAccess::retrieveRequest(const uint32_t& token)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
if(checkRequestStatus(token, status, reqtype, anstype, ts))
return NULL;
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "RsGxsDataAccess::retrieveRequest() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "RsGxsDataAccess::retrieveRequest() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "RsGxsDataAccess::retrieveRequest() ERROR Status Incomplete" << std::endl;
return false;
}
if(mRequests.find(token) == mRequests.end()) return NULL;
GxsRequest* req = mRequests;
return req;
}
#define MAX_REQUEST_AGE 10
void RsGxsDataAccess::processRequests()
{
std::list<uint32_t> toClear;
std::list<uint32_t>::iterator cit;
time_t now = time(NULL);
{
RsStackMutex stack(mDataMutex); /******* LOCKED *******/
std::map<uint32_t, GxsRequest*>::iterator it;
GroupMetaReq* gmr;
GroupDataReq* gdr;
GroupIdReq* gir;
MsgMetaReq* mmr;
MsgDataReq* mdr;
MsgIdReq* mir;
for(it = mRequests.begin(); it != mRequests.end(); it++)
{
GxsRequest* req = it->second;
if (req->status == GXS_REQUEST_STATUS_PENDING)
{
std::cerr << "p3GxsDataService::fakeprocessrequests() Processing Token: " << req->token << " Status: "
<< req->status << " ReqType: " << req->reqType << " Age: "
<< now - req->reqTime << std::endl;
req->status = GXS_REQUEST_STATUS_PARTIAL;
/* PROCESS REQUEST! */
if((gmr = dynamic_cast<GroupMetaReq*>(req)) != NULL)
{
getGroupSummary(gmr);
}
else if((gdr = dynamic_cast<GroupDataReq*>(req)) != NULL)
{
getGroupData(gdr);
}
else if((gir = dynamic_cast<GroupIdReq*>(req)) != NULL)
{
getGroupList(gir);
}
else if((mmr = dynamic_cast<MsgMetaReq*>(req)) != NULL)
{
getMsgSummary(mmr);
}
else if((mdr = dynamic_cast<MsgDataReq*>(req)) != NULL)
{
getMsgData(mdr);
}
else if((mir = dynamic_cast<MsgIdReq*>(req)) != NULL)
{
getMsgList(mir);
}
else
{
#ifdef GXSDATA_SERVE_DEBUG
std::cerr << "RsGxsDataAccess::processRequests() Failed to process request, token: "
<< req->token << std::endl;
#endif
req->status = GXS_REQUEST_STATUS_FAILED;
}
}
else if (req->status == GXS_REQUEST_STATUS_PARTIAL)
{
req->status = GXS_REQUEST_STATUS_COMPLETE;
}
else if (req->status == GXS_REQUEST_STATUS_DONE)
{
std::cerr << "RsGxsDataAccess::processrequests() Clearing Done Request Token: "
<< req->token;
std::cerr << std::endl;
toClear.push_back(req->token);
}
else if (now - req->reqTime > MAX_REQUEST_AGE)
{
std::cerr << "RsGxsDataAccess::processrequests() Clearing Old Request Token: " << req->token;
std::cerr << std::endl;
toClear.push_back(req->token);
}
}
} // END OF MUTEX.
for(cit = toClear.begin(); cit != toClear.end(); cit++)
{
clearRequest(*cit);
}
return;
}
bool RsGxsDataAccess::getGroupData(GroupDataReq* req)
{
std::map<std::string, RsGxsGrpMetaData*> grpMeta;
mDataStore->retrieveGxsGrpMetaData(grpMeta);
return true;
}

View File

@ -1,5 +0,0 @@
#include "rsgxsdataaccess.h"
RsGxsDataAccess::RsGxsDataAccess()
{
}

View File

@ -4,20 +4,111 @@
#include "rstokenservice.h" #include "rstokenservice.h"
#include "rsgds.h" #include "rsgds.h"
typedef std::map<std::string, std::vector<std::string> > GxsMsgReq;
typedef std::map<std::string, std::vector<std::string> > GxsMsgIdResult;
typedef std::map<std::string, std::vector<RsGxsMsgMetaData*> > GxsMsgMetaResult;
typedef std::map<std::string, std::vector<RsNxsMsg*> > GxsMsgDataResult;
class GxsRequest
{
public:
uint32_t token;
uint32_t reqTime;
uint32_t ansType;
uint32_t reqType;
RsTokReqOptions Options;
uint32_t status;
};
class GroupMetaReq : public GxsRequest
{
public:
std::list<RsGxsGrpMetaData*> mGroupMetaData;
};
class GroupIdReq : public GxsRequest
{
public:
std::list<std::string> mGroupIdResult;
};
class MsgIdReq : public GxsRequest
{
public:
GxsMsgIdResult mMsgIdResult;
};
class MsgMetaReq : public GxsRequest
{
public:
std::map<std::string, std::vector<RsMsgMetaData*> > mMsgMetaData;
};
class MsgDataReq : public GxsRequest
{
public:
GxsMsgDataResult mMsgData;
};
class GroupDataReq : public GxsRequest
{
public:
std::list<RsNxsGrp*> mGroupData;
};
class RsGxsDataAccess : public RsTokenService class RsGxsDataAccess : public RsTokenService
{ {
public: public:
RsGxsDataAccess(RsGeneralDataService* ds, RsSerialType* serviceSerialiser); RsGxsDataAccess(RsGeneralDataService* ds);
virtual ~RsGxsDataAccess() { return ;} virtual ~RsGxsDataAccess() { return ;}
public: public:
/** start: From RsTokenService **/ /** S: RsTokenService **/
/*!
*
* @param token
* @param ansType
* @param opts
* @param groupIds
* @return
*/
bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds); bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds);
/*!
* For requesting info on all messages of one or more groups
* @param token
* @param ansType
* @param opts
* @param groupIds
* @return
*/
bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds); bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds);
bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &msgIds);
bool requestGroupSubscribe(uint32_t &token, const std::string &groupId, bool subscribe); /*!
* More involved for request of particular information for msg
* @param token set to value if , should be discarded if routine returns false
* @param ansType
* @param opts
* @param msgIds
* @return true if successful in placing request, false otherwise
*/
bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts,
const GxsMsgReq &msgIds);
bool requestGroupSubscribe(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::string &grpId);
/* Poll */ /* Poll */
uint32_t requestStatus(const uint32_t token); uint32_t requestStatus(const uint32_t token);
@ -25,7 +116,7 @@ public:
/* Cancel Request */ /* Cancel Request */
bool cancelRequest(const uint32_t &token); bool cancelRequest(const uint32_t &token);
/** end : From RsTokenService **/ /** E: RsTokenService **/
public: public:
@ -45,44 +136,50 @@ public:
* @param token request token to be redeemed * @param token request token to be redeemed
* @param msgIds * @param msgIds
*/ */
bool getMsgList(const uint32_t &token, std::list<std::string> &msgIds); bool getMsgList(const uint32_t &token, GxsMsgIdResult &msgIds);
/*! /*!
* @param token request token to be redeemed * @param token request token to be redeemed
* @param groupInfo * @param groupInfo
*/ */
bool getGroupSummary(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo); bool getGroupSummary(const uint32_t &token, std::list<RsGxsGrpMetaData*> &groupInfo);
/*! /*!
* *
* @param token request token to be redeemed * @param token request token to be redeemed
* @param msgInfo * @param msgInfo
*/ */
bool getMsgSummary(const uint32_t &token, std::list<RsMsgMetaData> &msgInfo); bool getMsgSummary(const uint32_t &token, GxsMsgMetaResult &msgInfo);
/*! /*!
* *
* @param token request token to be redeemed * @param token request token to be redeemed
* @param grpItem * @param grpData
*/ */
bool getGroupData(const uint32_t &token, RsGxsGrpItem* grpItem); bool getGroupData(const uint32_t &token, std::list<RsNxsGrp*>& grpData);
/*! /*!
* *
* @param token request token to be redeemed * @param token request token to be redeemed
* @param msgItems * @param msgData
* @return false if * @return false if data cannot be found for token
*/ */
bool getMsgData(const uint32_t &token, std::vector<RsGxsMsgItem*> msgItems); bool getMsgData(const uint32_t &token, GxsMsgDataResult& msgData);
private: private:
/** helper functions to implement token service **/ /** helper functions to implement token service **/
bool generateToken(uint32_t &token); bool generateToken(uint32_t &token);
GxsRequest* retrieveRequest(const uint32_t& token);
bool storeRequest(const uint32_t &token, const uint32_t &ansType, const RsTokReqOptions &opts, bool storeRequest(const uint32_t &token, const uint32_t &ansType, const RsTokReqOptions &opts,
const uint32_t &type, const std::list<std::string> &ids); const uint32_t &type, const std::list<std::string> &ids);
bool storeRequest(const uint32_t &token, const uint32_t &ansType, const RsTokReqOptions &opts,
const uint32_t &type, const GxsMsgReq& msgIds);
bool storeRequest(const uint32_t &token, const uint32_t &ansType, const RsTokReqOptions &opts,
const uint32_t &type, const std::string& grpId);
bool clearRequest(const uint32_t &token); bool clearRequest(const uint32_t &token);
bool updateRequestStatus(const uint32_t &token, const uint32_t &status); bool updateRequestStatus(const uint32_t &token, const uint32_t &status);
@ -108,6 +205,57 @@ private:
private: private:
/*!
* Attempts to retrieve group id list from data store
* @param req
* @return false if unsuccessful, true otherwise
*/
bool getGroupList(GroupIdReq* req);
/*!
* Attempts to retrieve msg id list from data store
* @param req
* @return false if unsuccessful, true otherwise
*/
bool getMsgList(MsgIdReq* req);
/*!
* Attempts to retrieve group meta data from data store
* @param req
* @return false if unsuccessful, true otherwise
*/
bool getGroupSummary(GroupMetaReq* req);
/*!
* Attempts to retrieve msg meta data from data store
* @param req
* @return false if unsuccessful, true otherwise
*/
bool getMsgSummary(MsgMetaReq* req);
/*!
* Attempts to retrieve group data from data store
* @param req The request specifying data to retrieve
* @return false if unsuccessful, true otherwise
*/
bool getGroupData(GroupDataReq* req);
/*!
* Attempts to retrieve message data from data store
* @param req The request specifying data to retrieve
* @return false if unsuccessful, true otherwise
*/
bool getMsgData(MsgDataReq* req);
private:
RsGeneralDataService* mDataStore;
uint32_t mNextToken;
std::map<uint32_t, GxsRequest*> mRequests;
RsMutex mDataMutex;
}; };

View File

@ -73,15 +73,63 @@ public:
virtual ~RsTokenService() { return; } virtual ~RsTokenService() { return; }
/* Data Requests */ /* Data Requests */
/*!
* Use this to request group related information
* @param token
* @param ansType The type of result (e.g. group data, meta, ids)
* @param opts
* @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<std::string> &groupIds) = 0; virtual bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds) = 0;
/*!
*
* @param token
* @param ansType
* @param opts
* @param groupIds
* @return
*/
virtual bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds) = 0; virtual bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds) = 0;
/*!
*
* @param token
* @param ansType
* @param opts
* @param msgIds
* @return
*/
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &msgIds) = 0; virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &msgIds) = 0;
virtual bool requestGroupSubscribe(uint32_t &token, const std::string &groupId, bool subscribe) = 0;
/*!
*
* @param token
* @param ansType
* @param opts
* @param grpId
* @return
*/
virtual bool requestGroupSubscribe(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::string &grpId) = 0;
/* Poll */ /* Poll */
/*!
*
* @param token
* @return
*/
virtual uint32_t requestStatus(const uint32_t token) = 0; virtual uint32_t requestStatus(const uint32_t token) = 0;
/* Cancel Request */ /* Cancel Request */
/*!
*
* @param token
* @return
*/
virtual bool cancelRequest(const uint32_t &token) = 0; virtual bool cancelRequest(const uint32_t &token) = 0;