diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index 44caaca9a..d8764849a 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -36,6 +36,24 @@ * The requests can be generic, but the reponses are service specific (dependent on data types). */ +// This bit will be filled out over time. +#define RS_TOKREQOPT_MSG_VERSIONS 0x0001 +#define RS_TOKREQOPT_MSG_ORIGMSG 0x0002 +#define RS_TOKREQOPT_MSG_LATEST 0x0003 + +#define RS_TOKREQOPT_MSG_THREAD 0x0004 +#define RS_TOKREQOPT_MSG_PARENT 0x0005 + +class RsTokReqOptions +{ + public: + RsTokReqOptions() { mOptions = 0; mBefore = 0; mAfter = 0; } + + uint32_t mOptions; + time_t mBefore; + time_t mAfter; +}; + class RsTokenService { public: @@ -44,10 +62,12 @@ class RsTokenService virtual ~RsTokenService() { return; } /* Data Requests */ -virtual bool requestGroupList(uint32_t &token) = 0; -virtual bool requestGroupData(uint32_t &token, const std::list &ids) = 0; -virtual bool requestMsgList(uint32_t &token, const std::list &ids) = 0; -virtual bool requestMsgData(uint32_t &token, const std::list &ids) = 0; +virtual bool requestGroupList( uint32_t &token, const RsTokReqOptions &opts) = 0; +virtual bool requestMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds) = 0; +virtual bool requestMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list &msgIds) = 0; + +virtual bool requestGroupData( uint32_t &token, const std::list &groupIds) = 0; +virtual bool requestMsgData( uint32_t &token, const std::list &msgIds) = 0; /* Poll */ virtual uint32_t requestStatus(const uint32_t token) = 0; diff --git a/libretroshare/src/retroshare/rsphoto.h b/libretroshare/src/retroshare/rsphoto.h index 3a95e21e0..6fc43b297 100644 --- a/libretroshare/src/retroshare/rsphoto.h +++ b/libretroshare/src/retroshare/rsphoto.h @@ -111,7 +111,31 @@ virtual ~RsPhoto() { return; } /* changed? */ virtual bool updated() = 0; + /* Data Requests (from RsTokenService) */ +//virtual bool requestGroupList( uint32_t &token, const RsTokReqOptions &opts) = 0; +//virtual bool requestMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds) = 0; +//virtual bool requestMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list &msgIds) = 0; +//virtual bool requestGroupData( uint32_t &token, const std::list &groupIds) = 0; +//virtual bool requestMsgData( uint32_t &token, const std::list &msgIds) = 0; + + /* Poll */ +//virtual uint32_t requestStatus(const uint32_t token) = 0; + + /* Generic List Data */ +virtual bool getGroupList(const uint32_t &token, std::list &groupIds) = 0; +virtual bool getMsgList(const uint32_t &token, std::list &msgIds) = 0; + + /* Specific Service Data */ +virtual bool getAlbum(const uint32_t &token, RsPhotoAlbum &album) = 0; +virtual bool getPhoto(const uint32_t &token, RsPhotoPhoto &photo) = 0; + +/* details are updated in album - to choose Album ID, and storage path */ +virtual bool submitAlbumDetails(RsPhotoAlbum &album) = 0; +virtual bool submitPhoto(RsPhotoPhoto &photo) = 0; + + +#if 0 virtual bool requestAlbumList(uint32_t &token) = 0; virtual bool requestPhotoList(uint32_t &token, const std::list &albumids) = 0; @@ -121,23 +145,15 @@ virtual bool requestPhotos(uint32_t &token, const std::list &photoi virtual bool getAlbumList(const uint32_t &token, std::list &albums) = 0; virtual bool getPhotoList(const uint32_t &token, std::list &photos) = 0; -virtual bool getAlbum(const uint32_t &token, RsPhotoAlbum &album) = 0; -virtual bool getPhoto(const uint32_t &token, RsPhotoPhoto &photo) = 0; - -/* details are updated in album - to choose Album ID, and storage path */ -virtual bool submitAlbumDetails(RsPhotoAlbum &album) = 0; -virtual bool submitPhoto(RsPhotoPhoto &photo) = 0; - /* Data Requests (from RsTokenService) */ virtual bool requestGroupList(uint32_t &token) { return requestAlbumList(token); } virtual bool requestGroupData(uint32_t &token, const std::list &ids) { return requestAlbums(token, ids); } virtual bool requestMsgList(uint32_t &token, const std::list &ids) { return requestPhotoList(token, ids); } virtual bool requestMsgData(uint32_t &token, const std::list &ids) { return requestPhotos(token, ids); } +#endif - /* Poll */ -virtual uint32_t requestStatus(const uint32_t token) = 0; }; diff --git a/libretroshare/src/retroshare/rswiki.h b/libretroshare/src/retroshare/rswiki.h index 1f55c6c7b..f98d5131a 100644 --- a/libretroshare/src/retroshare/rswiki.h +++ b/libretroshare/src/retroshare/rswiki.h @@ -30,6 +30,8 @@ #include #include +#include + /* The Main Interface Class - for information about your Peers */ class RsWiki; extern RsWiki *rsWiki; @@ -76,7 +78,7 @@ class RsWikiPage std::string mHashTags; }; -class RsWiki +class RsWiki: public RsTokenService { public: @@ -86,16 +88,39 @@ virtual ~RsWiki() { return; } /* changed? */ virtual bool updated() = 0; + /* Data Requests (from RsTokenService) */ +//virtual bool requestGroupList( uint32_t &token, const RsTokReqOptions &opts) = 0; +//virtual bool requestMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds) = 0; +//virtual bool requestMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list &msgIds) = 0; + +//virtual bool requestGroupData( uint32_t &token, const std::list &groupIds) = 0; +//virtual bool requestMsgData( uint32_t &token, const std::list &msgIds) = 0; + + /* Poll */ +//virtual uint32_t requestStatus(const uint32_t token) = 0; + + /* Generic List Data */ +virtual bool getGroupList(const uint32_t &token, std::list &groupIds) = 0; +virtual bool getMsgList(const uint32_t &token, std::list &msgIds) = 0; + + /* Specific Service Data */ +virtual bool getGroupData(const uint32_t &token, RsWikiGroup &group) = 0; +virtual bool getMsgData(const uint32_t &token, RsWikiPage &page) = 0; + + + +/* details are updated in group - to choose GroupID */ +virtual bool createGroup(RsWikiGroup &group) = 0; +virtual bool createPage(RsWikiPage &page) = 0; + +#if 0 virtual bool getGroupList(std::list &groups) = 0; virtual bool getGroup(const std::string &groupid, RsWikiGroup &group) = 0; virtual bool getPage(const std::string &pageid, RsWikiPage &page) = 0; virtual bool getPageVersions(const std::string &origPageId, std::list &pages) = 0; virtual bool getOrigPageList(const std::string &groupid, std::list &pageIds) = 0; virtual bool getLatestPage(const std::string &origPageId, std::string &pageId) = 0; - -/* details are updated in group - to choose GroupID */ -virtual bool createGroup(RsWikiGroup &group) = 0; -virtual bool createPage(RsWikiPage &page) = 0; +#endif }; diff --git a/libretroshare/src/services/p3gxsservice.cc b/libretroshare/src/services/p3gxsservice.cc index d3968cc52..5e7d179e6 100644 --- a/libretroshare/src/services/p3gxsservice.cc +++ b/libretroshare/src/services/p3gxsservice.cc @@ -193,3 +193,50 @@ bool p3GxsService::popRequestList(const uint32_t &token, std::string &id) } +#define MAX_REQUEST_AGE 10 + +bool p3GxsService::fakeprocessrequests() + { + std::list::iterator it; + std::list tokens; + + tokenList(tokens); + + time_t now = time(NULL); + for(it = tokens.begin(); it != tokens.end(); it++) + { + uint32_t status; + uint32_t reqtype; + uint32_t token = *it; + time_t ts; + checkRequestStatus(token, status, reqtype, ts); + + std::cerr << "p3GxsService::fakeprocessrequests() Token: " << token << " Status: " << status << " ReqType: " << reqtype << "Age: " << now - ts << std::endl; + + if (status == GXS_REQUEST_STATUS_PENDING) + { + updateRequestStatus(token, GXS_REQUEST_STATUS_PARTIAL); + } + else if (status == GXS_REQUEST_STATUS_PARTIAL) + { + updateRequestStatus(token, GXS_REQUEST_STATUS_COMPLETE); + } + else if (status == GXS_REQUEST_STATUS_DONE) + { + std::cerr << "p3GxsService::fakeprocessrequests() Clearing Done Request Token: " << token; + std::cerr << std::endl; + clearRequest(token); + } + else if (now - ts > MAX_REQUEST_AGE) + { + std::cerr << "p3GxsService::fakeprocessrequests() Clearing Old Request Token: " << token; + std::cerr << std::endl; + clearRequest(token); + } + } + + return true; +} + + + diff --git a/libretroshare/src/services/p3gxsservice.h b/libretroshare/src/services/p3gxsservice.h index 9fc6c96af..cce667c88 100644 --- a/libretroshare/src/services/p3gxsservice.h +++ b/libretroshare/src/services/p3gxsservice.h @@ -84,6 +84,7 @@ bool checkRequestStatus(const uint32_t &token, uint32_t &status, uint32_t &re // special ones for testing (not in final design) bool tokenList(std::list &tokens); bool popRequestList(const uint32_t &token, std::string &id); +bool fakeprocessrequests(); private: diff --git a/libretroshare/src/services/p3photoservice.cc b/libretroshare/src/services/p3photoservice.cc index 02e4a9a51..00331ead4 100644 --- a/libretroshare/src/services/p3photoservice.cc +++ b/libretroshare/src/services/p3photoservice.cc @@ -40,10 +40,10 @@ PhotoAlbum::PhotoAlbum() } #endif -#define PHOTO_REQUEST_ALBUMLIST 1 -#define PHOTO_REQUEST_PHOTOLIST 2 -#define PHOTO_REQUEST_ALBUMS 3 -#define PHOTO_REQUEST_PHOTOS 4 +#define PHOTO_REQUEST_ALBUMLIST 0x0001 +#define PHOTO_REQUEST_PHOTOLIST 0x0002 +#define PHOTO_REQUEST_ALBUMS 0x0004 +#define PHOTO_REQUEST_PHOTOS 0x0008 /********************************************************************************/ /******************* Startup / Tick ******************************************/ @@ -80,11 +80,11 @@ bool p3PhotoService::updated() } -bool p3PhotoService::requestAlbumList(uint32_t &token) +bool p3PhotoService::requestGroupList( uint32_t &token, const RsTokReqOptions &opts) { generateToken(token); - std::cerr << "p3PhotoService::requestAlbumList() gets Token: " << token << std::endl; + std::cerr << "p3PhotoService::requestGroupList() gets Token: " << token << std::endl; std::list ids; storeRequest(token, GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_GROUPS | PHOTO_REQUEST_ALBUMLIST, ids); @@ -92,39 +92,43 @@ bool p3PhotoService::requestAlbumList(uint32_t &token) return true; } - -bool p3PhotoService::requestPhotoList(uint32_t &token, const std::list &albumids) +bool p3PhotoService::requestMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds) { generateToken(token); - std::cerr << "p3PhotoService::requestPhotoList() gets Token: " << token << std::endl; - storeRequest(token, GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_MSGS | PHOTO_REQUEST_PHOTOLIST, albumids); + std::cerr << "p3PhotoService::requestMsgList() gets Token: " << token << std::endl; + storeRequest(token, GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_MSGS | PHOTO_REQUEST_PHOTOLIST, groupIds); return true; } +bool p3PhotoService::requestMsgRelatedList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds) +{ + std::cerr << "p3PhotoService::requestMsgRelatedList() gets Token: " << token << std::endl; + return false; +} -bool p3PhotoService::requestAlbums(uint32_t &token, const std::list &albumids) +bool p3PhotoService::requestGroupData(uint32_t &token, const std::list &albumids) { generateToken(token); - std::cerr << "p3PhotoService::requestAlbums() gets Token: " << token << std::endl; + std::cerr << "p3PhotoService::requestGroupData() gets Token: " << token << std::endl; storeRequest(token, GXS_REQUEST_TYPE_DATA | GXS_REQUEST_TYPE_GROUPS | PHOTO_REQUEST_ALBUMS, albumids); return true; } -bool p3PhotoService::requestPhotos(uint32_t &token, const std::list &photoids) +bool p3PhotoService::requestMsgData(uint32_t &token, const std::list &photoids) { generateToken(token); - std::cerr << "p3PhotoService::requestPhotos() gets Token: " << token << std::endl; + std::cerr << "p3PhotoService::requestMsgData() gets Token: " << token << std::endl; storeRequest(token, GXS_REQUEST_TYPE_DATA | GXS_REQUEST_TYPE_MSGS | PHOTO_REQUEST_PHOTOS, photoids); return true; } -bool p3PhotoService::getAlbumList(const uint32_t &token, std::list &albums) +bool p3PhotoService::getGroupList(const uint32_t &token, std::list &groupIds) { uint32_t status; uint32_t reqtype; @@ -133,24 +137,24 @@ bool p3PhotoService::getAlbumList(const uint32_t &token, std::list if (reqtype != (GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_GROUPS | PHOTO_REQUEST_ALBUMLIST)) { - std::cerr << "p3PhotoService::getAlbumList() ERROR Type Wrong" << std::endl; + std::cerr << "p3PhotoService::getGroupList() ERROR Type Wrong" << std::endl; return false; } if (status != GXS_REQUEST_STATUS_COMPLETE) { - std::cerr << "p3PhotoService::getAlbumList() ERROR Status Incomplete" << std::endl; + std::cerr << "p3PhotoService::getGroupList() ERROR Status Incomplete" << std::endl; return false; } - bool ans = InternalgetAlbumList(albums); + bool ans = InternalgetAlbumList(groupIds); updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); return ans; } -bool p3PhotoService::getPhotoList(const uint32_t &token, std::list &photos) +bool p3PhotoService::getMsgList(const uint32_t &token, std::list &msgIds) { uint32_t status; uint32_t reqtype; @@ -159,13 +163,13 @@ bool p3PhotoService::getPhotoList(const uint32_t &token, std::list if (reqtype != (GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_MSGS | PHOTO_REQUEST_PHOTOLIST)) { - std::cerr << "p3PhotoService::getPhotoList() ERROR Type Wrong" << std::endl; + std::cerr << "p3PhotoService::getMsgList() ERROR Type Wrong" << std::endl; return false; } if (status != GXS_REQUEST_STATUS_COMPLETE) { - std::cerr << "p3PhotoService::getPhotoList() ERROR Status Incomplete" << std::endl; + std::cerr << "p3PhotoService::getMsgList() ERROR Status Incomplete" << std::endl; return false; } @@ -177,7 +181,7 @@ bool p3PhotoService::getPhotoList(const uint32_t &token, std::list return false; } - bool ans = InternalgetPhotoList(id, photos); + bool ans = InternalgetPhotoList(id, msgIds); // Only one Album at a time -> so finish it! updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); @@ -260,6 +264,7 @@ uint32_t p3PhotoService::requestStatus(const uint32_t token) } +#if 0 #define MAX_REQUEST_AGE 60 bool p3PhotoService::fakeprocessrequests() @@ -304,6 +309,7 @@ bool p3PhotoService::fakeprocessrequests() return true; } +#endif diff --git a/libretroshare/src/services/p3photoservice.h b/libretroshare/src/services/p3photoservice.h index b77d38e50..6f90c7963 100644 --- a/libretroshare/src/services/p3photoservice.h +++ b/libretroshare/src/services/p3photoservice.h @@ -81,16 +81,22 @@ virtual int tick(); virtual bool updated(); + /* Data Requests (from RsTokenService) */ +virtual bool requestGroupList( uint32_t &token, const RsTokReqOptions &opts); +virtual bool requestMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds); +virtual bool requestMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list &msgIds); -virtual bool requestAlbumList(uint32_t &token); -virtual bool requestPhotoList(uint32_t &token, const std::list &albumids); +virtual bool requestGroupData( uint32_t &token, const std::list &groupIds); +virtual bool requestMsgData( uint32_t &token, const std::list &msgIds); -virtual bool requestAlbums(uint32_t &token, const std::list &albumids); -virtual bool requestPhotos(uint32_t &token, const std::list &photoids); + /* Poll */ +virtual uint32_t requestStatus(const uint32_t token); -virtual bool getAlbumList(const uint32_t &token, std::list &albums); -virtual bool getPhotoList(const uint32_t &token, std::list &photos); + /* Generic List Data */ +virtual bool getGroupList(const uint32_t &token, std::list &groupIds); +virtual bool getMsgList(const uint32_t &token, std::list &msgIds); + /* Specific Service Data */ virtual bool getAlbum(const uint32_t &token, RsPhotoAlbum &album); virtual bool getPhoto(const uint32_t &token, RsPhotoPhoto &photo); @@ -98,10 +104,6 @@ virtual bool getPhoto(const uint32_t &token, RsPhotoPhoto &photo); virtual bool submitAlbumDetails(RsPhotoAlbum &album); virtual bool submitPhoto(RsPhotoPhoto &photo); - /* Poll */ -virtual uint32_t requestStatus(const uint32_t token); - -bool fakeprocessrequests(); bool InternalgetAlbumList(std::list &album); bool InternalgetPhotoList(const std::string &albumid, std::list &photoIds); diff --git a/libretroshare/src/services/p3wikiservice.cc b/libretroshare/src/services/p3wikiservice.cc index 292b9007f..d5e548ea9 100644 --- a/libretroshare/src/services/p3wikiservice.cc +++ b/libretroshare/src/services/p3wikiservice.cc @@ -33,13 +33,22 @@ RsWiki *rsWiki = NULL; +#define WIKI_REQUEST_GROUPLIST 0x0001 +#define WIKI_REQUEST_MSGLIST 0x0002 +#define WIKI_REQUEST_GROUPS 0x0004 +#define WIKI_REQUEST_MSGS 0x0008 + +#define WIKI_REQUEST_PAGEVERSIONS 0x0010 +#define WIKI_REQUEST_ORIGPAGE 0x0020 +#define WIKI_REQUEST_LATESTPAGE 0x0040 + /********************************************************************************/ /******************* Startup / Tick ******************************************/ /********************************************************************************/ p3WikiService::p3WikiService(uint16_t type) - :p3Service(type), mWikiMtx("p3WikiService"), mUpdated(true) + :p3GxsService(type), mWikiMtx("p3WikiService"), mUpdated(true) { RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ return; @@ -51,6 +60,8 @@ int p3WikiService::tick() std::cerr << "p3WikiService::tick()"; std::cerr << std::endl; + fakeprocessrequests(); + return 0; } @@ -66,7 +77,245 @@ bool p3WikiService::updated() return false; } -bool p3WikiService::getGroupList(std::list &groups) + + +/***********************************************************************************************/ + + /* Data Requests */ +bool p3WikiService::requestGroupList( uint32_t &token, const RsTokReqOptions &opts) +{ + generateToken(token); + std::cerr << "p3WikiService::requestGroupList() gets Token: " << token << std::endl; + + std::list ids; + storeRequest(token, GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_GROUPS | WIKI_REQUEST_GROUPLIST, ids); + + return true; +} + + +bool p3WikiService::requestMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds) +{ + generateToken(token); + std::cerr << "p3WikiService::requestMsgList() gets Token: " << token << std::endl; + storeRequest(token, GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_MSGS | WIKI_REQUEST_ORIGPAGE, groupIds); + + return true; +} + +bool p3WikiService::requestMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list &msgIds) +{ + generateToken(token); + std::cerr << "p3WikiService::requestMsgRelatedList() gets Token: " << token << std::endl; + + // Look at opts to set the flags. + uint32_t optFlags = 0; + if (opts.mOptions == RS_TOKREQOPT_MSG_VERSIONS) + { + optFlags = WIKI_REQUEST_PAGEVERSIONS; + } + else if (opts.mOptions == RS_TOKREQOPT_MSG_LATEST) + { + optFlags = WIKI_REQUEST_LATESTPAGE; + } + + storeRequest(token, GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_MSGS | optFlags, msgIds); + + return true; +} + + +bool p3WikiService::requestGroupData( uint32_t &token, const std::list &groupIds) +{ + generateToken(token); + std::cerr << "p3WikiService::requestGroupData() gets Token: " << token << std::endl; + storeRequest(token, GXS_REQUEST_TYPE_DATA | GXS_REQUEST_TYPE_GROUPS | WIKI_REQUEST_GROUPS, groupIds); + + return true; +} + +bool p3WikiService::requestMsgData( uint32_t &token, const std::list &msgIds) +{ + generateToken(token); + std::cerr << "p3WikiService::requestMsgData() gets Token: " << token << std::endl; + storeRequest(token, GXS_REQUEST_TYPE_DATA | GXS_REQUEST_TYPE_MSGS | WIKI_REQUEST_MSGS, msgIds); + + return true; +} + +/**************** Return Data *************/ + +bool p3WikiService::getGroupList(const uint32_t &token, std::list &groupIds) +{ + uint32_t status; + uint32_t reqtype; + time_t ts; + checkRequestStatus(token, status, reqtype, ts); + + if (reqtype != (GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_GROUPS | WIKI_REQUEST_GROUPLIST)) + { + std::cerr << "p3WikiService::getGroupList() ERROR Type Wrong" << std::endl; + return false; + } + + if (status != GXS_REQUEST_STATUS_COMPLETE) + { + std::cerr << "p3WikiService::getGroupList() ERROR Status Incomplete" << std::endl; + return false; + } + + bool ans = InternalgetGroupList(groupIds); + + updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); + + return ans; +} + +bool p3WikiService::getMsgList(const uint32_t &token, std::list &msgIds) +{ + uint32_t status; + uint32_t reqtype; + time_t ts; + checkRequestStatus(token, status, reqtype, ts); + + // MULTIPLY TYPES MATCH HERE.... + if (!((reqtype & GXS_REQUEST_TYPE_LIST) && (reqtype & GXS_REQUEST_TYPE_MSGS))) + { + std::cerr << "p3WikiService::getMsgList() ERROR Type Wrong" << std::endl; + return false; + } + + if (status != GXS_REQUEST_STATUS_COMPLETE) + { + std::cerr << "p3WikiService::getMsgList() ERROR Status Incomplete" << std::endl; + return false; + } + + std::string id; + bool ans = false; + while (popRequestList(token, id)) + { + std::cerr << "p3WikiService::getMsgList() Processing Id: " << id << std::endl; + if (reqtype & WIKI_REQUEST_PAGEVERSIONS) + { + std::cerr << "p3WikiService::getMsgList() get PAGEVERSIONS" << std::endl; + if (InternalgetPageVersions(id, msgIds)) + { + ans = true; + } + } + else if (reqtype & WIKI_REQUEST_ORIGPAGE) + { + std::cerr << "p3WikiService::getMsgList() get ORIGPAGE" << std::endl; + if (InternalgetOrigPageList(id, msgIds)) + { + ans = true; + } + } + else if (reqtype & WIKI_REQUEST_LATESTPAGE) + { + std::cerr << "p3WikiService::getMsgList() get LATESTPAGE" << std::endl; + std::string latestpage; + if (InternalgetLatestPage(id, latestpage)) + { + msgIds.push_back(latestpage); + ans = true; + } + } + else + { + std::cerr << "p3WikiService::getMsgList() ERROR Invalid Request Type" << std::endl; + return false; + } + + } + updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); + return ans; +} + + +bool p3WikiService::getGroupData(const uint32_t &token, RsWikiGroup &group) +{ + uint32_t status; + uint32_t reqtype; + time_t ts; + checkRequestStatus(token, status, reqtype, ts); + + if (reqtype != (GXS_REQUEST_TYPE_DATA | GXS_REQUEST_TYPE_GROUPS | WIKI_REQUEST_GROUPS)) + { + std::cerr << "p3WikiService::getGroupData() ERROR Type Wrong" << std::endl; + return false; + } + + if (status != GXS_REQUEST_STATUS_COMPLETE) + { + std::cerr << "p3WikiService::getGroupData() ERROR Status Incomplete" << std::endl; + return false; + } + + std::string id; + if (!popRequestList(token, id)) + { + /* finished */ + updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); + return false; + } + + bool ans = InternalgetGroup(id, group); + return ans; +} + + +bool p3WikiService::getMsgData(const uint32_t &token, RsWikiPage &page) +{ + uint32_t status; + uint32_t reqtype; + time_t ts; + checkRequestStatus(token, status, reqtype, ts); + + if (reqtype != (GXS_REQUEST_TYPE_DATA | GXS_REQUEST_TYPE_MSGS | WIKI_REQUEST_MSGS)) + { + std::cerr << "p3WikiService::getMsgData() ERROR Type Wrong" << std::endl; + return false; + } + + if (status != GXS_REQUEST_STATUS_COMPLETE) + { + std::cerr << "p3WikiService::getMsgData() ERROR Status Incomplete" << std::endl; + return false; + } + + std::string id; + if (!popRequestList(token, id)) + { + /* finished */ + updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); + return false; + } + + bool ans = InternalgetPage(id, page); + return ans; +} + + /* Poll */ +uint32_t p3WikiService::requestStatus(const uint32_t token) +{ + uint32_t status; + uint32_t reqtype; + time_t ts; + checkRequestStatus(token, status, reqtype, ts); + + return status; +} + + + + + +/****************** INTERNALS ***********************/ + + +bool p3WikiService::InternalgetGroupList(std::list &groups) { RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ @@ -79,7 +328,7 @@ bool p3WikiService::getGroupList(std::list &groups) return false; } -bool p3WikiService::getGroup(const std::string &groupid, RsWikiGroup &group) +bool p3WikiService::InternalgetGroup(const std::string &groupid, RsWikiGroup &group) { RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ @@ -96,7 +345,7 @@ bool p3WikiService::getGroup(const std::string &groupid, RsWikiGroup &group) -bool p3WikiService::getPage(const std::string &pageid, RsWikiPage &page) +bool p3WikiService::InternalgetPage(const std::string &pageid, RsWikiPage &page) { RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ @@ -112,7 +361,7 @@ bool p3WikiService::getPage(const std::string &pageid, RsWikiPage &page) } -bool p3WikiService::getLatestPage(const std::string &origPageId, std::string &pageId) +bool p3WikiService::InternalgetLatestPage(const std::string &origPageId, std::string &pageId) { RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ @@ -128,7 +377,7 @@ bool p3WikiService::getLatestPage(const std::string &origPageId, std::string &pa } -bool p3WikiService::getPageVersions(const std::string &origPageId, std::list &pageIds) +bool p3WikiService::InternalgetPageVersions(const std::string &origPageId, std::list &pageIds) { RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ @@ -148,7 +397,7 @@ bool p3WikiService::getPageVersions(const std::string &origPageId, std::list &pageIds) +bool p3WikiService::InternalgetOrigPageList(const std::string &groupid, std::list &pageIds) { RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ diff --git a/libretroshare/src/services/p3wikiservice.h b/libretroshare/src/services/p3wikiservice.h index 92c623b41..a9ee93fdc 100644 --- a/libretroshare/src/services/p3wikiservice.h +++ b/libretroshare/src/services/p3wikiservice.h @@ -26,7 +26,7 @@ #ifndef P3_WIKI_SERVICE_HEADER #define P3_WIKI_SERVICE_HEADER -#include "services/p3service.h" +#include "services/p3gxsservice.h" #include "retroshare/rswiki.h" @@ -48,7 +48,7 @@ * */ -class p3WikiService: public p3Service, public RsWiki +class p3WikiService: public p3GxsService, public RsWiki { public: @@ -58,8 +58,32 @@ virtual int tick(); public: -// NEW INTERFACE. -/************* Extern Interface *******/ + +virtual bool updated(); + + /* Data Requests */ +virtual bool requestGroupList( uint32_t &token, const RsTokReqOptions &opts); +virtual bool requestMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds); +virtual bool requestMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list &msgIds); + +virtual bool requestGroupData( uint32_t &token, const std::list &groupIds); +virtual bool requestMsgData( uint32_t &token, const std::list &msgIds); + +virtual bool getGroupList(const uint32_t &token, std::list &groupIds); +virtual bool getMsgList(const uint32_t &token, std::list &msgIds); + +virtual bool getGroupData(const uint32_t &token, RsWikiGroup &group); +virtual bool getMsgData(const uint32_t &token, RsWikiPage &page); + + /* Poll */ +virtual uint32_t requestStatus(const uint32_t token); + +virtual bool createGroup(RsWikiGroup &group); +virtual bool createPage(RsWikiPage &page); + + +/************* Old Extern Interface *******/ +#if 0 virtual bool updated(); virtual bool getGroupList(std::list &group); @@ -73,8 +97,17 @@ virtual bool getLatestPage(const std::string &origPageId, std::string &page); virtual bool createGroup(RsWikiGroup &group); virtual bool createPage(RsWikiPage &page); +#endif + private: +virtual bool InternalgetGroupList(std::list &group); +virtual bool InternalgetGroup(const std::string &groupid, RsWikiGroup &group); +virtual bool InternalgetPage(const std::string &pageid, RsWikiPage &page); +virtual bool InternalgetPageVersions(const std::string &origPageId, std::list &pages); +virtual bool InternalgetOrigPageList(const std::string &groupid, std::list &pageIds); +virtual bool InternalgetLatestPage(const std::string &origPageId, std::string &page); + std::string genRandomId(); RsMutex mWikiMtx;