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