mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Convert PhotoService to Request / Response data access.
- Added generic RsTokenService interface to simplify requesting data. - Put the thumbnail images inside RsPhotoPhoto. etc. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5202 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e4ecd898af
commit
d85aff3d0e
@ -30,6 +30,33 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
|
||||||
|
/********** Generic Token Request Interface ***********************
|
||||||
|
* This is packaged here, as most TokenServices will require ID Services too.
|
||||||
|
* The requests can be generic, but the reponses are service specific (dependent on data types).
|
||||||
|
*/
|
||||||
|
|
||||||
|
class RsTokenService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
RsTokenService() { return; }
|
||||||
|
virtual ~RsTokenService() { return; }
|
||||||
|
|
||||||
|
/* Data Requests */
|
||||||
|
virtual bool requestGroupList(uint32_t &token) = 0;
|
||||||
|
virtual bool requestGroupData(uint32_t &token, const std::list<std::string> &ids) = 0;
|
||||||
|
virtual bool requestMsgList(uint32_t &token, const std::list<std::string> &ids) = 0;
|
||||||
|
virtual bool requestMsgData(uint32_t &token, const std::list<std::string> &ids) = 0;
|
||||||
|
|
||||||
|
/* Poll */
|
||||||
|
virtual uint32_t requestStatus(const uint32_t token) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* The Main Interface Class - for information about your Peers */
|
/* The Main Interface Class - for information about your Peers */
|
||||||
class RsIdentity;
|
class RsIdentity;
|
||||||
extern RsIdentity *rsIdentity;
|
extern RsIdentity *rsIdentity;
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <retroshare/rsidentity.h>
|
||||||
|
|
||||||
/* The Main Interface Class - for information about your Peers */
|
/* The Main Interface Class - for information about your Peers */
|
||||||
class RsPhoto;
|
class RsPhoto;
|
||||||
@ -40,6 +41,20 @@ extern RsPhoto *rsPhoto;
|
|||||||
#define RSPHOTO_MODE_OWN 2
|
#define RSPHOTO_MODE_OWN 2
|
||||||
#define RSPHOTO_MODE_REMOTE 3
|
#define RSPHOTO_MODE_REMOTE 3
|
||||||
|
|
||||||
|
class RsPhotoThumbnail
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsPhotoThumbnail()
|
||||||
|
:data(NULL), size(0), type("N/A") { return; }
|
||||||
|
|
||||||
|
bool copyFrom(const RsPhotoThumbnail &nail);
|
||||||
|
|
||||||
|
// Holds Thumbnail image.
|
||||||
|
uint8_t *data;
|
||||||
|
int size;
|
||||||
|
std::string type;
|
||||||
|
};
|
||||||
|
|
||||||
class RsPhotoPhoto
|
class RsPhotoPhoto
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -60,6 +75,8 @@ class RsPhotoPhoto
|
|||||||
|
|
||||||
int mOrder;
|
int mOrder;
|
||||||
|
|
||||||
|
RsPhotoThumbnail mThumbnail;
|
||||||
|
|
||||||
int mMode;
|
int mMode;
|
||||||
std::string path; // if in Mode NEW.
|
std::string path; // if in Mode NEW.
|
||||||
};
|
};
|
||||||
@ -83,22 +100,8 @@ class RsPhotoAlbum: public RsPhotoPhoto
|
|||||||
RsPhotoAlbumShare mShareOptions;
|
RsPhotoAlbumShare mShareOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsPhotoThumbnail
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RsPhotoThumbnail()
|
|
||||||
:data(NULL), size(0), type("N/A") { return; }
|
|
||||||
|
|
||||||
bool copyFrom(const RsPhotoThumbnail &nail);
|
class RsPhoto: public RsTokenService
|
||||||
|
|
||||||
// Holds Thumbnail image.
|
|
||||||
uint8_t *data;
|
|
||||||
int size;
|
|
||||||
std::string type;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class RsPhoto
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -108,17 +111,33 @@ virtual ~RsPhoto() { return; }
|
|||||||
/* changed? */
|
/* changed? */
|
||||||
virtual bool updated() = 0;
|
virtual bool updated() = 0;
|
||||||
|
|
||||||
virtual bool getAlbumList(std::list<std::string> &album) = 0;
|
|
||||||
|
|
||||||
virtual bool getAlbum(const std::string &albumid, RsPhotoAlbum &album) = 0;
|
virtual bool requestAlbumList(uint32_t &token) = 0;
|
||||||
virtual bool getPhoto(const std::string &photoid, RsPhotoPhoto &photo) = 0;
|
virtual bool requestPhotoList(uint32_t &token, const std::list<std::string> &albumids) = 0;
|
||||||
virtual bool getPhotoList(const std::string &albumid, std::list<std::string> &photoIds) = 0;
|
|
||||||
virtual bool getPhotoThumbnail(const std::string &photoid, RsPhotoThumbnail &thumbnail) = 0;
|
virtual bool requestAlbums(uint32_t &token, const std::list<std::string> &albumids) = 0;
|
||||||
virtual bool getAlbumThumbnail(const std::string &albumid, RsPhotoThumbnail &thumbnail) = 0;
|
virtual bool requestPhotos(uint32_t &token, const std::list<std::string> &photoids) = 0;
|
||||||
|
|
||||||
|
virtual bool getAlbumList(const uint32_t &token, std::list<std::string> &albums) = 0;
|
||||||
|
virtual bool getPhotoList(const uint32_t &token, std::list<std::string> &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 */
|
/* details are updated in album - to choose Album ID, and storage path */
|
||||||
virtual bool submitAlbumDetails(RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail) = 0;
|
virtual bool submitAlbumDetails(RsPhotoAlbum &album) = 0;
|
||||||
virtual bool submitPhoto(RsPhotoPhoto &photo, const RsPhotoThumbnail &thumbnail) = 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<std::string> &ids) { return requestAlbums(token, ids); }
|
||||||
|
virtual bool requestMsgList(uint32_t &token, const std::list<std::string> &ids) { return requestPhotoList(token, ids); }
|
||||||
|
virtual bool requestMsgData(uint32_t &token, const std::list<std::string> &ids) { return requestPhotos(token, ids); }
|
||||||
|
|
||||||
|
|
||||||
|
/* Poll */
|
||||||
|
virtual uint32_t requestStatus(const uint32_t token) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,18 +33,24 @@
|
|||||||
RsPhoto *rsPhoto = NULL;
|
RsPhoto *rsPhoto = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
PhotoAlbum::PhotoAlbum()
|
PhotoAlbum::PhotoAlbum()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PHOTO_REQUEST_ALBUMLIST 1
|
||||||
|
#define PHOTO_REQUEST_PHOTOLIST 2
|
||||||
|
#define PHOTO_REQUEST_ALBUMS 3
|
||||||
|
#define PHOTO_REQUEST_PHOTOS 4
|
||||||
|
|
||||||
/********************************************************************************/
|
/********************************************************************************/
|
||||||
/******************* Startup / Tick ******************************************/
|
/******************* Startup / Tick ******************************************/
|
||||||
/********************************************************************************/
|
/********************************************************************************/
|
||||||
|
|
||||||
p3PhotoService::p3PhotoService(uint16_t type)
|
p3PhotoService::p3PhotoService(uint16_t type)
|
||||||
:p3Service(type), mPhotoMtx("p3PhotoService"), mUpdated(true)
|
:p3GxsService(type), mPhotoMtx("p3PhotoService"), mUpdated(true)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||||
return;
|
return;
|
||||||
@ -55,6 +61,8 @@ int p3PhotoService::tick()
|
|||||||
{
|
{
|
||||||
std::cerr << "p3PhotoService::tick()";
|
std::cerr << "p3PhotoService::tick()";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
fakeprocessrequests();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -71,7 +79,237 @@ bool p3PhotoService::updated()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3PhotoService::getAlbumList(std::list<std::string> &album)
|
|
||||||
|
bool p3PhotoService::requestAlbumList(uint32_t &token)
|
||||||
|
{
|
||||||
|
|
||||||
|
generateToken(token);
|
||||||
|
std::cerr << "p3PhotoService::requestAlbumList() gets Token: " << token << std::endl;
|
||||||
|
|
||||||
|
std::list<std::string> ids;
|
||||||
|
storeRequest(token, GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_GROUPS | PHOTO_REQUEST_ALBUMLIST, ids);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3PhotoService::requestPhotoList(uint32_t &token, const std::list<std::string> &albumids)
|
||||||
|
{
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3PhotoService::requestAlbums(uint32_t &token, const std::list<std::string> &albumids)
|
||||||
|
{
|
||||||
|
generateToken(token);
|
||||||
|
std::cerr << "p3PhotoService::requestAlbums() 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<std::string> &photoids)
|
||||||
|
{
|
||||||
|
|
||||||
|
generateToken(token);
|
||||||
|
std::cerr << "p3PhotoService::requestPhotos() 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<std::string> &albums)
|
||||||
|
{
|
||||||
|
uint32_t status;
|
||||||
|
uint32_t reqtype;
|
||||||
|
time_t ts;
|
||||||
|
checkRequestStatus(token, status, reqtype, ts);
|
||||||
|
|
||||||
|
if (reqtype != (GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_GROUPS | PHOTO_REQUEST_ALBUMLIST))
|
||||||
|
{
|
||||||
|
std::cerr << "p3PhotoService::getAlbumList() ERROR Type Wrong" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
||||||
|
{
|
||||||
|
std::cerr << "p3PhotoService::getAlbumList() ERROR Status Incomplete" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ans = InternalgetAlbumList(albums);
|
||||||
|
|
||||||
|
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||||
|
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3PhotoService::getPhotoList(const uint32_t &token, std::list<std::string> &photos)
|
||||||
|
{
|
||||||
|
uint32_t status;
|
||||||
|
uint32_t reqtype;
|
||||||
|
time_t ts;
|
||||||
|
checkRequestStatus(token, status, reqtype, ts);
|
||||||
|
|
||||||
|
if (reqtype != (GXS_REQUEST_TYPE_LIST | GXS_REQUEST_TYPE_MSGS | PHOTO_REQUEST_PHOTOLIST))
|
||||||
|
{
|
||||||
|
std::cerr << "p3PhotoService::getPhotoList() ERROR Type Wrong" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
||||||
|
{
|
||||||
|
std::cerr << "p3PhotoService::getPhotoList() 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 = InternalgetPhotoList(id, photos);
|
||||||
|
|
||||||
|
// Only one Album at a time -> so finish it!
|
||||||
|
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
|
||||||
|
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3PhotoService::getAlbum(const uint32_t &token, RsPhotoAlbum &album)
|
||||||
|
{
|
||||||
|
uint32_t status;
|
||||||
|
uint32_t reqtype;
|
||||||
|
time_t ts;
|
||||||
|
checkRequestStatus(token, status, reqtype, ts);
|
||||||
|
|
||||||
|
if (reqtype != (GXS_REQUEST_TYPE_DATA | GXS_REQUEST_TYPE_GROUPS | PHOTO_REQUEST_ALBUMS))
|
||||||
|
{
|
||||||
|
std::cerr << "p3PhotoService::getAlbum() ERROR Type Wrong" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
||||||
|
{
|
||||||
|
std::cerr << "p3PhotoService::getAlbum() 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 = InternalgetAlbum(id, album);
|
||||||
|
return ans;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3PhotoService::getPhoto(const uint32_t &token, RsPhotoPhoto &photo)
|
||||||
|
{
|
||||||
|
uint32_t status;
|
||||||
|
uint32_t reqtype;
|
||||||
|
time_t ts;
|
||||||
|
checkRequestStatus(token, status, reqtype, ts);
|
||||||
|
|
||||||
|
if (reqtype != (GXS_REQUEST_TYPE_DATA | GXS_REQUEST_TYPE_MSGS | PHOTO_REQUEST_PHOTOS))
|
||||||
|
{
|
||||||
|
std::cerr << "p3PhotoService::getPhoto() ERROR Type Wrong" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status != GXS_REQUEST_STATUS_COMPLETE)
|
||||||
|
{
|
||||||
|
std::cerr << "p3PhotoService::getPhoto() 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 = InternalgetPhoto(id, photo);
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Poll */
|
||||||
|
uint32_t p3PhotoService::requestStatus(const uint32_t token)
|
||||||
|
{
|
||||||
|
uint32_t status;
|
||||||
|
uint32_t reqtype;
|
||||||
|
time_t ts;
|
||||||
|
checkRequestStatus(token, status, reqtype, ts);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_REQUEST_AGE 60
|
||||||
|
|
||||||
|
bool p3PhotoService::fakeprocessrequests()
|
||||||
|
{
|
||||||
|
std::list<uint32_t>::iterator it;
|
||||||
|
std::list<uint32_t> 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 << "p3PhotoService::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 << "p3PhotoService::fakeprocessrequests() Clearing Done Request Token: " << token;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
clearRequest(token);
|
||||||
|
}
|
||||||
|
else if (now - ts > MAX_REQUEST_AGE)
|
||||||
|
{
|
||||||
|
std::cerr << "p3PhotoService::fakeprocessrequests() Clearing Old Request Token: " << token;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
clearRequest(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/******************* INTERNALS UNTIL ITS PROPERLY LINKED IN ************************/
|
||||||
|
|
||||||
|
bool p3PhotoService::InternalgetAlbumList(std::list<std::string> &album)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
@ -84,7 +322,7 @@ bool p3PhotoService::getAlbumList(std::list<std::string> &album)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3PhotoService::getAlbum(const std::string &albumid, RsPhotoAlbum &album)
|
bool p3PhotoService::InternalgetAlbum(const std::string &albumid, RsPhotoAlbum &album)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
@ -99,7 +337,7 @@ bool p3PhotoService::getAlbum(const std::string &albumid, RsPhotoAlbum &album)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3PhotoService::getPhoto(const std::string &photoid, RsPhotoPhoto &photo)
|
bool p3PhotoService::InternalgetPhoto(const std::string &photoid, RsPhotoPhoto &photo)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
@ -114,7 +352,7 @@ bool p3PhotoService::getPhoto(const std::string &photoid, RsPhotoPhoto &photo)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3PhotoService::getPhotoList(const std::string &albumid, std::list<std::string> &photoIds)
|
bool p3PhotoService::InternalgetPhotoList(const std::string &albumid, std::list<std::string> &photoIds)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
@ -133,6 +371,76 @@ bool p3PhotoService::getPhotoList(const std::string &albumid, std::list<std::str
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* details are updated in album - to choose Album ID, and storage path */
|
||||||
|
bool p3PhotoService::submitAlbumDetails(RsPhotoAlbum &album)
|
||||||
|
{
|
||||||
|
/* check if its a modification or a new album */
|
||||||
|
|
||||||
|
|
||||||
|
/* add to database */
|
||||||
|
|
||||||
|
/* check if its a mod or new photo */
|
||||||
|
if (album.mId.empty())
|
||||||
|
{
|
||||||
|
/* new photo */
|
||||||
|
|
||||||
|
/* generate a temp id */
|
||||||
|
album.mAlbumId = genRandomId();
|
||||||
|
}
|
||||||
|
|
||||||
|
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
mUpdated = true;
|
||||||
|
|
||||||
|
/* add / modify */
|
||||||
|
mAlbums[album.mAlbumId] = album;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3PhotoService::submitPhoto(RsPhotoPhoto &photo)
|
||||||
|
{
|
||||||
|
if (photo.mAlbumId.empty())
|
||||||
|
{
|
||||||
|
/* new photo */
|
||||||
|
std::cerr << "p3PhotoService::submitPhoto() Missing AlbumID: ERROR";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check if its a mod or new photo */
|
||||||
|
if (photo.mId.empty())
|
||||||
|
{
|
||||||
|
/* new photo */
|
||||||
|
|
||||||
|
/* generate a temp id */
|
||||||
|
photo.mId = genRandomId();
|
||||||
|
}
|
||||||
|
|
||||||
|
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
mUpdated = true;
|
||||||
|
|
||||||
|
std::map<std::string, std::list<std::string> >::iterator it;
|
||||||
|
it = mAlbumToPhotos.find(photo.mAlbumId);
|
||||||
|
if (it == mAlbumToPhotos.end())
|
||||||
|
{
|
||||||
|
std::list<std::string> emptyList;
|
||||||
|
mAlbumToPhotos[photo.mAlbumId] = emptyList;
|
||||||
|
|
||||||
|
it = mAlbumToPhotos.find(photo.mAlbumId);
|
||||||
|
}
|
||||||
|
|
||||||
|
it->second.push_back(photo.mId);
|
||||||
|
|
||||||
|
/* add / modify */
|
||||||
|
mPhotos[photo.mId] = photo;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
bool p3PhotoService::getPhotoThumbnail(const std::string &photoid, RsPhotoThumbnail &thumbnail)
|
bool p3PhotoService::getPhotoThumbnail(const std::string &photoid, RsPhotoThumbnail &thumbnail)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||||
@ -165,7 +473,6 @@ bool p3PhotoService::getAlbumThumbnail(const std::string &albumid, RsPhotoThumbn
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* details are updated in album - to choose Album ID, and storage path */
|
/* details are updated in album - to choose Album ID, and storage path */
|
||||||
bool p3PhotoService::submitAlbumDetails(RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail)
|
bool p3PhotoService::submitAlbumDetails(RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail)
|
||||||
{
|
{
|
||||||
@ -244,6 +551,7 @@ bool p3PhotoService::submitPhoto(RsPhotoPhoto &photo, const RsPhotoThumbnail &th
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string p3PhotoService::genRandomId()
|
std::string p3PhotoService::genRandomId()
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#ifndef P3_PHOTO_SERVICE_HEADER
|
#ifndef P3_PHOTO_SERVICE_HEADER
|
||||||
#define P3_PHOTO_SERVICE_HEADER
|
#define P3_PHOTO_SERVICE_HEADER
|
||||||
|
|
||||||
#include "services/p3service.h"
|
#include "services/p3gxsservice.h"
|
||||||
#include "retroshare/rsphoto.h"
|
#include "retroshare/rsphoto.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -47,6 +47,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
class PhotoAlbum
|
class PhotoAlbum
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -61,9 +62,11 @@ class PhotoAlbum
|
|||||||
std::map<std::string, RsPhotoThumbnail> mNails;
|
std::map<std::string, RsPhotoThumbnail> mNails;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class p3PhotoService: public p3Service, public RsPhoto
|
|
||||||
|
class p3PhotoService: public p3GxsService, public RsPhoto
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -77,6 +80,36 @@ virtual int tick();
|
|||||||
/************* Extern Interface *******/
|
/************* Extern Interface *******/
|
||||||
|
|
||||||
virtual bool updated();
|
virtual bool updated();
|
||||||
|
|
||||||
|
|
||||||
|
virtual bool requestAlbumList(uint32_t &token);
|
||||||
|
virtual bool requestPhotoList(uint32_t &token, const std::list<std::string> &albumids);
|
||||||
|
|
||||||
|
virtual bool requestAlbums(uint32_t &token, const std::list<std::string> &albumids);
|
||||||
|
virtual bool requestPhotos(uint32_t &token, const std::list<std::string> &photoids);
|
||||||
|
|
||||||
|
virtual bool getAlbumList(const uint32_t &token, std::list<std::string> &albums);
|
||||||
|
virtual bool getPhotoList(const uint32_t &token, std::list<std::string> &photos);
|
||||||
|
|
||||||
|
virtual bool getAlbum(const uint32_t &token, RsPhotoAlbum &album);
|
||||||
|
virtual bool getPhoto(const uint32_t &token, RsPhotoPhoto &photo);
|
||||||
|
|
||||||
|
/* details are updated in album - to choose Album ID, and storage path */
|
||||||
|
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<std::string> &album);
|
||||||
|
bool InternalgetPhotoList(const std::string &albumid, std::list<std::string> &photoIds);
|
||||||
|
bool InternalgetAlbum(const std::string &albumid, RsPhotoAlbum &album);
|
||||||
|
bool InternalgetPhoto(const std::string &photoid, RsPhotoPhoto &photo);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
virtual bool updated();
|
||||||
virtual bool getAlbumList(std::list<std::string> &album);
|
virtual bool getAlbumList(std::list<std::string> &album);
|
||||||
|
|
||||||
virtual bool getAlbum(const std::string &albumid, RsPhotoAlbum &album);
|
virtual bool getAlbum(const std::string &albumid, RsPhotoAlbum &album);
|
||||||
@ -88,6 +121,7 @@ virtual bool getAlbumThumbnail(const std::string &albumid, RsPhotoThumbnail &thu
|
|||||||
/* details are updated in album - to choose Album ID, and storage path */
|
/* details are updated in album - to choose Album ID, and storage path */
|
||||||
virtual bool submitAlbumDetails(RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail);
|
virtual bool submitAlbumDetails(RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail);
|
||||||
virtual bool submitPhoto(RsPhotoPhoto &photo, const RsPhotoThumbnail &thumbnail);
|
virtual bool submitPhoto(RsPhotoPhoto &photo, const RsPhotoThumbnail &thumbnail);
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -101,10 +135,7 @@ std::string genRandomId();
|
|||||||
|
|
||||||
std::map<std::string, std::list<std::string > > mAlbumToPhotos;
|
std::map<std::string, std::list<std::string > > mAlbumToPhotos;
|
||||||
std::map<std::string, RsPhotoPhoto> mPhotos;
|
std::map<std::string, RsPhotoPhoto> mPhotos;
|
||||||
std::map<std::string, RsPhotoThumbnail *> mPhotoThumbnails;
|
|
||||||
|
|
||||||
std::map<std::string, RsPhotoAlbum> mAlbums;
|
std::map<std::string, RsPhotoAlbum> mAlbums;
|
||||||
std::map<std::string, RsPhotoThumbnail *> mAlbumThumbnails;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user