This commit is contained in:
2022-04-23 00:44:52 +03:00
parent 8da0469dbf
commit 7a458c5cbe
3 changed files with 204 additions and 61 deletions

View File

@@ -34,30 +34,44 @@
#ifdef DOXYGEN
//! Declare plugin export functions, should be used before other PIP_PLUGIN_* macros
//! \relatedalso PIPluginLoader
//! \~english Declare plugin, should be used before other PIP_PLUGIN_* macros
//! \~russian Объявляет плагин, должен быть использован перед любыми другими PIP_PLUGIN_* макросами
//! \~\relatesalso PIPluginLoader
#define PIP_PLUGIN
//! Set user version to check it while loading
//! \relatedalso PIPluginLoader
//! \~english Set user version to check it while loading, "version" is quoted string
//! \~russian Устанавливает пользовательскую версию для проверки во время загрузки, "version" - строка в кавычках
//! \~\relatesalso PIPluginLoader
#define PIP_PLUGIN_SET_USER_VERSION(version)
//! Add pointer to future merge with plugin. Type is integer
//! \relatedalso PIPluginLoader
//! \~english Add pointer to future merge with plugin. Type is integer
//! \~russian Добавляет указатель для будущего слияния. Тип - целое число
//! \~\relatesalso PIPluginLoader
#define PIP_PLUGIN_ADD_STATIC_SECTION(type, ptr)
//! Declare function to merge static sections. This is functions
//! with 3 arguments: (int type, void * from, void * to).
//! \~english Declare function to merge static sections
//! \~russian Объявляет метод для слияния статических секций
//! \~\details
//! \~english
//! This is functions with 3 arguments: (int type, void * from, void * to).
//! This function invoked first while loading plugin with
//! "from" - plugin scope, "to" - application scope, and second
//! (optionally) on \a PIPluginLoader::mergeStatic() method with
//! "from" - application scope, "to" - plugin scope. So with macro
//! you can merge application and plugin static data.
//! \relatedalso PIPluginLoader
//! \~russian
//! Этот метод имеет 3 аргумента: (int type, void * from, void * to).
//! Он вызывается первый раз при загрузке плагина с "from" - областью плагина,
//! "to" - областью приложения, и второй раз (необязательно) при вызове
//! \a PIPluginLoader::mergeStatic() с "from" - областью приложения и
//! "to" - областью плагина. Таким образом, этот макрос позволяет провести
//! слияние статических данных приложения и плагина.
//! \~\relatesalso PIPluginLoader
#define PIP_PLUGIN_STATIC_SECTION_MERGE
//! Mark method to export
//! \relatedalso PIPluginLoader
//! \~english Mark method to export
//! \~russian Пометить метод на экспорт
//! \~\relatesalso PIPluginLoader
#define PIP_PLUGIN_EXPORT
@@ -147,54 +161,65 @@ public:
typedef int(*FunctionLoaderVersion)();
typedef void(*FunctionStaticMerge)(int, void *, void *);
//! Possible load plugin error
//! \~english Possible load plugin error
//! \~russian Возможные ошибки загрузки плагина
enum Error {
Unknown /** No \a load call yet */ ,
NoError /** No error */ ,
LibraryLoadError /** System can`t load library */ ,
MissingSymbols /** Can`t find necessary symbols */ ,
InvalidLoaderVersion /** Integer version mismatch */ ,
InvalidUserVersion /** User version mismatch */ ,
Unknown /** \~english No \a load() call yet \~russian Не было вызова \a load() */ ,
NoError /** \~english No error \~russian Нет ошибки */ ,
LibraryLoadError /** \~english System can`t load library \~russian Система не смогла загрузить библиотеку */ ,
MissingSymbols /** \~english Can`t find necessary symbols \~russian Нет необходимых методов */ ,
InvalidLoaderVersion /** \~english Internal version mismatch \~russian Неверная внутренняя версия */ ,
InvalidUserVersion /** \~english User version mismatch \~russian Неверная пользовательская версия */ ,
};
//! Contruscts loader with filename "name"
//! \~english Contruct loader with base filename "name" and call \a load() if "name" not empty
//! \~russian Создает загрузчик с базовым именем файла "name" и вызывает \a load() если "name" не пустое
PIPluginLoader(const PIString & name = PIString());
//! Destructor
//! \~english Destructor, unload library
//! \~russian Деструктор, выгружает библиотеку
~PIPluginLoader();
//! Load plugin with base filename "name". Loader try prefix "lib"
//! and suffix ".dll", ".so" or ".dylib", depends on platform
//! \~english Load plugin with base filename "name"
//! \~russian Загружает плагин с базовым именем "name"
bool load(const PIString & name);
//! Unload plugin and free library
//! \~english Unload plugin and free library
//! \~russian Выгружает плагин и освобождает библиотеку
void unload();
//! Returns if plugin is successfully loaded
//! \~english Returns if plugin is successfully loaded
//! \~russian Возвращает успешно ли загружен плагин
bool isLoaded() const;
//! Returns error of last \a load() call
//! \~english Returns error of last \a load() call
//! \~russian Возвращает ошибку последнего вызова \a load()
Error lastError() const;
//! Returns error message of last \a load() call
//! \~english Returns error message of last \a load() call
//! \~russian Возвращает сообщение об ошибке последнего вызова \a load()
PIString lastErrorText() const;
//! Set if %PIPluginLoader should print load messages, \b true by default
//! \~english Set if %PIPluginLoader should print load messages, \b true by default
//! \~russian Устанавливает должен ли %PIPluginLoader выводить сообщения, \b true по умолчанию
void setMessages(bool yes);
//! Returns if %PIPluginLoader should print load messages, \b true by default
//! \~english Returns if %PIPluginLoader should print load messages, \b true by default
//! \~russian Возвращает должен ли %PIPluginLoader выводить сообщения, \b true по умолчанию
bool isMessages() const;
//! Returns loaded plugin library path
//! \~english Returns loaded plugin library path
//! \~russian Возвращает путь к загруженной библиотеке
PIString libPath();
//! Resolve symbol "name" from plugin library
//! \~english Obtain exported library method with name "symbol"
//! \~russian Получает экспортированный метод библиотеки с именем "symbol"
//! \~\sa PILibrary::resolve()
void * resolve(const char * name);
//! Invoke plugin PIP_PLUGIN_STATIC_SECTION_MERGE function
//! on every common type, with "from" - application scope,
//! "to" - plugin scope
//! \~english Invoke plugin \a PIP_PLUGIN_STATIC_SECTION_MERGE
//! \~russian Вызывает у плагина \a PIP_PLUGIN_STATIC_SECTION_MERGE
void mergeStatic();
static PIStringList pluginsDirectories(const PIString & name);