Commit | Line | Data |
---|---|---|
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 | |
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 | ******************************************************************************/ | |
970ed795 EL |
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 | ||
72 | static void send_version(); | |
73 | static void send_configure_ack(); | |
74 | static void send_configure_nak(); | |
75 | static void send_create_nak(component component_reference, | |
76 | const char *fmt_str, ...) | |
77 | __attribute__ ((__format__ (__printf__, 2, 3))); | |
78 | ||
79 | static void send_hc_ready(); | |
80 | ||
81 | static void send_create_req(const char *component_type_module, | |
82 | const char *component_type_name, | |
83 | const char *component_name, | |
84 | const char *component_location, boolean is_alive); | |
85 | static void prepare_start_req(Text_Buf& text_buf, | |
86 | component component_reference, const char *module_name, | |
87 | const char *function_name); | |
88 | static void send_stop_req(component component_reference); | |
89 | static void send_kill_req(component component_reference); | |
90 | static void send_is_running(component component_reference); | |
91 | static void send_is_alive(component component_reference); | |
92 | static void send_done_req(component component_reference); | |
93 | static void send_killed_req(component component_reference); | |
94 | static void send_cancel_done_ack(component component_reference); | |
95 | static void send_connect_req(component src_component, | |
96 | const char *src_port, component dst_component, | |
97 | const char *dst_port); | |
98 | static void send_connect_listen_ack_inet_stream(const char *local_port, | |
99 | component remote_component, const char *remote_port, | |
100 | const IPAddress *local_address); | |
101 | ||
102 | static void send_connect_listen_ack_unix_stream(const char *local_port, | |
103 | component remote_component, const char *remote_port, | |
104 | const struct sockaddr_un *local_address); | |
105 | ||
106 | static void send_connected(const char *local_port, | |
107 | component remote_component, const char *remote_port); | |
108 | static void send_connect_error(const char *local_port, | |
109 | component remote_component, const char *remote_port, | |
110 | const char *fmt_str, ...) | |
111 | __attribute__ ((__format__ (__printf__, 4, 5))); | |
112 | static void send_disconnect_req(component src_component, | |
113 | const char *src_port, component dst_component, | |
114 | const char *dst_port); | |
115 | static void send_disconnected(const char *local_port, | |
116 | component remote_component, const char *remote_port); | |
117 | static void send_map_req(component src_component, const char *src_port, | |
118 | const char *system_port); | |
119 | static void send_mapped(const char *local_port, | |
120 | const char *system_port); | |
121 | static void send_unmap_req(component src_component, | |
122 | const char *src_port, const char *system_port); | |
123 | static void send_unmapped(const char *local_port, | |
124 | const char *system_port); | |
125 | ||
126 | static void send_mtc_created(); | |
127 | static void send_testcase_started(const char *testcase_module, | |
128 | const char *testcase_name, const char *mtc_comptype_module, | |
129 | const char *mtc_comptype_name, | |
130 | const char *system_comptype_module, | |
131 | const char *system_comptype_name); | |
132 | static void send_testcase_finished(verdicttype final_verdict, | |
133 | const char* reason = ""); | |
134 | static void send_mtc_ready(); | |
135 | ||
136 | static void send_ptc_created(component component_reference); | |
137 | static void prepare_stopped(Text_Buf& text_buf, | |
138 | const char *return_type); | |
139 | static void send_stopped(); | |
140 | static void prepare_stopped_killed(Text_Buf& text_buf, | |
141 | verdicttype final_verdict, const char *return_type, | |
142 | const char* reason = ""); | |
143 | static void send_stopped_killed(verdicttype final_verdict, | |
144 | const char* reason = ""); | |
145 | static void send_killed(verdicttype final_verdict, const char* reason = ""); | |
146 | ||
147 | ||
148 | /** @brief Send a log message to the MC. | |
149 | ||
150 | @param timestamp_sec integral part of timestamp (seconds since 1970) | |
151 | @param timestamp_usec fractional part of timestamp | |
152 | @param event_severity a TTCN_Logger::Severity value converted to an integer | |
153 | @param message_text_len length of message string | |
154 | @param message_text the message itself (does not need to be 0-terminated) | |
155 | ||
156 | If connected, constructs a Text_Buf and calls send_message(). | |
157 | ||
158 | @return TRUE if sending the message appears to be successful or | |
159 | the message doesn't need to be logged to the console. | |
160 | @return FALSE if sending appears to fail or the message should be logged | |
161 | to the console in any case. | |
162 | */ | |
163 | static boolean send_log(time_t timestamp_sec, long timestamp_usec, | |
164 | unsigned int event_severity, size_t message_text_len, | |
165 | const char *message_text); | |
166 | ||
167 | /// Constructs a Text_Buf and calls send_message(). | |
168 | static void send_error(const char *fmt_str, ...) | |
169 | __attribute__ ((__format__ (__printf__, 1, 2))); | |
170 | ||
171 | static void send_message(Text_Buf& text_buf); | |
172 | ||
173 | private: | |
174 | /** @name Handlers of various messages | |
175 | * @{ | |
176 | */ | |
177 | static void process_configure(int msg_end); | |
178 | static void process_create_mtc(); | |
179 | static void process_create_ptc(); | |
180 | static void process_kill_process(); | |
181 | static void process_exit_hc(); | |
182 | ||
183 | static void process_create_ack(); | |
184 | static void process_start_ack(); | |
185 | static void process_stop(); | |
186 | static void process_stop_ack(); | |
187 | static void process_kill_ack(); | |
188 | static void process_running(); | |
189 | static void process_alive(); | |
190 | static void process_done_ack(int msg_end); | |
191 | static void process_killed_ack(); | |
192 | static void process_cancel_done_mtc(); | |
193 | static void process_cancel_done_ptc(); | |
194 | static void process_component_status_mtc(int msg_end); | |
195 | static void process_component_status_ptc(int msg_end); | |
196 | static void process_connect_listen(); | |
197 | static void process_connect(); | |
198 | static void process_connect_ack(); | |
199 | static void process_disconnect(); | |
200 | static void process_disconnect_ack(); | |
201 | static void process_map(); | |
202 | static void process_map_ack(); | |
203 | static void process_unmap(); | |
204 | static void process_unmap_ack(); | |
205 | ||
206 | static void process_execute_control(); | |
207 | static void process_execute_testcase(); | |
208 | static void process_ptc_verdict(); | |
209 | static void process_continue(); | |
210 | static void process_exit_mtc(); | |
211 | ||
212 | static void process_start(); | |
213 | static void process_kill(); | |
214 | ||
215 | static void process_error(); | |
216 | static void process_unsupported_message(int msg_type, int msg_end); | |
217 | /** @} */ | |
218 | }; | |
219 | ||
220 | #endif |