2007-12-11 20:29:14 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/pqi pqiservice.h
|
|
|
|
*
|
|
|
|
* 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef PQI_SERVICE_HEADER
|
|
|
|
#define PQI_SERVICE_HEADER
|
|
|
|
|
2013-10-01 06:11:34 -04:00
|
|
|
#include "pqi/pqi.h"
|
2007-12-11 20:29:14 -05:00
|
|
|
#include "pqi/pqi_base.h"
|
2008-11-22 08:15:07 -05:00
|
|
|
#include "util/rsthreads.h"
|
2007-12-11 20:29:14 -05:00
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
#include "retroshare/rsservicecontrol.h"
|
|
|
|
#include "pqi/p3servicecontrol.h"
|
|
|
|
|
2007-12-11 20:29:14 -05:00
|
|
|
// PQI Service, is a generic lower layer on which services can run on.
|
|
|
|
//
|
|
|
|
// these packets get passed through the
|
|
|
|
// server, to a service that is registered.
|
|
|
|
//
|
|
|
|
// example services:
|
|
|
|
// proxytunnel. -> p3proxy.
|
|
|
|
// sockettunnel
|
|
|
|
// -> either broadcast (attach to
|
|
|
|
// open socket instead
|
|
|
|
// of broadcast address)
|
|
|
|
// -> or requested/signon.
|
|
|
|
//
|
|
|
|
// games,
|
|
|
|
// voice
|
|
|
|
// video
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// DataType is defined in the serialiser directory.
|
|
|
|
|
|
|
|
class RsRawItem;
|
2014-04-18 17:58:14 -04:00
|
|
|
class p3ServiceServerIface;
|
2013-10-01 06:11:34 -04:00
|
|
|
|
2007-12-11 20:29:14 -05:00
|
|
|
|
|
|
|
class pqiService
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
pqiService() // our type of packets.
|
|
|
|
:mServiceServer(NULL) { return; }
|
2007-12-11 20:29:14 -05:00
|
|
|
|
|
|
|
virtual ~pqiService() { return; }
|
|
|
|
|
|
|
|
public:
|
2014-04-18 17:58:14 -04:00
|
|
|
void setServiceServer(p3ServiceServerIface *server);
|
2007-12-11 20:29:14 -05:00
|
|
|
//
|
2013-10-01 06:11:34 -04:00
|
|
|
virtual bool recv(RsRawItem *) = 0;
|
|
|
|
virtual bool send(RsRawItem *item);
|
2007-12-11 20:29:14 -05:00
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
virtual RsServiceInfo getServiceInfo() = 0;
|
2007-12-11 20:29:14 -05:00
|
|
|
|
|
|
|
virtual int tick() { return 0; }
|
|
|
|
|
|
|
|
private:
|
2014-04-18 17:58:14 -04:00
|
|
|
p3ServiceServerIface *mServiceServer; // const, no need for mutex.
|
2007-12-11 20:29:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
/* We are pushing the packets back through p3ServiceServer,
|
2013-10-01 06:11:34 -04:00
|
|
|
* so that we can filter services at this level later...
|
2014-03-21 23:53:44 -04:00
|
|
|
* if we decide not to do this, pqiService can call through
|
2013-10-01 06:11:34 -04:00
|
|
|
* to the base level pqiPublisher instead.
|
|
|
|
*/
|
2007-12-11 20:29:14 -05:00
|
|
|
|
2014-04-18 17:58:14 -04:00
|
|
|
// use interface to allow DI
|
|
|
|
class p3ServiceServerIface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~p3ServiceServerIface() {}
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool recvItem(RsRawItem *) = 0;
|
|
|
|
virtual bool sendItem(RsRawItem *) = 0;
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class p3ServiceServer : public p3ServiceServerIface
|
2007-12-11 20:29:14 -05:00
|
|
|
{
|
|
|
|
public:
|
2014-03-21 23:53:44 -04:00
|
|
|
p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl);
|
2007-12-11 20:29:14 -05:00
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
int addService(pqiService *, bool defaultOn);
|
2015-06-16 10:20:59 -04:00
|
|
|
int removeService(pqiService *);
|
2007-12-11 20:29:14 -05:00
|
|
|
|
2013-10-01 06:11:34 -04:00
|
|
|
bool recvItem(RsRawItem *);
|
|
|
|
bool sendItem(RsRawItem *);
|
2007-12-11 20:29:14 -05:00
|
|
|
|
|
|
|
int tick();
|
2014-04-18 17:58:14 -04:00
|
|
|
public:
|
2007-12-11 20:29:14 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2013-10-01 06:11:34 -04:00
|
|
|
pqiPublisher *mPublisher; // constant no need for mutex.
|
2014-03-21 23:53:44 -04:00
|
|
|
p3ServiceControl *mServiceControl;
|
2013-10-01 06:11:34 -04:00
|
|
|
|
2008-11-22 08:15:07 -05:00
|
|
|
RsMutex srvMtx;
|
2014-03-21 23:53:44 -04:00
|
|
|
std::map<uint32_t, pqiService *> services;
|
2007-12-11 20:29:14 -05:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PQI_SERVICE_HEADER
|