bool Plugin::Load(/*out*/std::string* error_msg) {
Locks::mutator_lock_->AssertNotHeld(Thread::Current());
DCHECK(!IsLoaded()); void* res = dlopen(library_.c_str(), RTLD_LAZY); if (res == nullptr) {
*error_msg = StringPrintf("dlopen failed: %s", dlerror()); returnfalse;
} // Get the initializer function
PluginInitializationFunction init = reinterpret_cast<PluginInitializationFunction>(
dlsym(res, PLUGIN_INITIALIZATION_FUNCTION_NAME)); if (init != nullptr) { if (!init()) {
dlclose(res);
*error_msg = StringPrintf("Initialization of plugin failed"); returnfalse;
}
} else {
LOG(WARNING) << this << " does not include an initialization function";
}
dlopen_handle_ = res; returntrue;
}
bool Plugin::Unload() {
Locks::mutator_lock_->AssertNotHeld(Thread::Current());
DCHECK(IsLoaded()); bool ret = true; void* handle = dlopen_handle_;
PluginDeinitializationFunction deinit = reinterpret_cast<PluginDeinitializationFunction>(
dlsym(handle, PLUGIN_DEINITIALIZATION_FUNCTION_NAME)); if (deinit != nullptr) { if (!deinit()) {
LOG(WARNING) << this << " failed deinitialization";
ret = false;
}
} else {
LOG(WARNING) << this << " does not include a deinitialization function";
}
dlopen_handle_ = nullptr; // Don't bother to actually dlclose since we are shutting down anyway and there might be small // amounts of processing still being done. return ret;
}
std::ostream& operator<<(std::ostream &os, const Plugin* m) { return os << *m;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.