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 case NOTIFICATION_CLICK_EVENT:
115 return sizeof (struct haiku_notification_click_event);
116 }
117
118 emacs_abort ();
119 }
120
121
122
123 void
124 haiku_read_size (ssize_t *len, bool popup_menu_p)
125 {
126 port_id from = (popup_menu_p
127 ? port_popup_menu_to_emacs
128 : port_application_to_emacs);
129 ssize_t size;
130
131 size = port_buffer_size_etc (from, B_TIMEOUT, 0);
132
133 if (size < B_OK)
134 *len = -1;
135 else
136 *len = size;
137 }
138
139
140
141
142 int
143 haiku_read (enum haiku_event_type *type, void *buf, ssize_t len)
144 {
145 int32 typ;
146 port_id from = port_application_to_emacs;
147
148 if (read_port (from, &typ, buf, len) < B_OK)
149 return -1;
150
151 *type = (enum haiku_event_type) typ;
152 eassert (len >= haiku_len (typ));
153 return 0;
154 }
155
156
157
158
159 int
160 haiku_read_with_timeout (enum haiku_event_type *type, void *buf, ssize_t len,
161 bigtime_t timeout, bool popup_menu_p)
162 {
163 int32 typ;
164 port_id from = (popup_menu_p
165 ? port_popup_menu_to_emacs
166 : port_application_to_emacs);
167
168 block_input ();
169 if (read_port_etc (from, &typ, buf, len,
170 B_TIMEOUT, (bigtime_t) timeout) < B_OK)
171 {
172 unblock_input ();
173 return -1;
174 }
175 unblock_input ();
176 *type = (enum haiku_event_type) typ;
177 eassert (len >= haiku_len (typ));
178 return 0;
179 }
180
181
182 int
183 haiku_write (enum haiku_event_type type, void *buf)
184 {
185 port_id to = port_application_to_emacs;
186
187 if (write_port (to, (int32_t) type, buf, haiku_len (type)) < B_OK)
188 return -1;
189
190 kill (getpid (), SIGPOLL);
191
192 return 0;
193 }
194
195 int
196 haiku_write_without_signal (enum haiku_event_type type, void *buf,
197 bool popup_menu_p)
198 {
199 port_id to = (popup_menu_p
200 ? port_popup_menu_to_emacs
201 : port_application_to_emacs);
202
203 if (write_port (to, (int32_t) type, buf, haiku_len (type)) < B_OK)
204 return -1;
205
206 return 0;
207 }
208
209 void
210 haiku_io_init_in_app_thread (void)
211 {
212 sigset_t set;
213 sigfillset (&set);
214
215 if (pthread_sigmask (SIG_BLOCK, &set, NULL))
216 perror ("pthread_sigmask");
217 }