1147128f8e09dc8b72b83e09e9d08e34ab26b0c4
[deliverable/titan.core.git] / core / Communication.hh
1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Baji, Laszlo
10 * Balasko, Jeno
11 * Beres, Szabolcs
12 * Feher, Csaba
13 * Forstner, Matyas
14 * Kovacs, Ferenc
15 * Raduly, Csaba
16 * Szabo, Bence Janos
17 * Szabo, Janos Zoltan – initial implementation
18 * Zalanyi, Balazs Andor
19 *
20 ******************************************************************************/
21 #ifndef COMMUNICATION_HH
22 #define COMMUNICATION_HH
23
24 #include <sys/types.h>
25 struct in_addr;
26 struct sockaddr_in;
27 struct sockaddr_un;
28
29 #include <time.h>
30
31 #include "Types.h"
32 #include "Textbuf.hh"
33 #include "NetworkHandler.hh"
34
35 class MC_Connection;
36
37 class TTCN_Communication {
38 static int mc_fd;
39 static HCNetworkHandler hcnh;
40 static boolean local_addr_set, mc_addr_set, is_connected;
41 static Text_Buf incoming_buf;
42 static MC_Connection mc_connection;
43 static double call_interval;
44
45 public:
46 static const NetworkFamily& get_network_family() { return hcnh.get_family(); }
47 static bool has_local_address() { return local_addr_set; }
48 static void set_local_address(const char *host_name);
49 static const IPAddress *get_local_address();
50 static void set_mc_address(const char *host_name,
51 unsigned short tcp_port);
52 static const IPAddress *get_mc_address();
53 static bool is_mc_connected();
54 static void connect_mc();
55 static void disconnect_mc();
56 static void close_mc_connection();
57
58 static boolean transport_unix_stream_supported();
59
60 static boolean set_close_on_exec(int fd);
61 static boolean set_non_blocking_mode(int fd, boolean enable_nonblock);
62
63 static boolean set_tcp_nodelay(int fd);
64 static boolean increase_send_buffer(int fd, int &old_size,
65 int& new_size);
66
67 static void enable_periodic_call();
68 static void increase_call_interval();
69 static void disable_periodic_call();
70
71 static void process_all_messages_hc();
72 static void process_all_messages_tc();
73 static void process_debug_messages();
74
75 static void send_version();
76 static void send_configure_ack();
77 static void send_configure_nak();
78 static void send_create_nak(component component_reference,
79 const char *fmt_str, ...)
80 __attribute__ ((__format__ (__printf__, 2, 3)));
81
82 static void send_hc_ready();
83
84 static void send_create_req(const char *component_type_module,
85 const char *component_type_name,
86 const char *component_name,
87 const char *component_location, boolean is_alive);
88 static void prepare_start_req(Text_Buf& text_buf,
89 component component_reference, const char *module_name,
90 const char *function_name);
91 static void send_stop_req(component component_reference);
92 static void send_kill_req(component component_reference);
93 static void send_is_running(component component_reference);
94 static void send_is_alive(component component_reference);
95 static void send_done_req(component component_reference);
96 static void send_killed_req(component component_reference);
97 static void send_cancel_done_ack(component component_reference);
98 static void send_connect_req(component src_component,
99 const char *src_port, component dst_component,
100 const char *dst_port);
101 static void send_connect_listen_ack_inet_stream(const char *local_port,
102 component remote_component, const char *remote_port,
103 const IPAddress *local_address);
104
105 static void send_connect_listen_ack_unix_stream(const char *local_port,
106 component remote_component, const char *remote_port,
107 const struct sockaddr_un *local_address);
108
109 static void send_connected(const char *local_port,
110 component remote_component, const char *remote_port);
111 static void send_connect_error(const char *local_port,
112 component remote_component, const char *remote_port,
113 const char *fmt_str, ...)
114 __attribute__ ((__format__ (__printf__, 4, 5)));
115 static void send_disconnect_req(component src_component,
116 const char *src_port, component dst_component,
117 const char *dst_port);
118 static void send_disconnected(const char *local_port,
119 component remote_component, const char *remote_port);
120 static void send_map_req(component src_component, const char *src_port,
121 const char *system_port);
122 static void send_mapped(const char *local_port,
123 const char *system_port);
124 static void send_unmap_req(component src_component,
125 const char *src_port, const char *system_port);
126 static void send_unmapped(const char *local_port,
127 const char *system_port);
128
129 static void send_mtc_created();
130 static void send_testcase_started(const char *testcase_module,
131 const char *testcase_name, const char *mtc_comptype_module,
132 const char *mtc_comptype_name,
133 const char *system_comptype_module,
134 const char *system_comptype_name);
135 static void send_testcase_finished(verdicttype final_verdict,
136 const char* reason = "");
137 static void send_mtc_ready();
138
139 static void send_ptc_created(component component_reference);
140 static void prepare_stopped(Text_Buf& text_buf,
141 const char *return_type);
142 static void send_stopped();
143 static void prepare_stopped_killed(Text_Buf& text_buf,
144 verdicttype final_verdict, const char *return_type,
145 const char* reason = "");
146 static void send_stopped_killed(verdicttype final_verdict,
147 const char* reason = "");
148 static void send_killed(verdicttype final_verdict, const char* reason = "");
149
150 static void send_debug_return_value(int return_type, const char* message);
151 static void send_debug_halt_req();
152
153 /** @brief Send a log message to the MC.
154
155 @param timestamp_sec integral part of timestamp (seconds since 1970)
156 @param timestamp_usec fractional part of timestamp
157 @param event_severity a TTCN_Logger::Severity value converted to an integer
158 @param message_text_len length of message string
159 @param message_text the message itself (does not need to be 0-terminated)
160
161 If connected, constructs a Text_Buf and calls send_message().
162
163 @return TRUE if sending the message appears to be successful or
164 the message doesn't need to be logged to the console.
165 @return FALSE if sending appears to fail or the message should be logged
166 to the console in any case.
167 */
168 static boolean send_log(time_t timestamp_sec, long timestamp_usec,
169 unsigned int event_severity, size_t message_text_len,
170 const char *message_text);
171
172 /// Constructs a Text_Buf and calls send_message().
173 static void send_error(const char *fmt_str, ...)
174 __attribute__ ((__format__ (__printf__, 1, 2)));
175
176 static void send_message(Text_Buf& text_buf);
177
178 private:
179 /** @name Handlers of various messages
180 * @{
181 */
182 static void process_configure(int msg_end);
183 static void process_create_mtc();
184 static void process_create_ptc();
185 static void process_kill_process();
186 static void process_exit_hc();
187
188 static void process_create_ack();
189 static void process_start_ack();
190 static void process_stop();
191 static void process_stop_ack();
192 static void process_kill_ack();
193 static void process_running();
194 static void process_alive();
195 static void process_done_ack(int msg_end);
196 static void process_killed_ack();
197 static void process_cancel_done_mtc();
198 static void process_cancel_done_ptc();
199 static void process_component_status_mtc(int msg_end);
200 static void process_component_status_ptc(int msg_end);
201 static void process_connect_listen();
202 static void process_connect();
203 static void process_connect_ack();
204 static void process_disconnect();
205 static void process_disconnect_ack();
206 static void process_map();
207 static void process_map_ack();
208 static void process_unmap();
209 static void process_unmap_ack();
210
211 static void process_execute_control();
212 static void process_execute_testcase();
213 static void process_ptc_verdict();
214 static void process_continue();
215 static void process_exit_mtc();
216
217 static void process_start();
218 static void process_kill();
219
220 static void process_error();
221 static void process_unsupported_message(int msg_type, int msg_end);
222
223 static void process_debug_command();
224 /** @} */
225 };
226
227 #endif
This page took 0.035265 seconds and 4 git commands to generate.