mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 14:45:12 -04:00
Addition of two more Services / Applications.
(1) A PhotoService / Dialog to share slideshows. (2) A Network View service, derived from p3disc for a graphical view of peers. Both of these need a little help to get them fully functional. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@375 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
3ed1eef186
commit
08860b25e6
28 changed files with 3297 additions and 235 deletions
48
libretroshare/src/rsiface/rsdisc.h
Normal file
48
libretroshare/src/rsiface/rsdisc.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef RETROSHARE_DISC_GUI_INTERFACE_H
|
||||
#define RETROSHARE_DISC_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsdisc.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2008-2008 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 RsDisc;
|
||||
extern RsDisc *rsDisc;
|
||||
|
||||
class RsDisc
|
||||
{
|
||||
public:
|
||||
|
||||
RsDisc() { return; }
|
||||
virtual ~RsDisc() { return; }
|
||||
|
||||
virtual bool getDiscFriends(std::string id, std::list<std::string> &friends) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
122
libretroshare/src/rsiface/rsphoto.h
Normal file
122
libretroshare/src/rsiface/rsphoto.h
Normal file
|
@ -0,0 +1,122 @@
|
|||
#ifndef RETROSHARE_PHOTO_GUI_INTERFACE_H
|
||||
#define RETROSHARE_PHOTO_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsphoto.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2008-2008 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 RsPhoto;
|
||||
extern RsPhoto *rsPhoto;
|
||||
|
||||
class RsPhotoDetails;
|
||||
class RsPhotoShowDetails;
|
||||
|
||||
class RsPhotoShowInfo
|
||||
{
|
||||
public:
|
||||
|
||||
std::string photoId;
|
||||
std::wstring altComment;
|
||||
uint32_t deltaT; /* in 100ths of sec? */
|
||||
};
|
||||
|
||||
class RsPhotoShowDetails
|
||||
{
|
||||
public:
|
||||
|
||||
RsPhotoShowDetails();
|
||||
|
||||
std::string id;
|
||||
std::string showid;
|
||||
|
||||
std::string name;
|
||||
std::wstring location;
|
||||
std::wstring comment;
|
||||
std::string date;
|
||||
std::list<RsPhotoShowInfo> photos;
|
||||
};
|
||||
|
||||
/* Details class */
|
||||
class RsPhotoDetails
|
||||
{
|
||||
public:
|
||||
|
||||
RsPhotoDetails();
|
||||
|
||||
std::string id;
|
||||
std::string srcid;
|
||||
|
||||
std::string hash;
|
||||
|
||||
std::string name;
|
||||
std::wstring location;
|
||||
std::wstring comment;
|
||||
std::string date;
|
||||
|
||||
uint32_t format;
|
||||
|
||||
bool isAvailable;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsPhotoShowDetails &detail);
|
||||
std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail);
|
||||
|
||||
class RsPhoto
|
||||
{
|
||||
public:
|
||||
|
||||
RsPhoto() { return; }
|
||||
virtual ~RsPhoto() { return; }
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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 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;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -9,14 +9,16 @@ include $(RS_TOP_DIR)/scripts/config.mk
|
|||
|
||||
RSOBJ = p3peers.o \
|
||||
p3rank.o \
|
||||
p3photo.o \
|
||||
p3msgs.o \
|
||||
p3discovery.o \
|
||||
p3face-file.o \
|
||||
p3face-server.o \
|
||||
p3face-config.o \
|
||||
p3face-startup.o \
|
||||
p3face-msgs.o \
|
||||
rstypes.o \
|
||||
rsiface.o \
|
||||
p3face-msgs.o
|
||||
rsiface.o
|
||||
|
||||
# pqistrings.o \
|
||||
# p3face-people.o
|
||||
|
|
40
libretroshare/src/rsserver/p3discovery.cc
Normal file
40
libretroshare/src/rsserver/p3discovery.cc
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* libretroshare/src/rsserver: p3discovery.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2008-2008 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 "rsserver/p3discovery.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
RsDisc *rsDisc = NULL;
|
||||
|
||||
bool p3Discovery::getDiscFriends(std::string id, std::list<std::string> &friends)
|
||||
{
|
||||
if (mDisc)
|
||||
{
|
||||
return mDisc->potentialproxies(id, friends);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
48
libretroshare/src/rsserver/p3discovery.h
Normal file
48
libretroshare/src/rsserver/p3discovery.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef RETROSHARE_P3_DISC_INTERFACE_H
|
||||
#define RETROSHARE_P3_DISC_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsserver: p3discovery.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2008-2008 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 "rsiface/rsdisc.h"
|
||||
#include "services/p3disc.h"
|
||||
|
||||
class p3Discovery: public RsDisc
|
||||
{
|
||||
public:
|
||||
|
||||
p3Discovery(p3disc *disc)
|
||||
:mDisc(disc) { return; }
|
||||
virtual ~p3Discovery() { return; }
|
||||
|
||||
virtual bool getDiscFriends(std::string id, std::list<std::string> &friends);
|
||||
|
||||
private:
|
||||
|
||||
p3disc *mDisc;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -47,6 +47,7 @@
|
|||
#include "services/p3chatservice.h"
|
||||
#include "services/p3gamelauncher.h"
|
||||
#include "services/p3ranking.h"
|
||||
#include "services/p3photoservice.h"
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
@ -55,10 +56,13 @@
|
|||
// for blocking signals
|
||||
#include <signal.h>
|
||||
|
||||
/* Implemented Rs Interfaces */
|
||||
#include "rsserver/p3face.h"
|
||||
#include "rsserver/p3peers.h"
|
||||
#include "rsserver/p3rank.h"
|
||||
#include "rsserver/p3msgs.h"
|
||||
#include "rsserver/p3discovery.h"
|
||||
#include "rsserver/p3photo.h"
|
||||
#include "rsiface/rsgame.h"
|
||||
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
@ -522,6 +526,13 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||
CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0));
|
||||
mCacheStrapper -> addCachePair(cp);
|
||||
|
||||
p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO,
|
||||
mCacheStrapper, mCacheTransfer,
|
||||
localcachedir, remotecachedir);
|
||||
|
||||
CachePair cp2(photoService, photoService, CacheId(RS_SERVICE_TYPE_PHOTO, 0));
|
||||
mCacheStrapper -> addCachePair(cp2);
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
mConnMgr->setDhtMgr(mDhtMgr);
|
||||
|
@ -661,6 +672,8 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||
rsGameLauncher = gameLauncher;
|
||||
rsRanks = new p3Rank(mRanking);
|
||||
rsMsgs = new p3Msgs(mAuthMgr, msgSrv, chatSrv);
|
||||
rsDisc = new p3Discovery(ad);
|
||||
rsPhoto = new p3Photo(photoService);
|
||||
|
||||
/* put a welcome message in! */
|
||||
if (config->firsttime_run)
|
||||
|
|
137
libretroshare/src/rsserver/p3photo.cc
Normal file
137
libretroshare/src/rsserver/p3photo.cc
Normal file
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* libretroshare/src/rsserver: p3photo.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-2008 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 "rsserver/p3photo.h"
|
||||
#include "services/p3photoservice.h"
|
||||
|
||||
RsPhoto *rsPhoto = NULL;
|
||||
|
||||
|
||||
RsPhotoDetails::RsPhotoDetails()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RsPhotoShowDetails::RsPhotoShowDetails()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
p3Photo::p3Photo(p3PhotoService *p3ps)
|
||||
:mPhoto(p3ps)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
p3Photo::~p3Photo()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* access data */
|
||||
bool p3Photo::getPhotoList(std::string id, std::list<std::string> hashs)
|
||||
{
|
||||
return mPhoto->getPhotoList(id, hashs);
|
||||
}
|
||||
|
||||
bool p3Photo::getShowList(std::string id, std::list<std::string> showIds)
|
||||
{
|
||||
return mPhoto -> getShowList(id, showIds);
|
||||
}
|
||||
|
||||
|
||||
bool p3Photo::getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &detail)
|
||||
{
|
||||
return mPhoto -> getShowDetails(id, showId, detail);
|
||||
}
|
||||
|
||||
|
||||
bool p3Photo::getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail)
|
||||
{
|
||||
return mPhoto -> getPhotoDetails(id, photoId, detail);
|
||||
}
|
||||
|
||||
|
||||
/* add / delete */
|
||||
std::string p3Photo::createShow(std::string name)
|
||||
{
|
||||
return mPhoto -> createShow(name);
|
||||
}
|
||||
|
||||
bool p3Photo::deleteShow(std::string showId)
|
||||
{
|
||||
return mPhoto -> deleteShow(showId);
|
||||
}
|
||||
|
||||
bool p3Photo::addPhotoToShow(std::string showId, std::string photoId, int16_t index)
|
||||
{
|
||||
return mPhoto -> addPhotoToShow(showId, photoId, index);
|
||||
}
|
||||
|
||||
bool p3Photo::movePhotoInShow(std::string showId, std::string photoId, int16_t index)
|
||||
{
|
||||
return mPhoto -> movePhotoInShow(showId, photoId, index);
|
||||
}
|
||||
|
||||
bool p3Photo::removePhotoFromShow(std::string showId, std::string photoId)
|
||||
{
|
||||
return mPhoto -> removePhotoFromShow(showId, photoId);
|
||||
}
|
||||
|
||||
|
||||
std::string p3Photo::addPhoto(std::string path) /* add from file */
|
||||
{
|
||||
return mPhoto -> addPhoto(path); /* add from file */
|
||||
}
|
||||
|
||||
bool p3Photo::addPhoto(std::string srcId, std::string photoId) /* add from peers photos */
|
||||
{
|
||||
return mPhoto -> addPhoto(srcId, photoId); /* add from peers photos */
|
||||
|
||||
}
|
||||
|
||||
bool p3Photo::deletePhoto(std::string photoId)
|
||||
{
|
||||
return mPhoto -> deletePhoto(photoId);
|
||||
}
|
||||
|
||||
|
||||
/* modify properties (TODO) */
|
||||
bool p3Photo::modifyShow(std::string showId, std::wstring name, std::wstring comment)
|
||||
{
|
||||
return mPhoto -> modifyShow(showId, name, comment);
|
||||
}
|
||||
|
||||
bool p3Photo::modifyPhoto(std::string photoId, std::wstring name, std::wstring comment)
|
||||
{
|
||||
return mPhoto -> modifyPhoto(photoId, name, comment);
|
||||
}
|
||||
|
||||
bool p3Photo::modifyShowComment(std::string showId, std::string photoId, std::wstring comment)
|
||||
{
|
||||
return mPhoto -> modifyShowComment(showId, photoId, comment);
|
||||
}
|
||||
|
||||
|
66
libretroshare/src/rsserver/p3photo.h
Normal file
66
libretroshare/src/rsserver/p3photo.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
#ifndef RETROSHARE_P3_PHOTO_INTERFACE_H
|
||||
#define RETROSHARE_P3_PHOTO_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsserver: p3photo.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-2008 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 "rsiface/rsphoto.h"
|
||||
#include "services/p3photoservice.h"
|
||||
|
||||
class p3Photo: public RsPhoto
|
||||
{
|
||||
public:
|
||||
|
||||
p3Photo(p3PhotoService *p3ps);
|
||||
virtual ~p3Photo();
|
||||
|
||||
/* access data */
|
||||
virtual bool getPhotoList(std::string id, std::list<std::string> hashs);
|
||||
virtual bool getShowList(std::string id, std::list<std::string> showIds);
|
||||
virtual bool getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &detail);
|
||||
virtual bool getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail);
|
||||
|
||||
/* add / delete */
|
||||
virtual std::string createShow(std::string name);
|
||||
virtual bool deleteShow(std::string showId);
|
||||
virtual bool addPhotoToShow(std::string showId, std::string photoId, int16_t index);
|
||||
virtual bool movePhotoInShow(std::string showId, std::string photoId, int16_t index);
|
||||
virtual bool removePhotoFromShow(std::string showId, std::string photoId);
|
||||
|
||||
virtual std::string addPhoto(std::string path); /* add from file */
|
||||
virtual bool addPhoto(std::string srcId, std::string photoId); /* add from peers photos */
|
||||
virtual bool deletePhoto(std::string photoId);
|
||||
|
||||
/* modify properties (TODO) */
|
||||
virtual bool modifyShow(std::string showId, std::wstring name, std::wstring comment);
|
||||
virtual bool modifyPhoto(std::string photoId, std::wstring name, std::wstring comment);
|
||||
virtual bool modifyShowComment(std::string showId, std::string photoId, std::wstring comment);
|
||||
|
||||
private:
|
||||
|
||||
p3PhotoService *mPhoto;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -11,6 +11,7 @@ RSOBJ = rsserial.o rsbaseserial.o rstlvbase.o rstlvtypes.o
|
|||
RSOBJ += rstlvfileitem.o rstlvutil.o # TLV Objs
|
||||
RSOBJ += rsbaseitems.o rsconfigitems.o rsdiscitems.o # RsItems
|
||||
RSOBJ += rsmsgitems.o rsrankitems.o # RsItems
|
||||
RSOBJ += rsphotoitems.o # RsItems
|
||||
|
||||
TESTOBJ = tlvbase_test.o tlvbase_test2.o tlvfileitem_test.o
|
||||
TESTOBJ += tlvitems_test.o tlvstack_test.o tlvconfig_test.o
|
||||
|
|
290
libretroshare/src/serialiser/rsphotoitems.cc
Normal file
290
libretroshare/src/serialiser/rsphotoitems.cc
Normal file
|
@ -0,0 +1,290 @@
|
|||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsphotoitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 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 "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsphotoitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#define RSSERIAL_DEBUG 1
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void RsPhotoItem::clear()
|
||||
{
|
||||
srcId.clear();
|
||||
photoId.clear();
|
||||
size = 0;
|
||||
|
||||
name.clear();
|
||||
comment.clear();
|
||||
|
||||
location.clear();
|
||||
date.clear();
|
||||
|
||||
/* not serialised */
|
||||
isAvailable = false;
|
||||
path.clear();
|
||||
}
|
||||
|
||||
std::ostream &RsPhotoItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsPhotoItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
printIndent(out, int_Indent);
|
||||
out << "srcId: " << srcId << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "photoId: " << photoId << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "size: " << size << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "name: " << name << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_comment(comment.begin(), comment.end());
|
||||
out << "msg: " << cnv_comment << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "location: " << location << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "date: " << date << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "(NS) isAvailable: " << isAvailable << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "(NS) path: " << path << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsPhotoItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
void RsPhotoShowItem::clear()
|
||||
{
|
||||
showId.clear();
|
||||
name.clear();
|
||||
comment.clear();
|
||||
|
||||
location.clear();
|
||||
date.clear();
|
||||
|
||||
photos.clear();
|
||||
}
|
||||
|
||||
std::ostream &RsPhotoShowItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsPhotoShowItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
uint16_t int_Indent2 = int_Indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "showId: " << showId << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "name: " << name << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_comment(comment.begin(), comment.end());
|
||||
out << "msg: " << cnv_comment << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "location: " << location << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
out << "date: " << date << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Photos in Show: " << photos.size() << std::endl;
|
||||
|
||||
std::list<RsPhotoRefItem>::iterator it;
|
||||
for(it = photos.begin(); it != photos.end(); it++)
|
||||
{
|
||||
printIndent(out, int_Indent2);
|
||||
out << "PhotoId: " << it->photoId << std::endl;
|
||||
printIndent(out, int_Indent2 + 2);
|
||||
std::string cnv_comment2(it->altComment.begin(), it->altComment.end());
|
||||
out << "AltComment: " << cnv_comment2 << std::endl;
|
||||
printIndent(out, int_Indent2 + 2);
|
||||
out << "Delta T: " << it->deltaT << std::endl;
|
||||
}
|
||||
|
||||
printRsItemEnd(out, "RsPhotoShowItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
RsPhotoRefItem::RsPhotoRefItem()
|
||||
:deltaT(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
/* TODO serialiser */
|
||||
|
||||
#if 0
|
||||
|
||||
uint32_t RsPhotoSerialiser::sizeLink(RsPhotoLinkMsg *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvStringSize(item->rid);
|
||||
s += 4; /* timestamp */
|
||||
s += GetTlvWideStringSize(item->title);
|
||||
s += GetTlvWideStringSize(item->comment);
|
||||
s += 4; /* linktype */
|
||||
s += GetTlvWideStringSize(item->link);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsPhotoSerialiser::serialiseLink(RsPhotoLinkMsg *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeLink(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Header: " << ok << std::endl;
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Size: " << tlvsize << std::endl;
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GENID, item->rid);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() rid: " << ok << std::endl;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->timestamp);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() timestamp: " << ok << std::endl;
|
||||
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_TITLE, item->title);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Title: " << ok << std::endl;
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Comment: " << ok << std::endl;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->linktype);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() linktype: " << ok << std::endl;
|
||||
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_LINK, item->link);
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Link: " << ok << std::endl;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsPhotoLinkSerialiser::serialiseLink() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsPhotoLinkMsg *RsPhotoSerialiser::deserialiseLink(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_RANK != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_RANK_LINK != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsPhotoLinkMsg *item = new RsPhotoLinkMsg();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GENID, item->rid);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->timestamp));
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_TITLE, item->title);
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->linktype));
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_LINK, item->link);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsPhotoSerialiser::size(RsItem *item)
|
||||
{
|
||||
return sizeLink((RsPhotoLinkMsg *) item);
|
||||
}
|
||||
|
||||
bool RsPhotoSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
return serialiseLink((RsPhotoLinkMsg *) item, data, pktsize);
|
||||
}
|
||||
|
||||
RsItem *RsPhotoSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
return deserialiseLink(data, pktsize);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
138
libretroshare/src/serialiser/rsphotoitems.h
Normal file
138
libretroshare/src/serialiser/rsphotoitems.h
Normal file
|
@ -0,0 +1,138 @@
|
|||
#ifndef P3_PHOTO_ITEMS_H
|
||||
#define P3_PHOTO_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsphotoitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 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 <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM = 0x03;
|
||||
const uint8_t RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM = 0x04;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsPhotoItem;
|
||||
class RsPhotoShowItem;
|
||||
class RsPhotoCommentItem;
|
||||
|
||||
class RsPhotoItem: public RsItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsPhotoItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_ITEM) { return; }
|
||||
virtual ~RsPhotoItem() { return; }
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
std::string srcId;
|
||||
std::string photoId; /* same as hash */
|
||||
uint64_t size; /* file size */
|
||||
|
||||
std::string name;
|
||||
std::wstring comment;
|
||||
|
||||
std::string location; /* TODO: change to TLV */
|
||||
std::string date; /* TODO: change to TLV */
|
||||
|
||||
/* not serialised */
|
||||
bool isAvailable;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
/* THIS must be turned into a TLV type + set (TOD) */
|
||||
class RsPhotoRefItem
|
||||
{
|
||||
public:
|
||||
RsPhotoRefItem();
|
||||
|
||||
std::string photoId;
|
||||
std::wstring altComment;
|
||||
uint32_t deltaT; /* in 100ths of sec? */
|
||||
};
|
||||
|
||||
class RsPhotoShowItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsPhotoShowItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO,
|
||||
RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM) { return; }
|
||||
|
||||
virtual ~RsPhotoShowItem() { return; }
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
std::string showId;
|
||||
|
||||
std::string name;
|
||||
std::wstring comment;
|
||||
|
||||
std::string location; /* TODO -> TLV */
|
||||
std::string date; /* TODO -> TLV */
|
||||
std::list<RsPhotoRefItem> photos; /* list as ordered */
|
||||
};
|
||||
|
||||
class RsPhotoSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsPhotoSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PHOTO)
|
||||
{ return; }
|
||||
virtual ~RsPhotoSerialiser()
|
||||
{ return; }
|
||||
|
||||
virtual uint32_t size(RsItem *) { return 0; }
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size) { return false; }
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size) { return NULL; }
|
||||
|
||||
private:
|
||||
|
||||
/* For RS_PKT_SUBTYPE_PHOTO_ITEM */
|
||||
//virtual uint32_t sizeLink(RsPhotoItem *);
|
||||
//virtual bool serialiseLink (RsPhotoItem *item, void *data, uint32_t *size);
|
||||
//virtual RsPhotoItem *deserialiseLink(void *data, uint32_t *size);
|
||||
|
||||
/* For RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM */
|
||||
//virtual uint32_t sizeLink(RsPhotoShowItem *);
|
||||
//virtual bool serialiseLink (RsPhotoShowItem *item, void *data, uint32_t *size);
|
||||
//virtual RsPhotoShowItem *deserialiseLink(void *data, uint32_t *size);
|
||||
|
||||
/* For RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM */
|
||||
//virtual uint32_t sizeLink(RsPhotoCommentItem *);
|
||||
//virtual bool serialiseLink (RsPhotoCommentItem *item, void *data, uint32_t *size);
|
||||
//virtual RsPhotoCommentItem *deserialiseLink(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_PHOTO_ITEMS_H */
|
||||
|
|
@ -40,6 +40,7 @@
|
|||
/* These are Cache Only */
|
||||
const uint16_t RS_SERVICE_TYPE_FILE_INDEX = 0x0001;
|
||||
const uint16_t RS_SERVICE_TYPE_RANK = 0x0002;
|
||||
const uint16_t RS_SERVICE_TYPE_PHOTO = 0x0003;
|
||||
|
||||
/* These are Services only */
|
||||
const uint16_t RS_SERVICE_TYPE_DISC = 0x0011;
|
||||
|
|
|
@ -8,7 +8,8 @@ include $(RS_TOP_DIR)/scripts/config.mk
|
|||
###############################################################
|
||||
|
||||
RSOBJ = p3service.o p3chatservice.o p3msgservice.o \
|
||||
p3gamelauncher.o p3ranking.o p3disc.o
|
||||
p3gamelauncher.o p3ranking.o p3disc.o \
|
||||
p3photoservice.o
|
||||
|
||||
#TESTOBJ =
|
||||
|
||||
|
|
|
@ -656,7 +656,7 @@ int p3disc::addDiscoveryData(std::string fromId, std::string aboutId,
|
|||
/* Extracting Network Graph Details */
|
||||
/*************************************************************************************/
|
||||
|
||||
bool p3disc::potentialproxies(std::string id, std::list<std::string> proxyIds)
|
||||
bool p3disc::potentialproxies(std::string id, std::list<std::string> &proxyIds)
|
||||
{
|
||||
/* find id -> and extract the neighbour_of ids */
|
||||
|
||||
|
|
|
@ -88,6 +88,9 @@ virtual void statusChange(const std::list<pqipeer> &plist);
|
|||
|
||||
int tick();
|
||||
|
||||
/* GUI requires access */
|
||||
bool potentialproxies(std::string id, std::list<std::string> &proxyIds);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
@ -107,7 +110,6 @@ int addDiscoveryData(std::string fromId, std::string aboutId,
|
|||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
uint32_t flags, time_t ts);
|
||||
|
||||
bool potentialproxies(std::string id, std::list<std::string> proxyIds);
|
||||
int idServers();
|
||||
|
||||
|
||||
|
|
818
libretroshare/src/services/p3photoservice.cc
Normal file
818
libretroshare/src/services/p3photoservice.cc
Normal file
|
@ -0,0 +1,818 @@
|
|||
/*
|
||||
* libretroshare/src/services p3ranking.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-2008 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/p3photoservice.h"
|
||||
|
||||
#include "pqi/pqibin.h"
|
||||
#include "pqi/p3authmgr.h"
|
||||
|
||||
std::string generateRandomShowId();
|
||||
|
||||
#define PHOTO_DEBUG 1
|
||||
|
||||
|
||||
PhotoSet::PhotoSet()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/********************************************************************************/
|
||||
/******************* 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)
|
||||
{
|
||||
|
||||
{ RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
mOwnId = getAuthMgr()->OwnId();
|
||||
}
|
||||
|
||||
// createDummyData();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void 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 << 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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
/* 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<RsPhotoItem *>(item);
|
||||
sitem = dynamic_cast<RsPhotoShowItem *>(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;
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::loadPhotoItem(RsPhotoItem *item)
|
||||
{
|
||||
#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 ******/
|
||||
|
||||
PhotoSet &pset = locked_getPhotoSet(item->PeerId());
|
||||
pset.photos[item->photoId] = item;
|
||||
|
||||
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;
|
||||
|
||||
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<std::string, RsPhotoItem *>::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<std::string, RsPhotoShowItem *>::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::getPhotoList(std::string id, std::list<std::string> photoIds)
|
||||
{
|
||||
#ifdef PHOTO_DEBUG
|
||||
std::cerr << "p3PhotoService::getPhotoList() pid: " << id;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
PhotoSet &pset = locked_getPhotoSet(id);
|
||||
|
||||
/* get the list of photoids */
|
||||
std::map<std::string, RsPhotoItem *>::iterator pit;
|
||||
for(pit = pset.photos.begin(); pit != pset.photos.end(); pit++)
|
||||
{
|
||||
photoIds.push_back(pit->first);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::getShowList(std::string id, std::list<std::string> 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<std::string, RsPhotoShowItem *>::iterator sit;
|
||||
for(sit = pset.shows.begin(); sit != pset.shows.end(); sit++)
|
||||
{
|
||||
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 */
|
||||
|
||||
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<std::string, RsPhotoShowItem *>::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;
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::addPhotoToShow(std::string showId, std::string photoId, int16_t index)
|
||||
{
|
||||
|
||||
#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))
|
||||
{
|
||||
#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;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3PhotoService::movePhotoInShow(std::string showId, std::string photoId, int16_t index)
|
||||
{
|
||||
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 */
|
||||
|
||||
/* copy to outgoing directory */
|
||||
|
||||
/* hash it */
|
||||
std::string hash = "PHOTO HASH";
|
||||
|
||||
/* create item */
|
||||
RsPhotoItem *item = new RsPhotoItem();
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/
|
||||
item->PeerId(mOwnId);
|
||||
}
|
||||
|
||||
item->srcId = item->PeerId();
|
||||
item->photoId = hash;
|
||||
item->name = hash;
|
||||
item->path = path;
|
||||
|
||||
/* 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<std::string, PhotoSet>::iterator it;
|
||||
it = mPhotos.find(id);
|
||||
if (it == mPhotos.end())
|
||||
{
|
||||
/* missing group -> add it in */
|
||||
PhotoSet pset;
|
||||
pset.pid = id;
|
||||
mPhotos[id] = pset;
|
||||
|
||||
it = mPhotos.find(id);
|
||||
}
|
||||
|
||||
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<std::string, RsPhotoItem *>::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<std::string, RsPhotoShowItem *>::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;
|
||||
|
||||
/* 4 bytes per random number: 4 x 4 = 16 bytes */
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
uint32_t rint = random();
|
||||
out << rint;
|
||||
}
|
||||
return out.str();
|
||||
}
|
||||
|
||||
|
||||
void p3PhotoService::createDummyData()
|
||||
{
|
||||
|
||||
#if 0
|
||||
RsRankLinkMsg *msg = new RsRankLinkMsg();
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
137
libretroshare/src/services/p3photoservice.h
Normal file
137
libretroshare/src/services/p3photoservice.h
Normal file
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* libretroshare/src/services: p3photoservice.h
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2008-2008 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef P3_PHOTO_SERVICE_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 "rsiface/rsphoto.h"
|
||||
|
||||
/*
|
||||
* Photo Service
|
||||
*/
|
||||
|
||||
class PhotoSet
|
||||
{
|
||||
public:
|
||||
|
||||
PhotoSet();
|
||||
std::string pid;
|
||||
|
||||
std::map<std::string, RsPhotoItem *> photos;
|
||||
std::map<std::string, RsPhotoShowItem *> shows;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class p3PhotoService: public CacheSource, public CacheStore
|
||||
{
|
||||
public:
|
||||
|
||||
p3PhotoService(uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
|
||||
std::string sourcedir, std::string storedir);
|
||||
|
||||
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 *********************/
|
||||
|
||||
public:
|
||||
|
||||
/************* Extern Interface *******/
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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();
|
||||
|
||||
|
||||
|
||||
RsMutex mPhotoMtx;
|
||||
|
||||
/***** below here is locked *****/
|
||||
|
||||
bool mRepublish;
|
||||
std::string mOwnId;
|
||||
|
||||
std::map<std::string, PhotoSet> mPhotos;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue