1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#pragma once
#include "Interface.h"
#ifdef _WIN32
# ifndef NOMINMAX
# define NOMINMAX
# endif
# include <windows.h>
#endif
namespace vst {
//--------------- ProcessHandle ------------------//
class ProcessHandle {
public:
#ifdef _WIN32
ProcessHandle() {
ZeroMemory(&pi_, sizeof(pi_));
}
ProcessHandle(const PROCESS_INFORMATION& pi)
: pi_(pi) {}
~ProcessHandle() {
close();
}
ProcessHandle(ProcessHandle&& other) noexcept {
pi_ = other.pi_;
other.pi_.dwProcessId = 0; // sentinel
}
ProcessHandle& operator=(ProcessHandle&& other) noexcept {
pi_ = other.pi_;
other.pi_.dwProcessId = 0; // sentinel
return *this;
}
#else
ProcessHandle() : pid_(-1) {}
ProcessHandle(int pid)
: pid_(pid) {}
ProcessHandle(ProcessHandle&& other) noexcept {
pid_ = other.pid_;
other.pid_ = -1; // sentinel
}
ProcessHandle& operator=(ProcessHandle&& other) noexcept {
pid_ = other.pid_;
other.pid_ = -1; // sentinel
return *this;
}
#endif
int pid() const;
int wait();
bool valid() const;
operator bool() const { return valid(); }
std::pair<bool, int> tryWait(double timeout);
bool checkIfRunning();
bool terminate();
private:
#ifdef _WIN32
PROCESS_INFORMATION pi_;
void close();
#else
int pid_;
int parseStatus(int status);
#endif
};
//-------------------- IHostApp -----------------------//
enum class CpuArch;
class IHostApp {
public:
static IHostApp* get(CpuArch arch);
virtual ~IHostApp() {}
virtual CpuArch arch() const = 0;
virtual const std::string& path() const = 0;
virtual ProcessHandle probe(const std::string& path, int id,
const std::string& tmpPath) const = 0;
virtual ProcessHandle bridge(const std::string& shmPath, intptr_t logPipe) const = 0;
};
} // vst
|