mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-07 06:02:41 -04:00
Final changes to add the new serialiser.
- added Chat / Msg and Disc services. - expanded rsiface to handle new serialiser. - mods to rsserver with new conversions etc. - added service directory to Makefile. - removed PROXY / CHANNELS from make.opt git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@276 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
d9efb76b01
commit
46a001af47
19 changed files with 3605 additions and 156 deletions
163
libretroshare/src/services/p3service.cc
Normal file
163
libretroshare/src/services/p3service.cc
Normal file
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* libretroshare/src/services p3service.cc
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-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 "pqi/pqi.h"
|
||||
#include "services/p3service.h"
|
||||
|
||||
void p3Service::addSerialType(RsSerialType *st)
|
||||
{
|
||||
rsSerialiser->addSerialType(st);
|
||||
}
|
||||
|
||||
RsItem *p3Service::recvItem()
|
||||
{
|
||||
srvMtx.lock(); /***** LOCK MUTEX *****/
|
||||
|
||||
if (recv_queue.size() == 0)
|
||||
{
|
||||
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||
return NULL; /* nothing there! */
|
||||
}
|
||||
|
||||
/* get something off front */
|
||||
RsItem *item = recv_queue.front();
|
||||
recv_queue.pop_front();
|
||||
|
||||
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
bool p3Service::receivedItems()
|
||||
{
|
||||
srvMtx.lock(); /***** LOCK MUTEX *****/
|
||||
|
||||
bool moreData = (recv_queue.size() != 0);
|
||||
|
||||
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||
|
||||
return moreData;
|
||||
}
|
||||
|
||||
|
||||
int p3Service::sendItem(RsItem *item)
|
||||
{
|
||||
srvMtx.lock(); /***** LOCK MUTEX *****/
|
||||
|
||||
send_queue.push_back(item);
|
||||
|
||||
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// overloaded pqiService interface.
|
||||
int p3Service::receive(RsRawItem *raw)
|
||||
{
|
||||
srvMtx.lock(); /***** LOCK MUTEX *****/
|
||||
|
||||
std::cerr << "p3Service::receive()" << std::endl;
|
||||
|
||||
/* convert to RsServiceItem */
|
||||
uint32_t size = raw->getRawLength();
|
||||
RsItem *item = rsSerialiser->deserialise(raw->getRawData(), &size);
|
||||
if ((!item) || (size != raw->getRawLength()))
|
||||
{
|
||||
/* error in conversion */
|
||||
std::cerr << "p3Service::receive() Error" << std::endl;
|
||||
std::cerr << "p3Service::receive() Size: " << size << std::endl;
|
||||
std::cerr << "p3Service::receive() RawLength: " << raw->getRawLength() << std::endl;
|
||||
if (item)
|
||||
{
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* if we have something - pass it on */
|
||||
if (item)
|
||||
{
|
||||
/* ensure PeerId is transferred */
|
||||
item->PeerId(raw->PeerId());
|
||||
recv_queue.push_back(item);
|
||||
}
|
||||
|
||||
/* cleanup input */
|
||||
delete raw;
|
||||
|
||||
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||
|
||||
return (item != NULL);
|
||||
}
|
||||
|
||||
RsRawItem *p3Service::send()
|
||||
{
|
||||
srvMtx.lock(); /***** LOCK MUTEX *****/
|
||||
|
||||
if (send_queue.size() == 0)
|
||||
{
|
||||
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||
return NULL; /* nothing there! */
|
||||
}
|
||||
|
||||
/* get something off front */
|
||||
RsItem *si = send_queue.front();
|
||||
send_queue.pop_front();
|
||||
|
||||
/* try to convert */
|
||||
uint32_t size = rsSerialiser->size(si);
|
||||
if (!size)
|
||||
{
|
||||
/* can't convert! */
|
||||
delete si;
|
||||
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsRawItem *raw = new RsRawItem(si->PacketId(), size);
|
||||
if (!rsSerialiser->serialise(si, raw->getRawData(), &size))
|
||||
{
|
||||
delete raw;
|
||||
raw = NULL;
|
||||
}
|
||||
|
||||
if ((raw) && (size != raw->getRawLength()))
|
||||
{
|
||||
delete raw;
|
||||
raw = NULL;
|
||||
}
|
||||
|
||||
/* ensure PeerId is transferred */
|
||||
raw->PeerId(si->PeerId());
|
||||
|
||||
/* cleanup */
|
||||
delete si;
|
||||
|
||||
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||
return raw;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue