mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Added helper function to GXS services to access token management and data store
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5680 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1ec5c7fe69
commit
57407fb8ae
@ -128,7 +128,8 @@ const std::string RsGeneralDataService::MSG_META_STATUS = KEY_MSG_STATUS;
|
||||
|
||||
RsDataService::RsDataService(const std::string &serviceDir, const std::string &dbName, uint16_t serviceType,
|
||||
RsGxsSearchModule *mod)
|
||||
: RsGeneralDataService(), mServiceDir(serviceDir), mDbName(mServiceDir + "/" + dbName), mServType(serviceType){
|
||||
: RsGeneralDataService(), mServiceDir(serviceDir), mDbName(mServiceDir + "/" + dbName), mServType(serviceType),
|
||||
mDbMutex("RsDataService"){
|
||||
|
||||
initialise();
|
||||
|
||||
@ -163,6 +164,8 @@ RsDataService::~RsDataService(){
|
||||
|
||||
void RsDataService::initialise(){
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
// initialise database
|
||||
mDb = new RetroDb(mDbName, RetroDb::OPEN_READWRITE_CREATE);
|
||||
|
||||
@ -417,6 +420,9 @@ RsNxsMsg* RsDataService::getMessage(RetroCursor &c)
|
||||
|
||||
int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData* >::iterator mit = msg.begin();
|
||||
|
||||
// start a transaction
|
||||
@ -496,6 +502,9 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
||||
|
||||
int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData* >::iterator sit = grp.begin();
|
||||
|
||||
// begin transaction
|
||||
@ -576,70 +585,72 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
|
||||
int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool withMeta, bool cache){
|
||||
|
||||
if(grp.empty()){
|
||||
if(grp.empty()){
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "", "");
|
||||
RsStackMutex stack(mDbMutex);
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "", "");
|
||||
|
||||
if(c)
|
||||
{
|
||||
std::vector<RsNxsGrp*> grps;
|
||||
|
||||
retrieveGroups(c, grps);
|
||||
std::vector<RsNxsGrp*>::iterator vit = grps.begin();
|
||||
|
||||
for(; vit != grps.end(); vit++)
|
||||
{
|
||||
grp[(*vit)->grpId] = *vit;
|
||||
}
|
||||
|
||||
delete c;
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin();
|
||||
|
||||
for(; mit != grp.end(); mit++)
|
||||
{
|
||||
const std::string& grpId = mit->first;
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "grpId='" + grpId + "'", "");
|
||||
|
||||
if(c)
|
||||
{
|
||||
std::vector<RsNxsGrp*> grps;
|
||||
retrieveGroups(c, grps);
|
||||
|
||||
if(!grps.empty())
|
||||
{
|
||||
RsNxsGrp* ng = grps.front();
|
||||
grp[ng->grpId] = ng;
|
||||
}else{
|
||||
grp.erase(grpId);
|
||||
}
|
||||
|
||||
delete c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(withMeta)
|
||||
if(c)
|
||||
{
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> metaMap;
|
||||
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin();
|
||||
for(; mit != grp.end(); mit++)
|
||||
metaMap.insert(std::make_pair(mit->first, (RsGxsGrpMetaData*)(NULL)));
|
||||
std::vector<RsNxsGrp*> grps;
|
||||
|
||||
retrieveGxsGrpMetaData(metaMap);
|
||||
retrieveGroups(c, grps);
|
||||
std::vector<RsNxsGrp*>::iterator vit = grps.begin();
|
||||
|
||||
mit = grp.begin();
|
||||
for(; mit != grp.end(); mit++)
|
||||
{
|
||||
RsNxsGrp* grpPtr = grp[mit->first];
|
||||
grpPtr->metaData = metaMap[mit->first];
|
||||
}
|
||||
for(; vit != grps.end(); vit++)
|
||||
{
|
||||
grp[(*vit)->grpId] = *vit;
|
||||
}
|
||||
|
||||
delete c;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}else{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin();
|
||||
|
||||
for(; mit != grp.end(); mit++)
|
||||
{
|
||||
const std::string& grpId = mit->first;
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, "grpId='" + grpId + "'", "");
|
||||
|
||||
if(c)
|
||||
{
|
||||
std::vector<RsNxsGrp*> grps;
|
||||
retrieveGroups(c, grps);
|
||||
|
||||
if(!grps.empty())
|
||||
{
|
||||
RsNxsGrp* ng = grps.front();
|
||||
grp[ng->grpId] = ng;
|
||||
}else{
|
||||
grp.erase(grpId);
|
||||
}
|
||||
|
||||
delete c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(withMeta)
|
||||
{
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> metaMap;
|
||||
std::map<std::string, RsNxsGrp *>::iterator mit = grp.begin();
|
||||
for(; mit != grp.end(); mit++)
|
||||
metaMap.insert(std::make_pair(mit->first, (RsGxsGrpMetaData*)(NULL)));
|
||||
|
||||
retrieveGxsGrpMetaData(metaMap);
|
||||
|
||||
mit = grp.begin();
|
||||
for(; mit != grp.end(); mit++)
|
||||
{
|
||||
RsNxsGrp* grpPtr = grp[mit->first];
|
||||
grpPtr->metaData = metaMap[mit->first];
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RsDataService::retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps){
|
||||
@ -677,6 +688,9 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
|
||||
std::vector<RsNxsMsg*> msgSet;
|
||||
|
||||
if(msgIdV.empty()){
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId + "'", "");
|
||||
|
||||
if(c)
|
||||
@ -690,6 +704,9 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
|
||||
|
||||
for(; sit!=msgIdV.end();sit++){
|
||||
const std::string& msgId = *sit;
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, KEY_GRP_ID+ "='" + grpId
|
||||
+ "' AND " + KEY_MSG_ID + "='" + msgId + "'", "");
|
||||
|
||||
@ -721,7 +738,6 @@ int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, b
|
||||
if(withMeta)
|
||||
{
|
||||
|
||||
|
||||
GxsMsgMetaResult metaResult;
|
||||
|
||||
// request with meta ids so there is no chance of
|
||||
@ -791,6 +807,9 @@ void RsDataService::retrieveMessages(RetroCursor *c, std::vector<RsNxsMsg *> &ms
|
||||
|
||||
int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaResult &msgMeta)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
GxsMsgReq::const_iterator mit = reqIds.begin();
|
||||
|
||||
for(; mit != reqIds.end(); mit++)
|
||||
@ -848,6 +867,7 @@ void RsDataService::retrieveMsgMeta(RetroCursor *c, std::vector<RsGxsMsgMetaData
|
||||
int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaData *>& grp)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
if(grp.empty()){
|
||||
|
||||
@ -918,6 +938,7 @@ int RsDataService::resetDataStore()
|
||||
std::map<std::string, RsNxsGrp*>::iterator mit
|
||||
= grps.begin();
|
||||
|
||||
|
||||
// remove all grp msgs files from service dir
|
||||
for(; mit != grps.end(); mit++){
|
||||
std::string file = mServiceDir + "/" + mit->first;
|
||||
@ -925,8 +946,11 @@ int RsDataService::resetDataStore()
|
||||
remove(file.c_str()); // remove group file
|
||||
remove(msgFile.c_str()); // and remove messages file
|
||||
}
|
||||
{
|
||||
RsStackMutex stack(mDbMutex);
|
||||
mDb->closeDb();
|
||||
}
|
||||
|
||||
mDb->closeDb();
|
||||
remove(mDbName.c_str()); // remove db file
|
||||
|
||||
// recreate database
|
||||
|
@ -190,6 +190,8 @@ private:
|
||||
|
||||
RetroDb* mDb;
|
||||
|
||||
RsMutex mDbMutex;
|
||||
|
||||
std::list<std::string> msgColumns;
|
||||
std::list<std::string> msgMetaColumns;
|
||||
|
||||
|
@ -688,6 +688,28 @@ void RsGenExchange::publishGrps()
|
||||
mGrpsToPublish.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t RsGenExchange::generatePublicToken()
|
||||
{
|
||||
return mDataAccess->generatePublicToken();
|
||||
}
|
||||
|
||||
bool RsGenExchange::updatePublicRequestStatus(const uint32_t &token, const uint32_t &status)
|
||||
{
|
||||
return mDataAccess->updatePublicRequestStatus(token, status);
|
||||
}
|
||||
|
||||
bool RsGenExchange::disposeOfPublicToken(const uint32_t &token)
|
||||
{
|
||||
return mDataAccess->disposeOfPublicToken(token);
|
||||
}
|
||||
|
||||
RsGeneralDataService* RsGenExchange::getDataStore()
|
||||
{
|
||||
return mDataStore;
|
||||
}
|
||||
|
||||
void RsGenExchange::createDummyGroup(RsGxsGrpItem *grpItem)
|
||||
{
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "rsnxsobserver.h"
|
||||
#include "retroshare/rsgxsservice.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
//#include "rsgixs.h"
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > GxsMsgDataMap;
|
||||
typedef std::map<RsGxsGroupId, RsGxsGrpItem*> GxsGroupDataMap;
|
||||
@ -98,6 +99,12 @@ public:
|
||||
*/
|
||||
void tick();
|
||||
|
||||
/*!
|
||||
* Any backgroup processing needed by
|
||||
*/
|
||||
virtual void service_tick() = 0;
|
||||
|
||||
|
||||
/*!
|
||||
*
|
||||
* @return handle to token service handle for making
|
||||
@ -160,6 +167,41 @@ protected:
|
||||
*/
|
||||
void createDummyGroup(RsGxsGrpItem* grpItem);
|
||||
|
||||
protected:
|
||||
|
||||
/*!
|
||||
* Assigns a token value to passed integer
|
||||
* The status of the token can still be queried from request status feature
|
||||
* @warning the token space is shared with RsGenExchange backend, so do not
|
||||
* modify tokens except does you have created by calling generatePublicToken()
|
||||
* @return token
|
||||
*/
|
||||
uint32_t generatePublicToken();
|
||||
|
||||
/*!
|
||||
* Updates the status of associate token
|
||||
* @warning the token space is shared with RsGenExchange backend, so do not
|
||||
* modify tokens except does you have created by calling generatePublicToken()
|
||||
* @param token
|
||||
* @param status
|
||||
* @return false if token could not be found, true if token disposed of
|
||||
*/
|
||||
bool updatePublicRequestStatus(const uint32_t &token, const uint32_t &status);
|
||||
|
||||
/*!
|
||||
* This gets rid of a publicly issued token
|
||||
* @param token
|
||||
* @return false if token could not found, true if token is disposed of
|
||||
*/
|
||||
bool disposeOfPublicToken(const uint32_t &token);
|
||||
|
||||
/*!
|
||||
* This gives access to the data store which hold msgs and groups
|
||||
* for the service
|
||||
* @return Data store for retrieving msgs and groups
|
||||
*/
|
||||
RsGeneralDataService* getDataStore();
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
|
@ -254,7 +254,7 @@ public:
|
||||
uint32_t generatePublicToken();
|
||||
|
||||
/*!
|
||||
* Update
|
||||
* Updates the status of associate token
|
||||
* @param token
|
||||
* @param status
|
||||
* @return false if token could not be found, true if token disposed of
|
||||
|
@ -2311,11 +2311,7 @@ int RsServer::StartupRetroShare()
|
||||
// Testing New Cache Services.
|
||||
p3WireVEG *mWire = new p3WireVEG(RS_SERVICE_GXSV1_TYPE_WIRE);
|
||||
pqih -> addService(mWire);
|
||||
|
||||
// Testing New Cache Services.
|
||||
p3IdServiceVEG *mIdentity = new p3IdServiceVEG(RS_SERVICE_GXSV1_TYPE_IDENTITY);
|
||||
pqih -> addService(mIdentity);
|
||||
|
||||
|
||||
// Testing New Cache Services.
|
||||
p3ForumsVEG *mForumsV2 = new p3ForumsVEG(RS_SERVICE_GXSV1_TYPE_FORUMS);
|
||||
pqih -> addService(mForumsV2);
|
||||
@ -2584,8 +2580,8 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
rsPhotoV2 = mPhotoV2;
|
||||
#ifdef ENABLE_GXS_SERVICES
|
||||
// Testing of new cache system interfaces.
|
||||
rsIdentityVEG = mIdentity;
|
||||
// Testing of new cache system interfaces.
|
||||
|
||||
rsWikiVEG = mWikis;
|
||||
rsWireVEG = mWire;
|
||||
rsForumsVEG = mForumsV2;
|
||||
|
@ -105,6 +105,11 @@ bool p3PhotoServiceV2::updated()
|
||||
return changed;
|
||||
}
|
||||
|
||||
void p3PhotoServiceV2::service_tick()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void p3PhotoServiceV2::groupsChanged(std::list<RsGxsGroupId>& grpIds)
|
||||
|
@ -43,6 +43,11 @@ public:
|
||||
*/
|
||||
bool updated();
|
||||
|
||||
/*!
|
||||
*
|
||||
*/
|
||||
void service_tick();
|
||||
|
||||
protected:
|
||||
|
||||
void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
Loading…
Reference in New Issue
Block a user