Vuo  2.0.1
VuoInputEditorWithEnumMenu.cc
Go to the documentation of this file.
1 
11 
12 #include <dlfcn.h>
13 
20 {
21  this->type = type;
22 }
23 
28 {
29  VuoInputEditorMenuItem *rootMenuItem = new VuoInputEditorMenuItem("root");
30 
31  QString allowedValuesFunctionName = this->type + "_getAllowedValues";
32  typedef void *(*allowedValuesFunctionType)(void);
33  allowedValuesFunctionType allowedValuesFunction = (allowedValuesFunctionType)dlsym(RTLD_DEFAULT, allowedValuesFunctionName.toUtf8().constData());
34 
35  QString summaryFunctionName = this->type + "_getSummary";
36  typedef char *(*summaryFunctionType)(int64_t);
37  summaryFunctionType summaryFunction = (summaryFunctionType)dlsym(RTLD_DEFAULT, summaryFunctionName.toUtf8().constData());
38 
39  QString jsonFunctionName = this->type + "_getJson";
40  typedef json_object *(*jsonFunctionType)(int64_t);
41  jsonFunctionType jsonFunction = (jsonFunctionType)dlsym(RTLD_DEFAULT, jsonFunctionName.toUtf8().constData());
42 
43  QString listCountFunctionName = "VuoListGetCount_" + this->type;
44  typedef unsigned long (*listCountFunctionType)(void *);
45  listCountFunctionType listCountFunction = (listCountFunctionType)dlsym(RTLD_DEFAULT, listCountFunctionName.toUtf8().constData());
46 
47  QString listValueFunctionName = "VuoListGetValue_" + this->type;
48  typedef int64_t (*listValueFunctionType)(void *, unsigned long);
49  listValueFunctionType listValueFunction = (listValueFunctionType)dlsym(RTLD_DEFAULT, listValueFunctionName.toUtf8().constData());
50 
51  if (allowedValuesFunction && summaryFunction && jsonFunction && listCountFunction && listValueFunction)
52  {
53  void *allowedValues = allowedValuesFunction();
54  unsigned long count = listCountFunction(allowedValues);
55  for (unsigned long i=1; i<=count; ++i)
56  {
57  int64_t value = listValueFunction(allowedValues, i);
58  json_object *valueJson = jsonFunction(value);
59  if (!shouldIncludeValue(valueJson))
60  continue;
61 
62  char *summary = summaryFunction(value);
63  rootMenuItem->addItem(new VuoInputEditorMenuItem(summary, valueJson));
64  free(summary);
65  }
66  }
67 
68  return rootMenuItem;
69 }