MCPcopy Create free account
hub / github.com/Yaafe/Yaafe / loadLibrary

Method loadLibrary

src_cpp/yaafe-core/ComponentFactory.cpp:137–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135 }
136
137 int ComponentFactory::loadLibrary(const std::string& libnamestr) {
138
139 if (m_libs.find(libnamestr)!=m_libs.end())
140 {
141 // library already loaded
142 return 0;
143 }
144
145 std::string complete_name = "lib" + libnamestr + YAAFE_DYNLIB_EXTENSION;
146
147 // first look at YAAFE_LIBRARY_DIR
148 if (getenv("YAAFE_PATH"))
149 {
150 string tmp = string(getenv("YAAFE_PATH")) + string(YAAFE_PATH_SEPARATOR) + complete_name;
151 struct stat st;
152 if (stat(tmp.c_str(),&st)==0)
153 {
154 // file exists
155 complete_name = tmp;
156 }
157 }
158
159 // then look at VIRTUAL_ENV/lib
160 if (getenv("VIRTUAL_ENV"))
161 {
162 string tmp = string(getenv("VIRTUAL_ENV")) + string(YAAFE_PATH_SEPARATOR) + string("lib") + string(YAAFE_PATH_SEPARATOR) + complete_name;
163 struct stat st;
164 if (stat(tmp.c_str(),&st)==0)
165 {
166 // file exists
167 complete_name = tmp;
168 }
169 } // else look at library in default library accessible dirs
170
171 const char* libname = complete_name.c_str();
172 LIBRARY_HANDLER library = dlopen(libname, RTLD_LAZY);
173 if (library == NULL) {
174 cerr << "ERROR: cannot load yaafe component library \"" << libname << "\" !" << endl;
175 cerr << dlerror() << endl;
176 return -1;
177 }
178
179 void* initializer = dlsym(library, "registerYaafeComponents");
180 if (initializer == NULL) {
181 cerr << "ERROR: cannot find 'registerYaafeComponents' function in component library '" << libname << "' !" << endl;
182 dlclose(library);
183 return -2;
184 }
185
186 m_libs[libnamestr] = library;
187
188 typedef void (*yaafelib_register_function_type)(void*);
189 yaafelib_register_function_type func =
190 *((yaafelib_register_function_type*) (&initializer));
191
192 func((void*) this);
193
194 return 0;

Callers 4

mainFunction · 0.80
loadMethod · 0.80
mexFunctionFunction · 0.80
loadComponentLibraryFunction · 0.80

Calls 5

dlopenFunction · 0.85
dlerrorFunction · 0.85
dlsymFunction · 0.85
dlcloseFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected