MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / registerResource

Method registerResource

libminifi/src/core/ClassLoader.cpp:36–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36uint16_t ClassLoader::registerResource(const std::string &resource, const std::string &resourceFunction) {
37 void *resource_ptr = nullptr;
38 if (resource.empty()) {
39 dlclose(dlopen(0, RTLD_LAZY | RTLD_GLOBAL));
40 resource_ptr = dlopen(0, RTLD_NOW | RTLD_GLOBAL);
41 } else {
42 dlclose(dlopen(resource.c_str(), RTLD_LAZY | RTLD_GLOBAL));
43 resource_ptr = dlopen(resource.c_str(), RTLD_NOW | RTLD_GLOBAL);
44 }
45 if (!resource_ptr) {
46 return RESOURCE_FAILURE;
47 } else {
48 std::lock_guard<std::mutex> lock(internal_mutex_);
49 dl_handles_.push_back(resource_ptr);
50 }
51
52 // reset errors
53 dlerror();
54
55 // load the symbols
56 createFactory* create_factory_func = reinterpret_cast<createFactory*>(dlsym(resource_ptr, resourceFunction.c_str()));
57 const char* dlsym_error = dlerror();
58 if ((dlsym_error != nullptr && strlen(dlsym_error) > 0) || create_factory_func == nullptr) {
59 return RESOURCE_FAILURE;
60 }
61
62 ObjectFactory *factory = create_factory_func();
63
64 std::lock_guard<std::mutex> lock(internal_mutex_);
65
66 auto initializer = factory->getInitializer();
67 if (initializer != nullptr) {
68 if (!initializer->initialize()) {
69 delete factory;
70 return RESOURCE_FAILURE;
71 }
72 initializers_.emplace_back(std::move(initializer));
73 }
74
75 for (auto class_name : factory->getClassNames()) {
76 loaded_factories_[class_name] = std::unique_ptr<ObjectFactory>(factory->assign(class_name));
77 }
78
79 delete factory;
80
81 return RESOURCE_SUCCESS;
82}
83
84} /* namespace core */
85} /* namespace minifi */

Callers 3

init_apiFunction · 0.45
GPSTests.cppFile · 0.45
configureMethod · 0.45

Calls 6

c_strMethod · 0.80
emptyMethod · 0.45
getInitializerMethod · 0.45
initializeMethod · 0.45
getClassNamesMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected