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:
drbob 2008-03-04 21:31:11 +00:00
parent 3ed1eef186
commit 08860b25e6
28 changed files with 3297 additions and 235 deletions

View file

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

View 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
/*************************************************************************/

View 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 */

View file

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