Vuo  2.3.2
VuoModuleCompiler.cc
Go to the documentation of this file.
1 
10 #include "VuoModuleCompiler.hh"
11 
12 #include <dlfcn.h>
13 
17 map<string, VuoModuleCompiler::Factory> *VuoModuleCompiler::factories;
18 
22 void __attribute__((constructor)) VuoModuleCompiler::init()
23 {
24  factories = new map<string, VuoModuleCompiler::Factory>;
25 
26  auto modules = VuoFileUtilities::findFilesInDirectory(VuoFileUtilities::getVuoFrameworkPath() + "/Helpers/ModuleCompiler", set<string>{"dylib"});
27  for (auto module : modules)
28  dlopen(module->path().c_str(), RTLD_NOW);
29 }
30 
37 {
38  auto existingFactory = factories->find(type);
39  if (existingFactory != factories->end())
40  {
41  VUserLog("Error: A VuoModuleCompiler for type '%s' is already registered. Ignoring the duplicate.", type.c_str());
42  return;
43  }
44 
45  (*factories)[type] = factory;
46 }
47 
51 VuoModuleCompiler *VuoModuleCompiler::newModuleCompiler(string type, const string &moduleKey, VuoFileUtilities::File *sourceFile)
52 {
53  auto factory = factories->find(type);
54  if (factory == factories->end())
55  {
56  VUserLog("Error creating compiler for '%s': Couldn't find a VuoModuleCompiler for type '%s'.", moduleKey.c_str(), type.c_str());
57  return NULL;
58  }
59 
60  return factory->second(moduleKey, sourceFile);
61 }
62 
63 VuoModuleCompiler::~VuoModuleCompiler(void)
64 {
65 }