Directory: | ./ |
---|---|
File: | src/BackEnd/backend_proxy_loader.cpp |
Date: | 2025-03-14 12:14:21 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 175 | 179 | 97.8% |
Branches: | 249 | 268 | 92.9% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include "backend.h" | ||
8 | #include "backend_proxy_loader.h" | ||
9 | |||
10 | ///Create the Header definition of the ProxyLoader class | ||
11 | /** @param libraryName : name of the library to be created (to avoid multiple definition) | ||
12 | * @param className : name of the ProxyLoader class | ||
13 | * @return corresponding code | ||
14 | */ | ||
15 | 3 | PString cpp_backendProxyLoaderHeader(const PString & libraryName, const PString & className){ | |
16 |
1/1✓ Branch 1 taken 3 times.
|
3 | PString body(cpp_licenceSaveStr()); |
17 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
6 | PString baseMacro("__" + className.toUpper() + "_H__"); |
18 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "#ifndef " + baseMacro + "\n"; |
19 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "#define " + baseMacro + "\n\n"; |
20 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "#include <string>\n\n\n"; |
21 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "///@brief Class which loads automatically the right sub-library of "+libraryName+"\n"; |
22 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "class "+className+"{\n"; |
23 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tpublic:\n"; |
24 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "\t\t"+className+"();\n"; |
25 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "\t\tvirtual ~"+className+"();\n"; |
26 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\t\n"; |
27 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tbool load(const std::string & libName);\n"; |
28 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tbool parseArchFile(const std::string & archfileName);\n"; |
29 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tbool isOpen() const;\n"; |
30 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tvoid close();\n"; |
31 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\t\n"; |
32 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tvoid updateFunction();\n"; |
33 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tprivate:\n"; |
34 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "\t\tvoid initialisation"+className+"();\n"; |
35 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\t\n"; |
36 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\t///Handle of the library we load\n"; |
37 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tvoid* p_handle;\n"; |
38 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "};\n\n"; |
39 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "#endif\n\n"; |
40 | 6 | return body; | |
41 | 3 | } | |
42 | |||
43 | ///Create the Source of the ProxyLoader class constructor | ||
44 | /** @param className : name of the ProxyLoader class | ||
45 | * @param defaultLib : default library to be use if no extention was found | ||
46 | * @return corresponding code | ||
47 | */ | ||
48 | 3 | PString cpp_backendProxyLoaderConstructorSource(const PString & className, const PString & defaultLib){ | |
49 | 3 | PString body(""); | |
50 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "///Default constructor of "+className+"\n"; |
51 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
|
3 | body += className+"::"+className+"(){\n"; |
52 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "\tinitialisation"+className+"();\n"; |
53 |
5/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
|
3 | body += "\tstd::cout << \""+className+"::"+className+"() : check current architecture\" << std::endl;\n"; |
54 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t//First get the /proc/cpuinfo file\n"; |
55 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tif(!parseArchFile(\"/proc/cpuinfo\")){\n"; |
56 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\t//No library found, let's load the default library\n"; |
57 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "\t\tload(\""+defaultLib+"\");\n"; |
58 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t}\n"; |
59 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tupdateFunction();\n"; |
60 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "}\n\n"; |
61 | 3 | return body; | |
62 | } | ||
63 | |||
64 | ///Create the Source of the ProxyLoader class desctructor | ||
65 | /** @param className : name of the ProxyLoader class | ||
66 | * @return corresponding code | ||
67 | */ | ||
68 | 3 | PString cpp_backendProxyLoaderDesonstructorSource(const PString & className){ | |
69 | 3 | PString body(""); | |
70 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "///Destructor of "+className+"\n"; |
71 |
5/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
|
3 | body += ""+className+"::~"+className+"(){\n"; |
72 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tclose();\n"; |
73 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "}\n\n"; |
74 | 3 | return body; | |
75 | } | ||
76 | |||
77 | ///Create the Source of the ProxyLoader load | ||
78 | /** @param className : name of the ProxyLoader class | ||
79 | * @return corresponding code | ||
80 | */ | ||
81 | 3 | PString cpp_backendProxyLoaderLoadSource(const PString & className){ | |
82 | 3 | PString body(""); | |
83 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "///Load the given library\n"; |
84 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "/**\t@param libName : name of the library to be loaded\n"; |
85 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "* \t@return true on success, false otherwise\n"; |
86 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "*/\n"; |
87 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "bool "+className+"::load(const std::string & libName){\n"; |
88 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tif(libName == \"\"){return false;}\n"; |
89 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tp_handle = dlopen(libName.c_str(), RTLD_LAZY);\n"; |
90 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "\tstd::cout << \""+className+"::load : loading library '\"<<libName<<\"'\" << std::endl;\n"; |
91 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tif(p_handle == NULL){\n"; |
92 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "\t\tfprintf(stderr, \""+className+"::load : %s\\n\", dlerror());\n"; |
93 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\treturn false;\n"; |
94 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t}\n"; |
95 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tdlerror(); //Erase an exsiting error\n"; |
96 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\treturn true;\n"; |
97 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "}\n\n"; |
98 | 3 | return body; | |
99 | } | ||
100 | |||
101 | |||
102 | ///Create the Source of the ProxyLoader load | ||
103 | /** @param vecArchLib : vector of library to be loaded on the fly by respect to the host architecture | ||
104 | * @param className : name of the ProxyLoader class | ||
105 | * @param libDir : directory where the sub libraries are installed | ||
106 | * @return corresponding code | ||
107 | */ | ||
108 | 3 | PString cpp_backendProxyLoaderParseArchFileSource(const PVecArchLib & vecArchLib, const PString & className, const PPath & libDir){ | |
109 |
1/1✓ Branch 1 taken 3 times.
|
3 | PString body(""); |
110 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "///Parse the given architecture file\n"; |
111 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "/**\t@param archfileName : name of the architecture file to be loaded\n"; |
112 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "* \t@return true on success, false otherwise\n"; |
113 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "*/\n"; |
114 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "bool "+className+"::parseArchFile(const std::string & archfileName){\n"; |
115 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tFILE * fp = fopen(archfileName.c_str(), \"r\");\n"; |
116 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tif(fp == NULL){\n"; |
117 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tstd::cerr << \"Cannot open file '\" << archfileName << \"'\" << std::endl;\n"; |
118 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\treturn false;\n"; |
119 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t}\n"; |
120 | |||
121 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tstd::string bufferAllFile(\"\");\n"; |
122 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tint buffer;\n"; |
123 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\twhile(!feof(fp)){\n"; |
124 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tbuffer = fgetc(fp);\n"; |
125 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tif(buffer != EOF) bufferAllFile += (char)buffer;\n"; |
126 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\telse break;\n"; |
127 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t}\n"; |
128 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tif(bufferAllFile == \"\"){\n"; |
129 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tstd::cerr << \"Empty file '\" << archfileName << \"'\" << std::endl;\n"; |
130 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\treturn false;\n\t}\n"; |
131 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tconst char * procCpuInfo = bufferAllFile.c_str();\n"; |
132 | //The following method does not work with text file for some reason | ||
133 | // body += "\t//Let's get the file size\n"; | ||
134 | // body += "\tfseek(fp, 0, SEEK_END);\n"; | ||
135 | // body += "\tsize_t fileSize(ftell(fp));\n"; | ||
136 | // body += "\tfseek(fp, 0, SEEK_SET);\n"; | ||
137 | // body += "\tif(fileSize == 0lu){\n"; | ||
138 | // body += "\t\tstd::cerr << \"Empty file '\" << archfileName << \"'\" << std::endl;\n"; | ||
139 | // body += "\t\treturn false;\n"; | ||
140 | // body += "\t}\n"; | ||
141 | // body += "\t//Now we can alloate the table to get the file content\n"; | ||
142 | // body += "\tchar * procCpuInfo = new char[fileSize];\n"; | ||
143 | // body += "\t//And load the file\n"; | ||
144 | // body += "\tif(fread(procCpuInfo, sizeof(char), fileSize, fp) != fileSize){\n"; | ||
145 | // body += "\t\tstd::cerr << \"Cannot read file '\" << archfileName << \"'\" << std::endl;\n"; | ||
146 | // body += "\t\treturn false;\n\t}\n"; | ||
147 | |||
148 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t//Let's check the avalaible architectures\n"; |
149 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tbool isLibFound(true);\n"; |
150 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | PString strElse("\t"), libraryFullDirectory(""); |
151 |
2/3✓ Branch 1 taken 3 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
|
3 | if(libDir != ""){ |
152 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | libraryFullDirectory = libDir + "/"; |
153 | } | ||
154 |
3/3✓ Branch 4 taken 25 times.
✓ Branch 6 taken 22 times.
✓ Branch 7 taken 3 times.
|
25 | for(PVecArchLib::const_reverse_iterator it(vecArchLib.rbegin()); it != vecArchLib.rend(); ++it){ |
155 |
6/6✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
✓ Branch 7 taken 22 times.
✓ Branch 10 taken 22 times.
✓ Branch 13 taken 22 times.
✓ Branch 16 taken 22 times.
|
22 | body += strElse + "if(strstr(procCpuInfo, \""+it->getArchitecture()+"\") != NULL){\n"; |
156 |
6/6✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
✓ Branch 7 taken 22 times.
✓ Branch 10 taken 22 times.
✓ Branch 13 taken 22 times.
✓ Branch 16 taken 22 times.
|
44 | PPath libName(libraryFullDirectory + it->getName().getFileName()); |
157 |
3/3✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
✓ Branch 7 taken 22 times.
|
22 | body += "\t\tload(\""+libName+"\");\n"; |
158 |
1/1✓ Branch 1 taken 22 times.
|
22 | body += "\t}"; |
159 |
1/1✓ Branch 1 taken 22 times.
|
22 | strElse = "else "; |
160 | 22 | } | |
161 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "else{\n\t\tisLibFound = false;\n\t}\n"; |
162 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\n"; |
163 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tfclose(fp);\n"; |
164 | // body += "\tdelete [] procCpuInfo;\n"; | ||
165 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\treturn isLibFound;\n"; |
166 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "}\n\n"; |
167 | 6 | return body; | |
168 | 3 | } | |
169 | |||
170 | ///Create the Source of the ProxyLoader isOpen | ||
171 | /** @param className : name of the ProxyLoader class | ||
172 | * @return corresponding code | ||
173 | */ | ||
174 | 3 | PString cpp_backendProxyLoaderIsOpenSource(const PString & className){ | |
175 | 3 | PString body(""); | |
176 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "///Say if the current library is opened or not\n"; |
177 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "/**\t@return true if the current library is opened, false otherwise\n"; |
178 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "*/\n"; |
179 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "bool "+className+"::isOpen() const{\n"; |
180 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\treturn p_handle != NULL;\n"; |
181 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "}\n\n"; |
182 | 3 | return body; | |
183 | } | ||
184 | |||
185 | ///Create the Source of the ProxyLoader close | ||
186 | /** @param className : name of the ProxyLoader class | ||
187 | * @return corresponding code | ||
188 | */ | ||
189 | 3 | PString cpp_backendProxyLoaderCloseSource(const PString & className){ | |
190 | 3 | PString body(""); | |
191 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "///Close the current library\n"; |
192 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "void "+className+"::close(){\n"; |
193 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tif(isOpen()){\n"; |
194 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t\tdlclose(p_handle);\n"; |
195 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t}\n"; |
196 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "}\n\n"; |
197 | 3 | return body; | |
198 | } | ||
199 | |||
200 | ///Create the Source of the ProxyLoader update | ||
201 | /** @param className : name of the ProxyLoader class | ||
202 | * @param vecSource : vector of source | ||
203 | * @return corresponding code | ||
204 | */ | ||
205 | 3 | PString cpp_backendProxyLoaderUpdateSource(const PString & className, const PVecSource & vecSource){ | |
206 | 3 | PString body(""); | |
207 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "///Update the functions to be used\n"; |
208 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "void "+className+"::updateFunction(){\n"; |
209 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tif(!isOpen()){exit(-1);return;}\n"; |
210 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\t//Then set all the function pointers\n"; |
211 |
2/2✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
|
6 | for(PVecSource::const_iterator it(vecSource.begin()); it != vecSource.end(); ++it){ |
212 |
5/5✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 8 taken 3 times.
✓ Branch 11 taken 3 times.
✓ Branch 14 taken 3 times.
|
3 | body += "\t"+getUpdateFunction(it->getName())+"(p_handle);\n"; |
213 | } | ||
214 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "}\n\n"; |
215 | 3 | return body; | |
216 | } | ||
217 | |||
218 | ///Create the Source of the ProxyLoader initialisation | ||
219 | /** @param className : name of the ProxyLoader class | ||
220 | * @return corresponding code | ||
221 | */ | ||
222 | 3 | PString cpp_backendProxyLoaderInitialisationSource(const PString & className){ | |
223 | 3 | PString body(""); | |
224 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "///Initialisation function of the class "+className+"\n"; |
225 |
5/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
|
3 | body += "void "+className+"::initialisation"+className+"(){\n"; |
226 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "\tp_handle = NULL;\n"; |
227 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "}\n\n"; |
228 | 3 | return body; | |
229 | } | ||
230 | |||
231 | ///Create the Source of the ProxyLoader class | ||
232 | /** @param vecSource : vector of source | ||
233 | * @param vecArchLib : vector of library to be loaded on the fly by respect to the host architecture | ||
234 | * @param className : name of the ProxyLoader class | ||
235 | * @param libDir : directory where the sub libraries are installed | ||
236 | * @return corresponding code | ||
237 | */ | ||
238 | 3 | PString cpp_backendProxyLoaderSource(const PVecSource & vecSource, const PVecArchLib & vecArchLib, | |
239 | const PString & className, const PString & libDir) | ||
240 | { | ||
241 |
1/1✓ Branch 1 taken 3 times.
|
3 | PString body(cpp_licenceSaveStr()); |
242 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "#include <stdio.h>\n"; |
243 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "#include <stdlib.h>\n"; |
244 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "#include <dlfcn.h>\n"; |
245 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "#include <string.h>\n\n"; |
246 | |||
247 |
2/2✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
|
6 | for(PVecSource::const_iterator it(vecSource.begin()); it != vecSource.end(); ++it){ |
248 |
4/4✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 8 taken 3 times.
✓ Branch 11 taken 3 times.
|
3 | body += "#include \""+it->getName()+".h\"\n"; |
249 | } | ||
250 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += "\n#include \""+className+".h\"\n\n"; |
251 |
1/1✓ Branch 1 taken 3 times.
|
3 | body += "///Variable which will load automatically the right library by respect to the given architecture\n"; |
252 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | body += className + " PROXY_LOADER;\n\n"; |
253 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
6 | PString defaultLib(getLibraryFile(vecArchLib).getFileName()); |
254 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | body += cpp_backendProxyLoaderConstructorSource(className, defaultLib); |
255 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | body += cpp_backendProxyLoaderDesonstructorSource(className); |
256 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | body += cpp_backendProxyLoaderLoadSource(className); |
257 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
3 | body += cpp_backendProxyLoaderParseArchFileSource(vecArchLib, className, libDir); |
258 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | body += cpp_backendProxyLoaderIsOpenSource(className); |
259 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | body += cpp_backendProxyLoaderCloseSource(className); |
260 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | body += cpp_backendProxyLoaderUpdateSource(className, vecSource); |
261 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | body += cpp_backendProxyLoaderInitialisationSource(className); |
262 | 6 | return body; | |
263 | 3 | } | |
264 | |||
265 | ///Save ProxyLoader with the corresponding a vector of PSource in the output directory | ||
266 | /** @param vecSource : vector of source | ||
267 | * @param libraryName : name of the library to be created | ||
268 | * @param vecArchLib : vector of library to be loaded on the fly by respect to the host architecture | ||
269 | * @param libDir : directory where the sub libraries are installed | ||
270 | * @param outputDir : output directory where to save ProxyLoader | ||
271 | * @return true on success, false otherwise | ||
272 | */ | ||
273 | 3 | bool cpp_backend_proxy(const PVecSource & vecSource, const PString & libraryName, const PVecArchLib & vecArchLib, const PPath & libDir, const PPath & outputDir){ | |
274 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
|
6 | PString className(PString(libraryName + "ProxyLoader").firstToUpper()); |
275 |
1/1✓ Branch 1 taken 3 times.
|
3 | PString headerSrc(cpp_backendProxyLoaderHeader(libraryName, className)); |
276 |
1/1✓ Branch 1 taken 3 times.
|
3 | PString sourceSrc(cpp_backendProxyLoaderSource(vecSource, vecArchLib, className, libDir)); |
277 |
5/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
|
6 | PPath outputHeaderFile(outputDir + "/" + className + ".h"); |
278 |
5/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
|
6 | PPath outputSourceFile(outputDir + "/" + className + ".cpp"); |
279 |
2/3✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
|
3 | if(!outputHeaderFile.saveFileContent(headerSrc)){ |
280 | ✗ | std::cerr << "cpp_backend : cannot save header file '"<<outputHeaderFile<<"'" << std::endl; | |
281 | ✗ | return false; | |
282 | } | ||
283 |
2/3✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
|
3 | if(!outputSourceFile.saveFileContent(sourceSrc)){ |
284 | ✗ | std::cerr << "cpp_backend : cannot save source file '"<<outputSourceFile<<"'" << std::endl; | |
285 | ✗ | return false; | |
286 | } | ||
287 | 3 | return true; | |
288 | 3 | } | |
289 | |||
290 | |||
291 |