X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fexamples%2Fgarageclient.cpp;h=c64528d0370e50399d384412e55692cd8f5ed411;hb=935fdb9b67b6c10d007e652e9e2e028fd6ccfe09;hp=ba8a09aaaf095928c6baf4fa69cd302e465e0949;hpb=00b3660e45c56cb3db35dc2596a054f801b5591a;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/examples/garageclient.cpp b/resource/examples/garageclient.cpp index ba8a09a..c64528d 100644 --- a/resource/examples/garageclient.cpp +++ b/resource/examples/garageclient.cpp @@ -32,6 +32,7 @@ using namespace OC; const int SUCCESS_RESPONSE = 0; std::shared_ptr curResource; +std::mutex curResourceLock; class Garage { @@ -43,6 +44,7 @@ public: std::vector m_lightPowers; OCRepresentation m_lightRep; std::vector m_reps; + std::vector> m_hingeStates; Garage() : m_state(false), m_name("") { @@ -57,7 +59,7 @@ void printRepresentation(const OCRepresentation& rep) // Check if attribute "name" exists, and then getValue if(rep.hasAttribute("name")) { - myGarage.m_name = rep.getValue("name"); + myGarage.m_name = rep["name"]; } std::cout << "\tname: " << myGarage.m_name << std::endl; @@ -92,10 +94,10 @@ void printRepresentation(const OCRepresentation& rep) std::cout << "\tnullAttribute is not null." << std::endl; } - rep.getValue("light", myGarage.m_lightRep); + myGarage.m_lightRep = rep["light"]; - myGarage.m_lightRep.getValue("states", myGarage.m_lightStates); - myGarage.m_lightRep.getValue("powers", myGarage.m_lightPowers); + myGarage.m_lightStates = myGarage.m_lightRep["states"]; + myGarage.m_lightPowers = myGarage.m_lightRep["powers"]; std::cout << "\tlightRep: states: "; @@ -131,13 +133,26 @@ void printRepresentation(const OCRepresentation& rep) 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("key1") << std::endl; - std::cout << "\treps[0].key2: " << myGarage.m_reps[1].getValue("key2") << std::endl; + myGarage.m_reps = rep["reps"]; + + int ct = 0; + for(auto& rep : myGarage.m_reps) + { + for(auto& attribute : rep) + { + std::cout<< "\treps["<("json") << std::endl; } // callback handler on PUT request void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode) @@ -166,7 +181,7 @@ void putLightRepresentation(std::shared_ptr resource) myGarage.m_state = true; - rep.setValue("state", myGarage.m_state); + rep["state"] = myGarage.m_state; // Create QueryParameters Map and add query params (if any) QueryParamsMap queryParamsMap; @@ -211,9 +226,11 @@ void getLightRepresentation(std::shared_ptr resource) // Callback to found resources void foundResource(std::shared_ptr resource) { + std::lock_guard lock(curResourceLock); if(curResource) { std::cout << "Found another resource, ignoring"< resource) } catch(std::exception& e) { - //log(e.what()); + std::cerr << "Exception in foundResource: "<< e.what()<