mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-04-18 09:25:06 +00:00
Module bug fixes
This commit is contained in:
parent
c2177929bc
commit
10ab4dded8
@ -118,6 +118,7 @@ error_t module_construct_add_start(struct Module* module);
|
||||
|
||||
/**
|
||||
* @brief Check if the module is started.
|
||||
* Can be used when module isn't constructed yet.
|
||||
* @param module module to check
|
||||
* @return true if the module is started, false otherwise
|
||||
*/
|
||||
|
||||
@ -12,8 +12,8 @@ struct ModuleInternal {
|
||||
};
|
||||
|
||||
struct ModuleLedger {
|
||||
std::vector<struct Module*> modules;
|
||||
struct Mutex mutex {};
|
||||
std::vector<Module*> modules;
|
||||
Mutex mutex {};
|
||||
|
||||
ModuleLedger() { mutex_construct(&mutex); }
|
||||
~ModuleLedger() { mutex_destruct(&mutex); }
|
||||
@ -23,36 +23,37 @@ static ModuleLedger ledger;
|
||||
|
||||
extern "C" {
|
||||
|
||||
error_t module_construct(struct Module* module) {
|
||||
error_t module_construct(Module* module) {
|
||||
module->internal = new (std::nothrow) ModuleInternal();
|
||||
if (module->internal == nullptr) return ERROR_OUT_OF_MEMORY;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t module_destruct(struct Module* module) {
|
||||
error_t module_destruct(Module* module) {
|
||||
delete static_cast<ModuleInternal*>(module->internal);
|
||||
module->internal = nullptr;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t module_add(struct Module* module) {
|
||||
error_t module_add(Module* module) {
|
||||
mutex_lock(&ledger.mutex);
|
||||
ledger.modules.push_back(module);
|
||||
mutex_unlock(&ledger.mutex);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t module_remove(struct Module* module) {
|
||||
error_t module_remove(Module* module) {
|
||||
mutex_lock(&ledger.mutex);
|
||||
ledger.modules.erase(std::remove(ledger.modules.begin(), ledger.modules.end(), module), ledger.modules.end());
|
||||
mutex_unlock(&ledger.mutex);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t module_start(struct Module* module) {
|
||||
error_t module_start(Module* module) {
|
||||
LOG_I(TAG, "start %s", module->name);
|
||||
|
||||
auto* internal = static_cast<ModuleInternal*>(module->internal);
|
||||
auto* internal = module->internal;
|
||||
if (internal == nullptr) return ERROR_INVALID_STATE;
|
||||
if (internal->started) return ERROR_NONE;
|
||||
|
||||
error_t error = module->start();
|
||||
@ -61,13 +62,15 @@ error_t module_start(struct Module* module) {
|
||||
}
|
||||
|
||||
bool module_is_started(struct Module* module) {
|
||||
return static_cast<ModuleInternal*>(module->internal)->started;
|
||||
auto* internal = module->internal;
|
||||
return internal != nullptr && internal->started;
|
||||
}
|
||||
|
||||
error_t module_stop(struct Module* module) {
|
||||
LOG_I(TAG, "stop %s", module->name);
|
||||
|
||||
auto* internal = static_cast<ModuleInternal*>(module->internal);
|
||||
auto* internal = module->internal;
|
||||
if (internal == nullptr) return ERROR_INVALID_STATE;
|
||||
if (!internal->started) return ERROR_NONE;
|
||||
|
||||
error_t error = module->stop();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user