feat: improve modulebase (#84)

This commit is contained in:
wtudio 2024-11-06 19:51:31 +08:00 committed by GitHub
parent 7b56221af4
commit 3771a907b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -76,24 +76,40 @@ class ModuleBase {
return aimrt_module_info_t{}; return aimrt_module_info_t{};
} }
}, },
.initialize = [](void* impl, const aimrt_core_base_t* core) -> bool { .initialize = [](void* impl, const aimrt_core_base_t* core_ptr) -> bool {
auto* module_ptr = static_cast<ModuleBase*>(impl);
module_ptr->core_ptr_ = core_ptr;
try { try {
return static_cast<ModuleBase*>(impl)->Initialize(CoreRef(core)); return module_ptr->Initialize(CoreRef(module_ptr->core_ptr_));
} catch (...) { } catch (const std::exception& e) {
AIMRT_HL_ERROR(
CoreRef(module_ptr->core_ptr_).GetLogger(),
"Initialize module get exception: {}", e.what());
return false; return false;
} }
}, },
.start = [](void* impl) -> bool { .start = [](void* impl) -> bool {
auto* module_ptr = static_cast<ModuleBase*>(impl);
try { try {
return static_cast<ModuleBase*>(impl)->Start(); return module_ptr->Start();
} catch (...) { } catch (const std::exception& e) {
AIMRT_HL_ERROR(
CoreRef(module_ptr->core_ptr_).GetLogger(),
"Start module get exception: {}", e.what());
return false; return false;
} }
}, },
.shutdown = [](void* impl) { .shutdown = [](void* impl) {
auto* module_ptr = static_cast<ModuleBase*>(impl);
try { try {
static_cast<ModuleBase*>(impl)->Shutdown(); module_ptr->Shutdown();
} catch (...) { } catch (const std::exception& e) {
AIMRT_HL_ERROR(
CoreRef(module_ptr->core_ptr_).GetLogger(),
"Shutdown module get exception: {}", e.what());
} // } //
}, },
.impl = impl}; .impl = impl};
@ -101,6 +117,7 @@ class ModuleBase {
private: private:
const aimrt_module_base_t base_; const aimrt_module_base_t base_;
const aimrt_core_base_t* core_ptr_ = nullptr;
}; };
} // namespace aimrt } // namespace aimrt