code format
This commit is contained in:
@@ -1,28 +1,29 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Plugin helpers
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Plugin helpers
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MICRO_PIP
|
||||
|
||||
#include "piplugin.h"
|
||||
#include "pifile.h"
|
||||
#include "pidir.h"
|
||||
#include "piincludes_p.h"
|
||||
# include "piplugin.h"
|
||||
|
||||
# include "pidir.h"
|
||||
# include "pifile.h"
|
||||
# include "piincludes_p.h"
|
||||
|
||||
//! \class PIPluginLoader piplugin.h
|
||||
//! \~\details
|
||||
@@ -232,12 +233,11 @@
|
||||
//! \endcode
|
||||
//!
|
||||
|
||||
#define STR_WF(s) #s
|
||||
#define STR(s) STR_WF(s)
|
||||
# define STR_WF(s) #s
|
||||
# define STR(s) STR_WF(s)
|
||||
|
||||
|
||||
PIPluginInfo::PIPluginInfo() {
|
||||
}
|
||||
PIPluginInfo::PIPluginInfo() {}
|
||||
|
||||
|
||||
void PIPluginInfo::setUserVersion(const PIString & v) {
|
||||
@@ -260,9 +260,6 @@ PIMap<int, void *> PIPluginInfo::staticSections() const {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
PIPluginInfoStorage::PIPluginInfoStorage() {
|
||||
enterPlugin(0);
|
||||
}
|
||||
@@ -305,16 +302,13 @@ PIPluginInfoStorage * PIPluginInfoStorage::instance() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PIPluginLoader::PIPluginLoader(const PIString & name) {
|
||||
func_loader_version = nullptr;
|
||||
func_static_merge = nullptr;
|
||||
error = Unknown;
|
||||
loaded = false;
|
||||
messages = true;
|
||||
if (!name.isEmpty())
|
||||
load(name);
|
||||
func_static_merge = nullptr;
|
||||
error = Unknown;
|
||||
loaded = false;
|
||||
messages = true;
|
||||
if (!name.isEmpty()) load(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -334,34 +328,35 @@ bool PIPluginLoader::load(const PIString & name) {
|
||||
unload();
|
||||
PIPluginInfo * ai = PIPluginInfoStorage::instance()->applicationInfo();
|
||||
PIPluginInfo * pi = PIPluginInfoStorage::instance()->enterPlugin(this);
|
||||
PIString fname = findLibrary(name);
|
||||
PIString fname = findLibrary(name);
|
||||
if (fname.isEmpty()) {
|
||||
error = NoSuchFile;
|
||||
error = NoSuchFile;
|
||||
error_str = "Load plugin \"" + lib.path() + "\" error: can`t find lib for \"" + name + "\"";
|
||||
if (messages) piCout << error_str;
|
||||
return false;
|
||||
}
|
||||
if (!lib.load(fname)) {
|
||||
unload();
|
||||
error = LibraryLoadError;
|
||||
error = LibraryLoadError;
|
||||
error_str = "Load plugin \"" + lib.path() + "\" error: can`t load lib: " + lib.lastError();
|
||||
if (messages) piCout << error_str;
|
||||
return false;
|
||||
}
|
||||
//piCout << "loading" << lib.path() << "...";
|
||||
// piCout << "loading" << lib.path() << "...";
|
||||
func_loader_version = (FunctionLoaderVersion)lib.resolve(STR(__PIP_PLUGIN_LOADER_VERSION_FUNC__));
|
||||
if (!func_loader_version) {
|
||||
unload();
|
||||
error = MissingSymbols;
|
||||
error = MissingSymbols;
|
||||
error_str = "Load plugin \"" + lib.path() + "\" error: can`t find " + STR(__PIP_PLUGIN_LOADER_VERSION_FUNC__);
|
||||
if (messages) piCout << error_str;
|
||||
return false;
|
||||
}
|
||||
if (__PIP_PLUGIN_LOADER_VERSION__ != func_loader_version()) {
|
||||
unload();
|
||||
error = InvalidLoaderVersion;
|
||||
error_str = "Load plugin \"" + lib.path() + "\" error: invalid loader version: application = " + PIString::fromNumber(func_loader_version())
|
||||
+ ", plugin = " + PIString::fromNumber(__PIP_PLUGIN_LOADER_VERSION__);
|
||||
error = InvalidLoaderVersion;
|
||||
error_str = "Load plugin \"" + lib.path() +
|
||||
"\" error: invalid loader version: application = " + PIString::fromNumber(func_loader_version()) +
|
||||
", plugin = " + PIString::fromNumber(__PIP_PLUGIN_LOADER_VERSION__);
|
||||
if (messages) piCout << error_str;
|
||||
return false;
|
||||
}
|
||||
@@ -370,7 +365,8 @@ bool PIPluginLoader::load(const PIString & name) {
|
||||
if (pversion != lversion) {
|
||||
unload();
|
||||
error = InvalidUserVersion;
|
||||
error_str = "Load plugin \"" + lib.path() + "\" error: invalid user version: application = " + lversion + ", plugin = " + pversion;
|
||||
error_str =
|
||||
"Load plugin \"" + lib.path() + "\" error: invalid user version: application = " + lversion + ", plugin = " + pversion;
|
||||
if (messages) piCout << error_str;
|
||||
return false;
|
||||
}
|
||||
@@ -378,18 +374,16 @@ bool PIPluginLoader::load(const PIString & name) {
|
||||
func_static_merge = (FunctionStaticMerge)lib.resolve(STR(__PIP_PLUGIN_STATIC_MERGE_FUNC__));
|
||||
if (func_static_merge) {
|
||||
auto pss = pi->staticSections(), lss = ai->staticSections();
|
||||
//piCout << lss.keys() << pss.keys();
|
||||
// piCout << lss.keys() << pss.keys();
|
||||
auto it = lss.makeIterator();
|
||||
while (it.next()) {
|
||||
if (!pss.contains(it.key()))
|
||||
continue;
|
||||
void * from = pss.value(it.key()), * to = it.value();
|
||||
if (from != to)
|
||||
func_static_merge(it.key(), from, to);
|
||||
if (!pss.contains(it.key())) continue;
|
||||
void *from = pss.value(it.key()), *to = it.value();
|
||||
if (from != to) func_static_merge(it.key(), from, to);
|
||||
}
|
||||
}
|
||||
loaded = true;
|
||||
error = NoError;
|
||||
error = NoError;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -453,11 +447,9 @@ void PIPluginLoader::mergeStatic() {
|
||||
auto pss = pi->staticSections(), lss = ai->staticSections();
|
||||
auto it = lss.makeIterator();
|
||||
while (it.next()) {
|
||||
if (!pss.contains(it.key()))
|
||||
continue;
|
||||
void * from = it.value(), * to = pss.value(it.key());
|
||||
if (from != to)
|
||||
func_static_merge(it.key(), from, to);
|
||||
if (!pss.contains(it.key())) continue;
|
||||
void *from = it.value(), *to = pss.value(it.key());
|
||||
if (from != to) func_static_merge(it.key(), from, to);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,10 +457,9 @@ void PIPluginLoader::mergeStatic() {
|
||||
PIStringList PIPluginLoader::pluginsDirectories(const PIString & name) {
|
||||
static PIStringList dl({".", "./plugins", "../PlugIns"});
|
||||
PIString ret;
|
||||
piForeachC (PIString d, dl) {
|
||||
piForeachC(PIString d, dl) {
|
||||
PIString dp = d + "/" + name;
|
||||
if (PIDir::isExists(dp))
|
||||
ret += dp;
|
||||
if (PIDir::isExists(dp)) ret += dp;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -479,11 +470,10 @@ PIString PIPluginLoader::findLibrary(const PIString & path) {
|
||||
static const PIStringList suffixes({"", libExtension()});
|
||||
PIFile::FileInfo fi(path);
|
||||
PIString dir = fi.dir(), name = fi.name();
|
||||
piForeachC (PIString & p, prefixes) {
|
||||
piForeachC (PIString & s, suffixes) {
|
||||
piForeachC(PIString & p, prefixes) {
|
||||
piForeachC(PIString & s, suffixes) {
|
||||
PIString fn = dir + p + name + s;
|
||||
if (PIFile::isExists(fn))
|
||||
return fn;
|
||||
if (PIFile::isExists(fn)) return fn;
|
||||
}
|
||||
}
|
||||
return PIString();
|
||||
@@ -492,14 +482,14 @@ PIString PIPluginLoader::findLibrary(const PIString & path) {
|
||||
|
||||
PIString PIPluginLoader::libExtension() {
|
||||
return
|
||||
#ifdef WINDOWS
|
||||
".dll"
|
||||
#elif defined(MAC_OS)
|
||||
".dylib"
|
||||
#else
|
||||
".so"
|
||||
#endif
|
||||
;
|
||||
# ifdef WINDOWS
|
||||
".dll"
|
||||
# elif defined(MAC_OS)
|
||||
".dylib"
|
||||
# else
|
||||
".so"
|
||||
# endif
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user