18 vector<VuoProtocol *> VuoProtocol::protocols;
32 imageFilterProtocol->
addOutputPort(
"outputImage",
"VuoImage");
33 protocols.push_back(imageFilterProtocol);
37 imageGeneratorProtocol->
addInputPort(
"width",
"VuoInteger");
38 imageGeneratorProtocol->
addInputPort(
"height",
"VuoInteger");
39 imageGeneratorProtocol->
addOutputPort(
"outputImage",
"VuoImage");
40 protocols.push_back(imageGeneratorProtocol);
43 imageTransitionProtocol->
addInputPort(
"time",
"VuoReal");
44 imageTransitionProtocol->
addInputPort(
"progress",
"VuoReal");
45 imageTransitionProtocol->
addInputPort(
"startImage",
"VuoImage");
46 imageTransitionProtocol->
addInputPort(
"endImage",
"VuoImage");
47 imageTransitionProtocol->
addOutputPort(
"outputImage",
"VuoImage");
48 protocols.push_back(imageTransitionProtocol);
61 for (vector<VuoProtocol *>::iterator it = protocols.begin(); it != protocols.end(); ++it)
62 if ((*it)->getId() ==
id)
65 VUserLog(
"Error: Couldn't find protocol '%s'.",
id.c_str());
79 this->name = protocolName;
104 return inputPortNamesAndTypes;
113 return outputPortNamesAndTypes;
121 for (vector<pair<string, string> >::iterator i = inputPortNamesAndTypes.begin(); i != inputPortNamesAndTypes.end(); ++i)
123 string currentPortName = i->first;
124 if (currentPortName == portName)
136 for (vector<pair<string, string> >::iterator i = outputPortNamesAndTypes.begin(); i != outputPortNamesAndTypes.end(); ++i)
138 string currentPortName = i->first;
139 if (currentPortName == portName)
151 for (vector<pair<string, string> >::iterator i = inputPortNamesAndTypes.begin(); i != inputPortNamesAndTypes.end(); ++i)
153 string currentPortName = i->first;
154 string currentPortType = i->second;
155 if (currentPortName == portName)
156 return currentPortType;
159 VUserLog(
"Error: Protocol '%s' has no input port with name '%s'.", this->name.c_str(), portName.c_str());
168 for (vector<pair<string, string> >::iterator i = outputPortNamesAndTypes.begin(); i != outputPortNamesAndTypes.end(); ++i)
170 string currentPortName = i->first;
171 string currentPortType = i->second;
172 if (currentPortName == portName)
173 return currentPortType;
176 VUserLog(
"Error: Protocol '%s' has no output port with name '%s'.", this->name.c_str(), portName.c_str());
190 __block
int charNum = 0;
191 bool (^getNextLine)(
string &linenumber) = ^(
string &linenumber){
195 char c = compositionAsString[charNum++];
206 string (^getLabel)(
string linenumber) = ^(
string linenumber){
207 string labelToken =
"label=\"";
208 string::size_type labelLocation = linenumber.find(labelToken);
209 if (labelLocation == string::npos)
212 labelLocation += labelToken.length();
214 while (labelLocation < linenumber.length() && linenumber[labelLocation] !=
'"')
215 label += linenumber[labelLocation++];
221 bool (^getNextPort)(
string &label,
string &portID) = ^(
string &label,
string &portID){
223 string portToken =
"|<";
224 string::size_type portLocation = label.find(portToken);
225 if (portLocation == string::npos)
228 portLocation += portToken.length();
229 while (portLocation < label.length() && label[portLocation] !=
'>')
230 portID += label[portLocation++];
232 label = label.substr(portLocation);
238 string (^getType)(
string linenumber,
string portID) = ^(
string linenumber,
string portID){
239 string typeToken =
"_" + portID +
"_type=\"";
240 string::size_type typeLocation = linenumber.find(typeToken);
241 if (typeLocation == string::npos)
244 typeLocation += typeToken.length();
246 while (typeLocation < linenumber.length() && linenumber[typeLocation] !=
'"')
247 type += linenumber[typeLocation++];
254 map<string,string> publishedInputs;
255 map<string,string> publishedOutputs;
257 while (getNextLine(linenumber))
261 bool isPublishedInputs =
false;
262 bool isPublishedOutputs =
false;
264 isPublishedInputs =
true;
266 isPublishedOutputs =
true;
268 if (!isPublishedInputs && !isPublishedOutputs)
271 string label = getLabel(linenumber);
276 while (getNextPort(label, portID))
278 if (isPublishedInputs)
279 publishedInputs[portID] = getType(linenumber, portID);
281 publishedOutputs[portID] = getType(linenumber, portID);
288 for (vector<pair<string, string> >::iterator i = protocolInputs.begin(); i != protocolInputs.end(); ++i)
290 string protocolInputName = i->first;
291 string protocolInputType = i->second;
293 map<string,string>::iterator publishedInput = publishedInputs.find(protocolInputName);
294 if (publishedInput == publishedInputs.end() || publishedInput->second != protocolInputType)
300 for (vector<pair<string, string> >::iterator i = protocolOutputs.begin(); i != protocolOutputs.end(); ++i)
302 string protocolOutputName = i->first;
303 string protocolOutputType = i->second;
305 map<string,string>::iterator publishedOutput = publishedOutputs.find(protocolOutputName);
306 if (publishedOutput == publishedOutputs.end() || publishedOutput->second != protocolOutputType)
321 for (vector<pair<string, string> >::iterator i = protocolInputs.begin(); i != protocolInputs.end(); ++i)
323 string protocolInputName = i->first;
324 string protocolInputType = i->second;
327 for (vector<VuoRunner::Port *>::iterator it = inputs.begin(); it != inputs.end(); ++it)
328 if ((*it)->getName() == protocolInputName
329 && (*it)->getType() == protocolInputType)
341 for (vector<pair<string, string> >::iterator i = protocolOutputs.begin(); i != protocolOutputs.end(); ++i)
343 string protocolOutputName = i->first;
344 string protocolOutputType = i->second;
347 for (vector<VuoRunner::Port *>::iterator it = outputs.begin(); it != outputs.end(); ++it)
348 if ((*it)->getName() == protocolOutputName
349 && (*it)->getType() == protocolOutputType)
367 vector<VuoProtocol *> adheresToProtocols;
368 for (vector<VuoProtocol *>::iterator i = allProtocols.begin(); i != allProtocols.end(); ++i)
369 if ((*i)->isCompositionCompliant(compositionAsString))
370 adheresToProtocols.push_back(*i);
371 return adheresToProtocols;
380 vector<VuoProtocol *> adheresToProtocols;
381 for (vector<VuoProtocol *>::iterator i = allProtocols.begin(); i != allProtocols.end(); ++i)
382 if ((*i)->isCompositionCompliant(runner))
383 adheresToProtocols.push_back(*i);
384 return adheresToProtocols;
395 pair<string, string> portNameAndType = make_pair(portName, portType);
397 for (vector<pair<string, string> >::iterator i = inputPortNamesAndTypes.begin(); i != inputPortNamesAndTypes.end(); ++i)
399 string currentPortName = i->first;
400 if (currentPortName == portName)
402 VUserLog(
"Error: Protocol '%s' already had an input port with name '%s'.", this->name.c_str(), portName.c_str());
407 inputPortNamesAndTypes.push_back(portNameAndType);
418 pair<string, string> portNameAndType = make_pair(portName, portType);
420 for (vector<pair<string, string> >::iterator i = outputPortNamesAndTypes.begin(); i != outputPortNamesAndTypes.end(); ++i)
422 string currentPortName = i->first;
423 if (currentPortName == portName)
425 VUserLog(
"Error: Protocol '%s' already had an output port with name '%s'.", this->name.c_str(), portName.c_str());
430 outputPortNamesAndTypes.push_back(portNameAndType);