// Local function to put a different state for this resource
int oicapp_client_put(int power , int level)
{
    std::shared_ptr< OCResource > resource = g_curResource;

    retv_if(NULL == g_curResource , -1);

    DBG("Putting light representation...");

    AttributeMap attributeMap;

    AttributeValues tempVal;
    AttributeValues humidVal;

    tempVal.push_back(to_string(power));
    humidVal.push_back(to_string(level));

    attributeMap["temp"] = tempVal;
    attributeMap["humid"] = humidVal;

    // Create QueryParameters Map and add query params (if any)
    QueryParamsMap queryParamsMap;

    OCRepresentation rep;
    rep.setAttributeMap(attributeMap);

    // Invoke resource's pit API with attribute map, query map and the callback parameter
    resource->put(rep , queryParamsMap , &onPut);

    return 0;
}
Ejemplo n.º 2
0
void*
ProgramValue::getValues (void) {

	AttributeValues *attr = NULL;
	if (m_Context != "CURRENT") {
//	if (m_TypeString != "CURRENT") {
		attr = NAU->getObjectAttributes(m_TypeString, m_Context, m_Id);
	}
	else {
		attr = NAU->getCurrentObjectAttributes(m_TypeString, m_Id);
	}

	if (attr != NULL) {
		m_Values = attr->getProp(m_ValueOf, m_ValueType);
	}
	// otherwise m_Values will have the default value
	return m_Values;
}
Ejemplo n.º 3
0
void *
Nau::getAttributeValue(std::string type, std::string context, std::string component, int number) {

	int id;
	Enums::DataType dt;
	AttributeValues *attrVal;

	if (context != "CURRENT") {
		attrVal = NAU->getObjectAttributes(type, context, number);
		m_Attributes[type]->getPropTypeAndId(component, &dt, &id);
	}
	else {
		attrVal = NAU->getCurrentObjectAttributes(type, number);
		m_Attributes[type]->getPropTypeAndId(component, &dt, &id);
	}

	if (attrVal == NULL || id == -1) {
		NAU_THROW("Getting an invalid Attribute\ntype: %s\ncontext: %s\ncomponent: %s", 
			type.c_str(), context.c_str(), component.c_str());
	}
	else
		return attrVal->getProp(id, dt);
}
Ejemplo n.º 4
0
bool 
Nau::setAttributeValue(std::string type, std::string context, std::string component, int number, Data *values) {

	int id;
	Enums::DataType dt; 
	AttributeValues *attrVal;

	if (context != "CURRENT") {
		m_Attributes[type]->getPropTypeAndId(component, &dt, &id);
		attrVal = NAU->getObjectAttributes(type, context, number);
	}
	else {
		m_Attributes[type]->getPropTypeAndId(component, &dt, &id);
		attrVal = NAU->getCurrentObjectAttributes(type, number);
	}

	if (attrVal == NULL || id == -1) {
		return false;
	}
	else {
		attrVal->setProp(id, dt, values);
		return true;
	}
}
Ejemplo n.º 5
0
int 
luaSet(lua_State *l) {

	const char *tipo = lua_tostring(l, -5);
	const char *context = lua_tostring(l, -4);
	const char *component = lua_tostring(l, -3);
	int number = (int)lua_tointeger(l, - 2);
	Data *arr = NULL;
	AttribSet *attr;

	if (!strcmp(context, "CURRENT")) {

		AttributeValues *av = NAU->getCurrentObjectAttributes(tipo);
		attr = av->getAttribSet();
		if (attr == NULL)
			NAU_THROW("Lua set: Invalid type: %s", tipo);
	}
	else {
		attr = NAU->getAttribs(tipo);
		if (attr == NULL)
			NAU_THROW("Lua set: invalid type: %s", tipo);
	}
	std::string s = component;
	Enums::DataType dt, bdt;
	int id;
	attr->getPropTypeAndId(s, &dt, &id);
	if (id == -1)
		NAU_THROW("Lua set: invalid component: %s", component);
	int card = Enums::getCardinality(dt);
	bdt = Enums::getBasicType(dt);
	float *arrF;
	int *arrI; 
	unsigned int *arrUI;

	switch (bdt) {

	case Enums::FLOAT:
		arrF = (float *)malloc(sizeof(float) * card);
		lua_pushnil(l);
		for (int i = 0; i < card && lua_next(l,-2) != 0; ++i) {
			arrF[i] = (float)lua_tonumber(l, -1);
			lua_pop(l, 1);
		}
		switch (dt) {
		case Enums::FLOAT:
			arr = new NauFloat(*arrF); break;
		case Enums::VEC2:
			arr = new vec2(arrF[0], arrF[1]); break;
		case Enums::VEC3:
			arr = new vec3(arrF[0], arrF[1], arrF[2]); break;
		case Enums::VEC4:
			arr = new vec4(arrF[0], arrF[1], arrF[2], arrF[3]); break;
		case Enums::MAT4:
		case Enums::MAT3:
			arr = new mat4(arrF); break;
		default:
			NAU_THROW("Lua set: Type %s not supported", Enums::DataTypeToString[dt].c_str());
		}
		free (arrF);
		break;
	case Enums::INT:
	case Enums::BOOL:
		arrI = (int *)malloc(sizeof(int) * card);
		lua_pushnil(l);
		for (int i = 0; i < card && lua_next(l, -2) != 0; ++i) {
			arrI[i] = (int)lua_tointeger(l, -1);
			lua_pop(l, 1);
		}
		switch (dt) {
		case Enums::BOOL:
		case Enums::INT:
			arr = new NauInt(arrI[0]); break;
		case Enums::IVEC2:
		case Enums::BVEC2:
			arr = new ivec2(arrI[0], arrI[1]); break;
		case Enums::IVEC3:
		case Enums::BVEC3:
			arr = new ivec3(arrI[0], arrI[1], arrI[2]); break;
		case Enums::IVEC4:
		case Enums::BVEC4:
			arr = new ivec4(arrI[0], arrI[1], arrI[2], arrI[3]); break;
		default:
			NAU_THROW("Lua set: Type %s not supported", Enums::DataTypeToString[dt].c_str());
		}
		free(arrI);
		break;
	case Enums::UINT :
		arrUI = (unsigned int *)malloc(sizeof(unsigned int) * card);
		lua_pushnil(l);
		for (int i = 0; i < card && lua_next(l, -2) != 0; ++i) {
			arrUI[i] = (unsigned int)lua_tointeger(l, -1);
			lua_pop(l, 1);
		}
		switch (dt) {
		case Enums::UINT:
			arr = new NauUInt(arrUI[0]); break;
		case Enums::UIVEC2:
			arr = new uivec2(arrUI[0], arrUI[1]); break;
		case Enums::UIVEC3:
			arr = new uivec3(arrUI[0], arrUI[1], arrUI[2]); break;
		case Enums::UIVEC4:
			arr = new uivec4(arrUI[0], arrUI[1], arrUI[2], arrUI[3]); break;
		default:
			NAU_THROW("Lua set: Type %s not supported", Enums::DataTypeToString[dt].c_str());
		}
		free(arrUI);
		break;
	default:
		NAU_THROW("Lua set: Type %s not supported", Enums::DataTypeToString[bdt].c_str());
	}

	if (!NAU->setAttributeValue(tipo, context, component, number, arr))
		NAU_THROW("Lua set: Invalid context: %s", context);

	delete arr;
	return 0;
}