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:
drbob 2012-02-04 14:16:39 +00:00
parent 35ab646aa2
commit 3ab62f147e
9 changed files with 862 additions and 968 deletions

View File

@ -1,7 +1,7 @@
TEMPLATE = lib
#CONFIG += staticlib release
#CONFIG += staticlib testnetwork
CONFIG += staticlib bitdht
CONFIG += staticlib bitdht newservices
CONFIG -= qt
TARGET = retroshare
@ -160,11 +160,7 @@ PUBLIC_HEADERS = retroshare/rsblogs.h \
HEADERS += plugins/pluginmanager.h \
plugins/dlfcn_win32.h \
serialiser/rspluginitems.h \
gxs/rsgxs.h \
gxs/rsgnp.h \
gxs/rsgdp.h \
util/retrodb.h \
gxs/rsgixs.h
HEADERS += $$PUBLIC_HEADERS
@ -172,6 +168,7 @@ HEADERS += $$PUBLIC_HEADERS
HEADERS += retroshare/rsgame.h \
retroshare/rsphoto.h
################################# Linux ##########################################
linux-* {
isEmpty(PREFIX) { PREFIX = /usr }
@ -406,7 +403,6 @@ HEADERS += rsserver/p3discovery.h \
rsserver/p3history.h \
rsserver/p3msgs.h \
rsserver/p3peers.h \
rsserver/p3photo.h \
rsserver/p3status.h \
rsserver/p3serverconfig.h
@ -445,7 +441,6 @@ HEADERS += services/p3channels.h \
services/p3gamelauncher.h \
services/p3gameservice.h \
services/p3msgservice.h \
services/p3photoservice.h \
services/p3service.h \
services/p3statusservice.h \
services/p3dsdv.h \
@ -537,7 +532,6 @@ SOURCES += rsserver/p3discovery.cc \
rsserver/p3history.cc \
rsserver/p3msgs.cc \
rsserver/p3peers.cc \
rsserver/p3photo.cc \
rsserver/p3status.cc \
rsserver/rsiface.cc \
rsserver/rsinit.cc \
@ -560,7 +554,6 @@ SOURCES += serialiser/rsbaseitems.cc \
serialiser/rsgameitems.cc \
serialiser/rshistoryitems.cc \
serialiser/rsmsgitems.cc \
serialiser/rsphotoitems.cc \
serialiser/rsserial.cc \
serialiser/rsstatusitems.cc \
serialiser/rstlvaddrs.cc \
@ -583,7 +576,6 @@ SOURCES += services/p3channels.cc \
services/p3forums.cc \
services/p3gamelauncher.cc \
services/p3msgservice.cc \
services/p3photoservice.cc \
services/p3service.cc \
services/p3statusservice.cc \
services/p3dsdv.cc \
@ -658,17 +650,38 @@ SOURCES += zeroconf/p3zeroconf.cc \
}
SOURCES += \
gxs/rsgxs.cpp
SOURCES += \
gxs/rsgnp.cpp
newcache {
SOURCES += \
gxs/rsgdp.cpp
HEADERS += gxs/rsgxs.h \
gxs/rsgnp.h \
gxs/rsgdp.h \
util/retrodb.h \
gxs/rsgixs.h
SOURCES += gxs/rsgxs.cpp \
gxs/rsgnp.cpp \
gxs/rsgdp.cpp \
util/retrodb.cpp \
gxs/rsgixs.cpp
}
newservices {
HEADERS += services/p3photoservice.h \
retroshare/rsphoto.h \
services/p3wikiservice.h \
retroshare/rswiki.h \
SOURCES += services/p3photoservice.cc \
serialiser/rsphotoitems.cc \
services/p3wikiservice.cc \
# Other Old Code.
# rsserver/p3photo.cc \
}
SOURCES += \
util/retrodb.cpp
SOURCES += \
gxs/rsgixs.cpp

View File

@ -2,11 +2,11 @@
#define RETROSHARE_PHOTO_GUI_INTERFACE_H
/*
* libretroshare/src/rsiface: rsphoto.h
* libretroshare/src/retroshare: rsphoto.h
*
* RetroShare C++ Interface.
*
* Copyright 2008-2008 by Robert Fernie.
* Copyright 2008-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
@ -34,61 +34,69 @@
class RsPhoto;
extern RsPhoto *rsPhoto;
class RsPhotoDetails;
class RsPhotoShowDetails;
/******************* NEW STUFF FOR NEW CACHE SYSTEM *********/
class RsPhotoShowInfo
#define RSPHOTO_MODE_NEW 1
#define RSPHOTO_MODE_OWN 2
#define RSPHOTO_MODE_REMOTE 3
class RsPhotoPhoto
{
public:
std::string photoId;
std::wstring altComment;
uint32_t deltaT; /* in 100ths of sec? */
std::string mAlbumId;
std::string mId;
std::string mTitle; // only used by Album.
std::string mCaption;
std::string mDescription;
std::string mPhotographer;
std::string mWhere;
std::string mWhen;
std::string mOther;
std::string mCategory;
std::string mHashTags;
int mOrder;
int mMode;
std::string path; // if in Mode NEW.
};
class RsPhotoShowDetails
class RsPhotoAlbumShare
{
public:
RsPhotoShowDetails();
std::string id;
std::string showid;
std::string name;
std::wstring location;
std::wstring comment;
std::string date;
std::list<RsPhotoShowInfo> photos;
uint32_t mShareType;
std::string mShareGroupId;
std::string mPublishKey;
uint32_t mCommentMode;
uint32_t mResizeMode;
};
/* Details class */
class RsPhotoDetails
class RsPhotoAlbum: public RsPhotoPhoto
{
public:
RsPhotoDetails();
std::string id;
std::string srcid;
std::string hash;
uint64_t size;
std::string name;
std::wstring comment;
std::string location;
std::string date;
uint32_t format;
bool isAvailable;
std::string path;
std::string mPhotoPath;
RsPhotoAlbumShare mShareOptions;
};
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;
};
std::ostream &operator<<(std::ostream &out, const RsPhotoShowDetails &detail);
std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail);
class RsPhoto
{
@ -100,28 +108,19 @@ virtual ~RsPhoto() { return; }
/* changed? */
virtual bool updated() = 0;
/* access data */
virtual bool getPhotoList(std::string id, std::list<std::string> &hashs) = 0;
virtual bool getShowList(std::string id, std::list<std::string> &showIds) = 0;
virtual bool getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &detail) = 0;
virtual bool getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail) = 0;
virtual bool getAlbumList(std::list<std::string> &album) = 0;
/* add / delete */
virtual std::string createShow(std::string name) = 0;
virtual bool deleteShow(std::string showId) = 0;
virtual bool addPhotoToShow(std::string showId, std::string photoId, int16_t index) = 0;
virtual bool movePhotoInShow(std::string showId, std::string photoId, int16_t index) = 0;
virtual bool removePhotoFromShow(std::string showId, std::string photoId) = 0;
virtual bool getAlbum(const std::string &albumid, RsPhotoAlbum &album) = 0;
virtual bool getPhoto(const std::string &photoid, RsPhotoPhoto &photo) = 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 getAlbumThumbnail(const std::string &albumid, RsPhotoThumbnail &thumbnail) = 0;
virtual std::string addPhoto(std::string path) = 0; /* add from file */
virtual bool addPhoto(std::string srcId, std::string photoId) = 0; /* add from peers photos */
virtual bool deletePhoto(std::string photoId) = 0;
/* modify properties (TODO) */
virtual bool modifyShow(std::string showId, std::wstring name, std::wstring comment) = 0;
virtual bool modifyPhoto(std::string photoId, std::wstring name, std::wstring comment) = 0;
virtual bool modifyShowComment(std::string showId, std::string photoId, std::wstring comment) = 0;
/* details are updated in album - to choose Album ID, and storage path */
virtual bool submitAlbumDetails(RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail) = 0;
virtual bool submitPhoto(RsPhotoPhoto &photo, const RsPhotoThumbnail &thumbnail) = 0;
};
#endif

View File

@ -0,0 +1,105 @@
#ifndef RETROSHARE_WIKI_GUI_INTERFACE_H
#define RETROSHARE_WIKI_GUI_INTERFACE_H
/*
* libretroshare/src/retroshare: rswiki.h
*
* RetroShare C++ Interface.
*
* 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 <inttypes.h>
#include <string>
#include <list>
/* The Main Interface Class - for information about your Peers */
class RsWiki;
extern RsWiki *rsWiki;
class RsWikiGroupShare
{
public:
uint32_t mShareType;
std::string mShareGroupId;
std::string mPublishKey;
uint32_t mCommentMode;
uint32_t mResizeMode;
};
class RsWikiGroup
{
public:
std::string mGroupId;
std::string mName;
std::string mDescription;
std::string mCategory;
std::string mHashTags;
RsWikiGroupShare mShareOptions;
};
class RsWikiPage
{
public:
std::string mGroupId;
std::string mOrigPageId;
std::string mPrevId;
std::string mPageId;
std::string mName;
std::string mPage; // all the text is stored here.
std::string mHashTags;
};
class RsWiki
{
public:
RsWiki() { return; }
virtual ~RsWiki() { return; }
/* changed? */
virtual bool updated() = 0;
virtual bool getGroupList(std::list<std::string> &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<std::string> &pages) = 0;
virtual bool getOrigPageList(const std::string &groupid, std::list<std::string> &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

View File

@ -1726,13 +1726,15 @@ RsTurtle *rsTurtle = NULL ;
#include "services/p3msgservice.h"
#include "services/p3chatservice.h"
#include "services/p3gamelauncher.h"
#include "services/p3photoservice.h"
#include "services/p3forums.h"
#include "services/p3channels.h"
#include "services/p3statusservice.h"
#include "services/p3blogs.h"
#include "turtle/p3turtle.h"
#include "services/p3photoservice.h"
#include "services/p3wikiservice.h"
#ifndef PQI_DISABLE_TUNNEL
#include "services/p3tunnel.h"
#endif
@ -1750,7 +1752,6 @@ RsTurtle *rsTurtle = NULL ;
#include "rsserver/p3peers.h"
#include "rsserver/p3msgs.h"
#include "rsserver/p3discovery.h"
#include "rsserver/p3photo.h"
#include "rsserver/p3status.h"
#include "rsserver/p3history.h"
#include "rsserver/p3serverconfig.h"
@ -2131,16 +2132,18 @@ int RsServer::StartupRetroShare()
mPluginsManager->registerClientServices(pqih) ;
mPluginsManager->registerCacheServices() ;
// Testing New Cache Services.
p3PhotoService *mPhotos = new p3PhotoService(RS_SERVICE_TYPE_PHOTO);
pqih -> addService(mPhotos);
// Testing New Cache Services.
p3WikiService *mWikis = new p3WikiService(RS_SERVICE_TYPE_WIKI);
pqih -> addService(mWikis);
#ifndef RS_RELEASE
p3GameLauncher *gameLauncher = new p3GameLauncher(mLinkMgr);
pqih -> addService(gameLauncher);
p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO, /* .... for photo service */
mCacheStrapper, mCacheTransfer,
localcachedir, remotecachedir);
CachePair cp2(photoService, photoService, CacheId(RS_SERVICE_TYPE_PHOTO, 0));
mCacheStrapper -> addCachePair(cp2);
#endif
#ifdef RS_VOIPTEST
@ -2396,10 +2399,17 @@ int RsServer::StartupRetroShare()
rsDisc = new p3Discovery(ad);
rsConfig = new p3ServerConfig(mPeerMgr, mLinkMgr, mNetMgr, mGeneralConfig);
#ifndef MINIMAL_LIBRS
rsMsgs = new p3Msgs(msgSrv, chatSrv);
rsForums = mForums;
rsChannels = mChannels;
// Testing of new cache system interfaces.
rsPhoto = mPhotos;
rsWiki = mWikis;
#ifdef RS_USE_BLOGS
rsBlogs = mBlogs;
#endif
@ -2408,10 +2418,8 @@ int RsServer::StartupRetroShare()
#ifndef RS_RELEASE
rsGameLauncher = gameLauncher;
rsPhoto = new p3Photo(photoService);
#else
rsGameLauncher = NULL;
rsPhoto = NULL;
#endif
#endif // MINIMAL_LIBRS

View File

@ -91,12 +91,14 @@ const uint16_t RS_SERVICE_TYPE_VOIP = 0xf011;
/* Proxy - Service only */
const uint16_t RS_SERVICE_TYPE_PROXY = 0xf030;
/* Photo - Cache Only */
const uint16_t RS_SERVICE_TYPE_PHOTO = 0xf040;
/* DSDV Testing at the moment - Service Only */
const uint16_t RS_SERVICE_TYPE_DSDV = 0xf050;
/* New Cache Services */
const uint16_t RS_SERVICE_TYPE_PHOTO = 0xf101;
const uint16_t RS_SERVICE_TYPE_WIKI = 0xf102;
const uint16_t RS_SERVICE_TYPE_WIRE = 0xf103;
/* Games/External Apps - Service Only */
const uint16_t RS_SERVICE_TYPE_GAME_LAUNCHER = 0xf200;

File diff suppressed because it is too large Load Diff

View File

@ -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;
};

View 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;
}

View 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