MCPcopy Create free account
hub / github.com/SoarGroup/Soar / LoadExternalLibrary

Method LoadExternalLibrary

Core/ClientSML/src/sml_ClientKernel.cpp:2456–2552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2454*************************************************************/
2455
2456std::string Kernel::LoadExternalLibrary(const char* pLibraryCommand)
2457{
2458
2459 // We'll break up the command in to this argv array
2460 std::vector<std::string> vectorArgv;
2461 Tokenize(pLibraryCommand, vectorArgv);
2462
2463 if (vectorArgv.size() == 0)
2464 {
2465 return "No library name.";
2466 }
2467
2468 // The first index of the argv is the library name
2469 // Make a copy of the library name so we can work on it.
2470 std::string libraryName = vectorArgv[0];
2471
2472 // We shouldn't be passed something with an extension
2473 // but if we are, we'll try to strip the extension to be helpful
2474 size_t pos = libraryName.find_last_of('.') ;
2475 if (pos != std::string::npos)
2476 {
2477 libraryName.erase(pos) ;
2478 }
2479
2480#ifdef _WIN32
2481 // The windows shared library
2482 libraryName = libraryName + ".dll";
2483
2484 // Now load the library itself.
2485 HMODULE hLibrary = LoadLibrary(libraryName.c_str()) ;
2486
2487#else
2488 std::string newLibraryName = "lib" + libraryName;
2489#if (defined(__APPLE__) && defined(__MACH__))
2490 newLibraryName.append(".dylib");
2491#else
2492 newLibraryName.append(".so");
2493#endif
2494 void* hLibrary = 0;
2495 hLibrary = dlopen(newLibraryName.c_str(), RTLD_LAZY);
2496#endif // !_WIN32
2497
2498 std::string resultString;
2499
2500 if (!hLibrary)
2501 {
2502#ifdef _WIN32
2503 return "Library not found.";
2504#else
2505 return std::string(dlerror());
2506#endif
2507 }
2508 else
2509 {
2510 InitLibraryFunction pInitLibraryFunction = Dangerous_Pointer_Cast<InitLibraryFunction>::from(GetProcAddress(hLibrary, "sml_InitLibrary"));
2511
2512 if (!pInitLibraryFunction)
2513 {

Callers 3

mainFunction · 0.80
Message_LibraryMethod · 0.80
LoadLibraryHandlerFunction · 0.80

Calls 3

sizeMethod · 0.45
appendMethod · 0.45
dataMethod · 0.45

Tested by 1

mainFunction · 0.64