Fixed some C/C++ compiler errors due to stricter checks.
[rubinius.git] / machine / console.hpp
blobfee8ba2c21cd2c4132952567b8f38eea5abaec88
1 #ifndef RBX_CONSOLE_HPP
2 #define RBX_CONSOLE_HPP
4 #include "machine_thread.hpp"
5 #include "spinlock.hpp"
7 #include <list>
8 #include <mutex>
9 #include <string>
11 namespace rubinius {
12 class Console;
13 class Channel;
14 class ThreadState;
15 class FSEvent;
16 class Object;
17 class String;
19 namespace console {
20 class Listener;
21 class Request;
22 class Response;
24 class Listener : public MachineThread {
25 Console* console_;
27 FSEvent* fsevent_;
29 int fd_;
31 public:
33 Listener(STATE, Console* console);
34 virtual ~Listener();
36 bool connection_initiated();
38 void start_thread(STATE);
39 void initialize(STATE);
40 void run(STATE);
41 void wakeup(STATE);
43 void trace_objects(STATE, std::function<void (STATE, Object**)> f);
46 typedef std::list<char*> RequestList;
48 class Response : public MachineThread {
49 Console* console_;
51 Channel* inbox_;
52 Channel* outbox_;
54 int fd_;
56 RequestList* request_list_;
58 locks::spinlock_mutex list_lock_;
60 std::mutex response_lock_;
61 std::condition_variable response_cond_;
63 public:
65 Response(STATE, Console* console);
66 virtual ~Response();
68 void initialize(STATE);
69 void start_thread(STATE);
70 void run(STATE);
71 void wakeup(STATE);
72 void stop_thread(STATE);
73 void after_fork_child(STATE);
75 void close_response();
76 void clear_requests();
78 void send_request(STATE, const char* request);
79 void write_response(STATE, const char* response, intptr_t size);
81 void trace_objects(STATE, std::function<void (STATE, Object**)> f);
84 class Request : public MachineThread {
85 Console* console_;
86 Response* response_;
88 bool enabled_;
90 int fd_;
92 FSEvent* fsevent_;
94 public:
96 Request(STATE, Console* console, Response* response);
98 bool enabled_p() {
99 return enabled_;
102 void initialize(STATE);
103 void start_thread(STATE);
104 void run(STATE);
105 void wakeup(STATE);
106 void stop_thread(STATE);
107 void after_fork_child(STATE);
109 void close_request();
111 char* read_request(STATE);
113 void trace_objects(STATE, std::function<void (STATE, Object**)> f);
117 using namespace console;
119 class Console {
120 std::string console_path_;
121 std::string request_path_;
122 std::string response_path_;
124 Listener* listener_;
125 Response* response_;
126 Request* request_;
128 Object* ruby_console_;
130 public:
131 Console(STATE);
132 virtual ~Console();
134 Object* ruby_console() {
135 return ruby_console_;
138 std::string& console_path() {
139 return console_path_;
142 std::string& request_path() {
143 return request_path_;
146 std::string& response_path() {
147 return response_path_;
150 bool connected_p();
152 void reset();
154 void start(STATE);
155 void stop(STATE);
156 void after_fork_child(STATE);
158 void accept(STATE);
159 Class* server_class(STATE);
161 void trace_objects(STATE, std::function<void (STATE, Object**)> f);
165 #endif