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