コード例 #1
0
ファイル: bml_event.cpp プロジェクト: gsi-upm/SmartSim
BehaviorRequestPtr BML::parse_bml_event( DOMElement* elem, const std::string& unique_id, BehaviorSyncPoints& behav_syncs, bool required, BmlRequestPtr request, SmartBody::SBScene* scene ) {

    const XMLCh* tag      = elem->getTagName();

	// message (the event behavior) can be retrieved either via the attribute, or via the text content.
	std::string msg  = xml_parse_string( BMLDefs::ATTR_MESSAGE, elem, "");	

	std::string spNameOld = xml_parse_string( BMLDefs::ATTR_STROKE, elem, ""); // if 'stroke' is used, assume old-style command sent via VHMSG	
	std::string spNameNew = xml_parse_string( BMLDefs::ATTR_START, elem, ""); // if 'start' is used, assume Python style internally only
	std::string localId  = xml_parse_string( BMLDefs::ATTR_ID, elem, "");

	DOMNode* child = elem->getFirstChild();
	while (child)
	{
		DOMNode::NodeType type = child->getNodeType();
		if (type == DOMNode::CDATA_SECTION_NODE)
		{
			child->normalize();
			DOMText* textNode = dynamic_cast<DOMText*>(child);
			const XMLCh* messageData = textNode->getNodeValue();
			msg = xml_utils::xml_translate_string(messageData);

			break;
		}
	
		child = child->getNextSibling();
	}

	if (msg != "" )
	{	
		if (spNameNew.size() > 0)
		{
			// new style event sent via Python
			return BehaviorRequestPtr( new EventRequest( unique_id, localId, "", msg, behav_syncs, spNameNew ) );
		}
		else
		{
			// old style command send via vhmsg
			return BehaviorRequestPtr( new EventRequest( unique_id, localId, msg, "", behav_syncs, spNameOld ) );
		}
	} 
	else
	{
		xml_parse_error( BMLDefs::ATTR_MESSAGE, elem );
		return BehaviorRequestPtr();  // a.k.a., NULL
	}
}