Fixed compile issues for VEG in librs (rs-gui VEG ui cannot be compiled as was the case prior to issues)

removed VEG photoservice
Enabled group synchronisation between retroshare peers! test synchro between two rs peers worked.
Added crude commenting facility to photoshare, much tuning to be done



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5602 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-09-25 21:04:04 +00:00
parent 51362f7bac
commit 0fc3a2704b
29 changed files with 653 additions and 1087 deletions

View file

@ -5,6 +5,11 @@
RsPhotoV2 *rsPhotoV2 = NULL;
const uint32_t RsPhotoV2::FLAG_MSG_TYPE_MASK = 0x000f;
const uint32_t RsPhotoV2::FLAG_MSG_TYPE_PHOTO_POST = 0x0001;
const uint32_t RsPhotoV2::FLAG_MSG_TYPE_PHOTO_COMMENT = 0x0002;
bool RsPhotoThumbnail::copyFrom(const RsPhotoThumbnail &nail)
@ -75,33 +80,46 @@ std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album)
}
p3PhotoServiceV2::p3PhotoServiceV2(RsGeneralDataService* gds, RsNetworkExchangeService* nes)
: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser(), RS_SERVICE_GXSV1_TYPE_PHOTO)
: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser(), RS_SERVICE_GXSV1_TYPE_PHOTO), mPhotoMutex(std::string("Photo Mutex"))
{
// create dummy grps
RsGxsPhotoAlbumItem* item1 = new RsGxsPhotoAlbumItem(), *item2 = new RsGxsPhotoAlbumItem();
item1->meta.mGroupName = "Dummy Album 1";
item2->meta.mGroupName = "Dummy Album 2";
createDummyGroup(item1);
createDummyGroup(item2);
}
bool p3PhotoServiceV2::updated()
{
bool changed = (!mGroupChange.empty() || !mMsgChange.empty());
RsStackMutex stack(mPhotoMutex);
return changed;
bool changed = (!mGroupChange.empty() || !mMsgChange.empty());
return changed;
}
void p3PhotoServiceV2::groupsChanged(std::list<RsGxsGroupId>& grpIds)
{
while(!mGroupChange.empty())
{
RsGxsGroupChange* gc = mGroupChange.back();
std::list<RsGxsGroupId>& gList = gc->grpIdList;
std::list<RsGxsGroupId>::iterator lit = gList.begin();
for(; lit != gList.end(); lit++)
grpIds.push_back(*lit);
RsStackMutex stack(mPhotoMutex);
mGroupChange.pop_back();
delete gc;
}
while(!mGroupChange.empty())
{
RsGxsGroupChange* gc = mGroupChange.back();
std::list<RsGxsGroupId>& gList = gc->grpIdList;
std::list<RsGxsGroupId>::iterator lit = gList.begin();
for(; lit != gList.end(); lit++)
grpIds.push_back(*lit);
mGroupChange.pop_back();
delete gc;
}
}
@ -192,13 +210,14 @@ bool p3PhotoServiceV2::getPhoto(const uint32_t& token, PhotoResult& photos)
if(item)
{
RsPhotoPhoto photo = item->photo;
RsPhotoPhoto photo = item->photo;
photo.mMeta = item->meta;
photos[grpId].push_back(photo);
delete item;
}else
{
delete *vit;
std::cerr << "Not a photo Item, deleting!" << std::endl;
delete *vit;
}
}
}
@ -207,40 +226,79 @@ bool p3PhotoServiceV2::getPhoto(const uint32_t& token, PhotoResult& photos)
return ok;
}
bool p3PhotoServiceV2::getPhotoComment(const uint32_t &token, PhotoCommentResult &comments)
{
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<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
for(; vit != msgItems.end(); vit++)
{
RsGxsPhotoCommentItem* item = dynamic_cast<RsGxsPhotoCommentItem*>(*vit);
if(item)
{
RsPhotoComment comment = item->comment;
comment.mMeta = item->meta;
comments[grpId].push_back(comment);
delete item;
}else
{
std::cerr << "Not a comment Item, deleting!" << std::endl;
delete *vit;
}
}
}
}
return ok;
}
bool p3PhotoServiceV2::submitAlbumDetails(uint32_t& token, RsPhotoAlbum& album)
{
RsGxsPhotoAlbumItem* albumItem = new RsGxsPhotoAlbumItem();
albumItem->album = album;
albumItem->meta = album.mMeta;
RsGenExchange::publishGroup(token, albumItem);
return true;
RsGxsPhotoAlbumItem* albumItem = new RsGxsPhotoAlbumItem();
albumItem->album = album;
albumItem->meta = album.mMeta;
RsGenExchange::publishGroup(token, albumItem);
return true;
}
void p3PhotoServiceV2::notifyChanges(std::vector<RsGxsNotify*>& changes)
{
std::vector<RsGxsNotify*>::iterator vit = changes.begin();
for(; vit != changes.end(); vit++)
{
RsGxsNotify* n = *vit;
RsGxsGroupChange* gc;
RsGxsMsgChange* mc;
if((mc = dynamic_cast<RsGxsMsgChange*>(n)) != NULL)
{
mMsgChange.push_back(mc);
}
else if((gc = dynamic_cast<RsGxsGroupChange*>(n)) != NULL)
{
mGroupChange.push_back(gc);
}
else
{
delete n;
}
}
RsStackMutex stack(mPhotoMutex);
std::vector<RsGxsNotify*>::iterator vit = changes.begin();
for(; vit != changes.end(); vit++)
{
RsGxsNotify* n = *vit;
RsGxsGroupChange* gc;
RsGxsMsgChange* mc;
if((mc = dynamic_cast<RsGxsMsgChange*>(n)) != NULL)
{
mMsgChange.push_back(mc);
}
else if((gc = dynamic_cast<RsGxsGroupChange*>(n)) != NULL)
{
mGroupChange.push_back(gc);
}
else
{
delete n;
}
}
}
bool p3PhotoServiceV2::submitPhoto(uint32_t& token, RsPhotoPhoto& photo)
@ -248,6 +306,7 @@ bool p3PhotoServiceV2::submitPhoto(uint32_t& token, RsPhotoPhoto& photo)
RsGxsPhotoPhotoItem* photoItem = new RsGxsPhotoPhotoItem();
photoItem->photo = photo;
photoItem->meta = photo.mMeta;
photoItem->meta.mMsgFlags = FLAG_MSG_TYPE_PHOTO_POST;
RsGenExchange::publishMsg(token, photoItem);
return true;
@ -258,6 +317,7 @@ bool p3PhotoServiceV2::submitComment(uint32_t &token, RsPhotoComment &comment)
RsGxsPhotoCommentItem* commentItem = new RsGxsPhotoCommentItem();
commentItem->comment = comment;
commentItem->meta = comment.mMeta;
commentItem->meta.mMsgFlags = FLAG_MSG_TYPE_PHOTO_COMMENT;
RsGenExchange::publishMsg(token, commentItem);
return true;

View file

@ -73,6 +73,7 @@ public:
/* Specific Service Data */
bool getAlbum(const uint32_t &token, std::vector<RsPhotoAlbum> &albums);
bool getPhoto(const uint32_t &token, PhotoResult &photos);
bool getPhotoComment(const uint32_t &token, PhotoCommentResult &comments);
public:
@ -134,6 +135,8 @@ private:
std::vector<RsGxsGroupChange*> mGroupChange;
std::vector<RsGxsMsgChange*> mMsgChange;
RsMutex mPhotoMutex;
};
#endif // P3PHOTOSERVICEV2_H

View file

@ -1,680 +0,0 @@
/*
* libretroshare/src/services p3photoservice.cc
*
* Photo Service for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "services/p3photoserviceVEG.h"
#include "util/rsrandom.h"
/****
* #define PHOTO_DEBUG 1
****/
RsPhotoVEG *rsPhotoVEG = NULL;
/********************************************************************************/
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3PhotoServiceVEG::p3PhotoServiceVEG(uint16_t type)
:p3GxsDataServiceVEG(type, new PhotoDataProxy()), mPhotoMtx("p3PhotoService"), mUpdated(true)
{
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
mPhotoProxy = (PhotoDataProxy *) mProxy;
return;
}
int p3PhotoServiceVEG::tick()
{
//std::cerr << "p3PhotoServiceVEG::tick()";
//std::cerr << std::endl;
fakeprocessrequests();
return 0;
}
bool p3PhotoServiceVEG::updated()
{
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
if (mUpdated)
{
mUpdated = false;
return true;
}
return false;
}
/* Data Requests */
bool p3PhotoServiceVEG::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "p3PhotoServiceVEG::requestGroupInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
return true;
}
bool p3PhotoServiceVEG::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds)
{
generateToken(token);
std::cerr << "p3PhotoServiceVEG::requestMsgInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds);
return true;
}
bool p3PhotoServiceVEG::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds)
{
generateToken(token);
std::cerr << "p3PhotoServiceVEG::requestMsgRelatedInfo() gets Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
/* Generic Lists */
bool p3PhotoServiceVEG::getGroupList( const uint32_t &token, std::list<std::string> &groupIds)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
{
std::cerr << "p3PhotoServiceVEG::getGroupList() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3PhotoServiceVEG::getGroupList() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3PhotoServiceVEG::getGroupList() ERROR Status Incomplete" << std::endl;
return false;
}
bool ans = loadRequestOutList(token, groupIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return ans;
}
bool p3PhotoServiceVEG::getMsgList( const uint32_t &token, std::list<std::string> &msgIds)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_LIST)
{
std::cerr << "p3PhotoServiceVEG::getMsgList() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3PhotoServiceVEG::getMsgList() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3PhotoServiceVEG::getMsgList() ERROR Status Incomplete" << std::endl;
return false;
}
bool ans = loadRequestOutList(token, msgIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return ans;
}
/* Generic Summary */
bool p3PhotoServiceVEG::getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "p3PhotoServiceVEG::getGroupSummary() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3PhotoServiceVEG::getGroupSummary() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3PhotoServiceVEG::getGroupSummary() ERROR Status Incomplete" << std::endl;
return false;
}
std::list<std::string> groupIds;
bool ans = loadRequestOutList(token, groupIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
/* convert to RsGroupMetaData */
mProxy->getGroupSummary(groupIds, groupInfo);
return ans;
}
bool p3PhotoServiceVEG::getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY)
{
std::cerr << "p3PhotoServiceVEG::getMsgSummary() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3PhotoServiceVEG::getMsgSummary() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3PhotoServiceVEG::getMsgSummary() ERROR Status Incomplete" << std::endl;
return false;
}
std::list<std::string> msgIds;
bool ans = loadRequestOutList(token, msgIds);
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
/* convert to RsMsgMetaData */
mProxy->getMsgSummary(msgIds, msgInfo);
return ans;
}
/* Specific Service Data */
bool p3PhotoServiceVEG::getAlbum(const uint32_t &token, RsPhotoAlbum &album)
{
std::cerr << "p3PhotoServiceVEG::getAlbum() Token: " << token;
std::cerr << std::endl;
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
{
std::cerr << "p3PhotoServiceVEG::getAlbum() ERROR AnsType Wrong" << std::endl;
return false;
}
if (reqtype != GXS_REQUEST_TYPE_GROUPS)
{
std::cerr << "p3PhotoServiceVEG::getAlbum() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3PhotoServiceVEG::getAlbum() ERROR Status Incomplete" << std::endl;
return false;
}
std::string id;
if (!popRequestOutList(token, id))
{
/* finished */
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return false;
}
/* convert to RsPhotoAlbum */
bool ans = mPhotoProxy->getAlbum(id, album);
return ans;
}
bool p3PhotoServiceVEG::getPhoto(const uint32_t &token, RsPhotoPhoto &photo)
{
std::cerr << "p3PhotoServiceVEG::getPhoto() Token: " << token;
std::cerr << std::endl;
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
if (anstype != RS_TOKREQ_ANSTYPE_DATA)
{
std::cerr << "p3PhotoServiceVEG::getPhoto() ERROR AnsType Wrong" << std::endl;
return false;
}
if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED))
{
std::cerr << "p3PhotoServiceVEG::getPhoto() ERROR ReqType Wrong" << std::endl;
return false;
}
if (status != GXS_REQUEST_STATUS_COMPLETE)
{
std::cerr << "p3PhotoServiceVEG::getPhoto() ERROR Status Incomplete" << std::endl;
return false;
}
std::string id;
if (!popRequestOutList(token, id))
{
/* finished */
updateRequestStatus(token, GXS_REQUEST_STATUS_DONE);
return false;
}
/* convert to RsPhotoAlbum */
bool ans = mPhotoProxy->getPhoto(id, photo);
return ans;
}
/* Poll */
uint32_t p3PhotoServiceVEG::requestStatus(const uint32_t token)
{
uint32_t status;
uint32_t reqtype;
uint32_t anstype;
time_t ts;
checkRequestStatus(token, status, reqtype, anstype, ts);
return status;
}
/* Cancel Request */
bool p3PhotoServiceVEG::cancelRequest(const uint32_t &token)
{
return clearRequest(token);
}
bool p3PhotoServiceVEG::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask)
{
return mPhotoProxy->setMessageStatus(msgId, status, statusMask);
}
bool p3PhotoServiceVEG::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask)
{
return mPhotoProxy->setGroupStatus(groupId, status, statusMask);
}
bool p3PhotoServiceVEG::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask)
{
return mPhotoProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask);
}
bool p3PhotoServiceVEG::setMessageServiceString(const std::string &msgId, const std::string &str)
{
return mPhotoProxy->setMessageServiceString(msgId, str);
}
bool p3PhotoServiceVEG::setGroupServiceString(const std::string &grpId, const std::string &str)
{
return mPhotoProxy->setGroupServiceString(grpId, str);
}
bool p3PhotoServiceVEG::groupRestoreKeys(const std::string &groupId)
{
return false;
}
bool p3PhotoServiceVEG::groupShareKeys(const std::string &groupId, std::list<std::string>& peers)
{
return false;
}
/* details are updated in album - to choose Album ID, and storage path */
bool p3PhotoServiceVEG::submitAlbumDetails(uint32_t &token, RsPhotoAlbum &album, bool isNew)
{
/* check if its a modification or a new album */
/* add to database */
/* check if its a mod or new photo */
if (album.mMeta.mGroupId.empty())
{
/* new photo */
/* generate a temp id */
album.mMeta.mGroupId = genRandomId();
// TODO.
//album.mMeta.mPublishTs = time(NULL);
std::cerr << "p3PhotoServiceVEG::submitAlbumDetails() Generated New GroupID: " << album.mMeta.mGroupId;
std::cerr << std::endl;
}
album.mModFlags = 0; // These are always cleared.
{
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
mUpdated = true;
/* add / modify */
mPhotoProxy->addAlbum(album);
}
// Fake a request to return the GroupMetaData.
generateToken(token);
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptionsVEG opts; // NULL is good.
std::list<std::string> groupIds;
groupIds.push_back(album.mMeta.mGroupId); // It will just return this one.
std::cerr << "p3PhotoServiceVEG::submitAlbumDetails() Generating Request Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds);
return true;
}
bool p3PhotoServiceVEG::submitPhoto(uint32_t &token, RsPhotoPhoto &photo, bool isNew)
{
if (photo.mMeta.mGroupId.empty())
{
/* new photo */
std::cerr << "p3PhotoServiceVEG::submitPhoto() Missing GroupID: ERROR";
std::cerr << std::endl;
return false;
}
/* generate a new id */
photo.mMeta.mMsgId = genRandomId();
photo.mMeta.mPublishTs = time(NULL);
if (isNew)
{
/* new (Original Msg) photo */
photo.mMeta.mOrigMsgId = photo.mMeta.mMsgId;
std::cerr << "p3PhotoServiceVEG::submitPhoto() New Msg";
std::cerr << std::endl;
}
else
{
std::cerr << "p3PhotoServiceVEG::submitPhoto() Updated Msg";
std::cerr << std::endl;
}
photo.mModFlags = 0; // These are always cleared.
std::cerr << "p3PhotoServiceVEG::submitPhoto() OrigMsgId: " << photo.mMeta.mOrigMsgId;
std::cerr << " MsgId: " << photo.mMeta.mMsgId;
std::cerr << std::endl;
{
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
mUpdated = true;
mPhotoProxy->addPhoto(photo);
}
// Fake a request to return the MsgMetaData.
generateToken(token);
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptionsVEG opts; // NULL is good.
std::list<std::string> msgIds;
msgIds.push_back(photo.mMeta.mMsgId); // It will just return this one.
std::cerr << "p3PhotoServiceVEG::submitPhoto() Generating Request Token: " << token << std::endl;
storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds);
return true;
}
/********************************************************************************************/
bool PhotoDataProxy::getAlbum(const std::string &id, RsPhotoAlbum &album)
{
void *groupData = NULL;
RsGroupMetaData meta;
if (getGroupData(id, groupData) && getGroupSummary(id, meta))
{
RsPhotoAlbum *pA = (RsPhotoAlbum *) groupData;
// Shallow copy of thumbnail.
album = *pA;
// update definitive version of the metadata.
album.mMeta = meta;
std::cerr << "PhotoDataProxy::getAlbum() Id: " << id;
std::cerr << " MetaData: " << meta << " DataPointer: " << groupData;
std::cerr << std::endl;
return true;
}
std::cerr << "PhotoDataProxy::getAlbum() FAILED Id: " << id;
std::cerr << std::endl;
return false;
}
bool PhotoDataProxy::getPhoto(const std::string &id, RsPhotoPhoto &photo)
{
void *msgData = NULL;
RsMsgMetaData meta;
if (getMsgData(id, msgData) && getMsgSummary(id, meta))
{
RsPhotoPhoto *pP = (RsPhotoPhoto *) msgData;
// Shallow copy of thumbnail.
photo = *pP;
// update definitive version of the metadata.
photo.mMeta = meta;
std::cerr << "PhotoDataProxy::getPhoto() Id: " << id;
std::cerr << " MetaData: " << meta << " DataPointer: " << msgData;
std::cerr << std::endl;
return true;
}
std::cerr << "PhotoDataProxy::getPhoto() FAILED Id: " << id;
std::cerr << std::endl;
return false;
}
bool PhotoDataProxy::addAlbum(const RsPhotoAlbum &album)
{
// Make duplicate.
RsPhotoAlbum *pA = new RsPhotoAlbum();
*pA = album;
std::cerr << "PhotoDataProxy::addAlbum()";
std::cerr << " MetaData: " << pA->mMeta << " DataPointer: " << pA;
std::cerr << std::endl;
// deep copy thumbnail.
pA->mThumbnail.data = NULL;
pA->mThumbnail.copyFrom(album.mThumbnail);
return createGroup(pA);
}
bool PhotoDataProxy::addPhoto(const RsPhotoPhoto &photo)
{
// Make duplicate.
RsPhotoPhoto *pP = new RsPhotoPhoto();
*pP = photo;
std::cerr << "PhotoDataProxy::addPhoto()";
std::cerr << " MetaData: " << pP->mMeta << " DataPointer: " << pP;
std::cerr << std::endl;
// deep copy thumbnail.
pP->mThumbnail.data = NULL;
pP->mThumbnail.copyFrom(photo.mThumbnail);
return createMsg(pP);
}
/* These Functions must be overloaded to complete the service */
bool PhotoDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta)
{
RsPhotoAlbum *album = (RsPhotoAlbum *) groupData;
meta = album->mMeta;
return true;
}
bool PhotoDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta)
{
RsPhotoPhoto *photo = (RsPhotoPhoto *) msgData;
meta = photo->mMeta;
return true;
}
/********************************************************************************************/
std::string p3PhotoServiceVEG::genRandomId()
{
std::string randomId;
for(int i = 0; i < 20; i++)
{
randomId += (char) ('a' + (RSRandom::random_u32() % 26));
}
return randomId;
}
bool RsPhotoThumbnail::copyFrom(const RsPhotoThumbnail &nail)
{
if (data)
{
deleteImage();
}
if ((!nail.data) || (nail.size == 0))
{
return false;
}
size = nail.size;
type = nail.type;
data = (uint8_t *) malloc(size);
memcpy(data, nail.data, size);
return true;
}
bool RsPhotoThumbnail::deleteImage()
{
if (data)
{
free(data);
data = NULL;
size = 0;
type.clear();
}
return true;
}
/********************************************************************************************/
RsPhotoPhoto::RsPhotoPhoto()
:mSetFlags(0), mOrder(0), mMode(0), mModFlags(0)
{
return;
}
RsPhotoAlbum::RsPhotoAlbum()
:mMode(0), mSetFlags(0), mModFlags(0)
{
return;
}
std::ostream &operator<<(std::ostream &out, const RsPhotoPhoto &photo)
{
out << "RsPhotoPhoto [ ";
out << "Title: " << photo.mMeta.mMsgName;
out << "]";
return out;
}
std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album)
{
out << "RsPhotoAlbum [ ";
out << "Title: " << album.mMeta.mGroupName;
out << "]";
return out;
}

View file

@ -1,138 +0,0 @@
/*
* libretroshare/src/services: p3photoservice.h
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2012-2012 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#ifndef P3_PHOTO_SERVICE_VEG_HEADER
#define P3_PHOTO_SERVICE_VEG_HEADER
#include "services/p3gxsserviceVEG.h"
#include "retroshare/rsphotoVEG.h"
#include <map>
#include <string>
/*
* Photo Service
*
* This is an example service for the new cache system.
* For the moment, it will only hold data passed to it from the GUI.
* and spew that back when asked....
*
* We are doing it like this - so we can check the required interface functionality.
*
* Expect it won't take long before it'll be properly linked into the backend!
*
* This will be transformed into a Plugin Service, once the basics have been worked out.
*
*/
class PhotoDataProxy: public GxsDataProxyVEG
{
public:
bool addAlbum(const RsPhotoAlbum &album);
bool addPhoto(const RsPhotoPhoto &photo);
bool getAlbum(const std::string &id, RsPhotoAlbum &album);
bool getPhoto(const std::string &id, RsPhotoPhoto &photo);
/* These Functions must be overloaded to complete the service */
virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta);
virtual bool convertMsgToMetaData(void *groupData, RsMsgMetaData &meta);
};
class p3PhotoServiceVEG: public p3GxsDataServiceVEG, public RsPhotoVEG
{
public:
p3PhotoServiceVEG(uint16_t type);
virtual int tick();
public:
// NEW INTERFACE.
/************* Extern Interface *******/
/* changed? */
virtual bool updated();
/* Data Requests */
virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &groupIds);
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list<std::string> &msgIds);
/* Generic Lists */
virtual bool getGroupList( const uint32_t &token, std::list<std::string> &groupIds);
virtual bool getMsgList( const uint32_t &token, std::list<std::string> &msgIds);
/* Generic Summary */
virtual bool getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
virtual bool getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo);
/* Actual Data -> specific to Interface */
/* Specific Service Data */
virtual bool getAlbum(const uint32_t &token, RsPhotoAlbum &album);
virtual bool getPhoto(const uint32_t &token, RsPhotoPhoto &photo);
/* Poll */
virtual uint32_t requestStatus(const uint32_t token);
/* Cancel Request */
virtual bool cancelRequest(const uint32_t &token);
//////////////////////////////////////////////////////////////////////////////
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask);
virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
virtual bool setMessageServiceString(const std::string &msgId, const std::string &str);
virtual bool setGroupServiceString(const std::string &grpId, const std::string &str);
virtual bool groupRestoreKeys(const std::string &groupId);
virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
/* details are updated in album - to choose Album ID, and storage path */
virtual bool submitAlbumDetails(uint32_t &token, RsPhotoAlbum &album, bool isNew);
virtual bool submitPhoto(uint32_t &token, RsPhotoPhoto &photo, bool isNew);
private:
std::string genRandomId();
PhotoDataProxy *mPhotoProxy;
RsMutex mPhotoMtx;
bool mUpdated;
};
#endif