Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE > Class Template Reference

#include <RpcServer.hpp>

Classes

class  clienthandler
 

Public Member Functions

 RpcServer (const char *address)
 
 ~RpcServer ()
 
void process_queue ()
 This is essentially doing the sending/receiving. More...
 
void block_until_initialized ()
 This is used during the startup, we process_queue() until we receive a special event. More...
 

Static Public Member Functions

static void send_msg (const MSG_TYPE &msg, int excluded_id=-1)
 Send any variable changes in the core to all clients. More...
 

Public Attributes

bool initialized = false
 As soon as the tree arrived from the first client, this will be set to true. More...
 
std::string server_address
 

Static Public Attributes

static std::vector< clienthandlerclients
 

Private Types

typedef
grpc::ServerAsyncReaderWriter
< MSG_TYPE, MSG_TYPE > 
stream_type
 

Private Member Functions

void open_connect_slot ()
 
void handle_new_connection ()
 
void request_disconnect_client (int id)
 
void finish_disconnect_client (int id)
 
clienthandlerget_client (int id)
 
bool any_writes_outstanding ()
 
void kickoff_writes ()
 
void handle_queue_event (callback_event *encoded_callback, bool broadcast, std::function< void(const MSG_TYPE &)> receive_handler)
 
int pick_unused_id ()
 
bool change_variable (const MSG_TYPE &receivedval)
 

Private Attributes

std::unique_ptr< grpc::Server > grpc_server
 GRPC server instance, running while this class is alive. More...
 
grpc::ServerContext server_context
 settings like the ip/port of the server are saved in here. More...
 
ASYNC_SERVICE_TYPE service
 
std::unique_ptr
< grpc::ServerCompletionQueue > 
cq
 The completion queue (where notifications of the succcess of a network commands get retrieved). More...
 
std::unique_ptr< stream_typeconnect_slot
 Client which isn't connected yet, a buffer caused by the async API. More...
 

Member Typedef Documentation

template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
typedef grpc::ServerAsyncReaderWriter<MSG_TYPE, MSG_TYPE> inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::stream_type
private

Constructor & Destructor Documentation

template<typename MSG_TYPE , typename U >
inexor::rpc::RpcServer< MSG_TYPE, U >::RpcServer ( const char *  address)
inline
template<typename MSG_TYPE , typename U >
inexor::rpc::RpcServer< MSG_TYPE, U >::~RpcServer ( )
inline

References game::clients.

Member Function Documentation

template<typename MSG_TYPE , typename U >
bool inexor::rpc::RpcServer< MSG_TYPE, U >::any_writes_outstanding ( )
inlineprivate

References game::clients.

template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
void inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::block_until_initialized ( )
inline

This is used during the startup, we process_queue() until we receive a special event.

After 10 seconds of not receiving this event it throws a runtime error.

template<typename MSG_TYPE , typename U >
bool inexor::rpc::RpcServer< MSG_TYPE, U >::change_variable ( const MSG_TYPE &  receivedval)
inlineprivate
template<typename MSG_TYPE , typename U >
void inexor::rpc::RpcServer< MSG_TYPE, U >::finish_disconnect_client ( int  id)
inlineprivate

References game::clients.

template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
clienthandler* inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::get_client ( int  id)
inlineprivate
template<typename MSG_TYPE , typename U >
void inexor::rpc::RpcServer< MSG_TYPE, U >::handle_new_connection ( )
inlineprivate
template<typename MSG_TYPE , typename U >
void inexor::rpc::RpcServer< MSG_TYPE, U >::handle_queue_event ( callback_event encoded_callback,
bool  broadcast,
std::function< void(const MSG_TYPE &)>  receive_handler 
)
inlineprivate
template<typename MSG_TYPE , typename U >
void inexor::rpc::RpcServer< MSG_TYPE, U >::kickoff_writes ( )
inlineprivate

References game::clients.

template<typename MSG_TYPE , typename U >
void inexor::rpc::RpcServer< MSG_TYPE, U >::open_connect_slot ( )
inlineprivate
template<typename T , typename U >
int inexor::rpc::RpcServer< T, U >::pick_unused_id ( )
private

References game::clients.

template<typename MSG_TYPE , typename U >
void inexor::rpc::RpcServer< MSG_TYPE, U >::process_queue ( )
inline

This is essentially doing the sending/receiving.

Quits if there are no more values to send and we don't receive anything anymore or if MAX_RPC_EVENT_CHECKS_PER_TICK is reached. In case of errors it throws a std::exception (TODO).

References MAX_RPC_EVENT_CHECKS_PER_TICK.

template<typename MSG_TYPE , typename U >
void inexor::rpc::RpcServer< MSG_TYPE, U >::request_disconnect_client ( int  id)
inlineprivate
template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
static void inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::send_msg ( const MSG_TYPE &  msg,
int  excluded_id = -1 
)
inlinestatic

Send any variable changes in the core to all clients.

For broadcasting purpose param excluded_id is given: you don't want to send back a change you just received from a client.

References inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::clients.

Member Data Documentation

template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
std::vector<clienthandler> inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::clients
static
template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
std::unique_ptr<stream_type> inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::connect_slot
private

Client which isn't connected yet, a buffer caused by the async API.

template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
std::unique_ptr<grpc::ServerCompletionQueue> inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::cq
private

The completion queue (where notifications of the succcess of a network commands get retrieved).

Referenced by inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::RpcServer().

template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
std::unique_ptr<grpc::Server> inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::grpc_server
private

GRPC server instance, running while this class is alive.

Referenced by inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::RpcServer().

template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
bool inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::initialized = false

As soon as the tree arrived from the first client, this will be set to true.

template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
std::string inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::server_address
template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
grpc::ServerContext inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::server_context
private

settings like the ip/port of the server are saved in here.

template<typename MSG_TYPE , typename ASYNC_SERVICE_TYPE >
ASYNC_SERVICE_TYPE inexor::rpc::RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE >::service
private

The documentation for this class was generated from the following file: