obs-module.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. MODULE_EXPORT uint32_t obs_module_ver(void); \
  29. uint32_t obs_module_ver(void) {return LIBOBS_API_VER;}
  30. /**
  31. * Required: Called when the module is loaded. Use this function to load all
  32. * the sources/encoders/outputs/services for your module, or anything else that
  33. * may need loading.
  34. *
  35. * @param libobs_ver The version of libobs.
  36. * @return Return true to continue loading the module, otherwise
  37. * false to indcate failure and unload the module
  38. */
  39. MODULE_EXPORT bool obs_module_load(uint32_t libobs_version);
  40. /** Optional: Called when the module is unloaded. */
  41. MODULE_EXPORT void obs_module_unload(void);
  42. /** Called to set the current locale data for the module. */
  43. MODULE_EXPORT void obs_module_set_locale(const char *locale);
  44. /**
  45. * Optional: Use this macro in a module to use default locale handling. Use
  46. * the OBS_MODULE_FREE_DEFAULT_LOCALE macro in obs_module_unload to free the
  47. * locale data when the module unloads.
  48. */
  49. #define OBS_MODULE_USE_DEFAULT_LOCALE(module_name, default_locale) \
  50. lookup_t obs_module_lookup = NULL; \
  51. const char *obs_module_text(const char *val) \
  52. { \
  53. const char *out = val; \
  54. text_lookup_getstr(obs_module_lookup, val, &out); \
  55. return out; \
  56. } \
  57. void obs_module_set_locale(const char *locale) \
  58. { \
  59. if (obs_module_lookup) text_lookup_destroy(obs_module_lookup); \
  60. obs_module_lookup = obs_module_load_locale(module_name, \
  61. default_locale, locale); \
  62. }
  63. #define OBS_MODULE_FREE_DEFAULT_LOCALE() \
  64. text_lookup_destroy(obs_module_lookup)
  65. /** Helper function for looking up locale if default locale handler was used */
  66. extern const char *obs_module_text(const char *lookup_string);
  67. /**
  68. * Optional: Declares the author(s) of the module
  69. *
  70. * @param name Author name(s)
  71. */
  72. #define OBS_MODULE_AUTHOR(name) \
  73. MODULE_EXPORT const char *obs_module_author(void); \
  74. const char *obs_module_author(void) {return name;}
  75. /** Optional: Returns a description of the module */
  76. MODULE_EXPORT const char *obs_module_description(void);