Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 2 | * Copyright (C) 2017 Richard Hughes <richard@hughsie.com> |
| 3 | * |
Mario Limonciello | 51308e6 | 2018-05-28 20:05:46 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: LGPL-2.1+ |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __FU_COMMON_H__ |
| 8 | #define __FU_COMMON_H__ |
| 9 | |
Richard Hughes | adc9dad | 2017-09-04 13:19:27 +0100 | [diff] [blame] | 10 | #include <gio/gio.h> |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 11 | |
Richard Hughes | 5b5f655 | 2018-05-18 10:22:39 +0100 | [diff] [blame] | 12 | typedef enum { |
| 13 | FU_APP_FLAGS_NONE = 0, |
| 14 | FU_APP_FLAGS_NO_IDLE_SOURCES = 1 << 0, |
| 15 | FU_APP_FLAGS_LAST |
| 16 | } FuAppFlags; |
| 17 | |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 18 | typedef enum { |
| 19 | FU_PATH_KIND_CACHEDIR_PKG, |
| 20 | FU_PATH_KIND_DATADIR_PKG, |
Mario Limonciello | e6e2bf9 | 2018-07-10 12:11:25 -0500 | [diff] [blame] | 21 | FU_PATH_KIND_EFIAPPDIR, |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 22 | FU_PATH_KIND_LOCALSTATEDIR, |
| 23 | FU_PATH_KIND_LOCALSTATEDIR_PKG, |
| 24 | FU_PATH_KIND_PLUGINDIR_PKG, |
| 25 | FU_PATH_KIND_SYSCONFDIR, |
| 26 | FU_PATH_KIND_SYSCONFDIR_PKG, |
Richard Hughes | 282b10d | 2018-06-22 14:48:00 +0100 | [diff] [blame] | 27 | FU_PATH_KIND_SYSFSDIR_FW, |
Richard Hughes | 83390f6 | 2018-06-22 20:36:46 +0100 | [diff] [blame] | 28 | FU_PATH_KIND_SYSFSDIR_DRIVERS, |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 29 | FU_PATH_KIND_LAST |
| 30 | } FuPathKind; |
| 31 | |
Richard Hughes | 049ccc8 | 2017-08-09 15:26:56 +0100 | [diff] [blame] | 32 | typedef void (*FuOutputHandler) (const gchar *line, |
| 33 | gpointer user_data); |
| 34 | |
| 35 | gboolean fu_common_spawn_sync (const gchar * const *argv, |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 36 | FuOutputHandler handler_cb, |
Richard Hughes | 049ccc8 | 2017-08-09 15:26:56 +0100 | [diff] [blame] | 37 | gpointer handler_user_data, |
| 38 | GCancellable *cancellable, |
| 39 | GError **error); |
| 40 | |
Richard Hughes | 4be17d1 | 2018-05-30 20:36:29 +0100 | [diff] [blame] | 41 | gchar *fu_common_get_path (FuPathKind path_kind); |
Richard Hughes | 954dd9f | 2017-08-08 13:36:25 +0100 | [diff] [blame] | 42 | gboolean fu_common_rmtree (const gchar *directory, |
| 43 | GError **error); |
Richard Hughes | 89e968b | 2018-03-07 10:01:08 +0000 | [diff] [blame] | 44 | GPtrArray *fu_common_get_files_recursive (const gchar *path, |
| 45 | GError **error); |
Richard Hughes | 7ee42fe | 2017-08-15 14:06:21 +0100 | [diff] [blame] | 46 | gboolean fu_common_mkdir_parent (const gchar *filename, |
| 47 | GError **error); |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 48 | gboolean fu_common_set_contents_bytes (const gchar *filename, |
Richard Hughes | 4eada34 | 2017-10-03 21:20:32 +0100 | [diff] [blame] | 49 | GBytes *bytes, |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 50 | GError **error); |
Richard Hughes | d0d2ae6 | 2017-08-08 12:22:30 +0100 | [diff] [blame] | 51 | GBytes *fu_common_get_contents_bytes (const gchar *filename, |
| 52 | GError **error); |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 53 | GBytes *fu_common_get_contents_fd (gint fd, |
| 54 | gsize count, |
| 55 | GError **error); |
Richard Hughes | 94f939a | 2017-08-08 12:21:39 +0100 | [diff] [blame] | 56 | gboolean fu_common_extract_archive (GBytes *blob, |
| 57 | const gchar *dir, |
| 58 | GError **error); |
Richard Hughes | 41cbe2a | 2017-08-08 14:13:35 +0100 | [diff] [blame] | 59 | GBytes *fu_common_firmware_builder (GBytes *bytes, |
| 60 | const gchar *script_fn, |
| 61 | const gchar *output_fn, |
| 62 | GError **error); |
Richard Hughes | e82eef3 | 2018-05-20 10:41:26 +0100 | [diff] [blame] | 63 | GError *fu_common_error_array_get_best (GPtrArray *errors); |
Richard Hughes | 73bf233 | 2018-08-28 09:38:09 +0100 | [diff] [blame] | 64 | guint64 fu_common_strtoull (const gchar *str); |
Richard Hughes | 22367e7 | 2018-08-30 10:24:04 +0100 | [diff] [blame] | 65 | gchar *fu_common_find_program_in_path (const gchar *basename, |
| 66 | GError **error); |
Richard Hughes | a574a75 | 2018-08-31 13:31:03 +0100 | [diff] [blame] | 67 | gchar *fu_common_strstrip (const gchar *str); |
Richard Hughes | e59cb9a | 2018-12-05 14:37:40 +0000 | [diff] [blame^] | 68 | void fu_common_dump_raw (const gchar *log_domain, |
| 69 | const gchar *title, |
| 70 | const guint8 *data, |
| 71 | gsize len); |
| 72 | void fu_common_dump_bytes (const gchar *log_domain, |
| 73 | const gchar *title, |
| 74 | GBytes *bytes); |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 75 | |
Richard Hughes | ae252cd | 2017-12-08 10:48:15 +0000 | [diff] [blame] | 76 | typedef guint FuEndianType; |
| 77 | |
| 78 | void fu_common_write_uint16 (guint8 *buf, |
| 79 | guint16 val_native, |
| 80 | FuEndianType endian); |
| 81 | void fu_common_write_uint32 (guint8 *buf, |
| 82 | guint32 val_native, |
| 83 | FuEndianType endian); |
| 84 | guint16 fu_common_read_uint16 (const guint8 *buf, |
| 85 | FuEndianType endian); |
| 86 | guint32 fu_common_read_uint32 (const guint8 *buf, |
| 87 | FuEndianType endian); |
| 88 | |
Richard Hughes | 83e56c1 | 2018-10-10 20:24:41 +0100 | [diff] [blame] | 89 | guint fu_common_string_replace (GString *string, |
| 90 | const gchar *search, |
| 91 | const gchar *replace); |
| 92 | |
Richard Hughes | 943d2c9 | 2017-06-21 09:04:39 +0100 | [diff] [blame] | 93 | #endif /* __FU_COMMON_H__ */ |