Skip to content

Mars2004/mmodule

Repository files navigation

MarsTech Module Library

MarsTech module library contains module interface, DLL module adapter and module manager which manage all created modules.

Installation

Download all MarsTech dependencies and put them to a same directory. Create a new subdirectory "3rdParty" and put there "3rdParty" dependencies (inih, SQLite3, spdlog).

Dependencies

Configuration

No build configuration is needed - just build whole solution.

Module Manager

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);
}

MarsTech Module

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;
	}
};

MarsTech DLL Module Adapter

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));

MarsTech Module Configurator

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)));

Usage Example

There is also an usage example which uses the most of MarsTech projects and libraries. Its source codes and readme can be found at:

Source Code Documentation

You can find generated source code documentation at https://www.marstech.cz/projects/mmodule/1.0.1/doc.

License

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.

About

Contains implementation and all definitions of MarsTech Module library. Implements module manager to manage modules.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages