Vuo  2.0.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 
37 void 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  isPathUnloadable[path] = isUnloadable;
45  dependenciesToLoad[path] = dependenciesInLibrary;
46  }
47 }
48 
55 void VuoRunningCompositionLibraries::enqueueCacheLibraryToLoad(const string &path, const set<string> &dependenciesInLibrary,
56  bool isUnloadable)
57 {
58  if (find(cachePathsLoaded.begin(), cachePathsLoaded.end(), path) == cachePathsLoaded.end() ||
59  find(cachePathsToUnload.begin(), cachePathsToUnload.end(), path) != cachePathsToUnload.end())
60  {
61  cachePathsToLoad.push_back(path);
62  isPathUnloadable[path] = isUnloadable;
63  dependenciesToLoad[path] = dependenciesInLibrary;
64  }
65 }
66 
71 {
72  for (map<string, set<string> >::iterator i = dependenciesLoaded.begin(); i != dependenciesLoaded.end(); ++i)
73  {
74  if (i->second.find(dependency) != i->second.end())
75  {
76  string libraryPath = i->first;
77 
78  if (! isPathUnloadable[libraryPath])
79  {
80  VUserLog("The library containing %s (%s) can't be unloaded.", dependency.c_str(), libraryPath.c_str());
81  break;
82  }
83 
84  if (find(resourcePathsLoaded.begin(), resourcePathsLoaded.end(), libraryPath) != resourcePathsLoaded.end())
85  resourcePathsToUnload.insert(libraryPath);
86  if (find(cachePathsLoaded.begin(), cachePathsLoaded.end(), libraryPath) != cachePathsLoaded.end())
87  cachePathsToUnload.insert(libraryPath);
88 
89  break;
90  }
91  }
92 }
93 
101 {
102  vector<string> libraryPathsToLoad;
103 
104  for (vector<string>::iterator i = cachePathsLoaded.begin(); i != cachePathsLoaded.end(); ++i)
105  if (isPathUnloadable[*i])
106  libraryPathsToLoad.push_back(*i);
107 
108  libraryPathsToLoad.insert(libraryPathsToLoad.end(), cachePathsToLoad.begin(), cachePathsToLoad.end());
109 
110  for (vector<string>::iterator i = resourcePathsLoaded.begin(); i != resourcePathsLoaded.end(); ++i)
111  if (isPathUnloadable[*i])
112  libraryPathsToLoad.push_back(*i);
113 
114  libraryPathsToLoad.insert(libraryPathsToLoad.end(), resourcePathsToLoad.begin(), resourcePathsToLoad.end());
115 
116  resourcePathsLoaded.insert(resourcePathsLoaded.end(), resourcePathsToLoad.begin(), resourcePathsToLoad.end());
117  resourcePathsToLoad.clear();
118 
119  cachePathsLoaded.insert(cachePathsLoaded.end(), cachePathsToLoad.begin(), cachePathsToLoad.end());
120  cachePathsToLoad.clear();
121 
122  dependenciesLoaded.insert(dependenciesToLoad.begin(), dependenciesToLoad.end());
123  dependenciesToLoad.clear();
124 
125  return libraryPathsToLoad;
126 }
127 
136 {
137  for (set<string>::iterator i = resourcePathsToUnload.begin(); i != resourcePathsToUnload.end(); ++i)
138  {
139  dependenciesLoaded.erase(*i);
140  isPathUnloadable.erase(*i);
141 
142  if (shouldDeleteResourceLibraries)
144  }
145 
146  for (int i = resourcePathsLoaded.size()-1; i >= 0; --i)
147  if (find(resourcePathsToUnload.begin(), resourcePathsToUnload.end(), resourcePathsLoaded[i]) != resourcePathsToUnload.end())
148  resourcePathsLoaded.erase(resourcePathsLoaded.begin() + i);
149 
150  for (int i = cachePathsLoaded.size()-1; i >= 0; --i)
151  if (find(cachePathsToUnload.begin(), cachePathsToUnload.end(), cachePathsLoaded[i]) != cachePathsToUnload.end())
152  cachePathsLoaded.erase(cachePathsLoaded.begin() + i);
153 
154  vector<string> libraryPathsToUnload;
155 
156  libraryPathsToUnload.insert(libraryPathsToUnload.end(), resourcePathsToUnload.rbegin(), resourcePathsToUnload.rend());
157 
158  for (vector<string>::reverse_iterator i = resourcePathsLoaded.rbegin(); i != resourcePathsLoaded.rend(); ++i)
159  if (isPathUnloadable[*i])
160  libraryPathsToUnload.push_back(*i);
161 
162  libraryPathsToUnload.insert(libraryPathsToUnload.end(), cachePathsToUnload.rbegin(), cachePathsToUnload.rend());
163 
164  for (vector<string>::reverse_iterator i = cachePathsLoaded.rbegin(); i != cachePathsLoaded.rend(); ++i)
165  if (isPathUnloadable[*i])
166  libraryPathsToUnload.push_back(*i);
167 
168  resourcePathsToUnload.clear();
169  cachePathsToUnload.clear();
170 
171  return libraryPathsToUnload;
172 }
173 
178 {
179  vector<string> libraryPathsLoaded;
180 
181  for (vector<string>::iterator i = cachePathsLoaded.begin(); i != cachePathsLoaded.end(); ++i)
182  if (! isPathUnloadable[*i])
183  libraryPathsLoaded.push_back(*i);
184 
185  for (vector<string>::iterator i = resourcePathsLoaded.begin(); i != resourcePathsLoaded.end(); ++i)
186  if (! isPathUnloadable[*i])
187  libraryPathsLoaded.push_back(*i);
188 
189  return libraryPathsLoaded;
190 }
191 
196 {
197  vector<string> libraryPathsLoaded;
198 
199  for (vector<string>::iterator i = cachePathsLoaded.begin(); i != cachePathsLoaded.end(); ++i)
200  if (isPathUnloadable[*i] && cachePathsToUnload.find(*i) == cachePathsToUnload.end())
201  libraryPathsLoaded.push_back(*i);
202 
203  for (vector<string>::iterator i = resourcePathsLoaded.begin(); i != resourcePathsLoaded.end(); ++i)
204  if (isPathUnloadable[*i] && resourcePathsToUnload.find(*i) == resourcePathsToUnload.end())
205  libraryPathsLoaded.push_back(*i);
206 
207  return libraryPathsLoaded;
208 }
209 
214 {
215  set<string> dependenciesLoadedSet;
216 
217  set<string> libraryPathsLoaded;
218  vector<string> nonUnloadable = getNonUnloadableLibrariesLoaded();
219  vector<string> unloadable = getUnloadableLibrariesLoaded();
220  libraryPathsLoaded.insert(nonUnloadable.begin(), nonUnloadable.end());
221  libraryPathsLoaded.insert(unloadable.begin(), unloadable.end());
222 
223  for (set<string>::iterator i = libraryPathsLoaded.begin(); i != libraryPathsLoaded.end(); ++i)
224  {
225  map<string, set<string> >::iterator j = dependenciesLoaded.find(*i);
226  if (j != dependenciesLoaded.end())
227  dependenciesLoadedSet.insert(j->second.begin(), j->second.end());
228  }
229 
230  return dependenciesLoadedSet;
231 }
232 
238 {
239  externalLibraries.insert(paths.begin(), paths.end());
240 }
241 
247 {
248  externalFrameworks.insert(paths.begin(), paths.end());
249 }
250 
255 {
256  return externalLibraries;
257 }
258 
263 {
264  return externalFrameworks;
265 }
266 
271 void VuoRunningCompositionLibraries::setDeleteResourceLibraries(bool shouldDeleteResourceLibraries)
272 {
273  this->shouldDeleteResourceLibraries = shouldDeleteResourceLibraries;
274 }