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