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