Vuo 2.4.4
Loading...
Searching...
No Matches
VuoInputEditorManager.cc
Go to the documentation of this file.
1
13#include "VuoFileUtilities.hh"
14#include "VuoType.hh"
15
16#include <dlfcn.h>
17
21VuoInputEditorManager::VuoInputEditorManager(QList<QDir> extraPluginDirectories)
22{
23 initialization.lock();
24 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
25 QList<QDir> pluginDirectories;
26 pluginDirectories += QCoreApplication::applicationDirPath() + "/../Resources/InputEditors";
27 pluginDirectories += QString::fromUtf8(VuoFileUtilities::getSystemModulesPath().c_str());
28 pluginDirectories += QString::fromUtf8(VuoFileUtilities::getUserModulesPath().c_str());
29 pluginDirectories += extraPluginDirectories;
30
31 foreach (QDir pluginDirectory, pluginDirectories)
32 {
33 foreach (QString pluginFileName, pluginDirectory.entryList(QDir::Files))
34 {
35 QPluginLoader loader(pluginDirectory.absoluteFilePath(pluginFileName));
36 QObject *plugin = loader.instance();
37 if (plugin)
38 {
39 VuoInputEditorFactory *inputEditorFactory = qobject_cast<VuoInputEditorFactory *>(plugin);
40 plugins[loader.metaData().value("MetaData").toObject().value("type").toString()] = inputEditorFactory;
41 }
42 }
43 }
44 initialization.unlock();
45 });
46}
47
52{
53 while (!initialization.try_lock())
54 {
55 // Allow plugins to execute code on the main thread.
56 QApplication::processEvents();
57 usleep(USEC_PER_SEC/10);
58 }
59}
60
67{
68 if (!type)
69 return NULL;
70
71 json_object *menuItemsValue = NULL;
72 if (type->getModuleKey() == "VuoInteger" && details && json_object_object_get_ex(details, "menuItems", &menuItemsValue))
73 return new VuoInputEditorNamedEnum();
74
75 VuoInputEditorFactory *inputEditorFactory = plugins[type->getModuleKey().c_str()];
76
77 if (!inputEditorFactory)
78 {
79 // There's no explicitly-defined input editor for this type — but if it's an enum type, we can provide the standard enum input editor.
80 string allowedValuesFunctionName = type->getModuleKey() + "_getAllowedValues";
81 if (dlsym(RTLD_SELF, allowedValuesFunctionName.c_str()))
82 return new VuoInputEditorWithEnumMenu(type->getModuleKey().c_str());
83
84 return NULL;
85 }
86
87 return inputEditorFactory->newInputEditor();
88}
89
99{
100 if (!type)
101 return false;
102
103 VuoInputEditor *inputEditorLoadedForPortDataType = newInputEditor(type);
104 if (inputEditorLoadedForPortDataType)
105 {
106 inputEditorLoadedForPortDataType->deleteLater();
107 return true;
108 }
109
110 return false;
111}