Ejemplo n.º 1
0
bool PacketUtility::getStrings(const SingleAcknowledge& singleAck, vector<string>& values)
{
	bool success = false;
	values.clear();
	for (int i = 0; i < singleAck.parameter_size(); i++)
	{
		if (singleAck.parameter(i).type() == AnyParameter::P_STRING)
		{
			values.push_back(singleAck.parameter(i).p_string());
			success = true;
		}
	}
	return success;
}
Ejemplo n.º 2
0
bool PacketUtility::getValues(const SingleAcknowledge& singleAck)
{
	bool formatIsCorrect = true;
	if (singleAck.parameter_size() != this->_params.size())
		formatIsCorrect =  false;

	// Check return types.
	if (formatIsCorrect)
	{
		for (unsigned int i = 0; i < this->_params.size(); i++)
		{
			if (singleAck.parameter(i).type() != this->_params[i].get<0>())
			{
				formatIsCorrect = false;
				break;
			}
		}
	}

	// Everything checks out, get values.
	if (formatIsCorrect)
	{	
		for (int i = 0; i < singleAck.parameter_size(); i++)
		{
			switch (singleAck.parameter(i).type())
			{
				case AnyParameter::P_INT:
				 (*reinterpret_cast<int*>(this->_params[i].get<1>())) = singleAck.parameter(i).p_int();
				 break;
				case AnyParameter::P_BOOL:
				 (*reinterpret_cast<bool*>(this->_params[i].get<1>())) = singleAck.parameter(i).p_bool();
				 break;
				case AnyParameter::P_FLOAT:
				 (*reinterpret_cast<float*>(this->_params[i].get<1>())) = singleAck.parameter(i).p_float();
				 break;
				case AnyParameter::P_STRING:
				  (*reinterpret_cast<string*>(this->_params[i].get<1>())) = singleAck.parameter(i).p_string();
				  break;
				default: // not implemented
				 return false;
			}
		}
	}
	if (!this->persistent) this->clear();
	return true;
}
Ejemplo n.º 3
0
bool PropertyHelper::Parse(DEPacket& pkt)
{
	_min = _max = 0;
	_values.clear();

	SingleAcknowledge ack = pkt.acknowledge(0);
	if (ack.parameter_size() == 0) return false;
	
	if (string("property").compare(ack.parameter(0).name()) != 0 ||
		ack.parameter(0).type() != AnyParameter::P_STRING)
		return false;

	string property_type = ack.parameter(0).p_string();
	if( property_type.compare("string")==0 )
		this->_property = String; 
	else if( property_type.compare("float")==0 )
		this->_property = Float; 
	else if( property_type.compare("int")==0 )
		this->_property = Integer; 
	else
		return false;

	if (string("type").compare(ack.parameter(1).name()) != 0 ||
		ack.parameter(1).type() != AnyParameter::P_STRING)
		return false;	

	string property_allowable_type = ack.parameter(1).p_string();

	if (property_allowable_type.compare("range") == 0)
	{
		switch (this->_property) {
		case Float:
			this->_type = Range;
			if (ack.parameter_size() == 4 &&
				ack.parameter(2).type() == AnyParameter::P_FLOAT &&
				ack.parameter(3).type() == AnyParameter::P_FLOAT)
			{
				this->_min = ack.parameter(2).p_float();
				this->_max = ack.parameter(3).p_float();
			}
			break;
		case Integer:
			this->_type = Range;
			if (ack.parameter_size() == 4 &&
				ack.parameter(2).type() == AnyParameter::P_INT &&
				ack.parameter(3).type() == AnyParameter::P_INT)
			{
				this->_min = (double)ack.parameter(2).p_int();
				this->_max = (double)ack.parameter(3).p_int();
			}
			break;
		default: 
			return false;
		}
	}
	else if (property_allowable_type.compare("set") == 0)
	{
		this->_type = Set;
		for (int i = 2; i < ack.parameter_size(); i++)
		{
			if (ack.parameter(i).type() == AnyParameter::P_STRING)
			{
				this->_values.push_back(ack.parameter(i).p_string());
			}
		}
	}
	else if (property_allowable_type.compare("allow_all") == 0)
	{
		this->_type = Allow_All;
	}
	else if (property_allowable_type.compare("ReadOnly") == 0)
	{
		this->_type = ReadOnly;
	}
	else 
		return false;

	return true;
}