2007-12-11 20:29:14 -05:00
/*
* libretroshare / src / pqi pqiservice . h
*
* 3 P / 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
{
2017-04-20 14:54:51 -04:00
protected :
2007-12-11 20:29:14 -05:00
2014-03-21 23:53:44 -04:00
pqiService ( ) // our type of packets.
2017-04-20 14:54:51 -04:00
: mServiceServer ( NULL ) { return ; }
2007-12-11 20:29:14 -05:00
2017-04-20 14:54:51 -04:00
virtual ~ pqiService ( ) { return ; }
2007-12-11 20:29:14 -05:00
2017-04-20 14:54:51 -04:00
public :
void setServiceServer ( p3ServiceServerIface * server ) ;
//
virtual bool recv ( RsRawItem * ) = 0 ;
virtual bool send ( RsRawItem * item ) ;
virtual RsServiceInfo getServiceInfo ( ) = 0 ;
2007-12-11 20:29:14 -05:00
2017-04-20 14:54:51 -04:00
virtual int tick ( ) { return 0 ; }
2007-12-11 20:29:14 -05:00
2017-04-20 14:54:51 -04: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-11 20:29:14 -05:00
2017-04-20 14:54:51 -04:00
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 ( ) { }
2017-04-20 14:54:51 -04:00
virtual bool recvItem ( RsRawItem * ) = 0 ;
virtual bool sendItem ( RsRawItem * ) = 0 ;
2014-04-18 17:58:14 -04:00
2017-04-20 14:54:51 -04:00
virtual bool getServiceItemNames ( uint32_t service_type , std : : map < uint8_t , std : : string > & names ) = 0 ;
2014-04-18 17:58:14 -04:00
} ;
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
2017-04-20 14:54:51 -04:00
int addService ( pqiService * , bool defaultOn ) ;
int removeService ( pqiService * ) ;
bool recvItem ( RsRawItem * ) ;
bool sendItem ( RsRawItem * ) ;
2007-12-11 20:29:14 -05:00
2017-04-20 14:54:51 -04:00
bool getServiceItemNames ( uint32_t service_type , std : : map < uint8_t , std : : string > & names ) ;
2007-12-11 20:29:14 -05:00
2017-04-20 14:54:51 -04: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
2017-04-20 14:54:51 -04: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