* Added the basics of GxsCircles service to libretroshare.

- Defined the control group stuff.
  	- Background task to determine friend membership.
	- Caching of Circle info,
	- Added GXS interface class to gxs/rsgixs.h
 	- TODO: Serialiser is incomplete.
	- TODO: SubCircles to be done in Phase 2.

 * Improvements to RsMemCache:
	- Added Value& ref(Key) to avoid data copying.
	- Added Statistics to check cache performance.
	- Fixed up bugs in tracking membership.

 * Improvements to RsTickEvent:
	- Added additional string parameter for more specificity.




git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5910 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-11-29 22:48:28 +00:00
parent baa949eaac
commit 5a55c1b5d6
18 changed files with 2353 additions and 427 deletions

View file

@ -0,0 +1,408 @@
/*
* libretroshare/src/serialiser: rswikiitems.cc
*
* 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.1 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 <iostream>
#include "rswireitems.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsbaseserial.h"
#define CIRCLE_DEBUG 1
uint32_t RsGxsCircleSerialiser::size(RsItem *item)
{
RsGxsCircleGroupItem* grp_item = NULL;
RsGxsCircleMsgItem* snap_item = NULL;
if((grp_item = dynamic_cast<RsGxsCircleGroupItem*>(item)) != NULL)
{
return sizeGxsCircleGroupItem(grp_item);
}
else if((snap_item = dynamic_cast<RsGxsCircleMsgItem*>(item)) != NULL)
{
return sizeGxsCircleMsgItem(snap_item);
}
return NULL;
}
bool RsGxsCircleSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
{
RsGxsCircleGroupItem* grp_item = NULL;
RsGxsCircleMsgItem* snap_item = NULL;
if((grp_item = dynamic_cast<RsGxsCircleGroupItem*>(item)) != NULL)
{
return serialiseGxsCircleGroupItem(grp_item, data, size);
}
else if((snap_item = dynamic_cast<RsGxsCircleMsgItem*>(item)) != NULL)
{
return serialiseGxsCircleMsgItem(snap_item, data, size);
}
return false;
}
RsItem* RsGxsCircleSerialiser::deserialise(void* data, uint32_t* size)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM:
return deserialiseGxsCircleGroupItem(data, size);
break;
case RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM:
return deserialiseGxsCircleMsgItem(data, size);
break;
default:
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialise(): unknown subtype";
std::cerr << std::endl;
#endif
break;
}
return NULL;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsCircleGroupItem::clear()
{
group.mDescription.clear();
}
std::ostream& RsGxsCircleGroupItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsCircleGroupItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Description: " << group.mDescription << std::endl;
printRsItemEnd(out ,"RsGxsCircleGroupItem", indent);
return out;
}
uint32_t RsGxsCircleSerialiser::sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item)
{
const RsCircleGroup& group = item->group;
uint32_t s = 8; // header
s += GetTlvStringSize(group.mDescription);
return s;
}
bool RsGxsCircleSerialiser::serialiseGxsCircleGroupItem(RsGxsCircleGroupItem *item, void *data, uint32_t *size)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsCircleGroupItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsCircleGroupItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mDescription);
if(offset != tlvsize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef CIRCLE_DEBUG
if (!ok)
{
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsCircleGroupItem* RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem(void *data, uint32_t *size)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem()" << std::endl;
#endif
/* 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_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM != getRsItemSubType(rstype)))
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsCircleGroupItem* item = new RsGxsCircleGroupItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mDescription);
if (offset != rssize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/
void RsGxsCircleMsgItem::clear()
{
pulse.mPulseText.clear();
pulse.mHashTags.clear();
}
std::ostream& RsGxsCircleMsgItem::print(std::ostream& out, uint16_t indent)
{
printRsItemBase(out, "RsGxsCircleMsgItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "Page: " << pulse.mPulseText << std::endl;
printIndent(out, int_Indent);
out << "HashTags: " << pulse.mHashTags << std::endl;
printRsItemEnd(out ,"RsGxsCircleMsgItem", indent);
return out;
}
uint32_t RsGxsCircleSerialiser::sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item)
{
const RsCircleMsg& pulse = item->pulse;
uint32_t s = 8; // header
s += GetTlvStringSize(pulse.mPulseText);
s += GetTlvStringSize(pulse.mHashTags);
return s;
}
bool RsGxsCircleSerialiser::serialiseGxsCircleMsgItem(RsGxsCircleMsgItem *item, void *data, uint32_t *size)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem()" << std::endl;
#endif
uint32_t tlvsize = sizeGxsCircleMsgItem(item);
uint32_t offset = 0;
if(*size < tlvsize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem()" << std::endl;
#endif
return false;
}
*size = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
/* skip the header */
offset += 8;
/* GxsCircleMsgItem */
ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mPulseText);
ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mHashTags);
if(offset != tlvsize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem() FAIL Size Error! " << std::endl;
#endif
ok = false;
}
#ifdef CIRCLE_DEBUG
if (!ok)
{
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem() NOK" << std::endl;
}
#endif
return ok;
}
RsGxsCircleMsgItem* RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem(void *data, uint32_t *size)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem()" << std::endl;
#endif
/* 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_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM != getRsItemSubType(rstype)))
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL wrong type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL wrong size" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*size = rssize;
bool ok = true;
RsGxsCircleMsgItem* item = new RsGxsCircleMsgItem();
/* skip the header */
offset += 8;
ok &= GetTlvString(data, rssize, &offset, 1, item->pulse.mPulseText);
ok &= GetTlvString(data, rssize, &offset, 1, item->pulse.mHashTags);
if (offset != rssize)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL size mismatch" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok)
{
#ifdef CIRCLE_DEBUG
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() NOK" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
/*****************************************************************************************/
/*****************************************************************************************/
/*****************************************************************************************/

View file

@ -0,0 +1,93 @@
/*
* libretroshare/src/serialiser: rsgxscircleitems.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.1 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 RS_GXSCIRCLE_ITEMS_H
#define RS_GXSCIRCLE_ITEMS_H
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvtypes.h"
#include "rsgxsitems.h"
#include "retroshare/rsgxscircles.h"
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM = 0x03;
class RsGxsCircleGroupItem : public RsGxsGrpItem
{
public:
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE,
RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM) { return;}
virtual ~RsGxsCircleGroupItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsCircleGroup group;
};
class RsGxsCircleMsgItem : public RsGxsMsgItem
{
public:
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE,
RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {return; }
virtual ~RsGxsCircleMsgItem() { return;}
void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsGxsCircleMsg msg;
};
class RsGxsCircleSerialiser : public RsSerialType
{
public:
RsGxsCircleSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_GXSCIRCLE)
{ return; }
virtual ~RsGxsCircleSerialiser() { return; }
uint32_t size(RsItem *item);
bool serialise (RsItem *item, void *data, uint32_t *size);
RsItem * deserialise(void *data, uint32_t *size);
private:
uint32_t sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item);
bool serialiseGxsCircleGroupItem (RsGxsCircleGroupItem *item, void *data, uint32_t *size);
RsGxsCircleGroupItem * deserialiseGxsCircleGroupItem(void *data, uint32_t *size);
uint32_t sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item);
bool serialiseGxsCircleMsgItem (RsGxsCircleMsgItem *item, void *data, uint32_t *size);
RsGxsCircleMsgItem * deserialiseGxsCircleMsgItem(void *data, uint32_t *size);
};
#endif /* RS_GXSCIRCLE_ITEMS_H */

View file

@ -138,14 +138,16 @@ const uint16_t RS_SERVICE_GXSV1_TYPE_WIRE = 0xf304;
const uint16_t RS_SERVICE_GXSV1_TYPE_FORUMS = 0xf305;
const uint16_t RS_SERVICE_GXSV1_TYPE_POSTED = 0xf306;
const uint16_t RS_SERVICE_GXSV1_TYPE_CHANNELS = 0xf307;
const uint16_t RS_SERVICE_GXSV1_TYPE_GXSCIRCLE = 0xf307;
const uint16_t RS_SERVICE_GXSV2_TYPE_GXSID = 0xf311;
const uint16_t RS_SERVICE_GXSV2_TYPE_PHOTO = 0xf312;
const uint16_t RS_SERVICE_GXSV2_TYPE_WIKI = 0xf313;
const uint16_t RS_SERVICE_GXSV2_TYPE_WIRE = 0xf314;
const uint16_t RS_SERVICE_GXSV2_TYPE_FORUMS = 0xf315;
const uint16_t RS_SERVICE_GXSV2_TYPE_POSTED = 0xf316;
const uint16_t RS_SERVICE_GXSV2_TYPE_CHANNELS = 0xf317;
const uint16_t RS_SERVICE_GXSV2_TYPE_GXSCIRCLE = 0xf312;
const uint16_t RS_SERVICE_GXSV2_TYPE_PHOTO = 0xf313;
const uint16_t RS_SERVICE_GXSV2_TYPE_WIKI = 0xf314;
const uint16_t RS_SERVICE_GXSV2_TYPE_WIRE = 0xf315;
const uint16_t RS_SERVICE_GXSV2_TYPE_FORUMS = 0xf316;
const uint16_t RS_SERVICE_GXSV2_TYPE_POSTED = 0xf317;
const uint16_t RS_SERVICE_GXSV2_TYPE_CHANNELS = 0xf318;
/* Example Versions (VEG) of New Cache Services */
const uint16_t RS_SERVICE_VEG_TYPE_IDENTITY = 0xf320;