ProcessManager.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Types.h>
  8. #include <AK/Vector.h>
  9. #include <LibCore/EventReceiver.h>
  10. #include <LibCore/Platform/ProcessStatistics.h>
  11. #include <LibThreading/Mutex.h>
  12. #include <LibWebView/Forward.h>
  13. #include <LibWebView/Process.h>
  14. #include <LibWebView/ProcessType.h>
  15. namespace WebView {
  16. ProcessType process_type_from_name(StringView);
  17. StringView process_name_from_type(ProcessType type);
  18. class ProcessManager {
  19. AK_MAKE_NONCOPYABLE(ProcessManager);
  20. public:
  21. ProcessManager();
  22. ~ProcessManager();
  23. void add_process(Process&&);
  24. Optional<Process> remove_process(pid_t);
  25. Optional<Process&> find_process(pid_t);
  26. #if defined(AK_OS_MACH)
  27. void set_process_mach_port(pid_t, Core::MachPort&&);
  28. #endif
  29. void update_all_process_statistics();
  30. String generate_html();
  31. Function<void(Process&&)> on_process_exited;
  32. private:
  33. Core::Platform::ProcessStatistics m_statistics;
  34. HashMap<pid_t, Process> m_processes;
  35. int m_signal_handle { -1 };
  36. Threading::Mutex m_lock;
  37. };
  38. }