2018-05-28 22:03:39 +02:00
/*******************************************************************************
* libretroshare / src / pqi : pqiservice . h *
* *
* libretroshare : retroshare core library *
* *
* Copyright 2004 - 2008 by Robert Fernie . *
* *
* This program is free software : you can redistribute it and / or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation , either version 3 of the *
* License , or ( at your option ) any later version . *
* *
* This program 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 Lesser General Public License for more details . *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program . If not , see < https : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-12 01:29:14 +00:00
# ifndef PQI_SERVICE_HEADER
# define PQI_SERVICE_HEADER
2013-10-01 10:11:34 +00:00
# include "pqi/pqi.h"
2007-12-12 01:29:14 +00:00
# include "pqi/pqi_base.h"
2008-11-22 13:15:07 +00:00
# include "util/rsthreads.h"
2007-12-12 01:29:14 +00:00
2014-03-22 03:53:44 +00:00
# include "retroshare/rsservicecontrol.h"
# include "pqi/p3servicecontrol.h"
2007-12-12 01:29:14 +00: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 21:58:14 +00:00
class p3ServiceServerIface ;
2013-10-01 10:11:34 +00:00
2007-12-12 01:29:14 +00:00
class pqiService
{
2017-04-20 20:54:51 +02:00
protected :
2007-12-12 01:29:14 +00:00
2014-03-22 03:53:44 +00:00
pqiService ( ) // our type of packets.
2017-04-20 20:54:51 +02:00
: mServiceServer ( NULL ) { return ; }
2007-12-12 01:29:14 +00:00
2017-04-20 20:54:51 +02:00
virtual ~ pqiService ( ) { return ; }
2007-12-12 01:29:14 +00:00
2017-04-20 20:54:51 +02:00
public :
void setServiceServer ( p3ServiceServerIface * server ) ;
//
virtual bool recv ( RsRawItem * ) = 0 ;
virtual bool send ( RsRawItem * item ) ;
virtual RsServiceInfo getServiceInfo ( ) = 0 ;
2007-12-12 01:29:14 +00:00
2017-04-20 20:54:51 +02:00
virtual int tick ( ) { return 0 ; }
2007-12-12 01:29:14 +00:00
2017-04-21 19:55:37 +02:00
virtual void getItemNames ( std : : map < uint8_t , std : : string > & /*names*/ ) const { } // This does nothing by default. Service should derive it in order to give info for the UI
2007-12-12 01:29:14 +00:00
2017-04-20 20:54:51 +02:00
private :
2014-04-18 21:58:14 +00:00
p3ServiceServerIface * mServiceServer ; // const, no need for mutex.
2007-12-12 01:29:14 +00:00
} ;
# include <map>
2014-03-22 03:53:44 +00:00
/* We are pushing the packets back through p3ServiceServer,
2013-10-01 10:11:34 +00:00
* so that we can filter services at this level later . . .
2014-03-22 03:53:44 +00:00
* if we decide not to do this , pqiService can call through
2013-10-01 10:11:34 +00:00
* to the base level pqiPublisher instead .
*/
2007-12-12 01:29:14 +00:00
2014-04-18 21:58:14 +00:00
// use interface to allow DI
class p3ServiceServerIface
{
public :
virtual ~ p3ServiceServerIface ( ) { }
2017-04-20 20:54:51 +02:00
virtual bool recvItem ( RsRawItem * ) = 0 ;
virtual bool sendItem ( RsRawItem * ) = 0 ;
2014-04-18 21:58:14 +00:00
2017-04-20 20:54:51 +02:00
virtual bool getServiceItemNames ( uint32_t service_type , std : : map < uint8_t , std : : string > & names ) = 0 ;
2014-04-18 21:58:14 +00:00
} ;
class p3ServiceServer : public p3ServiceServerIface
2007-12-12 01:29:14 +00:00
{
public :
2014-03-22 03:53:44 +00:00
p3ServiceServer ( pqiPublisher * pub , p3ServiceControl * ctrl ) ;
2007-12-12 01:29:14 +00:00
2017-04-20 20:54:51 +02:00
int addService ( pqiService * , bool defaultOn ) ;
int removeService ( pqiService * ) ;
bool recvItem ( RsRawItem * ) ;
bool sendItem ( RsRawItem * ) ;
2007-12-12 01:29:14 +00:00
2017-04-20 20:54:51 +02:00
bool getServiceItemNames ( uint32_t service_type , std : : map < uint8_t , std : : string > & names ) ;
2007-12-12 01:29:14 +00:00
2017-04-20 20:54:51 +02:00
int tick ( ) ;
2014-04-18 21:58:14 +00:00
public :
2007-12-12 01:29:14 +00:00
private :
2013-10-01 10:11:34 +00:00
pqiPublisher * mPublisher ; // constant no need for mutex.
2014-03-22 03:53:44 +00:00
p3ServiceControl * mServiceControl ;
2013-10-01 10:11:34 +00:00
2017-04-20 20:54:51 +02:00
RsMutex srvMtx ;
2014-03-22 03:53:44 +00:00
std : : map < uint32_t , pqiService * > services ;
2007-12-12 01:29:14 +00:00
} ;
# endif // PQI_SERVICE_HEADER