1 // file.cxx - Joint header file for nearby component classes.
4 // Copyright (C) 1999, 2000 Red Hat.
5 // This file is part of SID and is licensed under the GPL.
6 // See the file COPYING.SID for conditions for redistribution.
12 #include <sidcomputil.h>
13 #include <sidattrutil.h>
14 #include <sidpinutil.h>
15 #include <sidbusutil.h>
17 #include <sidmiscutil.h>
18 #include <sidschedutil.h>
19 #include <sidpinattrutil.h>
35 #include <sys/ioctl.h>
37 #include <netinet/in.h>
40 #include <sys/socket.h>
43 #include <arpa/inet.h>
48 namespace console_stuff
62 using sid::host_int_1;
63 using sid::host_int_2;
64 using sid::little_int_1;
65 using sid::host_int_4;
66 using sid::host_int_8;
67 using sid::component_library;
69 using sidutil::no_bus_component;
70 using sidutil::fixed_attribute_map_component;
71 using sidutil::fixed_pin_map_component;
72 using sidutil::no_accessor_component;
73 using sidutil::no_relation_component;
74 using sidutil::output_pin;
75 using sidutil::callback_pin;
76 using sidutil::string2stream;
77 using sidutil::stream2string;
78 using sidutil::make_attribute;
79 using sidutil::parse_attribute;
80 using sidutil::scheduler_event_subscription;
81 using sidutil::std_error_string;
82 using sidutil::tokenize;
83 using sidutil::recursion_limited;
84 using sidutil::recursion_record;
85 using sidutil::make_numeric_attribute;
88 // -------------------------------------------------------------------------
90 class stdioConsole: public virtual component,
91 protected fixed_attribute_map_component,
92 protected no_bus_component,
93 protected fixed_pin_map_component,
94 protected no_accessor_component,
95 protected no_relation_component
101 void write(host_int_4 value);
102 void read(host_int_4);
104 callback_pin<stdioConsole> activity_pin;
105 callback_pin<stdioConsole> stdout_pin;
106 output_pin stdin_pin;
108 // save & restore state
109 string save_state ( );
110 component::status restore_state (const string& state);
115 // -------------------------------------------------------------------------
117 class socketio: public virtual component,
118 protected no_bus_component,
119 protected fixed_attribute_map_component,
120 protected fixed_pin_map_component,
121 protected no_accessor_component,
122 protected no_relation_component,
123 protected recursion_limited
126 callback_pin<socketio> init_pin, fini_pin;
127 void init_handler (host_int_4);
128 void fini_handler (host_int_4);
131 bool server_p; // server or client mode?
132 bool verbose_p; // verbosity?
133 bool trace_traffic_p; // trace all socket traffic?
134 bool buffer_disconnected_p; // keep outbound data while disconnected?
136 // this and other side
137 sockaddr_in sock_name;
138 sockaddr_in peer_name;
141 callback_pin<socketio> out_pin;
142 void tx_eof_handler();
143 void tx_handler(host_int_4 value);
152 float avg_out_buffer_size;
153 enum _bs { in_buffer_size = 2048 };
154 char in_buffer [in_buffer_size];
156 host_int_8 out_count;
157 host_int_8 poll_count;
160 friend class scheduler_event_subscription<socketio>;
161 scheduler_event_subscription<socketio> poll_control;
163 // Make these types small enough to avoid having to request long
164 // delays from the scheduler.
165 host_int_2 poll_interval;
166 host_int_2 max_poll_interval;
168 void asyncificate (int fd);
169 void update_poll_interval();
171 void poll_connect ();
172 void poll_receive ();
173 void poll_transmit ();
178 friend ostream& operator << (ostream& o, const socketio& it);
179 friend istream& operator >> (istream& i, socketio& it);
180 string save_state () { return make_attribute(*this); }
181 sid::component::status restore_state (const string& state)
182 { return parse_attribute (state, *this); }
186 socketio(bool server_p);
190 } // end of namespace console_stuff