os_unix.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**************************************************************************/
  2. /* os_unix.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef OS_UNIX_H
  31. #define OS_UNIX_H
  32. #ifdef UNIX_ENABLED
  33. #include "core/os/os.h"
  34. #include "drivers/unix/ip_unix.h"
  35. class OS_Unix : public OS {
  36. struct ProcessInfo {
  37. mutable bool is_running = true;
  38. mutable int exit_code = -1;
  39. };
  40. HashMap<ProcessID, ProcessInfo> *process_map = nullptr;
  41. Mutex process_map_mutex;
  42. protected:
  43. // UNIX only handles the core functions.
  44. // inheriting platforms under unix (eg. X11) should handle the rest
  45. virtual void initialize_core();
  46. virtual int unix_initialize_audio(int p_audio_driver);
  47. virtual void finalize_core() override;
  48. public:
  49. OS_Unix();
  50. virtual Vector<String> get_video_adapter_driver_info() const override;
  51. virtual String get_stdin_string(int64_t p_buffer_size = 1024) override;
  52. virtual PackedByteArray get_stdin_buffer(int64_t p_buffer_size = 1024) override;
  53. virtual StdHandleType get_stdin_type() const override;
  54. virtual StdHandleType get_stdout_type() const override;
  55. virtual StdHandleType get_stderr_type() const override;
  56. virtual Error get_entropy(uint8_t *r_buffer, int p_bytes) override;
  57. virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, GDExtensionData *p_data = nullptr) override;
  58. virtual Error close_dynamic_library(void *p_library_handle) override;
  59. virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String &p_name, void *&p_symbol_handle, bool p_optional = false) override;
  60. virtual Error set_cwd(const String &p_cwd) override;
  61. virtual String get_name() const override;
  62. virtual String get_distribution_name() const override;
  63. virtual String get_version() const override;
  64. virtual String get_temp_path() const override;
  65. virtual DateTime get_datetime(bool p_utc) const override;
  66. virtual TimeZoneInfo get_time_zone_info() const override;
  67. virtual double get_unix_time() const override;
  68. virtual void delay_usec(uint32_t p_usec) const override;
  69. virtual uint64_t get_ticks_usec() const override;
  70. virtual Dictionary get_memory_info() const override;
  71. virtual Error execute(const String &p_path, const List<String> &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false) override;
  72. virtual Dictionary execute_with_pipe(const String &p_path, const List<String> &p_arguments, bool p_blocking = true) override;
  73. virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
  74. virtual Error kill(const ProcessID &p_pid) override;
  75. virtual int get_process_id() const override;
  76. virtual bool is_process_running(const ProcessID &p_pid) const override;
  77. virtual int get_process_exit_code(const ProcessID &p_pid) const override;
  78. virtual bool has_environment(const String &p_var) const override;
  79. virtual String get_environment(const String &p_var) const override;
  80. virtual void set_environment(const String &p_var, const String &p_value) const override;
  81. virtual void unset_environment(const String &p_var) const override;
  82. virtual String get_locale() const override;
  83. virtual void initialize_debugging() override;
  84. virtual String get_executable_path() const override;
  85. virtual String get_user_data_dir(const String &p_user_dir) const override;
  86. };
  87. class UnixTerminalLogger : public StdLogger {
  88. public:
  89. virtual void log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify = false, ErrorType p_type = ERR_ERROR) override;
  90. virtual ~UnixTerminalLogger();
  91. };
  92. #endif // UNIX_ENABLED
  93. #endif // OS_UNIX_H