obs-module.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #define MODULE_EXTERN extern "C"
  19. #else
  20. #define MODULE_EXPORT EXPORT
  21. #define MODULE_EXTERN extern
  22. #endif
  23. /**
  24. * @file
  25. *
  26. * This file is used by modules for module declaration and module exports.
  27. */
  28. /** Required: Declares a libobs module. */
  29. #define OBS_DECLARE_MODULE() \
  30. static obs_module_t *obs_module_pointer; \
  31. MODULE_EXPORT void obs_module_set_pointer(obs_module_t *module); \
  32. void obs_module_set_pointer(obs_module_t *module) \
  33. { \
  34. obs_module_pointer = module; \
  35. } \
  36. obs_module_t *obs_current_module(void) {return obs_module_pointer;} \
  37. MODULE_EXPORT uint32_t obs_module_ver(void); \
  38. uint32_t obs_module_ver(void) {return LIBOBS_API_VER;}
  39. /**
  40. * Required: Called when the module is loaded. Use this function to load all
  41. * the sources/encoders/outputs/services for your module, or anything else that
  42. * may need loading.
  43. *
  44. * @return Return true to continue loading the module, otherwise
  45. * false to indcate failure and unload the module
  46. */
  47. MODULE_EXPORT bool obs_module_load(void);
  48. /** Optional: Called when the module is unloaded. */
  49. MODULE_EXPORT void obs_module_unload(void);
  50. /** Called to set the current locale data for the module. */
  51. MODULE_EXPORT void obs_module_set_locale(const char *locale);
  52. /** Called to free the current locale data for the module. */
  53. MODULE_EXPORT void obs_module_free_locale(void);
  54. /** Optional: Use this macro in a module to use default locale handling. */
  55. #define OBS_MODULE_USE_DEFAULT_LOCALE(module_name, default_locale) \
  56. lookup_t *obs_module_lookup = NULL; \
  57. const char *obs_module_text(const char *val) \
  58. { \
  59. const char *out = val; \
  60. text_lookup_getstr(obs_module_lookup, val, &out); \
  61. return out; \
  62. } \
  63. void obs_module_set_locale(const char *locale) \
  64. { \
  65. if (obs_module_lookup) text_lookup_destroy(obs_module_lookup); \
  66. obs_module_lookup = obs_module_load_locale( \
  67. obs_current_module(), \
  68. default_locale, locale); \
  69. } \
  70. void obs_module_free_locale(void) \
  71. { \
  72. text_lookup_destroy(obs_module_lookup); \
  73. }
  74. /** Helper function for looking up locale if default locale handler was used */
  75. MODULE_EXTERN const char *obs_module_text(const char *lookup_string);
  76. /** Helper function that returns the current module */
  77. MODULE_EXTERN obs_module_t *obs_current_module(void);
  78. /**
  79. * Returns the location to a module data file associated with the current
  80. * module. Free with bfree when complete. Equivalent to:
  81. * obs_find_module_file(obs_current_modile(), file);
  82. */
  83. #define obs_module_file(file) obs_find_module_file(obs_current_module(), file)
  84. /**
  85. * Optional: Declares the author(s) of the module
  86. *
  87. * @param name Author name(s)
  88. */
  89. #define OBS_MODULE_AUTHOR(name) \
  90. MODULE_EXPORT const char *obs_module_author(void); \
  91. const char *obs_module_author(void) {return name;}
  92. /** Optional: Returns the full name of the module */
  93. MODULE_EXPORT const char *obs_module_name(void);
  94. /** Optional: Returns a description of the module */
  95. MODULE_EXPORT const char *obs_module_description(void);