Exemple #1
0
Symbol COMPONENT_CLASS_CPP::event(Event* event)
{
	switch(event->type)
	{
		case EVENT_STATE_SET:
		{
			//	extract DataML
			EventStateSet* data = (EventStateSet*) event->data;
			XMLNode xmlNode(data->state);
			DataMLNode nodeState(&xmlNode);

			//	ok
			return C_OK;
		}

		case EVENT_INIT_CONNECT:
		{
			//	create output
			outputA.setName("adjacent");
			outputA.create(hComponent);
			outputA.setStructure(TYPE_DOUBLE | TYPE_COMPLEX | TYPE_CPXFMT_ADJACENT, Dims(2, 3).cdims());

			//	create output
			outputI.setName("interleaved");
			outputI.create(hComponent);
			outputI.setStructure(TYPE_DOUBLE | TYPE_COMPLEX | TYPE_CPXFMT_INTERLEAVED, Dims(2, 3).cdims());

			//	ok
			return C_OK;
		}

		case EVENT_RUN_SERVICE:
		{
			//	access output
			DOUBLE* pA = (DOUBLE*) outputA.getContent();
			DOUBLE* pI = (DOUBLE*) outputI.getContent();

			//	put incrementing numbers in
			UINT32 sz = 6;
			for (UINT32 i=0; i<sz; i++)
			{
				DOUBLE valR = i;
				DOUBLE valI = i + sz;

				pA[i] = valR;
				pA[i+sz] = valI;

				pI[i*2] = valR;
				pI[i*2+1] = valI;
			}

			//	ok
			return C_OK;
		}

	}

	//	not serviced
	return S_NULL;
}
TiXmlElement Converter::ProcessNode(BMessage *node)
{
	int32			i = 0;
	void			*tmpNode		= NULL;
	void			*fromNode		= NULL;
	void			*toNode			= NULL;
	BMessage		*connection		= NULL;
	BMessage		*data			= new BMessage();
	BMessage		*attrib			= new BMessage();

	bool			found			= false;
	char			*name			= NULL;

	TiXmlElement	xmlNode("node");
	node->FindPointer("this", &tmpNode);
	//add this node to the processed List
	processedIDs.insert((int32)tmpNode);
	//find the data field where name and attributes are stored
	node->FindMessage("Node::Data",data);
	data->FindString("Name",(const char **)&name);

	xmlNode.SetAttribute("ID",(int32)tmpNode);
	xmlNode.SetAttribute("TEXT",(const char *)name);
	//add all Attributes
	type_code	type	= 0;
	int32		count	= 0;
	#ifdef B_ZETA_VERSION_1_0_0
		while (data->GetInfo(B_MESSAGE_TYPE,i ,(const char **)&name, &type, &count) == B_OK)
	#else
		while (data->GetInfo(B_MESSAGE_TYPE,i ,(char **)&name, &type, &count) == B_OK)
	#endif
	{
		if ( (data->FindMessage(name,count-1,attrib) == B_OK) && (attrib) )
		{
			char *attribName	= NULL;
			char *value			= NULL;
			attrib->FindString("Name",(const char **)&attribName);
			attrib->FindString("Value",(const char **)&value);
			//**need to hanlde bool
			TiXmlElement	xmlAttrib("attribute");
			xmlAttrib.SetAttribute("NAME",attribName);
			if(value)
				xmlAttrib.SetAttribute("VALUE",value);
			xmlNode.InsertEndChild(xmlAttrib);
		}
		i++;
	}
	//find all outgoing connections
	map<int32,BMessage*>::iterator iter;
	iter = connections.begin();
	while (iter!=connections.end())
	{
		connection=(*iter).second;
		connection->FindPointer("Node::from",&fromNode);
		connection->FindPointer("Node::to", &toNode);
		if ((fromNode == tmpNode) && (processedIDs.find((*iter).first) == processedIDs.end()))
		{
			//check if the node was already insert if so we "connect via a arrowlink
			if (processedIDs.find((int32)toNode) != processedIDs.end())
			{
				TiXmlElement	xmlLink("arrowlink");
				xmlLink.SetAttribute("ID",(*iter).first);
				xmlLink.SetAttribute("DESTINATION",(int32)toNode);
				xmlNode.InsertEndChild(xmlLink);
				processedIDs.insert((*iter).first);
			}
			else
			{
				map<int32,BMessage*>::iterator	found;
				found = nodes.find((int32)toNode);
				if (found!=nodes.end())
				{
					processedIDs.insert((*iter).first);
					xmlNode.InsertEndChild(ProcessNode((*found).second));
				}
			}
		}
		else if ((toNode == tmpNode) && (processedIDs.find((*iter).first)==processedIDs.end()))
		{
			//check if the node was already insert if so we "connect via a arrowlink
			if (processedIDs.find((int32)fromNode)!=processedIDs.end())
			{
				TiXmlElement	xmlLink("arrowlink");
				xmlLink.SetAttribute("ID",(*iter).first);
				xmlLink.SetAttribute("DESTINATION",(int32)fromNode);
				xmlNode.InsertEndChild(xmlLink);
			}
		}
		iter++;
	}
	return xmlNode;
}
Exemple #3
0
Symbol COMPONENT_CLASS_CPP::event(Event* event)
{
	switch(event->type)
	{
		case EVENT_STATE_SET:
		{
			//	extract DataML
			EventStateSet* data = (EventStateSet*) event->data;
			XMLNode xmlNode(data->state);
			DataMLNode nodeState(&xmlNode);

			//	ok
			return C_OK;
		}

		case EVENT_INIT_CONNECT:
		{
			//	on first call
			if (event->flags & F_FIRST_CALL)
			{
				//	create output
				output.setName("out");
				output.create(hComponent);
				output.setStructure(TYPE_DOUBLE | TYPE_REAL, Dims(1).cdims());
			}

			//	on last call
			if (event->flags & F_LAST_CALL)
			{
				//	validate input
				inputs.resize(iif.getNumberOfPorts());
				for (UINT32 i=0; i<inputs.size(); i++)
				{
					inputs[i].attach(hComponent, i);
					inputs[i].validateStructure(TYPE_DOUBLE | TYPE_REAL, Dims(1).cdims());
				}
			}

			//	ok
			return C_OK;
		}

		case EVENT_RUN_SERVICE:
		{
			//	access output
			DOUBLE* out = (DOUBLE*) output.getContent();
			*out = 0.0;

			//	access inputs
			for (UINT32 i=0; i<inputs.size(); i++)
			{
				DOUBLE* in = (DOUBLE*) inputs[i].getContent();
				*out += *in;
			}

			//	ok
			return C_OK;
		}

	}

	//	if we service the event, we return C_OK
	//	if we don't, we should return S_NULL to indicate that
	return S_NULL;
}