| 1 |
#include <glib.h> |
| 2 |
#include "extra_arg.h" |
| 3 |
|
| 4 |
#ifndef BD_UTILS_EXEC |
| 5 |
#define BD_UTILS_EXEC |
| 6 |
|
| 7 |
typedef enum { |
| 8 |
BD_UTILS_PROG_STARTED, |
| 9 |
BD_UTILS_PROG_PROGRESS, |
| 10 |
BD_UTILS_PROG_FINISHED, |
| 11 |
} BDUtilsProgStatus; |
| 12 |
|
| 13 |
/** |
| 14 |
* BDUtilsProgFunc: |
| 15 |
* @task_id: ID of the task/action the progress is reported for |
| 16 |
* @status: progress status |
| 17 |
* @completion: percentage of completion |
| 18 |
* @msg: (nullable): arbitrary progress message (for the user) |
| 19 |
*/ |
| 20 |
typedef void (*BDUtilsProgFunc) (guint64 task_id, BDUtilsProgStatus status, guint8 completion, gchar *msg); |
| 21 |
|
| 22 |
/** |
| 23 |
* BDUtilsProgExtract: |
| 24 |
* @line: line to extract progress from |
| 25 |
* @completion: (out): percentage of completion |
| 26 |
* |
| 27 |
* Callback function used to process a line captured from spawned command's standard |
| 28 |
* output and standard error output. Typically used to extract completion percentage |
| 29 |
* of a long-running job. |
| 30 |
* |
| 31 |
* Note that both outputs are read simultaneously with no guarantees of message order |
| 32 |
* this function is called with. |
| 33 |
* |
| 34 |
* The value the @completion points to may contain value previously returned from |
| 35 |
* this callback or zero when called for the first time. This is useful for extractors |
| 36 |
* where only some kind of a tick mark is printed out as a progress and previous value |
| 37 |
* is needed to compute an incremented value. It's important to keep in mind that this |
| 38 |
* function is only called over lines, i.e. progress reporting printing out tick marks |
| 39 |
* (e.g. dots) without a newline character might not work properly. |
| 40 |
* |
| 41 |
* The @line string usually contains trailing newline character, which may be absent |
| 42 |
* however in case the spawned command exits without printing one. It's guaranteed |
| 43 |
* this function is called over remaining buffer no matter what the trailing |
| 44 |
* character is. |
| 45 |
* |
| 46 |
* Returns: whether the line was a progress reporting line and should be excluded |
| 47 |
* from the collected standard output string or not. |
| 48 |
*/ |
| 49 |
typedef gboolean (*BDUtilsProgExtract) (const gchar *line, guint8 *completion); |
| 50 |
|
| 51 |
GQuark bd_utils_exec_error_quark (void); |
| 52 |
#define BD_UTILS_EXEC_ERROR bd_utils_exec_error_quark () |
| 53 |
typedef enum { |
| 54 |
BD_UTILS_EXEC_ERROR_FAILED, |
| 55 |
BD_UTILS_EXEC_ERROR_NOOUT, |
| 56 |
BD_UTILS_EXEC_ERROR_INVAL_VER, |
| 57 |
BD_UTILS_EXEC_ERROR_UTIL_UNAVAILABLE, |
| 58 |
BD_UTILS_EXEC_ERROR_UTIL_UNKNOWN_VER, |
| 59 |
BD_UTILS_EXEC_ERROR_UTIL_LOW_VER, |
| 60 |
BD_UTILS_EXEC_ERROR_UTIL_CHECK_ERROR, |
| 61 |
BD_UTILS_EXEC_ERROR_UTIL_FEATURE_CHECK_ERROR, |
| 62 |
BD_UTILS_EXEC_ERROR_UTIL_FEATURE_UNAVAILABLE, |
| 63 |
} BDUtilsExecError; |
| 64 |
|
| 65 |
gboolean bd_utils_exec_and_report_error (const gchar **argv, const BDExtraArg **extra, GError **error); |
| 66 |
gboolean bd_utils_exec_and_report_error_no_progress (const gchar **argv, const BDExtraArg **extra, GError **error); |
| 67 |
gboolean bd_utils_exec_and_report_status_error (const gchar **argv, const BDExtraArg **extra, gint *status, GError **error); |
| 68 |
gboolean bd_utils_exec_and_capture_output (const gchar **argv, const BDExtraArg **extra, gchar **output, GError **error); |
| 69 |
gboolean bd_utils_exec_and_capture_output_no_progress (const gchar **argv, const BDExtraArg **extra, gchar **output, gchar **stderr, gint *status, GError **error); |
| 70 |
gboolean bd_utils_exec_and_report_progress (const gchar **argv, const BDExtraArg **extra, BDUtilsProgExtract prog_extract, gint *proc_status, GError **error); |
| 71 |
gboolean bd_utils_exec_with_input (const gchar **argv, const gchar *input, const BDExtraArg **extra, GError **error); |
| 72 |
gint bd_utils_version_cmp (const gchar *ver_string1, const gchar *ver_string2, GError **error); |
| 73 |
gboolean bd_utils_check_util_version (const gchar *util, const gchar *version, const gchar *version_arg, const gchar *version_regexp, GError **error); |
| 74 |
|
| 75 |
gboolean bd_utils_init_prog_reporting (BDUtilsProgFunc new_prog_func, GError **error); |
| 76 |
gboolean bd_utils_init_prog_reporting_thread (BDUtilsProgFunc new_prog_func, GError **error); |
| 77 |
gboolean bd_utils_mute_prog_reporting_thread (GError **error); |
| 78 |
gboolean bd_utils_prog_reporting_initialized (void); |
| 79 |
guint64 bd_utils_report_started (const gchar *msg); |
| 80 |
void bd_utils_report_progress (guint64 task_id, guint64 completion, const gchar *msg); |
| 81 |
void bd_utils_report_finished (guint64 task_id, const gchar *msg); |
| 82 |
|
| 83 |
guint64 bd_utils_get_next_task_id (void); |
| 84 |
void bd_utils_log_task_status (guint64 task_id, const gchar *msg); |
| 85 |
|
| 86 |
gboolean bd_utils_echo_str_to_file (const gchar *str, const gchar *file_path, GError **error); |
| 87 |
|
| 88 |
#endif /* BD_UTILS_EXEC */ |