/* * Class: org_iotivity_base_OcRepresentation * Method: isNull * Signature: (Ljava/lang/String;)Z */ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isNull (JNIEnv *env, jobject thiz, jstring jAttributeKey) { LOGD("OcRepresentation_isNull"); if (!jAttributeKey) { ThrowOcException(OC_STACK_INVALID_PARAM, "attributeKey cannot be null"); return false; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); if (!rep) return false; std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr); return static_cast<jboolean>(rep->isNULL(attributeKey)); }
void printRepresentation(const OCRepresentation& rep) { // Check if attribute "name" exists, and then getValue if(rep.hasAttribute("name")) { myGarage.m_name = rep.getValue<std::string>("name"); } std::cout << "\tname: " << myGarage.m_name << std::endl; // You can directly try to get the value. this function // return false if there is no attribute "state" if(!rep.getValue("state", myGarage.m_state)) { std::cout << "Attribute state doesn't exist in the representation\n"; } std::cout << "\tstate: " << myGarage.m_state << std::endl; OCRepresentation rep2 = rep; std::cout << "Number of attributes in rep2: " << rep2.numberOfAttributes() << std::endl; if(rep2.erase("name")) { std::cout << "attribute: name, was removed successfully from rep2.\n"; } std::cout << "Number of attributes in rep2: " << rep2.numberOfAttributes() << std::endl; if(rep.isNULL("nullAttribute")) { std::cout << "\tnullAttribute is null." << std::endl; } else { std::cout << "\tnullAttribute is not null." << std::endl; } rep.getValue("light", myGarage.m_lightRep); myGarage.m_lightRep.getValue("states", myGarage.m_lightStates); myGarage.m_lightRep.getValue("powers", myGarage.m_lightPowers); std::cout << "\tlightRep: states: "; int first = 1; for(auto state: myGarage.m_lightStates) { if(first) { std::cout << state; first = 0; } else { std::cout << "," << state; } } std::cout << std::endl; std::cout << "\tlightRep: powers: "; first = 1; for(auto power: myGarage.m_lightPowers) { if(first) { std::cout << power; first = 0; } else { std::cout << "," << power; } } std::cout << std::endl; // Get vector of representations rep.getValue("reps", myGarage.m_reps); // Client know that server is sending two representations // and has key1 and key2 repsectively std::cout << "\treps[0].key1: " << myGarage.m_reps[0].getValue<int>("key1") << std::endl; std::cout << "\treps[0].key2: " << myGarage.m_reps[1].getValue<int>("key2") << std::endl; std::cout << "\tjson: " << rep.getValue<std::string>("json") << std::endl; }
void printRepresentation(const OCRepresentation& rep) { // Check if attribute "name" exists, and then getValue if(rep.hasAttribute("name")) { myGarage.m_name = rep["name"]; } std::cout << "\tname: " << myGarage.m_name << std::endl; // You can directly try to get the value. this function // return false if there is no attribute "state" if(!rep.getValue("state", myGarage.m_state)) { std::cout << "Attribute state doesn't exist in the representation\n"; } std::cout << "\tstate: " << myGarage.m_state << std::endl; OCRepresentation rep2 = rep; std::cout << "Number of attributes in rep2: " << rep2.numberOfAttributes() << std::endl; if(rep2.erase("name")) { std::cout << "attribute: name, was removed successfully from rep2.\n"; } std::cout << "Number of attributes in rep2: " << rep2.numberOfAttributes() << std::endl; if(rep.isNULL("nullAttribute")) { std::cout << "\tnullAttribute is null." << std::endl; } else { std::cout << "\tnullAttribute is not null." << std::endl; } myGarage.m_lightRep = rep["light"]; myGarage.m_lightStates = myGarage.m_lightRep["states"]; myGarage.m_lightPowers = myGarage.m_lightRep["powers"]; std::cout << "\tlightRep: states: "; int first = 1; for(auto state: myGarage.m_lightStates) { if(first) { std::cout << state; first = 0; } else { std::cout << "," << state; } } std::cout << std::endl; std::cout << "\tlightRep: powers: "; first = 1; for(auto power: myGarage.m_lightPowers) { if(first) { std::cout << power; first = 0; } else { std::cout << "," << power; } } std::cout << std::endl; // Get vector of representations myGarage.m_reps = rep["reps"]; int ct = 0; for(auto& rep : myGarage.m_reps) { for(auto& attribute : rep) { std::cout<< "\treps["<<ct<<"]."<<attribute.attrname()<<":" << attribute.type()<<" with value " <<attribute.getValueToString() <<std::endl; } ++ct; } std::cout << "\tjson: " << rep["json"] << std::endl; myGarage.m_hingeStates = rep["hinges"]; std::cout<< "\tHinge parameter is type: " << rep["hinges"].type() << " with depth "<< rep["hinges"].depth() << " and a base type of "<< rep["hinges"].base_type()<<std::endl; }