2017-12-12 22:12:07 +08:00
|
|
|
#ifndef COMMAND_H
|
|
|
|
#define COMMAND_H
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
2017-12-12 22:12:07 +08:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2019-02-10 20:16:55 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
// not needed here, but winsock2.h must never be included AFTER windows.h
|
|
|
|
# include <winsock2.h>
|
2019-02-10 20:16:55 +08:00
|
|
|
# include <windows.h>
|
2018-03-16 15:51:46 +08:00
|
|
|
# define PRIexitcode "lu"
|
2019-02-10 20:16:55 +08:00
|
|
|
// <https://stackoverflow.com/a/44383330/1987178>
|
2017-12-12 22:12:07 +08:00
|
|
|
# ifdef _WIN64
|
|
|
|
# define PRIsizet PRIu64
|
|
|
|
# else
|
|
|
|
# define PRIsizet PRIu32
|
|
|
|
# endif
|
|
|
|
# define PROCESS_NONE NULL
|
|
|
|
typedef HANDLE process_t;
|
|
|
|
typedef DWORD exit_code_t;
|
2019-02-10 20:16:55 +08:00
|
|
|
|
2017-12-12 22:12:07 +08:00
|
|
|
#else
|
2019-02-10 20:16:55 +08:00
|
|
|
|
2017-12-12 22:12:07 +08:00
|
|
|
# include <sys/types.h>
|
2019-02-10 20:16:55 +08:00
|
|
|
# define PRIsizet "zu"
|
|
|
|
# define PRIexitcode "d"
|
2017-12-12 22:12:07 +08:00
|
|
|
# define PROCESS_NONE -1
|
|
|
|
typedef pid_t process_t;
|
|
|
|
typedef int exit_code_t;
|
2019-02-10 20:16:55 +08:00
|
|
|
|
2017-12-12 22:12:07 +08:00
|
|
|
#endif
|
2019-02-10 20:16:55 +08:00
|
|
|
|
2017-12-12 22:12:07 +08:00
|
|
|
# define NO_EXIT_CODE -1
|
|
|
|
|
2018-09-04 14:42:25 +08:00
|
|
|
enum process_result {
|
|
|
|
PROCESS_SUCCESS,
|
|
|
|
PROCESS_ERROR_GENERIC,
|
|
|
|
PROCESS_ERROR_MISSING_BINARY,
|
|
|
|
};
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
enum process_result
|
|
|
|
cmd_execute(const char *path, const char *const argv[], process_t *process);
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-03-03 03:09:56 +08:00
|
|
|
cmd_terminate(process_t pid);
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-03-03 03:09:56 +08:00
|
|
|
cmd_simple_wait(process_t pid, exit_code_t *exit_code);
|
|
|
|
|
|
|
|
process_t
|
2019-05-12 20:31:18 +08:00
|
|
|
adb_execute(const char *serial, const char *const adb_cmd[], size_t len);
|
2019-03-03 03:09:56 +08:00
|
|
|
|
|
|
|
process_t
|
|
|
|
adb_forward(const char *serial, uint16_t local_port,
|
|
|
|
const char *device_socket_name);
|
|
|
|
|
|
|
|
process_t
|
|
|
|
adb_forward_remove(const char *serial, uint16_t local_port);
|
|
|
|
|
|
|
|
process_t
|
|
|
|
adb_reverse(const char *serial, const char *device_socket_name,
|
|
|
|
uint16_t local_port);
|
|
|
|
|
|
|
|
process_t
|
|
|
|
adb_reverse_remove(const char *serial, const char *device_socket_name);
|
|
|
|
|
|
|
|
process_t
|
|
|
|
adb_push(const char *serial, const char *local, const char *remote);
|
|
|
|
|
|
|
|
process_t
|
|
|
|
adb_install(const char *serial, const char *local);
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2018-02-08 22:16:27 +08:00
|
|
|
// convenience function to wait for a successful process execution
|
|
|
|
// automatically log process errors with the provided process name
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-05-31 22:08:30 +08:00
|
|
|
process_check_success(process_t proc, const char *name);
|
2018-02-08 22:16:27 +08:00
|
|
|
|
2017-12-12 22:12:07 +08:00
|
|
|
#endif
|