util.h (2122B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2021--2024 GNUnet e.V. 4 5 GNUnet is free software: you can redistribute it and/or modify it 6 under the terms of the GNU Affero General Public License as published 7 by the Free Software Foundation, either version 3 of the License, 8 or (at your option) any later version. 9 10 GNUnet is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Affero General Public License for more details. 14 15 You should have received a copy of the GNU Affero General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 SPDX-License-Identifier: AGPL3.0-or-later 19 */ 20 /* 21 * @author Tobias Frisch 22 * @file util.h 23 */ 24 25 #ifndef UTIL_H_ 26 #define UTIL_H_ 27 28 #include <glib-2.0/glib.h> 29 30 #define UNUSED __attribute__((unused)) 31 32 #define _(String) ( \ 33 (const gchar*) g_dgettext( \ 34 MESSENGER_APPLICATION_DOMAIN, \ 35 (const gchar*) String \ 36 ) \ 37 ) 38 39 /** 40 * Cancel all open asynchronous tasks. 41 */ 42 void 43 util_scheduler_cleanup(); 44 45 /** 46 * Abstraction of `g_idle_add()` task 47 * to be cancelled externally. 48 */ 49 guint 50 util_idle_add(GSourceFunc function, 51 gpointer data); 52 53 guint 54 util_immediate_add(GSourceFunc function, 55 gpointer data); 56 57 /** 58 * Abstraction of `g_timeout_add()` task 59 * to be cancelled externally. 60 */ 61 guint 62 util_timeout_add(guint interval, 63 GSourceFunc function, 64 gpointer data); 65 66 /** 67 * Abstraction of `g_timeout_add_seconds()` task 68 * to be cancelled externally. 69 */ 70 guint 71 util_timeout_add_seconds(guint interval, 72 GSourceFunc function, 73 gpointer data); 74 75 /** 76 * Abstraction of `g_source_remove()` to 77 * cancel a task by its tag. 78 */ 79 gboolean 80 util_source_remove(guint tag); 81 82 /** 83 * Abstraction of `g_source_remove_by_userdata()` to 84 * cancel a task by its data. 85 */ 86 gboolean 87 util_source_remove_by_data(gpointer data); 88 89 #endif /* UTIL_H_ */