WebFramework v3.0.12
Web framework for C++.
Loading...
Searching...
No Matches
Sources.cpp
1#include "Sources.h"
2
3#include "DynamicLibraries.h"
4#include "Exceptions/FileDoesNotExistException.h"
5#include "Exceptions/CantLoadSourceException.h"
6#include "Log.h"
7
8using namespace std;
9
10namespace framework
11{
12 namespace utility
13 {
14 vector<HMODULE> loadSources(const vector<string>& pathToSources)
15 {
16 vector<HMODULE> result;
17
18 result.reserve(pathToSources.size());
19
20 for (const string& temp : pathToSources)
21 {
22 if (temp == json_settings::defaultLoadSourceValue)
23 {
24#ifdef __LINUX__
25 result.push_back(dlopen(nullptr, RTLD_LAZY));
26#else
27 result.push_back(nullptr);
28#endif
29
30 continue;
31 }
32
33 string pathToSource = makePathToDynamicLibrary(temp);
34
35 if (filesystem::exists(pathToSource))
36 {
37 HMODULE handle = nullptr;
38
39#ifdef __LINUX__
40 handle = dlopen(pathToSource.data(), RTLD_LAZY);
41#else
42 handle = LoadLibraryA(pathToSource.data());
43#endif
44 result.push_back(handle);
45 }
46 else
47 {
48 if (Log::isValid())
49 {
50 Log::error("Can't find source {}", "LogWebFrameworkSources", pathToSource);
51 }
52
53 throw file_manager::exceptions::FileDoesNotExistException(pathToSource);
54 }
55
56 if (!result.back())
57 {
58 if (Log::isValid())
59 {
60 Log::error("Can't load source {}", "LogWebFrameworkSources", pathToSource);
61 }
62
63 throw exceptions::CantLoadSourceException(pathToSource);
64 }
65 }
66
67 return result;
68 }
69 }
70}