Vuo  2.4.0
VuoRunningCompositionLibraries.cc
Go to the documentation of this file.
1
11#include "VuoFileUtilities.hh"
12
17{
18 shouldDeleteResourceLibraries = false;
19}
20
25{
26 if (shouldDeleteResourceLibraries)
27 for (vector<string>::iterator i = resourcePathsLoaded.begin(); i != resourcePathsLoaded.end(); ++i)
29}
30
37void VuoRunningCompositionLibraries::enqueueResourceLibraryToLoad(const string &path, const set<string> &dependenciesInLibrary,
38 bool isUnloadable)
39{
40 if (find(resourcePathsLoaded.begin(), resourcePathsLoaded.end(), path) == resourcePathsLoaded.end() ||
41 find(resourcePathsToUnload.begin(), resourcePathsToUnload.end(), path) != resourcePathsToUnload.end())
42 {
43 resourcePathsToLoad.push_back(path);
44 canUnloadPathToLoad[path] = isUnloadable;
45 dependenciesToLoad[path] = dependenciesInLibrary;
46 }
47}
48
53{
54 if (find(resourcePathsLoaded.begin(), resourcePathsLoaded.end(), path) != resourcePathsLoaded.end())
55 {
56 if (! canUnloadPathLoaded[path])
57 {
58 VUserLog("The resource library %s can't be unloaded.", path.c_str());
59 return;
60 }
61
62 resourcePathsToUnload.insert(path);
63 }
64}
65
72{
73 set<string> dependenciesInLibraries;
74
75 for (string path : resourcePathsLoaded)
76 {
77 if (canUnloadPathLoaded[path])
78 {
79 resourcePathsToUnload.insert(path);
80 dependenciesInLibraries.insert( dependenciesLoaded[path].begin(), dependenciesLoaded[path].end() );
81 }
82 }
83
84 return dependenciesInLibraries;
85}
86
93void VuoRunningCompositionLibraries::enqueueCacheLibraryToLoad(const string &path, const set<string> &dependenciesInLibrary,
94 bool isUnloadable)
95{
96 if (find(cachePathsLoaded.begin(), cachePathsLoaded.end(), path) == cachePathsLoaded.end() ||
97 find(cachePathsToUnload.begin(), cachePathsToUnload.end(), path) != cachePathsToUnload.end())
98 {
99 cachePathsToLoad.push_back(path);
100 canUnloadPathToLoad[path] = isUnloadable;
101 dependenciesToLoad[path] = dependenciesInLibrary;
102 }
103}
104
112{
113 if (find(cachePathsLoaded.begin(), cachePathsLoaded.end(), path) != cachePathsLoaded.end())
114 {
115 if (! canUnloadPathLoaded[path])
116 {
117 VUserLog("The cache library %s can't be unloaded.", path.c_str());
118 return {};
119 }
120
121 cachePathsToUnload.insert(path);
122 }
123 else if (find(cachePathsToUnload.begin(), cachePathsToUnload.end(), path) == cachePathsToUnload.end())
124 {
125 return {};
126 }
127
128 return dependenciesLoaded[path];
129}
130
135{
136 for (map<string, set<string> >::iterator i = dependenciesLoaded.begin(); i != dependenciesLoaded.end(); ++i)
137 {
138 if (i->second.find(dependency) != i->second.end())
139 {
140 string libraryPath = i->first;
141
142 if (! canUnloadPathLoaded[libraryPath])
143 {
144 VUserLog("The library containing %s (%s) can't be unloaded.", dependency.c_str(), libraryPath.c_str());
145 break;
146 }
147
148 if (find(resourcePathsLoaded.begin(), resourcePathsLoaded.end(), libraryPath) != resourcePathsLoaded.end())
149 resourcePathsToUnload.insert(libraryPath);
150 if (find(cachePathsLoaded.begin(), cachePathsLoaded.end(), libraryPath) != cachePathsLoaded.end())
151 cachePathsToUnload.insert(libraryPath);
152
153 break;
154 }
155 }
156}
157
165{
166 vector<string> libraryPathsToLoad;
167
168 for (vector<string>::iterator i = cachePathsLoaded.begin(); i != cachePathsLoaded.end(); ++i)
169 if (canUnloadPathLoaded[*i])
170 libraryPathsToLoad.push_back(*i);
171
172 libraryPathsToLoad.insert(libraryPathsToLoad.end(), cachePathsToLoad.begin(), cachePathsToLoad.end());
173
174 for (vector<string>::iterator i = resourcePathsLoaded.begin(); i != resourcePathsLoaded.end(); ++i)
175 if (canUnloadPathLoaded[*i])
176 libraryPathsToLoad.push_back(*i);
177
178 libraryPathsToLoad.insert(libraryPathsToLoad.end(), resourcePathsToLoad.begin(), resourcePathsToLoad.end());
179
180 resourcePathsLoaded.insert(resourcePathsLoaded.end(), resourcePathsToLoad.begin(), resourcePathsToLoad.end());
181 resourcePathsToLoad.clear();
182
183 cachePathsLoaded.insert(cachePathsLoaded.end(), cachePathsToLoad.begin(), cachePathsToLoad.end());
184 cachePathsToLoad.clear();
185
186 dependenciesLoaded.insert(dependenciesToLoad.begin(), dependenciesToLoad.end());
187 dependenciesToLoad.clear();
188
189 canUnloadPathLoaded.insert(canUnloadPathToLoad.begin(), canUnloadPathToLoad.end());
190 canUnloadPathToLoad.clear();
191
192 return libraryPathsToLoad;
193}
194
203{
204 for (set<string>::iterator i = resourcePathsToUnload.begin(); i != resourcePathsToUnload.end(); ++i)
205 {
206 dependenciesLoaded.erase(*i);
207 canUnloadPathLoaded.erase(*i);
208
209 if (shouldDeleteResourceLibraries)
211 }
212
213 for (set<string>::iterator i = cachePathsToUnload.begin(); i != cachePathsToUnload.end(); ++i)
214 {
215 dependenciesLoaded.erase(*i);
216 canUnloadPathLoaded.erase(*i);
217 }
218
219 for (int i = resourcePathsLoaded.size()-1; i >= 0; --i)
220 if (find(resourcePathsToUnload.begin(), resourcePathsToUnload.end(), resourcePathsLoaded[i]) != resourcePathsToUnload.end())
221 resourcePathsLoaded.erase(resourcePathsLoaded.begin() + i);
222
223 for (int i = cachePathsLoaded.size()-1; i >= 0; --i)
224 if (find(cachePathsToUnload.begin(), cachePathsToUnload.end(), cachePathsLoaded[i]) != cachePathsToUnload.end())
225 cachePathsLoaded.erase(cachePathsLoaded.begin() + i);
226
227 vector<string> libraryPathsToUnload;
228
229 libraryPathsToUnload.insert(libraryPathsToUnload.end(), resourcePathsToUnload.rbegin(), resourcePathsToUnload.rend());
230
231 for (vector<string>::reverse_iterator i = resourcePathsLoaded.rbegin(); i != resourcePathsLoaded.rend(); ++i)
232 if (canUnloadPathLoaded[*i])
233 libraryPathsToUnload.push_back(*i);
234
235 libraryPathsToUnload.insert(libraryPathsToUnload.end(), cachePathsToUnload.rbegin(), cachePathsToUnload.rend());
236
237 for (vector<string>::reverse_iterator i = cachePathsLoaded.rbegin(); i != cachePathsLoaded.rend(); ++i)
238 if (canUnloadPathLoaded[*i])
239 libraryPathsToUnload.push_back(*i);
240
241 resourcePathsToUnload.clear();
242 cachePathsToUnload.clear();
243
244 return libraryPathsToUnload;
245}
246
251{
252 vector<string> libraryPathsLoaded;
253
254 for (vector<string>::iterator i = cachePathsLoaded.begin(); i != cachePathsLoaded.end(); ++i)
255 if (! canUnloadPathLoaded[*i])
256 libraryPathsLoaded.push_back(*i);
257
258 for (vector<string>::iterator i = resourcePathsLoaded.begin(); i != resourcePathsLoaded.end(); ++i)
259 if (! canUnloadPathLoaded[*i])
260 libraryPathsLoaded.push_back(*i);
261
262 return libraryPathsLoaded;
263}
264
269{
270 vector<string> libraryPathsLoaded;
271
272 for (vector<string>::iterator i = cachePathsLoaded.begin(); i != cachePathsLoaded.end(); ++i)
273 if (canUnloadPathLoaded[*i] && cachePathsToUnload.find(*i) == cachePathsToUnload.end())
274 libraryPathsLoaded.push_back(*i);
275
276 for (vector<string>::iterator i = resourcePathsLoaded.begin(); i != resourcePathsLoaded.end(); ++i)
277 if (canUnloadPathLoaded[*i] && resourcePathsToUnload.find(*i) == resourcePathsToUnload.end())
278 libraryPathsLoaded.push_back(*i);
279
280 return libraryPathsLoaded;
281}
282
287{
288 vector<string> unloadableResourcePathsLoaded;
289
290 for (vector<string>::iterator i = resourcePathsLoaded.begin(); i != resourcePathsLoaded.end(); ++i)
291 if (canUnloadPathLoaded[*i] && resourcePathsToUnload.find(*i) == resourcePathsToUnload.end())
292 unloadableResourcePathsLoaded.push_back(*i);
293
294 return unloadableResourcePathsLoaded;
295}
296
301{
302 vector<string> unloadableCachePathsLoaded;
303
304 for (vector<string>::iterator i = cachePathsLoaded.begin(); i != cachePathsLoaded.end(); ++i)
305 if (canUnloadPathLoaded[*i] && cachePathsToUnload.find(*i) == cachePathsToUnload.end())
306 unloadableCachePathsLoaded.push_back(*i);
307
308 return unloadableCachePathsLoaded;
309}
310
315{
316 set<string> dependenciesLoadedSet;
317
318 set<string> libraryPathsLoaded;
319 vector<string> nonUnloadable = getNonUnloadableLibrariesLoaded();
320 vector<string> unloadable = getUnloadableLibrariesLoaded();
321 libraryPathsLoaded.insert(nonUnloadable.begin(), nonUnloadable.end());
322 libraryPathsLoaded.insert(unloadable.begin(), unloadable.end());
323
324 for (set<string>::iterator i = libraryPathsLoaded.begin(); i != libraryPathsLoaded.end(); ++i)
325 {
326 map<string, set<string> >::iterator j = dependenciesLoaded.find(*i);
327 if (j != dependenciesLoaded.end())
328 dependenciesLoadedSet.insert(j->second.begin(), j->second.end());
329 }
330
331 return dependenciesLoadedSet;
332}
333
338{
339 return ! cachePathsToUnload.empty();
340}
341
347{
348 externalLibraries.insert(paths.begin(), paths.end());
349}
350
356{
357 externalFrameworks.insert(paths.begin(), paths.end());
358}
359
364{
365 return externalLibraries;
366}
367
372{
373 return externalFrameworks;
374}
375
381{
382 this->shouldDeleteResourceLibraries = shouldDeleteResourceLibraries;
383}