1 /* vifm
2  * Copyright (C) 2014 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__UI__CANCELLATION_H__
20 #define VIFM__UI__CANCELLATION_H__
21 
22 /* Managing foreground operation cancellation.  Usage example:
23  *
24  *   ui_cancellation_push_on();
25  *   ...
26  *   Some code possibly checking ui_cancellation_requested() or just interacting
27  *   with child process which will get Ctrl-C request from the user.
28  *   ...
29  *     ui_cancellation_push_off();
30  *     ...
31  *     Can receive Ctrl-C as input or call ui_cancellation_requested() here.
32  *     ...
33  *     ui_cancellation_enable();
34  *       ...
35  *       Some code possibly checking ui_cancellation_requested() or just
36  *       interacting with child process which will get Ctrl-C request from the
37  *       user.
38  *       ...
39  *     ui_cancellation_disable();
40  *     ...
41  *     Can receive Ctrl-C as input or call ui_cancellation_requested() here.
42  *     ...
43  *     ui_cancellation_pop();
44  *   ...
45  *   Some code possibly checking ui_cancellation_requested() or just interacting
46  *   with child process which will get Ctrl-C request from the user.
47  *   ...
48  *   ui_cancellation_pop();
49  *   ...
50  *   Can call ui_cancellation_requested() here.
51  *
52  * As the example demonstrates cancellation states can be stacked to do not
53  * affect each other. */
54 
55 /* Convenience object for cases when UI cancellation is in use. */
56 extern const struct cancellation_t ui_cancellation_info;
57 
58 /* Pushes new state making sure that cancellation is enabled after the call. */
59 void ui_cancellation_push_on(void);
60 
61 /* Pushes new state making sure that cancellation is disabled after the call. */
62 void ui_cancellation_push_off(void);
63 
64 /* Enables handling of cancellation requests as interrupts. */
65 void ui_cancellation_enable(void);
66 
67 /* External callback for notifying this unit about cancellation request.  Should
68  * be called when cancellation is enabled. */
69 void ui_cancellation_request(void);
70 
71 /* If cancellation is enabled, checks whether cancelling current operation is
72  * requested.  Can be called when cancellation is disabled.  Returns non-zero if
73  * so, otherwise zero is returned. */
74 int ui_cancellation_requested(void);
75 
76 /* Disables handling of cancellation requests as interrupts. */
77 void ui_cancellation_disable(void);
78 
79 /* Removes the topmost state from the stack restoring previous state. */
80 void ui_cancellation_pop(void);
81 
82 #endif /* VIFM__UI__CANCELLATION_H__ */
83 
84 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
85 /* vim: set cinoptions+=t0 filetype=c : */
86