|
| 1 | +// Jackson Coxson |
| 2 | + |
| 3 | +#include <idevice++/process_control.hpp> |
| 4 | + |
| 5 | +namespace IdeviceFFI { |
| 6 | + |
| 7 | +Result<ProcessControl, FfiError> ProcessControl::create(RemoteServer& server) { |
| 8 | + ProcessControlHandle* out = nullptr; |
| 9 | + FfiError e(::process_control_new(server.raw(), &out)); |
| 10 | + if (e) { |
| 11 | + return Err(e); |
| 12 | + } |
| 13 | + return Ok(ProcessControl::adopt(out)); |
| 14 | +} |
| 15 | + |
| 16 | +Result<u_int64_t, FfiError> ProcessControl::launch_app(std::string bundle_id, |
| 17 | + Option<std::vector<std::string>> env_vars, |
| 18 | + Option<std::vector<std::string>> arguments, |
| 19 | + bool start_suspended, |
| 20 | + bool kill_existing) { |
| 21 | + std::vector<const char*> c_env_vars; |
| 22 | + size_t env_vars_len = 0; |
| 23 | + if (env_vars.is_some()) { |
| 24 | + c_env_vars.reserve(env_vars.unwrap().size()); |
| 25 | + for (auto& a : env_vars.unwrap()) { |
| 26 | + c_env_vars.push_back(a.c_str()); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + std::vector<const char*> c_arguments; |
| 31 | + size_t arguments_len = 0; |
| 32 | + if (arguments.is_some()) { |
| 33 | + c_arguments.reserve(arguments.unwrap().size()); |
| 34 | + for (auto& a : arguments.unwrap()) { |
| 35 | + c_arguments.push_back(a.c_str()); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + u_int64_t pid = 0; |
| 40 | + |
| 41 | + FfiError e(::process_control_launch_app( |
| 42 | + handle_.get(), |
| 43 | + bundle_id.c_str(), |
| 44 | + c_env_vars.empty() ? nullptr : const_cast<const char* const*>(c_env_vars.data()), |
| 45 | + env_vars_len, |
| 46 | + c_arguments.empty() ? nullptr : const_cast<const char* const*>(c_arguments.data()), |
| 47 | + arguments_len, |
| 48 | + start_suspended, |
| 49 | + kill_existing, |
| 50 | + &pid)); |
| 51 | + if (e) { |
| 52 | + return Err(e); |
| 53 | + } |
| 54 | + return Ok(pid); |
| 55 | +} |
| 56 | + |
| 57 | +Result<void, FfiError> ProcessControl::kill_app(u_int64_t pid) { |
| 58 | + FfiError e(::process_control_kill_app(handle_.get(), pid)); |
| 59 | + if (e) { |
| 60 | + return Err(e); |
| 61 | + } |
| 62 | + return Ok(); |
| 63 | +} |
| 64 | + |
| 65 | +Result<void, FfiError> ProcessControl::disable_memory_limit(u_int64_t pid) { |
| 66 | + FfiError e(::process_control_disable_memory_limit(handle_.get(), pid)); |
| 67 | + if (e) { |
| 68 | + return Err(e); |
| 69 | + } |
| 70 | + return Ok(); |
| 71 | +} |
| 72 | + |
| 73 | +} // namespace IdeviceFFI |
0 commit comments