gamemode.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. Copyright (c) 2017-2018, Feral Interactive
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of Feral Interactive nor the names of its contributors
  12. may be used to endorse or promote products derived from this software
  13. without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  24. POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <stdbool.h>
  28. #include <sys/types.h>
  29. #define INVALID_PROCFD -1
  30. typedef int procfd_t;
  31. /**
  32. * Opaque context
  33. */
  34. typedef struct GameModeContext GameModeContext;
  35. /**
  36. * Return the singleton instance
  37. */
  38. GameModeContext *game_mode_context_instance(void);
  39. /**
  40. * Initialise the GameModeContext
  41. *
  42. * This is performed in a thread-safe fashion.
  43. */
  44. void game_mode_context_init(GameModeContext *self);
  45. /**
  46. * Destroy the previously initialised GameModeContext.
  47. *
  48. * This is performed in a thread safe fashion.
  49. */
  50. void game_mode_context_destroy(GameModeContext *self);
  51. /**
  52. * Register a new game client with the context
  53. *
  54. * @param pid Process ID for the remote client
  55. * @returns True if the new client could be registered
  56. */
  57. bool game_mode_context_register(GameModeContext *self, pid_t pid);
  58. /**
  59. * Unregister an existing remote game client from the context
  60. *
  61. * @param pid Process ID for the remote client
  62. * @returns True if the client was removed, and existed.
  63. */
  64. bool game_mode_context_unregister(GameModeContext *self, pid_t pid);
  65. /**
  66. * Query the current status of gamemode
  67. *
  68. * @param pid Process ID for the remote client
  69. * @returns Positive if gamemode is active
  70. * 1 if gamemode is active but the client is not registered
  71. * 2 if gamemode is active and the client is registered
  72. */
  73. int game_mode_context_query_status(GameModeContext *self, pid_t pid);
  74. /** gamemode-env.c
  75. * Provides internal API functions specific to working environment
  76. * variables.
  77. */
  78. char *game_mode_lookup_proc_env(const procfd_t proc_fd, const char *var);
  79. char *game_mode_lookup_user_home(void);
  80. /** gamemode-proc.c
  81. * Provides internal API functions specific to working with process
  82. * environments.
  83. */
  84. procfd_t game_mode_open_proc(const pid_t pid);
  85. int game_mode_close_proc(const procfd_t procfd);