- Refactor on platform implementation. See comment in interface/platform.h for more info
This commit is contained in:
87
source/platform/linux/xkb/lib/loader.cpp
Normal file
87
source/platform/linux/xkb/lib/loader.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// 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 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 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 <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#define FENNEC_LIB(name) bool FENNEC_HAS_LIB_##name;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) using sym_##fn = ret(*)(__VA_ARGS__); \
|
||||
sym_##fn fn;
|
||||
#define FENNEC_GLOBAL(type, name) type* name;
|
||||
#include <fennec/platform/linux/xkb/lib/sym.h>
|
||||
|
||||
#include <fennec/platform/linux/xkb/lib/xkbcommon.h>
|
||||
#include <fennec/platform/linux/xkb/lib/loader.h>
|
||||
#include <fennec/platform/interface/platform.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
namespace libxkbcommon
|
||||
{
|
||||
|
||||
using shared_object = platform::shared_object;
|
||||
|
||||
struct shared_lib {
|
||||
shared_object* obj;
|
||||
const cstring name;
|
||||
};
|
||||
|
||||
static int _load_count = 0;
|
||||
|
||||
// Create private variables
|
||||
#define FENNEC_LIB(lib) static shared_lib _FENNEC_LIB_##lib = { nullptr, FENNEC_LIB_##lib };
|
||||
#include <fennec/platform/linux/xkb/lib/sym.h>
|
||||
|
||||
bool load_symbols(platform* platform) {
|
||||
if (_load_count++ != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
shared_lib* current_lib = nullptr;
|
||||
#define FENNEC_LIB(lib) _FENNEC_LIB_##lib.obj = platform->load_object(_FENNEC_LIB_##lib.name); \
|
||||
FENNEC_HAS_LIB_##lib = _FENNEC_LIB_##lib.obj != nullptr; \
|
||||
if(not FENNEC_HAS_LIB_##lib) { \
|
||||
unload_symbols(platform); \
|
||||
return false; \
|
||||
} \
|
||||
current_lib = &_FENNEC_LIB_##lib;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) fn = (sym_##fn)(platform->find_symbol(current_lib->obj, #fn)); \
|
||||
assertf(fn != nullptr, "Failed to find symbol: " #fn);
|
||||
#define FENNEC_GLOBAL(type, name) name = (type*)(platform->find_symbol(current_lib->obj, #name)); \
|
||||
assertf(name != nullptr, "Failed to find global: " #name);
|
||||
#include <fennec/platform/linux/xkb/lib/sym.h>
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void unload_symbols(platform* platform) {
|
||||
if (--_load_count != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
#define FENNEC_LIB(lib) platform->unload_object(_FENNEC_LIB_##lib.obj); \
|
||||
_FENNEC_LIB_##lib.obj = nullptr;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) fn = nullptr;
|
||||
#define FENNEC_GLOBAL(type, name) name = nullptr;
|
||||
#include <fennec/platform/linux/xkb/lib/sym.h>
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user