Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5231: Move LogFile management to the core module. It has its own Mod…
…uleRegistry instance now too.
- Loading branch information
1 parent
b397436
commit 47bde40
Showing
13 changed files
with
162 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "CoreModule.h" | ||
|
||
#include "DynamicLibrary.h" | ||
|
||
namespace module | ||
{ | ||
|
||
CoreModule::CoreModule(ApplicationContext& context) : | ||
_instance(nullptr) | ||
{ | ||
std::string coreModuleFile = std::string("DarkRadiantCore") + MODULE_FILE_EXTENSION; | ||
|
||
fs::path coreModulePath = context.getApplicationPath(); | ||
coreModulePath /= coreModuleFile; | ||
|
||
if (!fs::exists(coreModulePath)) | ||
{ | ||
throw FailureException("Cannot find the main module " + coreModuleFile); | ||
} | ||
|
||
_coreModuleLibrary.reset(new DynamicLibrary(coreModulePath.string())); | ||
|
||
if (_coreModuleLibrary->failed()) | ||
{ | ||
throw FailureException("Cannot load the main module " + _coreModuleLibrary->getName()); | ||
} | ||
|
||
auto symbol = _coreModuleLibrary->findSymbol(QUOTE(SYMBOL_CREATE_RADIANT)); | ||
|
||
if (symbol == nullptr) | ||
{ | ||
throw FailureException("Main module " + _coreModuleLibrary->getName() + | ||
" doesn't expose the symbol " + QUOTE(SYMBOL_CREATE_RADIANT)); | ||
} | ||
|
||
auto createFunc = reinterpret_cast<CreateRadiantFunc>(symbol); | ||
|
||
_instance = createFunc(context); | ||
} | ||
|
||
CoreModule::~CoreModule() | ||
{ | ||
destroy(); | ||
} | ||
|
||
radiant::IRadiant* CoreModule::get() | ||
{ | ||
return _instance; | ||
} | ||
|
||
void CoreModule::destroy() | ||
{ | ||
if (_instance) | ||
{ | ||
assert(_coreModuleLibrary); | ||
|
||
auto symbol = _coreModuleLibrary->findSymbol(QUOTE(SYMBOL_DESTROY_RADIANT)); | ||
|
||
if (symbol == nullptr) | ||
{ | ||
throw FailureException("Main module " + _coreModuleLibrary->getName() + | ||
" doesn't expose the symbol " + QUOTE(SYMBOL_DESTROY_RADIANT)); | ||
} | ||
|
||
auto destroyFunc = reinterpret_cast<DestroyRadiantFunc>(symbol); | ||
|
||
destroyFunc(_instance); | ||
_instance = nullptr; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.