Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RpcSubsystem.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <queue>
5 
6 #include <grpc/grpc.h>
7 #include <grpc++/grpc++.h>
8 
10 #include "inexor/io/Logging.hpp"
12 
13 namespace inexor {
14 namespace rpc {
15 
16 // These functions need to be implemented by the Context Provider (acquiring this submodule):
17 extern void set_on_change_functions();
18 extern void send_all_vars();
19 extern const std::unordered_map<int64, void *> cppvar_pointer_map;
20 extern const std::unordered_map<int64, int> index_to_type_map;
21 
22 template<typename MSG_TYPE, typename ASYNC_SERVICE_TYPE>
24 {
26 public:
28 
30  {
31  Log.sync->info("RPC server stopped ({0})", serv->server_address);
32  delete serv;
33  }
34 
35  virtual void initialize(int argc, char **argv) override
36  {
37  if(argc < 2) return;
38  std::string port = argv[1];
39  std::string full_address = "0.0.0.0:"+ port;
40  serv = new RpcServer<MSG_TYPE, ASYNC_SERVICE_TYPE>(full_address.c_str());
41  Log.sync->info("RPC server listening on {0}", serv->server_address);
43  serv->block_until_initialized();
44  }
45 
46  virtual void tick() override
47  {
48  if(serv) serv->process_queue();
49  }
50 };
51 
52 
53 } // namespace inexor
54 } // namespace rpc
55 
static Logger sync
Logger for synchronization messages.
Definition: Logging.hpp:96
Logging stuff including the ingame console logging functionality.
RpcServer< MSG_TYPE, ASYNC_SERVICE_TYPE > * serv
Definition: RpcSubsystem.hpp:25
void set_on_change_functions()
const std::unordered_map< int64, void * > cppvar_pointer_map
virtual void initialize(int argc, char **argv) override
Called once.
Definition: RpcSubsystem.hpp:35
inexor::util::log_manager Log
Definition: Logging.cpp:241
Definition: RpcServer.hpp:64
const std::unordered_map< int64, int > index_to_type_map
char string[MAXSTRLEN]
cube-strings (char arrays of fixed size).
Definition: cube_types.hpp:18
RpcSubsystem()
Definition: RpcSubsystem.hpp:27
Definition: RpcSubsystem.hpp:23
Subsystems are loosely coupled parts of inexor.
Definition: Subsystem.hpp:34
void send_all_vars()
virtual void tick() override
Called once per frame, or what ever our event loop is.
Definition: RpcSubsystem.hpp:46
~RpcSubsystem()
Definition: RpcSubsystem.hpp:29