obs-studio/libobs/obs-module.h
jp9000 59ea3becf2 (API Change) Refactor module handling
Changed API:
- char *obs_find_plugin_file(const char *sub_path);

  Changed to: char *obs_module_file(const char *file);

  Cahnge it so you no longer need to specify a sub-path such as:
  obs_find_plugin_file("module_name/file.ext")

  Instead, now automatically handle the module data path so all you need
  to do is:
  obs_module_file("file.ext")

- int obs_load_module(const char *name);

  Changed to: int obs_open_module(obs_module_t *module,
                                  const char *path,
                                  const char *data_path);
              bool obs_init_module(obs_module_t module);

  Change the module loading API so that if the front-end chooses, it can
  load modules directly from a specified path, and associate a data
  directory with it on the spot.

  The module will not be initialized immediately; obs_init_module must
  be called on the module pointer in order to fully initialize the
  module.  This is done so a module can be disabled by the front-end if
  the it so chooses.

New API:
- void obs_add_module_path(const char *bin, const char *data);

  These functions allow you to specify new module search paths to add,
  and allow you to search through them, or optionally just load all
  modules from them.  If the string %module% is included, it will
  replace it with the module's name when that string is used as a
  lookup.  Data paths are now directly added to the module's internal
  storage structure, and when obs_find_module_file is used, it will look
  up the pointer to the obs_module structure and get its data directory
  that way.

  Example:
  obs_add_module_path("/opt/obs/my-modules/%module%/bin",
                      "/opt/obs/my-modules/%module%/data");

  This would cause it to additionally look for the binary of a
  hypthetical module named "foo" at /opt/obs/my-modules/foo/bin/foo.so
  (or libfoo.so), and then look for the data in
  /opt/obs/my-modules/foo/data.

  This gives the front-end more flexibility for handling third-party
  plugin modules, or handling all plugin modules in a custom way.

- void obs_find_modules(obs_find_module_callback_t callback, void
                        *param);

  This searches the existing paths for modules and calls the callback
  function when any are found.  Useful for plugin management and custom
  handling of the paths by the front-end if desired.

- void obs_load_all_modules(void);

  Search through the paths and both loads and initializes all modules
  automatically without custom handling.

- void obs_enum_modules(obs_enum_module_callback_t callback,
                        void *param);

  Enumerates currently opened modules.
2014-07-27 17:29:10 -07:00

112 lines
3.9 KiB
C

/******************************************************************************
Copyright (C) 2014 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#pragma once
#include "obs.h"
#ifdef __cplusplus
#define MODULE_EXPORT extern "C" EXPORT
#else
#define MODULE_EXPORT EXPORT
#endif
/**
* @file
*
* This file is used by modules for module declaration and module exports.
*/
/** Required: Declares a libobs module. */
#define OBS_DECLARE_MODULE() \
static obs_module_t obs_module_pointer; \
MODULE_EXPORT void obs_module_set_pointer(obs_module_t module); \
void obs_module_set_pointer(obs_module_t module) \
{ \
obs_module_pointer = module; \
} \
obs_module_t obs_current_module(void) {return obs_module_pointer;} \
MODULE_EXPORT uint32_t obs_module_ver(void); \
uint32_t obs_module_ver(void) {return LIBOBS_API_VER;}
/**
* Required: Called when the module is loaded. Use this function to load all
* the sources/encoders/outputs/services for your module, or anything else that
* may need loading.
*
* @param libobs_ver The version of libobs.
* @return Return true to continue loading the module, otherwise
* false to indcate failure and unload the module
*/
MODULE_EXPORT bool obs_module_load(uint32_t libobs_version);
/** Optional: Called when the module is unloaded. */
MODULE_EXPORT void obs_module_unload(void);
/** Called to set the current locale data for the module. */
MODULE_EXPORT void obs_module_set_locale(const char *locale);
/** Called to free the current locale data for the module. */
MODULE_EXPORT void obs_module_free_locale(void);
/** Optional: Use this macro in a module to use default locale handling. */
#define OBS_MODULE_USE_DEFAULT_LOCALE(module_name, default_locale) \
lookup_t obs_module_lookup = NULL; \
const char *obs_module_text(const char *val) \
{ \
const char *out = val; \
text_lookup_getstr(obs_module_lookup, val, &out); \
return out; \
} \
void obs_module_set_locale(const char *locale) \
{ \
if (obs_module_lookup) text_lookup_destroy(obs_module_lookup); \
obs_module_lookup = obs_module_load_locale( \
obs_current_module(), \
default_locale, locale); \
}
#define OBS_MODULE_FREE_DEFAULT_LOCALE() \
text_lookup_destroy(obs_module_lookup)
/** Helper function for looking up locale if default locale handler was used */
extern const char *obs_module_text(const char *lookup_string);
/** Helper function that returns the current module */
extern obs_module_t obs_current_module(void);
/**
* Returns the location to a module data file associated with the current
* module. Free with bfree when complete. Equivalent to:
* obs_find_module_file(obs_current_modile(), file);
*/
#define obs_module_file(file) obs_find_module_file(obs_current_module(), file)
/**
* Optional: Declares the author(s) of the module
*
* @param name Author name(s)
*/
#define OBS_MODULE_AUTHOR(name) \
MODULE_EXPORT const char *obs_module_author(void); \
const char *obs_module_author(void) {return name;}
/** Optional: Returns the full name of the module */
MODULE_EXPORT const char *obs_module_name(void);
/** Optional: Returns a description of the module */
MODULE_EXPORT const char *obs_module_description(void);