Vuo  2.3.2
VuoCompilerTriggerDescription.cc
Go to the documentation of this file.
1 
10 #include "VuoCompilerGraph.hh"
11 #include "VuoCompilerNode.hh"
14 #include "VuoNode.hh"
15 #include "VuoNodeClass.hh"
16 #include "VuoPort.hh"
17 #include "VuoType.hh"
18 #include "VuoStringUtilities.hh"
19 
23 VuoCompilerTriggerDescription::VuoCompilerTriggerDescription(void)
24 {
25  nodeIndex = ULONG_MAX - 1;
26  portContextIndex = -1;
27  eventThrottling = VuoPortClass::EventThrottling_Enqueue;
28  dataType = NULL;
29  minWorkerThreadsNeeded = -1;
30  minWorkerThreadsNeeded = -1;
31  chainCount = -1;
32 }
33 
38 {
39  size_t nodeIndex = triggerNode->getIndexInOrderedNodes();
40  string nodeIdentifier = triggerNode->getGraphvizIdentifier();
41  string nodeClassName = triggerNode->getBase()->getNodeClass()->getClassName();
42  string portName = trigger->getBase()->getClass()->getName();
43  int portContextIndex = trigger->getIndexInPortContexts();
44  VuoPortClass::EventThrottling eventThrottling = trigger->getBase()->getEventThrottling();
45  string eventThrottlingStr = (eventThrottling == VuoPortClass::EventThrottling_Drop ? "drop" : "enqueue");
46  VuoType *dataType = trigger->getDataVuoType();
47  string dataTypeStr = (dataType ? dataType->getModuleKey() : "event");
48  int minWorkerThreadsNeeded, maxWorkerThreadsNeeded;
49  graph->getWorkerThreadsNeeded(trigger, minWorkerThreadsNeeded, maxWorkerThreadsNeeded);
50  int chainCount = (int)graph->getChains()[trigger].size();
51 
52  json_object *js = json_object_new_object();
53 
54  json_object_object_add(js, "nodeIndex", json_object_new_int64(nodeIndex));
55  json_object_object_add(js, "nodeIdentifier", json_object_new_string(nodeIdentifier.c_str()));
56  json_object_object_add(js, "nodeClassName", json_object_new_string(nodeClassName.c_str()));
57  json_object_object_add(js, "portName", json_object_new_string(portName.c_str()));
58  json_object_object_add(js, "portContextIndex", json_object_new_int(portContextIndex));
59  json_object_object_add(js, "eventThrottling", json_object_new_string(eventThrottlingStr.c_str()));
60  json_object_object_add(js, "dataType", json_object_new_string(dataTypeStr.c_str()));
61  json_object_object_add(js, "minWorkerThreadsNeeded", json_object_new_int(minWorkerThreadsNeeded));
62  json_object_object_add(js, "maxWorkerThreadsNeeded", json_object_new_int(maxWorkerThreadsNeeded));
63  json_object_object_add(js, "chainCount", json_object_new_int(chainCount));
64 
65  return js;
66 }
67 
71 vector<VuoCompilerTriggerDescription *> VuoCompilerTriggerDescription::parseFromJson(json_object *js)
72 {
73  vector<VuoCompilerTriggerDescription *> triggers;
74 
75  int itemCount = json_object_array_length(js);
76  for (int i = 0; i < itemCount; ++i)
77  {
78  json_object *itemJs = json_object_array_get_idx(js, i);
79  json_object *o = NULL;
80 
82 
83  if (json_object_object_get_ex(itemJs, "nodeIndex", &o))
84  trigger->nodeIndex = json_object_get_int64(o);
85  if (json_object_object_get_ex(itemJs, "nodeIdentifier", &o))
86  trigger->nodeIdentifier = json_object_get_string(o);
87  if (json_object_object_get_ex(itemJs, "nodeClassName", &o))
88  trigger->nodeClassName = json_object_get_string(o);
89  if (json_object_object_get_ex(itemJs, "portName", &o))
90  trigger->portName = json_object_get_string(o);
91  if (json_object_object_get_ex(itemJs, "portContextIndex", &o))
92  trigger->portContextIndex = json_object_get_int(o);
93  if (json_object_object_get_ex(itemJs, "eventThrottling", &o))
94  {
95  string eventThrottlingStr = json_object_get_string(o);
96  trigger->eventThrottling = (eventThrottlingStr == "drop" ? VuoPortClass::EventThrottling_Drop : VuoPortClass::EventThrottling_Enqueue);
97  }
98  if (json_object_object_get_ex(itemJs, "dataType", &o))
99  {
100  string dataTypeStr = json_object_get_string(o);
101  trigger->dataType = (dataTypeStr == "event" ? NULL : new VuoType(dataTypeStr));
102  }
103  if (json_object_object_get_ex(itemJs, "minWorkerThreadsNeeded", &o))
104  trigger->minWorkerThreadsNeeded = json_object_get_int(o);
105  if (json_object_object_get_ex(itemJs, "maxWorkerThreadsNeeded", &o))
106  trigger->maxWorkerThreadsNeeded = json_object_get_int(o);
107  if (json_object_object_get_ex(itemJs, "chainCount", &o))
108  trigger->chainCount = json_object_get_int(o);
109  if (json_object_object_get_ex(itemJs, "subcompositionNodeClassName", &o))
110  trigger->subcompositionNodeClassName = json_object_get_string(o);
111  if (json_object_object_get_ex(itemJs, "subcompositionNodeIdentifier", &o))
112  trigger->subcompositionNodeIdentifier = json_object_get_string(o);
113 
114  triggers.push_back(trigger);
115  }
116 
117  return triggers;
118 }
119 
125 {
126  string eventThrottlingStr = (getEventThrottling() == VuoPortClass::EventThrottling_Drop ? "drop" : "enqueue");
127  string dataTypeStr = (dataType ? dataType->getModuleKey() : "event");
128  string subcompositionNodeClassNameStr = (subcompositionNodeClassName.empty() ?
129  subcompositionNode->getBase()->getNodeClass()->getClassName() : subcompositionNodeClassName);
130  string subcompositionNodeIdentifierStr = (subcompositionNodeIdentifier.empty() ?
131  subcompositionNode->getGraphvizIdentifier() :
132  VuoStringUtilities::buildCompositionIdentifier(subcompositionNode->getGraphvizIdentifier(), subcompositionNodeIdentifier));
133 
134  json_object *js = json_object_new_object();
135 
136  json_object_object_add(js, "nodeIndex", json_object_new_int64(nodeIndex));
137  json_object_object_add(js, "nodeIdentifier", json_object_new_string(nodeIdentifier.c_str()));
138  json_object_object_add(js, "nodeClassName", json_object_new_string(nodeClassName.c_str()));
139  json_object_object_add(js, "portName", json_object_new_string(portName.c_str()));
140  json_object_object_add(js, "portContextIndex", json_object_new_int(portContextIndex));
141  json_object_object_add(js, "eventThrottling", json_object_new_string(eventThrottlingStr.c_str()));
142  json_object_object_add(js, "dataType", json_object_new_string(dataTypeStr.c_str()));
143  json_object_object_add(js, "minWorkerThreadsNeeded", json_object_new_int(minWorkerThreadsNeeded));
144  json_object_object_add(js, "maxWorkerThreadsNeeded", json_object_new_int(maxWorkerThreadsNeeded));
145  json_object_object_add(js, "chainCount", json_object_new_int(chainCount));
146  json_object_object_add(js, "subcompositionNodeClassName", json_object_new_string(subcompositionNodeClassNameStr.c_str()));
147  json_object_object_add(js, "subcompositionNodeIdentifier", json_object_new_string(subcompositionNodeIdentifierStr.c_str()));
148 
149  return js;
150 }
151 
156 {
157  return nodeIndex;
158 }
159 
164 {
165  return nodeIdentifier;
166 }
167 
172 {
173  return nodeClassName;
174 }
175 
180 {
181  return portName;
182 }
183 
188 {
189  return portContextIndex;
190 }
191 
196 {
197  return eventThrottling;
198 }
199 
204 {
205  return dataType;
206 }
207 
212 {
213  this->dataType = dataType;
214 }
215 
222 void VuoCompilerTriggerDescription::getWorkerThreadsNeeded(int &minThreadsNeeded, int &maxThreadsNeeded)
223 {
224  minThreadsNeeded = this->minWorkerThreadsNeeded;
225  maxThreadsNeeded = this->maxWorkerThreadsNeeded;
226 }
227 
232 {
233  return chainCount;
234 }
235 
240 {
241  return subcompositionNodeClassName;
242 }
243 
248 {
249  return subcompositionNodeIdentifier;
250 }