This source file includes following definitions.
- haiku_io_init
- haiku_len
- haiku_read_size
- haiku_read
- haiku_read_with_timeout
- haiku_write
- haiku_write_without_signal
- haiku_io_init_in_app_thread
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <signal.h>
22 #include <stdio.h>
23 #include <pthread.h>
24 #include <unistd.h>
25
26 #include <OS.h>
27
28 #include "haiku_support.h"
29 #include "lisp.h"
30 #include "haikuterm.h"
31 #include "blockinput.h"
32
33 #define PORT_CAP 1200
34
35
36
37 port_id port_application_to_emacs;
38
39
40
41 port_id port_popup_menu_to_emacs;
42
43
44
45 port_id port_emacs_to_session_manager;
46
47 void
48 haiku_io_init (void)
49 {
50 port_application_to_emacs = create_port (PORT_CAP, "application emacs port");
51 port_emacs_to_session_manager = create_port (1, "session manager port");
52 }
53
54 static ssize_t
55 haiku_len (enum haiku_event_type type)
56 {
57 switch (type)
58 {
59 case QUIT_REQUESTED:
60 return sizeof (struct haiku_quit_requested_event);
61 case FRAME_RESIZED:
62 return sizeof (struct haiku_resize_event);
63 case FRAME_EXPOSED:
64 return sizeof (struct haiku_expose_event);
65 case KEY_DOWN:
66 case KEY_UP:
67 return sizeof (struct haiku_key_event);
68 case ACTIVATION:
69 return sizeof (struct haiku_activation_event);
70 case MOUSE_MOTION:
71 return sizeof (struct haiku_mouse_motion_event);
72 case BUTTON_DOWN:
73 case BUTTON_UP:
74 return sizeof (struct haiku_button_event);
75 case ICONIFICATION:
76 return sizeof (struct haiku_iconification_event);
77 case MOVE_EVENT:
78 return sizeof (struct haiku_move_event);
79 case SCROLL_BAR_VALUE_EVENT:
80 return sizeof (struct haiku_scroll_bar_value_event);
81 case SCROLL_BAR_DRAG_EVENT:
82 return sizeof (struct haiku_scroll_bar_drag_event);
83 case WHEEL_MOVE_EVENT:
84 return sizeof (struct haiku_wheel_move_event);
85 case MENU_BAR_RESIZE:
86 return sizeof (struct haiku_menu_bar_resize_event);
87 case MENU_BAR_CLICK:
88 return sizeof (struct haiku_menu_bar_click_event);
89 case MENU_BAR_OPEN:
90 case MENU_BAR_CLOSE:
91 return sizeof (struct haiku_menu_bar_state_event);
92 case MENU_BAR_SELECT_EVENT:
93 return sizeof (struct haiku_menu_bar_select_event);
94 case MENU_BAR_HELP_EVENT:
95 return sizeof (struct haiku_menu_bar_help_event);
96 case ZOOM_EVENT:
97 return sizeof (struct haiku_zoom_event);
98 case DRAG_AND_DROP_EVENT:
99 return sizeof (struct haiku_drag_and_drop_event);
100 case APP_QUIT_REQUESTED_EVENT:
101 return sizeof (struct haiku_app_quit_requested_event);
102 case DUMMY_EVENT:
103 return sizeof (struct haiku_dummy_event);
104 case MENU_BAR_LEFT:
105 return sizeof (struct haiku_menu_bar_left_event);
106 case SCROLL_BAR_PART_EVENT:
107 return sizeof (struct haiku_scroll_bar_part_event);
108 case SCREEN_CHANGED_EVENT:
109 return sizeof (struct haiku_screen_changed_event);
110 case CLIPBOARD_CHANGED_EVENT:
111 return sizeof (struct haiku_clipboard_changed_event);
112 case FONT_CHANGE_EVENT:
113 return sizeof (struct haiku_font_change_event);
114 }
115
116 emacs_abort ();
117 }
118
119
120
121 void
122 haiku_read_size (ssize_t *len, bool popup_menu_p)
123 {
124 port_id from = (popup_menu_p
125 ? port_popup_menu_to_emacs
126 : port_application_to_emacs);
127 ssize_t size;
128
129 size = port_buffer_size_etc (from, B_TIMEOUT, 0);
130
131 if (size < B_OK)
132 *len = -1;
133 else
134 *len = size;
135 }
136
137
138
139
140 int
141 haiku_read (enum haiku_event_type *type, void *buf, ssize_t len)
142 {
143 int32 typ;
144 port_id from = port_application_to_emacs;
145
146 if (read_port (from, &typ, buf, len) < B_OK)
147 return -1;
148
149 *type = (enum haiku_event_type) typ;
150 eassert (len >= haiku_len (typ));
151 return 0;
152 }
153
154
155
156
157 int
158 haiku_read_with_timeout (enum haiku_event_type *type, void *buf, ssize_t len,
159 bigtime_t timeout, bool popup_menu_p)
160 {
161 int32 typ;
162 port_id from = (popup_menu_p
163 ? port_popup_menu_to_emacs
164 : port_application_to_emacs);
165
166 block_input ();
167 if (read_port_etc (from, &typ, buf, len,
168 B_TIMEOUT, (bigtime_t) timeout) < B_OK)
169 {
170 unblock_input ();
171 return -1;
172 }
173 unblock_input ();
174 *type = (enum haiku_event_type) typ;
175 eassert (len >= haiku_len (typ));
176 return 0;
177 }
178
179
180 int
181 haiku_write (enum haiku_event_type type, void *buf)
182 {
183 port_id to = port_application_to_emacs;
184
185 if (write_port (to, (int32_t) type, buf, haiku_len (type)) < B_OK)
186 return -1;
187
188 kill (getpid (), SIGPOLL);
189
190 return 0;
191 }
192
193 int
194 haiku_write_without_signal (enum haiku_event_type type, void *buf,
195 bool popup_menu_p)
196 {
197 port_id to = (popup_menu_p
198 ? port_popup_menu_to_emacs
199 : port_application_to_emacs);
200
201 if (write_port (to, (int32_t) type, buf, haiku_len (type)) < B_OK)
202 return -1;
203
204 return 0;
205 }
206
207 void
208 haiku_io_init_in_app_thread (void)
209 {
210 sigset_t set;
211 sigfillset (&set);
212
213 if (pthread_sigmask (SIG_BLOCK, &set, NULL))
214 perror ("pthread_sigmask");
215 }