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