86 #ifndef tcp_io_device_h
87 #define tcp_io_device_h
89 #include "../r_exec/mem.h"
91 #ifndef ENABLE_PROTOBUF
93 namespace tcp_io_device {
101 TcpIoDevice(
int number_of_servers,
int number_of_clients, std::vector<std::pair<std::string, std::string> > server_configurations, std::vector<std::string> client_configurations);
114 #pragma comment (lib, "Ws2_32.lib")
116 #define PROTOBUF_USE_DLLS
125 #include "AERA_Protobuf/tcp_connection.h"
127 namespace tcp_io_device {
138 template<
class O,
class S>
class TcpIoDevice :
143 TcpIoDevice(
int number_of_servers,
int number_of_clients, std::vector<std::pair<std::string, std::string> > server_configurations, std::vector<std::string> client_configurations);
155 virtual bool load(
const std::vector<r_code::Code*>* objects, uint32 stdin_oid, uint32 stdout_oid, uint32 self_oid);
171 virtual void on_diagnostic_time_tick() { on_time_tick(); }
175 class _Thread :
public Thread {
178 int number_of_servers_;
179 int number_of_clients_;
181 std::vector<std::pair<std::string, std::string> > server_configurations_;
182 std::vector<std::string> client_configurations_;
184 std::vector<TCPConnection*> tcp_connections_;
185 std::shared_ptr<SafeQueue> receive_queue_;
186 std::shared_ptr<SafeQueue> send_queue_;
188 std::map<int, std::string> id_mapping_;
189 std::map<std::string, r_code::Code*> entities_;
190 std::map<std::string, uint16> commands_;
191 std::map<std::string, r_code::Code*> objects_;
193 std::map<std::string, MetaData> meta_data_map_;
194 std::map<std::string, MsgData> data_map_;
196 Thread* timeTickThread_;
197 Timestamp lastInjectTime_;
198 Timestamp lastCommandTime_;
206 void startTimeTickThread();
219 static thread_ret thread_function_call timeTickRun(
void* args);
231 std::vector<T> getDataVec(
r_code::Code* cmd,
int start_index,
int end_index, tcp_io_device::VariableDescription_DataType type);
237 void handleMessage(std::unique_ptr<TCPMessage> msg);
243 void handleDataMessage(std::unique_ptr<TCPMessage> data_msg);
252 void injectDefault(
r_code::Code* entity,
r_code::Code*
object, std::vector<r_code::Code*> vals, core::Timestamp time);
268 void injectOpCode(
r_code::Code* entity,
r_code::Code*
object, std::vector<V> vals, core::Timestamp time, std::string opcode_handle);
275 void handleSetupMessage(std::unique_ptr<TCPMessage> setup_msg);
287 void sendMessage(std::unique_ptr<TCPMessage> msg);
291 #endif // !ENABLE_PROTOBUF