obs-module.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /******************************************************************************
  2. Copyright (C) 2014 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include "obs.h"
  16. #ifdef __cplusplus
  17. #define MODULE_EXPORT extern "C" EXPORT
  18. #else
  19. #define MODULE_EXPORT EXPORT
  20. #endif
  21. /**
  22. * @file
  23. *
  24. * This file is used by modules for module declaration and module exports.
  25. */
  26. /** Required: Declares a libobs module. */
  27. #define OBS_DECLARE_MODULE() \
  28. static obs_module_t obs_module_pointer; \
  29. MODULE_EXPORT void obs_module_set_pointer(obs_module_t module); \
  30. void obs_module_set_pointer(obs_module_t module) \
  31. { \
  32. obs_module_pointer = module; \
  33. } \
  34. obs_module_t obs_current_module(void) {return obs_module_pointer;} \
  35. MODULE_EXPORT uint32_t obs_module_ver(void); \
  36. uint32_t obs_module_ver(void) {return LIBOBS_API_VER;}
  37. /**
  38. * Required: Called when the module is loaded. Use this function to load all
  39. * the sources/encoders/outputs/services for your module, or anything else that
  40. * may need loading.
  41. *
  42. * @return Return true to continue loading the module, otherwise
  43. * false to indcate failure and unload the module
  44. */
  45. MODULE_EXPORT bool obs_module_load(void);
  46. /** Optional: Called when the module is unloaded. */
  47. MODULE_EXPORT void obs_module_unload(void);
  48. /** Called to set the current locale data for the module. */
  49. MODULE_EXPORT void obs_module_set_locale(const char *locale);
  50. /** Called to free the current locale data for the module. */
  51. MODULE_EXPORT void obs_module_free_locale(void);
  52. /** Optional: Use this macro in a module to use default locale handling. */
  53. #define OBS_MODULE_USE_DEFAULT_LOCALE(module_name, default_locale) \
  54. lookup_t obs_module_lookup = NULL; \
  55. const char *obs_module_text(const char *val) \
  56. { \
  57. const char *out = val; \
  58. text_lookup_getstr(obs_module_lookup, val, &out); \
  59. return out; \
  60. } \
  61. void obs_module_set_locale(const char *locale) \
  62. { \
  63. if (obs_module_lookup) text_lookup_destroy(obs_module_lookup); \
  64. obs_module_lookup = obs_module_load_locale( \
  65. obs_current_module(), \
  66. default_locale, locale); \
  67. } \
  68. void obs_module_free_locale(void) \
  69. { \
  70. text_lookup_destroy(obs_module_lookup); \
  71. }
  72. /** Helper function for looking up locale if default locale handler was used */
  73. extern const char *obs_module_text(const char *lookup_string);
  74. /** Helper function that returns the current module */
  75. extern obs_module_t obs_current_module(void);
  76. /**
  77. * Returns the location to a module data file associated with the current
  78. * module. Free with bfree when complete. Equivalent to:
  79. * obs_find_module_file(obs_current_modile(), file);
  80. */
  81. #define obs_module_file(file) obs_find_module_file(obs_current_module(), file)
  82. /**
  83. * Optional: Declares the author(s) of the module
  84. *
  85. * @param name Author name(s)
  86. */
  87. #define OBS_MODULE_AUTHOR(name) \
  88. MODULE_EXPORT const char *obs_module_author(void); \
  89. const char *obs_module_author(void) {return name;}
  90. /** Optional: Returns the full name of the module */
  91. MODULE_EXPORT const char *obs_module_name(void);
  92. /** Optional: Returns a description of the module */
  93. MODULE_EXPORT const char *obs_module_description(void);