X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fnotification%2Funittest%2FNSConsumerSimulator.h;h=161a9ee91addece6beac7a93d7d18b94d69c2e94;hb=refs%2Ftags%2Ftizen_4.0.m2_release;hp=d12e30e9ed6f8ec22cbf3c85ab0a2931ca1d9be5;hpb=a161a2b368a14eca7d93cf3dca896449360e9303;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/notification/unittest/NSConsumerSimulator.h b/service/notification/unittest/NSConsumerSimulator.h index d12e30e..161a9ee 100644 --- a/service/notification/unittest/NSConsumerSimulator.h +++ b/service/notification/unittest/NSConsumerSimulator.h @@ -34,11 +34,15 @@ private: std::function m_syncFunc; std::shared_ptr m_syncResource; + std::shared_ptr m_msgResource; + std::shared_ptr m_topicResource; + + bool isTopicPost; public: NSConsumerSimulator() : m_messageFunc(), m_syncFunc(), - m_syncResource() { }; + m_syncResource(), isTopicPost(false) { }; ~NSConsumerSimulator() = default; NSConsumerSimulator(const NSConsumerSimulator &) = delete; @@ -49,7 +53,7 @@ public: void findProvider() { - OC::OCPlatform::findResource("", std::string("/oic/res?rt=oic.r.notification"), + OC::OCPlatform::findResource("", std::string("/oic/res?rt=x.org.iotivity.notification"), OCConnectivityType::CT_DEFAULT, std::bind(&NSConsumerSimulator::findResultCallback, this, std::placeholders::_1), OC::QualityOfService::LowQos); @@ -59,18 +63,25 @@ public: { if (m_syncResource == nullptr) { - std::cout << "m_syncResource is null" << std::endl; return; } OC::OCRepresentation rep; - rep.setValue("PROVIDER_ID", providerID); - rep.setValue("MESSAGE_ID", id); - rep.setValue("STATE", type); + rep.setValue("x.org.iotivity.ns.providerid", providerID); + rep.setValue("x.org.iotivity.ns.messageid", id); + rep.setValue("x.org.iotivity.ns.state", type); m_syncResource->post(rep, OC::QueryParamsMap(), &onPost, OC::QualityOfService::LowQos); } + bool cancelObserves() + { + if(!msgResourceCancelObserve(OC::QualityOfService::HighQos) && + !syncResourceCancelObserve(OC::QualityOfService::HighQos)) + return true; + return false; + } + void setCallback(std::function messageFunc, const std::function & syncFunc) @@ -81,50 +92,38 @@ public: private: static void onPost(const OC::HeaderOptions &/*headerOption*/, - const OC::OCRepresentation & /*rep*/ , const int eCode) + const OC::OCRepresentation & /*rep*/ , const int /*eCode*/) { - std::cout << __func__ << " result : " << eCode << std::endl; } void findResultCallback(std::shared_ptr resource) { - - std::cout << __func__ << " " << resource->host() << std::endl; - if(resource->uri() == "/notification") { - resource->get(OC::QueryParamsMap(), - std::bind(&NSConsumerSimulator::onGet, this, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, resource), - OC::QualityOfService::LowQos); + resource->get(std::string("x.org.iotivity.notification"), std::string("oic.if.baseline"), + OC::QueryParamsMap(), std::bind(&NSConsumerSimulator::onGet, this, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, + resource), OC::QualityOfService::LowQos); } } void onGet(const OC::HeaderOptions &/*headerOption*/, - const OC::OCRepresentation & rep , const int eCode, + const OC::OCRepresentation & /*rep*/ , const int /*eCode*/, std::shared_ptr resource) { - std::cout << __func__ << " " << rep.getHost() << " result : " << eCode << std::endl; - OC::QueryParamsMap map; - map.insert(std::pair(std::string("consumerid"), std::string("123456789012345678901234567890123456"))); + map.insert(std::pair(std::string("x.org.iotivity.ns.consumerid"), + std::string("123456789012345678901234567890123456"))); try { - std::cout << "resourc : host " << resource->host() << std::endl; - std::cout << "resourc : uri " << resource->uri() << std::endl; - std::cout << " resource->connectivityType() " << resource->connectivityType() << std::endl; - std::cout << "resourc : getResourceInterfaces " << resource->getResourceInterfaces()[0] << std::endl; - std::cout << "resourc : getResourceTypes " << resource->getResourceTypes()[0] << std::endl; - - - std::vector rts{"oic.r.notification"}; + std::vector rts{"x.org.iotivity.notification"}; - std::shared_ptr msgResource + m_msgResource = OC::OCPlatform::constructResourceObject( std::string(resource->host()), std::string(resource->uri() + "/message"), OCConnectivityType(resource->connectivityType()), true, rts, std::vector(resource->getResourceInterfaces())); - msgResource->observe(OC::ObserveType::Observe, map, + m_msgResource->observe(OC::ObserveType::Observe, map, std::bind(&NSConsumerSimulator::onObserve, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, resource), @@ -145,31 +144,90 @@ private: std::placeholders::_3, std::placeholders::_4, resource), OC::QualityOfService::LowQos); + + m_topicResource + = OC::OCPlatform::constructResourceObject(resource->host(), resource->uri() + "/topic", + resource->connectivityType(), true, resource->getResourceTypes(), + resource->getResourceInterfaces()); + } void onObserve(const OC::HeaderOptions &/*headerOption*/, - const OC::OCRepresentation &rep , const int &eCode, const int &, + const OC::OCRepresentation &rep , const int & /*eCode*/, const int &, std::shared_ptr ) { - std::cout << __func__ << " " << rep.getHost() << " result : " << eCode; - std::cout << " uri : " << rep.getUri() << std::endl; - - if (rep.getUri() == "/notification/message" && rep.hasAttribute("MESSAGE_ID") - && rep.getValue("MESSAGE_ID") != 1) + if (rep.getUri() == "/notification/message" && rep.hasAttribute("x.org.iotivity.ns.messageid") + && rep.getValue("x.org.iotivity.ns.messageid") != 1) { - std::cout << "ID : " << rep.getValue("ID") << std::endl; - std::cout << "TITLE : " << rep.getValueToString("TITLE") << std::endl; - std::cout << "CONTENT : " << rep.getValueToString("CONTENT") << std::endl; - m_messageFunc(int(rep.getValue("MESSAGE_ID")), - std::string(rep.getValueToString("TITLE")), - std::string(rep.getValueToString("CONTENT")), - std::string(rep.getValueToString("SOURCE"))); + m_messageFunc(int(rep.getValue("x.org.iotivity.ns.messageid")), + std::string(rep.getValueToString("x.org.iotivity.ns.title")), + std::string(rep.getValueToString("x.org.iotivity.ns.contenttext")), + std::string(rep.getValueToString("x.org.iotivity.ns.source"))); + + if(rep.getValue("x.org.iotivity.ns.messageid") == 3) + { + m_topicResource->get(std::string("x.org.iotivity.notification"), + std::string("oic.if.baseline"), OC::QueryParamsMap(), + std::bind(&NSConsumerSimulator::onTopicGet, this, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3, m_topicResource), + OC::QualityOfService::LowQos); + } } else if (rep.getUri() == "/notification/sync") { - std::cout << "else if (rep.getUri() == sync) " << std::endl; - m_syncFunc(int(rep.getValue("STATE")), int(rep.getValue("ID"))); + m_syncFunc(int(rep.getValue("x.org.iotivity.ns.state")), int(rep.getValue("x.org.iotivity.ns.messageid"))); + } + } + + void onTopicGet(const OC::HeaderOptions &/*headerOption*/, + const OC::OCRepresentation & rep , const int /*eCode*/, + std::shared_ptr /*resource*/) + { + + if(!isTopicPost) + { + isTopicPost = true; + OC::OCRepresentation postRep; + + std::vector topicArr = + rep.getValue>("x.org.iotivity.ns.topiclist"); + + std::vector postTopicArr; + + for(std::vector::iterator it = topicArr.begin(); + it != topicArr.end(); ++it) + { + /* std::cout << *it; ... */ + OC::OCRepresentation topic = *it; + OC::OCRepresentation postTopic; + + postTopic.setValue("x.org.iotivity.ns.topicname", topic.getValueToString("x.org.iotivity.ns.topicname")); + postTopic.setValue("x.org.iotivity.ns.topicstate", (int) topic.getValue("x.org.iotivity.ns.topicstate")); + + postTopicArr.push_back(topic); + +// std::cout << "tName : " << tName << std::endl; +// std::cout << "tState : " << tState << std::endl; + } + + postRep.setValue> + ("x.org.iotivity.ns.topiclist", postTopicArr); + + OC::QueryParamsMap map; + map.insert(std::pair(std::string("x.org.iotivity.ns.consumerid"), + std::string("123456789012345678901234567890123456"))); + m_topicResource->post(postRep, map, &onPost, OC::QualityOfService::LowQos); } } + + OCStackResult msgResourceCancelObserve(OC::QualityOfService qos) + { + return m_msgResource->cancelObserve(qos); + } + + OCStackResult syncResourceCancelObserve(OC::QualityOfService qos) + { + return m_syncResource->cancelObserve(qos); + } };