- Installation
- Module Manager
- MarsTech Module
- MarsTech DLL Module Adapter
- MarsTech Module Configurator
- Usage Example
- Source Code Documentation
- License
MarsTech module library contains module interface, DLL module adapter and module manager which manage all created modules.
Download all MarsTech dependencies and put them to a same directory. Create a new subdirectory "3rdParty" and put there "3rdParty" dependencies (inih, SQLite3, spdlog).
- MarsTech Headers
- MarsTech Dependency Injection
- MarsTech Error Handling
- MarsTech Logging
- MarsTech Config
- MarsTech Threading
- MarsTech Dll Factory
- spdlog
- inih
- SQLite3
No build configuration is needed - just build whole solution.
Module manager manages all created modules. It can initialize, uninitialize, start and stop modules.
Example:
#include "mmodule/MsvModuleManager.h"
//module IDs (should be defined in separate header)
enum class MsvModuleId: int32_t
{
MSV_EXAMPLE_STATIC_MODULE_1 = 0,
MSV_EXAMPLE_STATIC_MODULE_2,
MSV_EXAMPLE_DYNAMIC_MODULE_1,
MSV_EXAMPLE_DYNAMIC_MODULE_2
};
std::shared_ptr<IMsvModuleManager> spModuleManager(new MsvModuleManager());
//add modules to module manager (example at https://github.com/Mars2004/msys/blob/master/Example/MsvMainInitializer.cpp)
//spModuleManager->AddModule(static_cast<int32_t>(MSV_EXAMPLE_STATIC_MODULE_1), spModule, spModuleConfigurator);
MsvErrorCode errorCode = spModuleManager->Initialize();
if (MSV_FAILED(errorCode))
{
MSV_LOG_ERROR(m_spLogger, "Initialize module module manager failed with error: {0:x}", errorCode);
return errorCode;
}
if (MSV_FAILED(errorCode = m_spModuleManager->Start()))
{
MSV_LOG_ERROR(m_spLogger, "Start module manager failed with error: {0:x}", errorCode);
return errorCode;
}
//some stop request synchronization (e.g. MsvEvent)
if (MSV_FAILED(errorCode = spModuleManager->Stop()))
{
MSV_LOG_ERROR(m_spLogger, "Stop module manager failed with error: {0:x}", errorCode);
}
if (MSV_FAILED(errorCode = m_spModuleManager->Uninitialize()))
{
MSV_LOG_ERROR(m_spLogger, "Uninitialize module manager failed with error: {0:x}", errorCode);
}
It is just interface. When you want to create module just inherit from IMsvModule interface and implement Initialize, Uninitialize, Start and Stop methods.
Example:
#include "mmodule/IMsvModule.h"
#include "mheaders/MsvObject.h"
#include "merror/MsvErrorCodes.h"
class MyModule:
public MsvObject<IMsvModule>
{
MyModule():
MsvObject<IMsvModule>()
{
}
virtual MsvErrorCode Initialize() override
{
return MSV_SUCCESS;
}
virtual MsvErrorCode Uninitialize() override
{
return MSV_SUCCESS;
}
virtual MsvErrorCode Start() override
{
return MSV_SUCCESS;
}
virtual MsvErrorCode Stop() override
{
return MSV_SUCCESS;
}
};
There is also implementation for modules in DLLs. These DLLs must implement GetDllObject function to be able to load by MarsTech Dll Factory.
Example:
#include "mmodule/MsvDllModuleAdapter.h"
//example from (https://github.com/Mars2004/msys/blob/master/modules/MsvModules.cpp)
std::shared_ptr<IMsvModule> spDllModule(new MsvDllModuleAdapter(moduleId, spDllFactory, spLogger));
Module manager needs to know if modules are installed and enabled. There is module configurator which usese MarsTech Active Config to check if each module is installed and enabled. It is possible to inherit from MsvModuleConfigurator and implement more configuration get and set methods.
Example:
#include "mmodule/MsvModuleConfigurator.h"
//example from usage example at https://github.com/Mars2004/msys/blob/master/Example/MsvMainInitializer.cpp
std::shared_ptr<IMsvModuleConfigurator> spModuleConfigurator(new MsvModuleConfigurator(spActiveCfg, static_cast<int32_t>(enabledCfgId), static_cast<int32_t>(installedCfgId)));
There is also an usage example which uses the most of MarsTech projects and libraries. Its source codes and readme can be found at:
You can find generated source code documentation at https://www.marstech.cz/projects/mmodule/1.0.1/doc.
This project is released under GNU General Public License version 3. If you can not or do not want to accept GNU GPLv3 license and you would like to use this project under another license, please contact me on info@marstech.cz or visit www.marstech.cz.