mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-15 10:00:51 -04:00
Adding backends for new Plugin Services: Photo and Wiki.
- These are dummy services at the moment, - they only hold stuff the current session and don't use the network at all. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@4889 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
35ab646aa2
commit
3ab62f147e
9 changed files with 862 additions and 968 deletions
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2008-2008 by Robert Fernie.
|
||||
* 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
|
||||
|
@ -26,117 +26,85 @@
|
|||
#ifndef P3_PHOTO_SERVICE_HEADER
|
||||
#define P3_PHOTO_SERVICE_HEADER
|
||||
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "pqi/pqiservice.h"
|
||||
#include "pqi/pqistreamer.h"
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rsphotoitems.h"
|
||||
|
||||
#include "services/p3service.h"
|
||||
#include "retroshare/rsphoto.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 PhotoSet
|
||||
class PhotoAlbum
|
||||
{
|
||||
public:
|
||||
|
||||
PhotoSet();
|
||||
std::string pid;
|
||||
PhotoAlbum();
|
||||
std::string albumid;
|
||||
|
||||
std::map<std::string, RsPhotoItem *> photos;
|
||||
std::map<std::string, RsPhotoShowItem *> shows;
|
||||
RsPhotoAlbum mAlbum;
|
||||
RsPhotoThumbnail mAlbumThumbnail;
|
||||
|
||||
std::map<std::string, RsPhotoPhoto> mPhotos;
|
||||
std::map<std::string, RsPhotoThumbnail> mNails;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class p3PhotoService: public CacheSource, public CacheStore
|
||||
class p3PhotoService: public p3Service, public RsPhoto
|
||||
{
|
||||
public:
|
||||
|
||||
p3PhotoService(uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
|
||||
std::string sourcedir, std::string storedir);
|
||||
p3PhotoService(uint16_t type);
|
||||
|
||||
void tick();
|
||||
|
||||
/******************************* CACHE SOURCE / STORE Interface *********************/
|
||||
|
||||
/* overloaded functions from Cache Source */
|
||||
virtual bool loadLocalCache(const CacheData &data);
|
||||
|
||||
/* overloaded functions from Cache Store */
|
||||
virtual int loadCache(const CacheData &data);
|
||||
|
||||
/******************************* CACHE SOURCE / STORE Interface *********************/
|
||||
virtual int tick();
|
||||
|
||||
public:
|
||||
|
||||
// NEW INTERFACE.
|
||||
/************* Extern Interface *******/
|
||||
|
||||
/* things changed */
|
||||
bool updated();
|
||||
virtual bool updated();
|
||||
virtual bool getAlbumList(std::list<std::string> &album);
|
||||
|
||||
/* access data */
|
||||
bool getPhotoList(std::string id, std::list<std::string> &hashs);
|
||||
bool getShowList(std::string id, std::list<std::string> &showIds);
|
||||
bool getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &detail);
|
||||
bool getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail);
|
||||
virtual bool getAlbum(const std::string &albumid, RsPhotoAlbum &album);
|
||||
virtual bool getPhoto(const std::string &photoid, RsPhotoPhoto &photo);
|
||||
virtual bool getPhotoList(const std::string &albumid, std::list<std::string> &photoIds);
|
||||
virtual bool getPhotoThumbnail(const std::string &photoid, RsPhotoThumbnail &thumbnail);
|
||||
virtual bool getAlbumThumbnail(const std::string &albumid, RsPhotoThumbnail &thumbnail);
|
||||
|
||||
/* add / delete */
|
||||
std::string createShow(std::string name);
|
||||
bool deleteShow(std::string showId);
|
||||
bool addPhotoToShow(std::string showId, std::string photoId, int16_t index);
|
||||
bool movePhotoInShow(std::string showId, std::string photoId, int16_t index);
|
||||
bool removePhotoFromShow(std::string showId, std::string photoId);
|
||||
|
||||
std::string addPhoto(std::string path); /* add from file */
|
||||
bool addPhoto(std::string srcId, std::string photoId); /* add from peers photos */
|
||||
bool deletePhoto(std::string photoId);
|
||||
|
||||
/* modify properties (TODO) */
|
||||
bool modifyShow(std::string showId, std::wstring name, std::wstring comment);
|
||||
bool modifyPhoto(std::string photoId, std::wstring name, std::wstring comment);
|
||||
bool modifyShowComment(std::string showId, std::string photoId, std::wstring comment);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/* cache processing */
|
||||
|
||||
void loadPhotoIndex(std::string filename, std::string hash, std::string src);
|
||||
void availablePhoto(std::string filename, std::string hash, std::string src);
|
||||
|
||||
bool loadPhotoItem(RsPhotoItem *item);
|
||||
bool loadPhotoShowItem(RsPhotoShowItem *item);
|
||||
void publishPhotos();
|
||||
|
||||
|
||||
/* locate info */
|
||||
|
||||
PhotoSet &locked_getPhotoSet(std::string id);
|
||||
RsPhotoItem *locked_getPhoto(std::string id, std::string photoId);
|
||||
RsPhotoShowItem *locked_getShow(std::string id, std::string showId);
|
||||
|
||||
|
||||
/* test functions */
|
||||
void createDummyData();
|
||||
/* details are updated in album - to choose Album ID, and storage path */
|
||||
virtual bool submitAlbumDetails(RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail);
|
||||
virtual bool submitPhoto(RsPhotoPhoto &photo, const RsPhotoThumbnail &thumbnail);
|
||||
|
||||
private:
|
||||
|
||||
std::string genRandomId();
|
||||
|
||||
RsMutex mPhotoMtx;
|
||||
|
||||
/***** below here is locked *****/
|
||||
|
||||
bool mRepublish;
|
||||
std::string mOwnId;
|
||||
|
||||
bool mUpdated;
|
||||
|
||||
std::map<std::string, PhotoSet> mPhotos;
|
||||
std::map<std::string, std::list<std::string > > mAlbumToPhotos;
|
||||
std::map<std::string, RsPhotoPhoto> mPhotos;
|
||||
std::map<std::string, RsPhotoThumbnail *> mPhotoThumbnails;
|
||||
|
||||
std::map<std::string, RsPhotoAlbum> mAlbums;
|
||||
std::map<std::string, RsPhotoThumbnail *> mAlbumThumbnails;
|
||||
|
||||
};
|
||||
|
||||
|
|
303
libretroshare/src/services/p3wikiservice.cc
Normal file
303
libretroshare/src/services/p3wikiservice.cc
Normal file
|
@ -0,0 +1,303 @@
|
|||
/*
|
||||
* libretroshare/src/services p3wikiservice.cc
|
||||
*
|
||||
* Wiki 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "services/p3wikiservice.h"
|
||||
|
||||
#include "util/rsrandom.h"
|
||||
|
||||
/****
|
||||
* #define WIKI_DEBUG 1
|
||||
****/
|
||||
|
||||
RsWiki *rsWiki = NULL;
|
||||
|
||||
|
||||
/********************************************************************************/
|
||||
/******************* Startup / Tick ******************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
p3WikiService::p3WikiService(uint16_t type)
|
||||
:p3Service(type), mWikiMtx("p3WikiService"), mUpdated(true)
|
||||
{
|
||||
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int p3WikiService::tick()
|
||||
{
|
||||
std::cerr << "p3WikiService::tick()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool p3WikiService::updated()
|
||||
{
|
||||
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (mUpdated)
|
||||
{
|
||||
mUpdated = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3WikiService::getGroupList(std::list<std::string> &groups)
|
||||
{
|
||||
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, RsWikiGroup>::iterator it;
|
||||
for(it = mGroups.begin(); it != mGroups.end(); it++)
|
||||
{
|
||||
groups.push_back(it->second.mGroupId);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3WikiService::getGroup(const std::string &groupid, RsWikiGroup &group)
|
||||
{
|
||||
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, RsWikiGroup>::iterator it;
|
||||
it = mGroups.find(groupid);
|
||||
if (it == mGroups.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
group = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool p3WikiService::getPage(const std::string &pageid, RsWikiPage &page)
|
||||
{
|
||||
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, RsWikiPage>::iterator it;
|
||||
it = mPages.find(pageid);
|
||||
if (it == mPages.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
page = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3WikiService::getLatestPage(const std::string &origPageId, std::string &pageId)
|
||||
{
|
||||
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
it = mOrigPageToLatestPage.find(origPageId);
|
||||
if (it == mOrigPageToLatestPage.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pageId = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3WikiService::getPageVersions(const std::string &origPageId, std::list<std::string> &pageIds)
|
||||
{
|
||||
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::list<std::string> >::iterator it;
|
||||
it = mOrigToPageVersions.find(origPageId);
|
||||
if (it == mOrigToPageVersions.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator lit;
|
||||
for(lit = it->second.begin(); lit != it->second.end(); lit++)
|
||||
{
|
||||
pageIds.push_back(*lit);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3WikiService::getOrigPageList(const std::string &groupid, std::list<std::string> &pageIds)
|
||||
{
|
||||
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::list<std::string> >::iterator it;
|
||||
it = mGroupToOrigPages.find(groupid);
|
||||
if (it == mGroupToOrigPages.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator lit;
|
||||
for(lit = it->second.begin(); lit != it->second.end(); lit++)
|
||||
{
|
||||
pageIds.push_back(*lit);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* details are updated in album - to choose Album ID, and storage path */
|
||||
bool p3WikiService::createGroup(RsWikiGroup &group)
|
||||
{
|
||||
if (group.mGroupId.empty())
|
||||
{
|
||||
/* new photo */
|
||||
|
||||
/* generate a temp id */
|
||||
group.mGroupId = genRandomId();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3WikiService::createGroup() Group with existing Id... dropping";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
mUpdated = true;
|
||||
|
||||
/* add / modify */
|
||||
mGroups[group.mGroupId] = group;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool p3WikiService::createPage(RsWikiPage &page)
|
||||
{
|
||||
if (page.mGroupId.empty())
|
||||
{
|
||||
/* new photo */
|
||||
std::cerr << "p3WikiService::createPage() Missing PageID";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* check if its a mod or new page */
|
||||
if (page.mOrigPageId.empty())
|
||||
{
|
||||
std::cerr << "p3WikiService::createPage() New Page";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* new page, generate a new OrigPageId */
|
||||
page.mOrigPageId = genRandomId();
|
||||
page.mPageId = page.mOrigPageId;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "p3WikiService::createPage() Modified Page";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* mod page, keep orig page id, generate a new PageId */
|
||||
page.mPageId = genRandomId();
|
||||
}
|
||||
|
||||
std::cerr << "p3WikiService::createPage() GroupId: " << page.mGroupId;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3WikiService::createPage() PageId: " << page.mPageId;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3WikiService::createPage() OrigPageId: " << page.mOrigPageId;
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
mUpdated = true;
|
||||
|
||||
std::map<std::string, std::list<std::string> >::iterator it;
|
||||
if (page.mPageId == page.mOrigPageId)
|
||||
{
|
||||
it = mGroupToOrigPages.find(page.mGroupId);
|
||||
if (it == mGroupToOrigPages.end())
|
||||
{
|
||||
std::cerr << "p3WikiService::createPage() First Page in Group";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::list<std::string> emptyList;
|
||||
mGroupToOrigPages[page.mGroupId] = emptyList;
|
||||
|
||||
it = mGroupToOrigPages.find(page.mGroupId);
|
||||
}
|
||||
it->second.push_back(page.mPageId);
|
||||
}
|
||||
|
||||
|
||||
it = mOrigToPageVersions.find(page.mOrigPageId);
|
||||
if (it == mOrigToPageVersions.end())
|
||||
{
|
||||
std::cerr << "p3WikiService::createPage() Adding OrigPage";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::list<std::string> emptyList;
|
||||
mOrigToPageVersions[page.mOrigPageId] = emptyList;
|
||||
|
||||
it = mOrigToPageVersions.find(page.mOrigPageId);
|
||||
}
|
||||
/* push back both Orig and all Mods */
|
||||
it->second.push_back(page.mPageId);
|
||||
|
||||
/* add / modify */
|
||||
mPages[page.mPageId] = page;
|
||||
|
||||
/* Total HACK - but will work for demo */
|
||||
mOrigPageToLatestPage[page.mOrigPageId] = page.mPageId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string p3WikiService::genRandomId()
|
||||
{
|
||||
std::string randomId;
|
||||
for(int i = 0; i < 20; i++)
|
||||
{
|
||||
randomId += (char) ('a' + (RSRandom::random_u32() % 26));
|
||||
}
|
||||
|
||||
return randomId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
94
libretroshare/src/services/p3wikiservice.h
Normal file
94
libretroshare/src/services/p3wikiservice.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* libretroshare/src/services: p3wikiservice.h
|
||||
*
|
||||
* Wiki 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_WIKI_SERVICE_HEADER
|
||||
#define P3_WIKI_SERVICE_HEADER
|
||||
|
||||
#include "services/p3service.h"
|
||||
|
||||
#include "retroshare/rswiki.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* Wiki 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 p3WikiService: public p3Service, public RsWiki
|
||||
{
|
||||
public:
|
||||
|
||||
p3WikiService(uint16_t type);
|
||||
|
||||
virtual int tick();
|
||||
|
||||
public:
|
||||
|
||||
// NEW INTERFACE.
|
||||
/************* Extern Interface *******/
|
||||
|
||||
virtual bool updated();
|
||||
virtual bool getGroupList(std::list<std::string> &group);
|
||||
|
||||
virtual bool getGroup(const std::string &groupid, RsWikiGroup &group);
|
||||
virtual bool getPage(const std::string &pageid, RsWikiPage &page);
|
||||
virtual bool getPageVersions(const std::string &origPageId, std::list<std::string> &pages);
|
||||
virtual bool getOrigPageList(const std::string &groupid, std::list<std::string> &pageIds);
|
||||
virtual bool getLatestPage(const std::string &origPageId, std::string &page);
|
||||
|
||||
virtual bool createGroup(RsWikiGroup &group);
|
||||
virtual bool createPage(RsWikiPage &page);
|
||||
|
||||
private:
|
||||
|
||||
std::string genRandomId();
|
||||
|
||||
RsMutex mWikiMtx;
|
||||
|
||||
/***** below here is locked *****/
|
||||
|
||||
bool mUpdated;
|
||||
|
||||
std::map<std::string, std::list<std::string > > mGroupToOrigPages;
|
||||
std::map<std::string, std::list<std::string > > mOrigToPageVersions;
|
||||
std::map<std::string, std::string> mOrigPageToLatestPage;
|
||||
std::map<std::string, RsWikiGroup> mGroups;
|
||||
std::map<std::string, RsWikiPage> mPages;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue