aboutsummaryrefslogtreecommitdiff
path: root/include/Program.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-30 16:47:40 +0100
committerdec05eba <dec05eba@protonmail.com>2020-10-30 18:30:46 +0100
commit928f2525c29929de0c2ab520f48c82b5cb882aa7 (patch)
treee97130909f65e7835e4740824e9f38f58e4c0fbe /include/Program.hpp
parente422322650f9cb057937182987071438f9c79e84 (diff)
Matrix: re-add /logout, cancel task immediately
Cancel video download when pressing escape, other fixes..
Diffstat (limited to 'include/Program.hpp')
-rw-r--r--include/Program.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/include/Program.hpp b/include/Program.hpp
new file mode 100644
index 0000000..8ac2d2d
--- /dev/null
+++ b/include/Program.hpp
@@ -0,0 +1,44 @@
+#ifndef QUICKMEDIA_PROGRAM_HPP
+#define QUICKMEDIA_PROGRAM_HPP
+
+#include <sys/types.h>
+#include <thread>
+
+typedef struct {
+ pid_t pid;
+ int read_fd;
+} ReadProgram;
+
+/* Return 0 if you want to continue reading. @data is null-terminated */
+typedef int (*ProgramOutputCallback)(char *data, int size, void *userdata);
+
+/*
+ @args need to have at least 2 arguments. The first which is the program name
+ and the last which is NULL, which indicates end of args
+*/
+int exec_program_pipe(const char **args, ReadProgram *read_program);
+
+/*
+ @args need to have at least 2 arguments. The first which is the program name
+ and the last which is NULL, which indicates end of args
+*/
+int exec_program(const char **args, ProgramOutputCallback output_callback, void *userdata);
+
+// Return the exit status, or a negative value if waiting failed
+int wait_program(pid_t process_id);
+
+/* Returns 1 if the program quit and exited properly (non-0 exit codes also count as exiting properly) */
+int wait_program_non_blocking(pid_t process_id, int *status);
+
+/*
+ @args need to have at least 2 arguments. The first which is the program name
+ and the last which is NULL, which indicates end of args.
+ @result_process_id should be set to NULL if you are not interested in the exit status of the child process
+ and you want the child process to be cleaned up automatically when it dies.
+*/
+int exec_program_async(const char **args, pid_t *result_process_id);
+
+void program_clear_current_thread();
+void program_kill_in_thread(const std::thread::id &thread_id);
+
+#endif /* QUICKMEDIA_PROGRAM_HPP */