1 /* vifm
2  * Copyright (C) 2020 xaizek.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #ifndef VIFM__UTILS__SELECTOR_H__
20 #define VIFM__UTILS__SELECTOR_H__
21 
22 /* This unit is meant to provide abstraction over platform-specific mechanism
23  * for waiting for available data. */
24 
25 /* Type of object selector works with. */
26 #ifdef _WIN32
27 #include <windows.h>
28 typedef HANDLE selector_item_t;
29 #else
30 typedef int selector_item_t;
31 #endif
32 
33 /* Opaque selector type. */
34 typedef struct selector_t selector_t;
35 
36 /* Allocates new selector object.  Returns the selector or NULL on error. */
37 selector_t * selector_alloc(void);
38 
39 /* Frees selector.  The parameter can be NULL. */
40 void selector_free(selector_t *selector);
41 
42 /* Resets selector to empty state. */
43 void selector_reset(selector_t *selector);
44 
45 /* Adds item to the set of objects to watch.  If error occurs, its ignored. */
46 void selector_add(selector_t *selector, selector_item_t item);
47 
48 /* Removes item from the set of objects to watch. */
49 void selector_remove(selector_t *selector, selector_item_t item);
50 
51 /* Waits for at least one of watched objects to become available for reading
52  * from during the period of time specified by the delay in milliseconds.
53  * Returns zero on error or if timeout was reached without any of the objects
54  * becoming available for read, otherwise non-zero is returned. */
55 int selector_wait(selector_t *selector, int delay);
56 
57 /* Checks whether specified element is ready for read.  Use this function after
58  * selector_wait().  Returns non-zero if so, otherwise zero is returned. */
59 int selector_is_ready(selector_t *selector, selector_item_t item);
60 
61 #endif /* VIFM__UTILS__SELECTOR_H__ */
62 
63 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
64 /* vim: set cinoptions+=t0 : */
65