Sync with 5.4.3
[deliverable/titan.core.git] / core / Port.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 #ifndef PORT_HH
9 #define PORT_HH
10
11 #include <sys/types.h>
12
13 #include "Types.h"
14 #include "Event_Handler.hh"
15 #include <stddef.h> // only for NULL
16 #include <sys/select.h>
17
18 class COMPONENT;
19 class COMPONENT_template;
20 class Text_Buf;
21 class OCTETSTRING;
22
23 extern const COMPONENT_template& any_compref;
24
25 struct port_connection; // no user serviceable parts inside
26
27 /** Base class for all test ports */
28 class PORT : public Fd_And_Timeout_Event_Handler {
29 friend class PORT_LIST;
30 friend struct port_connection;
31
32 static PORT *list_head, *list_tail;
33
34 void add_to_list();
35 void remove_from_list();
36 static PORT *lookup_by_name(const char *par_port_name);
37
38 struct port_parameter; // no user serviceable parts inside
39 static port_parameter *parameter_head, *parameter_tail;
40
41 /** @brief Apply the given port parameter.
42 *
43 * Applies the parameter to the appropriate port, or all ports if it's
44 * a parameter for all ports ( "*" )
45 * @param par_ptr pointer to the port parameter
46 */
47 static void apply_parameter(port_parameter *par_ptr);
48 void set_system_parameters(const char *system_port);
49
50 public:
51 struct msg_queue_item_base {
52 struct msg_queue_item_base *next_item;
53 };
54 msg_queue_item_base *msg_queue_head, *msg_queue_tail;
55 public:
56 /** @brief Store a port parameter
57 *
58 * @param component_id component identifier
59 * @param par_port_name string, name of the port, NULL if the parameter
60 * refers to all ports ( "*" )
61 * @param parameter_name string, name of the parameter
62 * @param parameter_value string, the value
63 */
64 static void add_parameter(const component_id_t& component_id,
65 const char *par_port_name, const char *parameter_name,
66 const char *parameter_value);
67 /** Deallocates the list of port parameters */
68 static void clear_parameters();
69 /** @brief Apply port parameters to component
70
71 Iterates through all known port parameters and
72
73 @param component_reference
74 @param component_name
75 */
76 static void set_parameters(component component_reference,
77 const char *component_name);
78
79 protected:
80 const char *port_name;
81 unsigned int msg_head_count, msg_tail_count, proc_head_count,
82 proc_tail_count;
83 boolean is_active, is_started, is_halted;
84
85 private:
86 int n_system_mappings;
87 char **system_mappings;
88 PORT *list_prev, *list_next;
89 port_connection *connection_list_head, *connection_list_tail;
90
91 private:
92 /// Copy constructor disabled.
93 PORT(const PORT& other_port);
94 /// Assignment disabled.
95 PORT& operator=(const PORT& other_port);
96
97 public:
98 PORT(const char *par_port_name);
99 virtual ~PORT();
100
101 inline const char *get_name() const { return port_name; }
102 void set_name(const char * name);
103
104 virtual void log() const;
105
106 void activate_port();
107 void deactivate_port();
108 static void deactivate_all();
109
110 void clear();
111 static void all_clear();
112 void start();
113 static void all_start();
114 void stop();
115 static void all_stop();
116 void halt();
117 static void all_halt();
118
119 virtual alt_status receive(const COMPONENT_template& sender_template =
120 any_compref, COMPONENT *sender_ptr = NULL);
121 static alt_status any_receive(const COMPONENT_template& sender_template =
122 any_compref, COMPONENT *sender_ptr = NULL);
123 virtual alt_status check_receive(const COMPONENT_template&
124 sender_template = any_compref, COMPONENT *sender_ptr = NULL);
125 static alt_status any_check_receive(const COMPONENT_template&
126 sender_template = any_compref, COMPONENT *sender_ptr = NULL);
127
128 virtual alt_status trigger(const COMPONENT_template& sender_template =
129 any_compref, COMPONENT *sender_ptr = NULL);
130 static alt_status any_trigger(const COMPONENT_template& sender_template =
131 any_compref, COMPONENT *sender_ptr = NULL);
132
133 virtual alt_status getcall(const COMPONENT_template& sender_template =
134 any_compref, COMPONENT *sender_ptr = NULL);
135 static alt_status any_getcall(const COMPONENT_template& sender_template =
136 any_compref, COMPONENT *sender_ptr = NULL);
137 virtual alt_status check_getcall(const COMPONENT_template&
138 sender_template = any_compref, COMPONENT *sender_ptr = NULL);
139 static alt_status any_check_getcall(const COMPONENT_template&
140 sender_template = any_compref, COMPONENT *sender_ptr = NULL);
141
142 virtual alt_status getreply(const COMPONENT_template& sender_template =
143 any_compref, COMPONENT *sender_ptr = NULL);
144 static alt_status any_getreply(const COMPONENT_template& sender_template =
145 any_compref, COMPONENT *sender_ptr = NULL);
146 virtual alt_status check_getreply(const COMPONENT_template&
147 sender_template = any_compref, COMPONENT *sender_ptr = NULL);
148 static alt_status any_check_getreply(const COMPONENT_template&
149 sender_template = any_compref, COMPONENT *sender_ptr = NULL);
150
151 virtual alt_status get_exception(const COMPONENT_template&
152 sender_template = any_compref, COMPONENT *sender_ptr = NULL);
153 static alt_status any_catch(const COMPONENT_template& sender_template =
154 any_compref, COMPONENT *sender_ptr = NULL);
155 virtual alt_status check_catch(const COMPONENT_template&
156 sender_template = any_compref, COMPONENT *sender_ptr = NULL);
157 static alt_status any_check_catch(const COMPONENT_template&
158 sender_template = any_compref, COMPONENT *sender_ptr = NULL);
159
160 alt_status check(const COMPONENT_template& sender_template = any_compref,
161 COMPONENT *sender_ptr = NULL);
162 static alt_status any_check(const COMPONENT_template& sender_template =
163 any_compref, COMPONENT *sender_ptr = NULL);
164
165 /** Set a parameter on the port.
166 * @param parameter_name string
167 * @param parameter_value
168 *
169 * The implementation in the PORT base class issues a warning and
170 * does nothing. Derived classes need to override this method.
171 */
172 virtual void set_parameter(const char *parameter_name,
173 const char *parameter_value);
174
175 void append_to_msg_queue(msg_queue_item_base*);
176 private:
177 /** Callback interface for handling events - introduced in TITAN R7E
178 * To use the finer granularity interface, this method must not be
179 * overridden in the descendant Test Port class.
180 * Note: Error event always triggers event handler call and is indicated in
181 * the is_error parameter even if not requested.
182 */
183 virtual void Handle_Fd_Event(int fd,
184 boolean is_readable, boolean is_writable, boolean is_error);
185
186 /** Callback interface for handling timeout - introduced in TITAN R7E
187 * May not be overridden in the descendant Test Port class if
188 * timeout is not used.
189 */
190 virtual void Handle_Timeout(double time_since_last_call);
191
192 /** Callback interface for handling events - introduced in TITAN R7E
193 * These methods in the descendant Test Port class are called only if
194 * Handle_Fd_Event is not overridden in the descendant Test Port class.
195 * The method handling an event which is not used in the Test Port
196 * may not be overridden in the descendant Test Port class.
197 * This is true even for the error event handler, although error events
198 * always trigger event handler call even if not requested.
199 * (There is an empty default implementation for the error event handler.)
200 */
201 virtual void Handle_Fd_Event_Error(int fd);
202 virtual void Handle_Fd_Event_Writable(int fd);
203 virtual void Handle_Fd_Event_Readable(int fd);
204
205 public:
206 /** Callback interface for handling events
207 * This method is provided for Test Ports developed for TITAN versions
208 * before R7E.
209 * (It is called only if event handler has been registered with
210 * Install_Handler.)
211 */
212 virtual void Event_Handler(const fd_set *read_fds, const fd_set *write_fds,
213 const fd_set *error_fds, double time_since_last_call);
214
215 protected:
216 /** Interface for handling events and timeout - introduced in TITAN R7E */
217 typedef enum {
218 EVENT_RD = FD_EVENT_RD, EVENT_WR = FD_EVENT_WR,
219 EVENT_ERR = FD_EVENT_ERR,
220 EVENT_ALL = FD_EVENT_RD | FD_EVENT_WR | FD_EVENT_ERR
221 } Fd_Event_Type;
222 void Handler_Add_Fd(int fd, Fd_Event_Type event_mask = EVENT_ALL);
223 void Handler_Add_Fd_Read(int fd);
224 void Handler_Add_Fd_Write(int fd);
225 void Handler_Remove_Fd(int fd, Fd_Event_Type event_mask = EVENT_ALL);
226 void Handler_Remove_Fd_Read(int fd);
227 void Handler_Remove_Fd_Write(int fd);
228 void Handler_Set_Timer(double call_interval, boolean is_timeout = TRUE,
229 boolean call_anyway = TRUE, boolean is_periodic = TRUE);
230
231 /** Interface for handling events and timeout
232 * This method is provided for Test Ports developed for TITAN versions
233 * before R7E.
234 */
235 void Install_Handler(const fd_set *read_fds, const fd_set *write_fds,
236 const fd_set *error_fds, double call_interval);
237 /** Interface for handling events and timeout
238 * This method is in use in Test Ports developed for TITAN versions
239 * before R7E.
240 * It can be used together with the interface introduced in TITAN R7E.
241 */
242 void Uninstall_Handler();
243
244 virtual void user_map(const char *system_port);
245 virtual void user_unmap(const char *system_port);
246
247 virtual void user_start();
248 virtual void user_stop();
249
250 virtual void clear_queue();
251
252 component get_default_destination();
253
254 static void prepare_message(Text_Buf& outgoing_buf,
255 const char *message_type);
256 static void prepare_call(Text_Buf& outgoing_buf,
257 const char *signature_name);
258 static void prepare_reply(Text_Buf& outgoing_buf,
259 const char *signature_name);
260 static void prepare_exception(Text_Buf& outgoing_buf,
261 const char *signature_name);
262 void send_data(Text_Buf& outgoing_buf,
263 const COMPONENT& destination_component);
264
265 void process_data(port_connection *conn_ptr, Text_Buf& incoming_buf);
266 virtual boolean process_message(const char *message_type,
267 Text_Buf& incoming_buf, component sender_component, OCTETSTRING&);
268 virtual boolean process_call(const char *signature_name,
269 Text_Buf& incoming_buf, component sender_component);
270 virtual boolean process_reply(const char *signature_name,
271 Text_Buf& incoming_buf, component sender_component);
272 virtual boolean process_exception(const char *signature_name,
273 Text_Buf& incoming_buf, component sender_component);
274
275 private:
276 port_connection *add_connection(component remote_component,
277 const char *remote_port, transport_type_enum transport_type);
278 void remove_connection(port_connection *conn_ptr);
279 port_connection *lookup_connection_to_compref(component remote_component,
280 boolean *is_unique);
281 port_connection *lookup_connection(component remote_component,
282 const char *remote_port);
283 void add_local_connection(PORT *other_endpoint);
284 void remove_local_connection(port_connection *conn_ptr);
285
286 static unsigned int get_connection_hash(component local_component,
287 const char *local_port, component remote_component,
288 const char *remote_port);
289 static void unlink_unix_pathname(int socket_fd);
290 void connect_listen_inet_stream(component remote_component,
291 const char *remote_port);
292 void connect_listen_unix_stream(component remote_component,
293 const char *remote_port);
294 void connect_local(component remote_component, const char *remote_port);
295 void connect_stream(component remote_component, const char *remote_port,
296 transport_type_enum transport_type, Text_Buf& text_buf);
297 void disconnect_local(port_connection *conn_ptr);
298 void disconnect_stream(port_connection *conn_ptr);
299
300 void send_data_local(port_connection *conn_ptr, Text_Buf& outgoing_data);
301 boolean send_data_stream(port_connection *conn_ptr, Text_Buf& outgoing_data,
302 boolean ignore_peer_disconnect);
303
304 void handle_incoming_connection(port_connection *conn_ptr);
305 void handle_incoming_data(port_connection *conn_ptr);
306 void process_last_message(port_connection *conn_ptr);
307
308 void map(const char *system_port);
309 void unmap(const char *system_port);
310
311 public:
312 static void process_connect_listen(const char *local_port,
313 component remote_component, const char *remote_port,
314 transport_type_enum transport_type);
315 static void process_connect(const char *local_port,
316 component remote_component, const char *remote_port,
317 transport_type_enum transport_type, Text_Buf& text_buf);
318 static void process_disconnect(const char *local_port,
319 component remote_component, const char *remote_port);
320 static void make_local_connection(const char *src_port,
321 const char *dest_port);
322 static void terminate_local_connection(const char *src_port,
323 const char *dest_port);
324
325 static void map_port(const char *component_port, const char *system_port);
326 static void unmap_port(const char *component_port, const char *system_port);
327 };
328
329 #endif
This page took 0.037619 seconds and 6 git commands to generate.