CProcessManager.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #define OBJPREFIX LR"(Local\)"
  3. constexpr size_t guidSize = std::size(L"{00000000-0000-0000-0000-000000000000}"); // including the null terminator
  4. constexpr size_t prefixSize = std::size(OBJPREFIX) - 1;
  5. constexpr size_t objNameSize = prefixSize + guidSize;
  6. struct ProcessInfo
  7. {
  8. DWORD processId;
  9. DWORD threadId;
  10. HWND hWndConsole;
  11. };
  12. enum struct State
  13. {
  14. Stop,
  15. Running,
  16. WaitStop
  17. };
  18. class CProcessManager : public SSingleton<CProcessManager>
  19. {
  20. public:
  21. CProcessManager();
  22. ~CProcessManager();
  23. void _UpdateClashCmd();
  24. void SetInsTanCe(HINSTANCE m);
  25. void SetArgs(std::filesystem::path exePath, std::filesystem::path homeDir, std::filesystem::path cconfigFile);
  26. void SetConfigFile(std::filesystem::path configFile);
  27. State IsRunning();
  28. const PROCESS_INFORMATION& GetSubProcessInfo();
  29. const PROCESS_INFORMATION& GetClashProcessInfo();
  30. HWND GetConsoleWindow();
  31. void StartTest();
  32. bool Start();
  33. void Stop();
  34. void SendStopSignal();
  35. int SubProcess(std::wstring_view guid);
  36. private:
  37. State _state = State::Stop;
  38. std::filesystem::path _exePath;
  39. std::filesystem::path _homeDir;
  40. std::filesystem::path _configFile;
  41. std::wstring _ctlAddr, _ctlSecret, _clashCmd;
  42. wil::unique_handle _hJob;
  43. wil::unique_process_information _subProcInfo, _clashProcInfo;
  44. HWND _hWndConsole = nullptr;
  45. wil::unique_handle _hEvent;
  46. HINSTANCE mInstance;
  47. };