From 3ab62f147e342d3f852cf5d0a43acbf4968fa781 Mon Sep 17 00:00:00 2001 From: drbob Date: Sat, 4 Feb 2012 14:16:39 +0000 Subject: [PATCH] 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 --- libretroshare/src/libretroshare.pro | 55 +- libretroshare/src/retroshare/rsphoto.h | 121 ++- libretroshare/src/retroshare/rswiki.h | 105 ++ libretroshare/src/rsserver/rsinit.cc | 28 +- libretroshare/src/serialiser/rsserviceids.h | 6 +- libretroshare/src/services/p3photoservice.cc | 996 ++++--------------- libretroshare/src/services/p3photoservice.h | 122 +-- libretroshare/src/services/p3wikiservice.cc | 303 ++++++ libretroshare/src/services/p3wikiservice.h | 94 ++ 9 files changed, 862 insertions(+), 968 deletions(-) create mode 100644 libretroshare/src/retroshare/rswiki.h create mode 100644 libretroshare/src/services/p3wikiservice.cc create mode 100644 libretroshare/src/services/p3wikiservice.h diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index a0e833b0c..c8cd44b47 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -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 diff --git a/libretroshare/src/retroshare/rsphoto.h b/libretroshare/src/retroshare/rsphoto.h index 9a16cce4f..eb0081f30 100644 --- a/libretroshare/src/retroshare/rsphoto.h +++ b/libretroshare/src/retroshare/rsphoto.h @@ -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 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 &hashs) = 0; -virtual bool getShowList(std::string id, std::list &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 &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 &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 diff --git a/libretroshare/src/retroshare/rswiki.h b/libretroshare/src/retroshare/rswiki.h new file mode 100644 index 000000000..1f55c6c7b --- /dev/null +++ b/libretroshare/src/retroshare/rswiki.h @@ -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 +#include +#include + +/* 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 &groups) = 0; +virtual bool getGroup(const std::string &groupid, RsWikiGroup &group) = 0; +virtual bool getPage(const std::string &pageid, RsWikiPage &page) = 0; +virtual bool getPageVersions(const std::string &origPageId, std::list &pages) = 0; +virtual bool getOrigPageList(const std::string &groupid, std::list &pageIds) = 0; +virtual bool getLatestPage(const std::string &origPageId, std::string &pageId) = 0; + +/* details are updated in group - to choose GroupID */ +virtual bool createGroup(RsWikiGroup &group) = 0; +virtual bool createPage(RsWikiPage &page) = 0; + + +}; + + + +#endif diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index 8f84a8d76..195cd95e0 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -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 diff --git a/libretroshare/src/serialiser/rsserviceids.h b/libretroshare/src/serialiser/rsserviceids.h index 14394abd4..8ebf9d77c 100644 --- a/libretroshare/src/serialiser/rsserviceids.h +++ b/libretroshare/src/serialiser/rsserviceids.h @@ -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; diff --git a/libretroshare/src/services/p3photoservice.cc b/libretroshare/src/services/p3photoservice.cc index fb6fc25fd..b63129506 100644 --- a/libretroshare/src/services/p3photoservice.cc +++ b/libretroshare/src/services/p3photoservice.cc @@ -1,9 +1,9 @@ /* - * libretroshare/src/services p3ranking.cc + * libretroshare/src/services p3photoservice.cc * - * 3P/PQI network interface for RetroShare. + * Phot Service for RetroShare. * - * Copyright 2007-2008 by Robert Fernie. + * Copyright 2007-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 @@ -24,20 +24,17 @@ */ #include "services/p3photoservice.h" - -#include "pqi/pqibin.h" -#include "pqi/authssl.h" - -#include "util/rsdir.h" - -std::string generateRandomShowId(); +#include "util/rsrandom.h" /**** * #define PHOTO_DEBUG 1 ****/ +RsPhoto *rsPhoto = NULL; -PhotoSet::PhotoSet() + + +PhotoAlbum::PhotoAlbum() { return; } @@ -46,371 +43,26 @@ PhotoSet::PhotoSet() /******************* Startup / Tick ******************************************/ /********************************************************************************/ -p3PhotoService::p3PhotoService(uint16_t type, CacheStrapper *cs, CacheTransfer *cft, - std::string sourcedir, std::string storedir) - :CacheSource(type, true, cs, sourcedir), - CacheStore(type, true, cs, cft, storedir), mPhotoMtx("p3PhotoService"), - mUpdated(true) +p3PhotoService::p3PhotoService(uint16_t type) + :p3Service(type), mPhotoMtx("p3PhotoService"), mUpdated(true) { - - { RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - mOwnId = AuthSSL::getAuthSSL()->OwnId(); - } - -// createDummyData(); + RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ return; } -void p3PhotoService::tick() +int p3PhotoService::tick() { - bool repub = false; - { - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - repub = mRepublish; - } - - if (repub) - { - //publishPhotos(); - - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - mRepublish = false; - } -} - - -/********************************************************************************/ -/******************* Cache Interaction ******************************************/ -/********************************************************************************/ - -bool p3PhotoService::loadLocalCache(const CacheData &data) -{ - std::string filename = data.path + '/' + data.name; - std::string hash = data.hash; - //uint64_t size = data.size; - std::string source = data.pid; - -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::loadLocalCache()"; + std::cerr << "p3PhotoService::tick()"; std::cerr << std::endl; - std::cerr << "\tSource: " << source; - std::cerr << std::endl; - std::cerr << "\tFilename: " << filename; - std::cerr << std::endl; - std::cerr << "\tHash: " << hash; - std::cerr << std::endl; - std::cerr << "\tSize: " << data.size; - std::cerr << std::endl; -#endif - - if (data.cid.subid == 0) - { - loadPhotoIndex(filename, hash, source); - } - else - { - availablePhoto(filename, hash, source); - } - - { - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - mRepublish = false; - mUpdated = true; - } - - if (data.size > 0) /* don't refresh zero sized caches */ - { - refreshCache(data); - } - return true; -} - -int p3PhotoService::loadCache(const CacheData &data) -{ - std::string filename = data.path + '/' + data.name; - std::string hash = data.hash; - //uint64_t size = data.size; - std::string source = data.pid; - -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::loadCache()"; - std::cerr << std::endl; - std::cerr << "\tSource: " << source; - std::cerr << std::endl; - std::cerr << "\tFilename: " << filename; - std::cerr << std::endl; - std::cerr << "\tHash: " << hash; - std::cerr << std::endl; - std::cerr << "\tSize: " << data.size; - std::cerr << std::endl; -#endif - - if (data.cid.subid == 0) - { - loadPhotoIndex(filename, hash, source); - } - else - { - availablePhoto(filename, hash, source); - } - - CacheStore::lockData(); /***** LOCK ****/ - locked_storeCacheEntry(data); - CacheStore::unlockData(); /***** UNLOCK ****/ - - return 1; -} - - -void p3PhotoService::loadPhotoIndex(std::string filename, std::string hash, std::string src) -{ - /* remove unused parameter warnings */ - (void) hash; - - /* create the serialiser to load info */ - RsSerialiser *rsSerialiser = new RsSerialiser(); - rsSerialiser->addSerialType(new RsPhotoSerialiser()); - uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_READABLE; - BinInterface *bio = new BinFileInterface(filename.c_str(), bioflags); - pqistreamer *stream = new pqistreamer(rsSerialiser, src, bio, 0); - -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::loadPhotoIndex()"; - std::cerr << std::endl; - std::cerr << "\tSource: " << src; - std::cerr << std::endl; - std::cerr << "\tHash: " << hash; - std::cerr << std::endl; - std::cerr << "\tFilename: " << filename; - std::cerr << std::endl; -#endif - - RsItem *item; - RsPhotoItem *pitem; - RsPhotoShowItem *sitem; - - stream->tick(); /* Tick to read! */ - while(NULL != (item = stream->GetItem())) - { - -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::loadPhotoIndex() Got Item:"; - std::cerr << std::endl; - item->print(std::cerr, 10); - std::cerr << std::endl; -#endif - - pitem = dynamic_cast(item); - sitem = dynamic_cast(item); - - if (pitem) - { - /* photo item */ -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::loadPhotoIndex() Loading Photo Item"; - std::cerr << std::endl; -#endif - loadPhotoItem(pitem); - - } - else if (sitem) - { - /* show item */ -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::loadPhotoIndex() Loading Show Item"; - std::cerr << std::endl; -#endif - loadPhotoShowItem(sitem); - } - else - { - /* unknown */ -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::loadRankFile() Unknown Item (deleting):"; - std::cerr << std::endl; -#endif - - } - delete item; - stream->tick(); /* Tick to read! */ - } - - delete stream; + return 0; } - -bool p3PhotoService::loadPhotoItem(RsPhotoItem *item) +bool p3PhotoService::updated() { -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::loadPhotoItem()"; - std::cerr << std::endl; - item->print(std::cerr); - std::cerr << std::endl; -#endif + RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - PhotoSet &pset = locked_getPhotoSet(item->PeerId()); - pset.photos[item->photoId] = item; - - mUpdated = true; - - return true; - - -} - - -bool p3PhotoService::loadPhotoShowItem(RsPhotoShowItem *item) -{ - -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::loadPhotoShowItem()"; - std::cerr << std::endl; - item->print(std::cerr); - std::cerr << std::endl; -#endif - - /* add to set */ - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - PhotoSet &pset = locked_getPhotoSet(item->PeerId()); - pset.shows[item->showId] = item; - - //mRepublish = true; - mUpdated = true; - - return true; -} - -void p3PhotoService::availablePhoto(std::string /*filename*/, std::string /*hash*/, std::string /*src*/) -{ - /* TODO */ - return; -} - - -void p3PhotoService::publishPhotos() -{ - -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::publishPhotos()"; - std::cerr << std::endl; -#endif - - /* determine filename */ - - std::string path = CacheSource::getCacheDir(); - std::ostringstream out; - out << "photo-index-" << time(NULL) << ".pdx"; - - std::string tmpname = out.str(); - std::string fname = path + "/" + tmpname; - -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::publishPhotos() Storing to: " << fname; - std::cerr << std::endl; -#endif - - - RsSerialiser *rsSerialiser = new RsSerialiser(); - rsSerialiser->addSerialType(new RsPhotoSerialiser()); - - uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_WRITEABLE; - BinInterface *bio = new BinFileInterface(fname.c_str(), bioflags); - pqistreamer *stream = new pqistreamer(rsSerialiser, mOwnId, bio, - BIN_FLAGS_NO_DELETE); - - - { RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - PhotoSet &pset = locked_getPhotoSet(mOwnId); - - std::map::iterator pit; - for(pit = pset.photos.begin(); pit != pset.photos.end(); pit++) - { - RsPhotoItem *pitem = pit->second; -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::publishPhotos() Storing Photo Item:"; - std::cerr << std::endl; - pitem->print(std::cerr, 10); - std::cerr << std::endl; -#endif - stream->SendItem(pitem); - stream->tick(); /* Tick to write! */ - - } - - std::map::iterator sit; - for(sit = pset.shows.begin(); sit != pset.shows.end(); sit++) - { - RsPhotoShowItem *sitem = sit->second; -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::publishPhotos() Storing PhotoShow Item:"; - std::cerr << std::endl; - sitem->print(std::cerr, 10); - std::cerr << std::endl; -#endif - stream->SendItem(sitem); - stream->tick(); /* Tick to write! */ - - } - } /********** STACK LOCKED MTX ******/ - stream->tick(); /* Tick for final write! */ - - /* flag as new info */ - CacheData data; - - { RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - data.pid = mOwnId; - } /********** STACK LOCKED MTX ******/ - - data.cid = CacheId(CacheSource::getCacheType(), 1); - - data.path = path; - data.name = tmpname; - - data.hash = bio->gethash(); - data.size = bio->bytecount(); - data.recvd = time(NULL); - -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::publishPhotos() refreshing Cache"; - std::cerr << std::endl; - std::cerr << "\tCache Path: " << data.path; - std::cerr << std::endl; - std::cerr << "\tCache Name: " << data.name; - std::cerr << std::endl; - std::cerr << "\tCache Hash: " << data.hash; - std::cerr << std::endl; - std::cerr << "\tCache Size: " << data.size; - std::cerr << std::endl; -#endif - if (data.size > 0) /* don't refresh zero sized caches */ - { - refreshCache(data); - } - - delete stream; - - /* TO HERE - * update Cache (new Photos (all Photos?)) - * */ - -} - - -/********************************************************************************/ -/******************* External Interface *****************************************/ -/********************************************************************************/ - -bool p3PhotoService::updated() -{ - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - if (mUpdated) { mUpdated = false; @@ -419,464 +71,214 @@ bool p3PhotoService::updated() return false; } -bool p3PhotoService::getPhotoList(std::string id, std::list &photoIds) +bool p3PhotoService::getAlbumList(std::list &album) { -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::getPhotoList() pid: " << id; - std::cerr << std::endl; -#endif + RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - PhotoSet &pset = locked_getPhotoSet(id); - - /* get the list of photoids */ - std::map::iterator pit; - for(pit = pset.photos.begin(); pit != pset.photos.end(); pit++) + std::map::iterator it; + for(it = mAlbums.begin(); it != mAlbums.end(); it++) { -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::getPhotoList() PhotoId: " << pit->first; - std::cerr << std::endl; -#endif - photoIds.push_back(pit->first); + album.push_back(it->second.mAlbumId); } - - return true; -} - - -bool p3PhotoService::getShowList(std::string id, std::list &showIds) -{ -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::getShowList() pid: " << id; - std::cerr << std::endl; -#endif - - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - PhotoSet &pset = locked_getPhotoSet(id); - - /* get the list of showIds */ - std::map::iterator sit; - for(sit = pset.shows.begin(); sit != pset.shows.end(); sit++) - { -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::getShowList() ShowId: " << sit->first; - std::cerr << std::endl; -#endif - showIds.push_back(sit->first); - } - - return true; -} - -bool p3PhotoService::getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &/*detail*/) -{ -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::getShowDetails() pid: " << id; - std::cerr << "showId: " << showId; - std::cerr << std::endl; -#endif - - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - RsPhotoShowItem *item = locked_getShow(id, showId); - if (!item) - { - return false; - } - - /* extract Show details */ - - return true; -} - - -bool p3PhotoService::getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail) -{ -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::getPhotoDetails() pid: " << id; - std::cerr << " photoId: " << photoId; - std::cerr << std::endl; -#endif - - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - RsPhotoItem *item = locked_getPhoto(id, photoId); - if (!item) - { - return false; - } - - /* extract Photo details */ - detail.id = item->PeerId(); - detail.srcid = item->srcId; - detail.hash = item->photoId; - detail.size = item->size; - detail.name = item->name; - detail.location = item->location; - detail.comment = item->comment; - detail.date = item->date; - detail.format = 0; - detail.isAvailable = item->isAvailable; - detail.path = item->path; - - return true; -} - -/* add / delete */ -std::string p3PhotoService::createShow(std::string name) -{ - std::string showId = generateRandomShowId(); - RsPhotoShowItem *newShow = new RsPhotoShowItem(); - - - newShow->showId = showId; - newShow->name = name; - - /* add to set */ - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - PhotoSet &pset = locked_getPhotoSet(mOwnId); - pset.shows[showId] = newShow; - - mRepublish = true; - - return showId; -} - - -bool p3PhotoService::deleteShow(std::string showId) -{ - /* add to set */ - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - PhotoSet &pset = locked_getPhotoSet(mOwnId); - - std::map::iterator sit; - sit = pset.shows.find(showId); - if (sit == pset.shows.end()) - { -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::deleteShow() no existant"; - std::cerr << std::endl; -#endif - return false; - } - - RsPhotoShowItem *oldShow = sit->second; - pset.shows.erase(sit); - delete oldShow; - - mRepublish = true; - - return true; + return false; } - -bool p3PhotoService::addPhotoToShow(std::string showId, std::string photoId, int16_t /*index*/) +bool p3PhotoService::getAlbum(const std::string &albumid, RsPhotoAlbum &album) { - -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::addPhotoToShow() showId: " << showId; - std::cerr << " photoId: " << photoId; - std::cerr << std::endl; -#endif - - /* add to set */ - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - - RsPhotoItem *photo = locked_getPhoto(mOwnId, photoId); - RsPhotoShowItem *show = locked_getShow(mOwnId, showId); - - if ((!photo) || (!show)) + RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator it; + it = mAlbums.find(albumid); + if (it == mAlbums.end()) { -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::addPhotoToShow() NULL data"; - std::cerr << std::endl; -#endif return false; } - - /* can have duplicates so just add it in */ - RsPhotoRefItem ref; - ref.photoId = photoId; - - /* add in at correct location! */ - //uint32_t i = 0; - //for(it = show.photos.begin(); - // (i < index) && (it != show.photos.end()); it++, i++); - - show->photos.push_back(ref); - - mRepublish = true; - + + album = it->second; return true; } -bool p3PhotoService::movePhotoInShow(std::string /*showId*/, std::string /*photoId*/, int16_t /*index*/) +bool p3PhotoService::getPhoto(const std::string &photoid, RsPhotoPhoto &photo) { - return false; -} - -bool p3PhotoService::removePhotoFromShow(std::string /*showId*/, std::string /*photoId*/) -{ - return false; -} - - -std::string p3PhotoService::addPhoto(std::string path) /* add from file */ -{ - /* check file exists */ - std::string hash; - uint64_t size; - - if (!RsDirUtil::getFileHash(path, hash, size)) - { - return hash; - } - - /* copy to outgoing directory TODO */ - - /* create item */ - RsPhotoItem *item = new RsPhotoItem(); - - { - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - item->PeerId(mOwnId); - } - - item->srcId = item->PeerId(); - item->photoId = hash; - item->name = RsDirUtil::getTopDir(path); - item->path = path; - item->size = size; - item->isAvailable = true; - item->comment = L"No Comment Yet!"; - - /* add in */ - loadPhotoItem(item); - - /* flag for republish */ - { - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - mRepublish = true; - } - - return hash; -} - - - - -bool p3PhotoService::addPhoto(std::string /*srcId*/, std::string /*photoId*/) /* add from peers photos */ -{ - return false; -} - -bool p3PhotoService::deletePhoto(std::string /*photoId*/) -{ - return false; -} - - -/* modify properties (TODO) */ -bool p3PhotoService::modifyShow(std::string /*showId*/, std::wstring /*name*/, std::wstring /*comment*/) -{ - return false; -} - -bool p3PhotoService::modifyPhoto(std::string /*photoId*/, std::wstring /*name*/, std::wstring /*comment*/) -{ - return false; -} - -bool p3PhotoService::modifyShowComment(std::string /*showId*/, std::string /*photoId*/, std::wstring /*comment*/) -{ - return false; -} - -/********************************************************************************/ -/******************* Utility Functions ******************************************/ -/********************************************************************************/ - -PhotoSet &p3PhotoService::locked_getPhotoSet(std::string id) -{ -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::locked_getPhotoSet() pid: " << id; - std::cerr << std::endl; -#endif - - std::map::iterator it; - it = mPhotos.find(id); + RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator it; + it = mPhotos.find(photoid); if (it == mPhotos.end()) { - /* missing group -> add it in */ - PhotoSet pset; - pset.pid = id; - mPhotos[id] = pset; - - it = mPhotos.find(id); + return false; } - - return (it->second); -} - - -RsPhotoItem *p3PhotoService::locked_getPhoto(std::string id, std::string photoId) -{ -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::locked_getPhoto() pid: " << id; - std::cerr << " photoId: " << photoId; - std::cerr << std::endl; -#endif - - PhotoSet &pset = locked_getPhotoSet(id); - - std::map::iterator pit; - pit = pset.photos.find(photoId); - if (pit == pset.photos.end()) - { -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::getPhotoDetails() Failed - noPhoto"; - std::cerr << std::endl; -#endif - return NULL; - } - return pit->second; -} - - -RsPhotoShowItem *p3PhotoService::locked_getShow(std::string id, std::string showId) -{ -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::locked_getShow() pid: " << id; - std::cerr << " showId: " << showId; - std::cerr << std::endl; -#endif - - PhotoSet &pset = locked_getPhotoSet(id); - - std::map::iterator sit; - sit = pset.shows.find(showId); - if (sit == pset.shows.end()) - { -#ifdef PHOTO_DEBUG - std::cerr << "p3PhotoService::locked_getShow() Failed - no Show"; - std::cerr << std::endl; -#endif - return NULL; - } - return sit->second; -} - - - - -std::string generateRandomShowId() -{ - std::ostringstream out; - out << std::hex; -/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ -#ifndef WINDOWS_SYS - /* 4 bytes per random number: 4 x 4 = 16 bytes */ - for(int i = 0; i < 4; i++) - { - out << std::setw(8) << std::setfill('0'); - uint32_t rint = random(); - out << rint; - } -#else - srand(time(NULL)); - /* 2 bytes per random number: 8 x 2 = 16 bytes */ - for(int i = 0; i < 8; i++) - { - out << std::setw(4) << std::setfill('0'); - uint16_t rint = rand(); /* only gives 16 bits */ - out << rint; - } -#endif -/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ + photo = it->second; + return true; +} - return out.str(); +bool p3PhotoService::getPhotoList(const std::string &albumid, std::list &photoIds) +{ + RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ + + std::map >::iterator it; + it = mAlbumToPhotos.find(albumid); + if (it == mAlbumToPhotos.end()) + { + return false; + } + + std::list::iterator lit; + for(lit = it->second.begin(); lit != it->second.end(); lit++) + { + photoIds.push_back(*lit); + } + return true; +} + +bool p3PhotoService::getPhotoThumbnail(const std::string &photoid, RsPhotoThumbnail &thumbnail) +{ + RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator it; + it = mPhotoThumbnails.find(photoid); + if (it == mPhotoThumbnails.end()) + { + return false; + } + + // shallow copy??? dangerous! + thumbnail = *(it->second); + return true; +} + +bool p3PhotoService::getAlbumThumbnail(const std::string &albumid, RsPhotoThumbnail &thumbnail) +{ + RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator it; + it = mAlbumThumbnails.find(albumid); + if (it == mAlbumThumbnails.end()) + { + return false; + } + + // shallow copy??? dangerous! + thumbnail = *(it->second); + return true; +} + + +/* details are updated in album - to choose Album ID, and storage path */ +bool p3PhotoService::submitAlbumDetails(RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail) +{ + /* 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; + + /* must fix this up later! */ + RsPhotoThumbnail *thumb = new RsPhotoThumbnail(); + thumb->copyFrom(thumbnail); + mAlbumThumbnails[album.mAlbumId] = thumb; + + return true; +} + + +bool p3PhotoService::submitPhoto(RsPhotoPhoto &photo, const RsPhotoThumbnail &thumbnail) +{ + 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 >::iterator it; + it = mAlbumToPhotos.find(photo.mAlbumId); + if (it == mAlbumToPhotos.end()) + { + std::list emptyList; + mAlbumToPhotos[photo.mAlbumId] = emptyList; + + it = mAlbumToPhotos.find(photo.mAlbumId); + } + + it->second.push_back(photo.mId); + + /* add / modify */ + mPhotos[photo.mId] = photo; + + /* must fix this up later! */ + RsPhotoThumbnail *thumb = new RsPhotoThumbnail(); + thumb->copyFrom(thumbnail); + mPhotoThumbnails[photo.mId] = thumb; + + return true; } - -void p3PhotoService::createDummyData() +std::string p3PhotoService::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) + { + free(data); + size = 0; + } -#if 0 - RsRankLinkMsg *msg = new RsRankLinkMsg(); + if ((!nail.data) || (nail.size == 0)) + { + return false; + } - time_t now = time(NULL); - - msg->PeerId(mOwnId); - msg->rid = "0001"; - msg->title = L"Original Awesome Site!"; - msg->timestamp = now - 60 * 60 * 24 * 15; - msg->link = L"http://www.retroshare.org"; - msg->comment = L"Retroshares Website"; - - addRankMsg(msg); - - msg = new RsRankLinkMsg(); - msg->PeerId(mOwnId); - msg->rid = "0002"; - msg->title = L"Awesome Site!"; - msg->timestamp = now - 123; - msg->link = L"http://www.lunamutt.org"; - msg->comment = L"Lunamutt's Website"; - - addRankMsg(msg); - - msg = new RsRankLinkMsg(); - msg->PeerId("ALTID"); - msg->rid = "0002"; - msg->title = L"Awesome Site!"; - msg->timestamp = now - 60 * 60 * 24 * 29; - msg->link = L"http://www.lunamutt.org"; - msg->comment = L"Lunamutt's Website (TWO) How Long can this comment be!\n"; - msg->comment += L"What happens to the second line?\n"; - msg->comment += L"And a 3rd!"; - - addRankMsg(msg); - - msg = new RsRankLinkMsg(); - msg->PeerId("ALTID2"); - msg->rid = "0002"; - msg->title = L"Awesome Site!"; - msg->timestamp = now - 60 * 60 * 7; - msg->link = L"http://www.lunamutt.org"; - msg->comment += L"A Short Comment"; - - addRankMsg(msg); - - - /***** Third one ****/ - - msg = new RsRankLinkMsg(); - msg->PeerId(mOwnId); - msg->rid = "0003"; - msg->title = L"Weird Site!"; - msg->timestamp = now - 60 * 60; - msg->link = L"http://www.lunamutt.com"; - msg->comment = L""; - - addRankMsg(msg); - - msg = new RsRankLinkMsg(); - msg->PeerId("ALTID"); - msg->rid = "0003"; - msg->title = L"Weird Site!"; - msg->timestamp = now - 60 * 60 * 24 * 2; - msg->link = L"http://www.lunamutt.com"; - msg->comment = L""; - - addRankMsg(msg); - -#endif + size = nail.size; + type = nail.type; + data = (uint8_t *) malloc(size); + memcpy(data, nail.data, size); + return true; } + + + + diff --git a/libretroshare/src/services/p3photoservice.h b/libretroshare/src/services/p3photoservice.h index 5d57a35bd..5f79553f0 100644 --- a/libretroshare/src/services/p3photoservice.h +++ b/libretroshare/src/services/p3photoservice.h @@ -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 +#include + /* * 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 photos; - std::map shows; + RsPhotoAlbum mAlbum; + RsPhotoThumbnail mAlbumThumbnail; + + std::map mPhotos; + std::map 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 &album); - /* access data */ -bool getPhotoList(std::string id, std::list &hashs); -bool getShowList(std::string id, std::list &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 &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 mPhotos; + std::map > mAlbumToPhotos; + std::map mPhotos; + std::map mPhotoThumbnails; + std::map mAlbums; + std::map mAlbumThumbnails; }; diff --git a/libretroshare/src/services/p3wikiservice.cc b/libretroshare/src/services/p3wikiservice.cc new file mode 100644 index 000000000..292b9007f --- /dev/null +++ b/libretroshare/src/services/p3wikiservice.cc @@ -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 &groups) +{ + RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ + + std::map::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::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::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::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 &pageIds) +{ + RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ + + std::map >::iterator it; + it = mOrigToPageVersions.find(origPageId); + if (it == mOrigToPageVersions.end()) + { + return false; + } + + std::list::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 &pageIds) +{ + RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ + + std::map >::iterator it; + it = mGroupToOrigPages.find(groupid); + if (it == mGroupToOrigPages.end()) + { + return false; + } + + std::list::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 >::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 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 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; +} + + + + + + + + + + + + diff --git a/libretroshare/src/services/p3wikiservice.h b/libretroshare/src/services/p3wikiservice.h new file mode 100644 index 000000000..92c623b41 --- /dev/null +++ b/libretroshare/src/services/p3wikiservice.h @@ -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 +#include + +/* + * 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 &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 &pages); +virtual bool getOrigPageList(const std::string &groupid, std::list &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 > mGroupToOrigPages; + std::map > mOrigToPageVersions; + std::map mOrigPageToLatestPage; + std::map mGroups; + std::map mPages; + +}; + +#endif