NS_LOG(DEBUG, "NSEntityHandlerTopicCb - OC_REST_POST");\r
// Accepter is provider. our service is not support sendtopiclist from OC_REST_POST\r
// Accepter is consumer. our service is support sendtopiclist from OC_REST_POST\r
- if(NSGetPolicy() == false)\r
+ if(NSGetPolicy() == false &&\r
+ NSProviderIsTopicAttributes(OCRepPayloadClone((OCRepPayload *)\r
+ entityHandlerRequest->payload)))\r
{\r
NSPushQueue(TOPIC_SCHEDULER, TASK_POST_TOPIC,\r
NSCopyOCEntityHandlerRequest(entityHandlerRequest));\r
OCRepPayloadValue * curr = payload->values;\r
while(curr)\r
{\r
- if (!NSProviderCompareSyncAttributes(curr->name))\r
+ if (!NSProviderCompareTopicAttributes(curr->name))\r
{\r
return false;\r
}\r
OCResourcePayloadAddStringLL(&payload->types, rtStr);\r
}\r
\r
- if(resourceType != NS_RESOURCE_TOPIC)\r
+ if (resourceType == NS_RESOURCE_TOPIC && entityHandlerRequest->method == OC_REST_GET)\r
{\r
- OCEntityHandlerResponse response;\r
- response.numSendVendorSpecificHeaderOptions = 0;\r
- memset(response.sendVendorSpecificHeaderOptions, 0,\r
- sizeof response.sendVendorSpecificHeaderOptions);\r
- memset(response.resourceUri, 0, sizeof response.resourceUri);\r
-\r
- response.requestHandle = entityHandlerRequest->requestHandle;\r
- response.resourceHandle = entityHandlerRequest->resource;\r
- response.persistentBufferFlag = 0;\r
- response.ehResult = ehResult;\r
- response.payload = (OCPayload *) payload;\r
-\r
- if (OCDoResponse(&response) != OC_STACK_OK)\r
- {\r
- NS_LOG(ERROR, "Fail to AccessPolicy send response");\r
- OCRepPayloadDestroy(payload);\r
- return ehResult;\r
- }\r
+ OCRepPayloadDestroy(payload);\r
+ return ehResult;\r
+ }\r
+\r
+ OCEntityHandlerResponse response;\r
+ response.numSendVendorSpecificHeaderOptions = 0;\r
+ memset(response.sendVendorSpecificHeaderOptions, 0,\r
+ sizeof response.sendVendorSpecificHeaderOptions);\r
+ memset(response.resourceUri, 0, sizeof response.resourceUri);\r
+\r
+ response.requestHandle = entityHandlerRequest->requestHandle;\r
+ response.resourceHandle = entityHandlerRequest->resource;\r
+ response.persistentBufferFlag = 0;\r
+ response.ehResult = ehResult;\r
+ response.payload = (OCPayload *) payload;\r
+\r
+ if (OCDoResponse(&response) != OC_STACK_OK)\r
+ {\r
+ NS_LOG(ERROR, "Fail to AccessPolicy send response");\r
+ ehResult = OC_STACK_ERROR;\r
}\r
\r
OCRepPayloadDestroy(payload);\r
std::shared_ptr<OC::OCResource> m_msgResource;
std::shared_ptr<OC::OCResource> m_topicResource;
+ bool isTopicPost;
+
public:
NSConsumerSimulator()
: m_messageFunc(), m_syncFunc(),
- m_syncResource() { };
+ m_syncResource(), isTopicPost(false) { };
~NSConsumerSimulator() = default;
NSConsumerSimulator(const NSConsumerSimulator &) = delete;
{
if(resource->uri() == "/notification")
{
- resource->get(OC::QueryParamsMap(),
- std::bind(&NSConsumerSimulator::onGet, this,
+ resource->get(std::string("oic.wk.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);
}
if(rep.getValue<int>("messageId") == 3)
{
- m_topicResource->get(OC::QueryParamsMap(),
+ m_topicResource->get(std::string("oic.wk.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);
}
void onTopicGet(const OC::HeaderOptions &/*headerOption*/,
- const OC::OCRepresentation & /*rep*/ , const int /*eCode*/,
+ const OC::OCRepresentation & rep , const int /*eCode*/,
std::shared_ptr<OC::OCResource> /*resource*/)
{
+
+ if(!isTopicPost)
+ {
+ isTopicPost = true;
+ OC::OCRepresentation postRep;
+
+ std::vector<OC::OCRepresentation> topicArr =
+ rep.getValue<std::vector<OC::OCRepresentation>>("topicList");
+
+ std::vector<OC::OCRepresentation> postTopicArr;
+
+ for(std::vector<OC::OCRepresentation>::iterator it = topicArr.begin();
+ it != topicArr.end(); ++it) {
+ /* std::cout << *it; ... */
+ OC::OCRepresentation topic = *it;
+ OC::OCRepresentation postTopic;
+
+ postTopic.setValue("topicName", topic.getValueToString("topicName"));
+ postTopic.setValue("topicState", (int) topic.getValue<int>("topicState"));
+
+ postTopicArr.push_back(topic);
+
+// std::cout << "tName : " << tName << std::endl;
+// std::cout << "tState : " << tState << std::endl;
+ }
+
+ postRep.setValue<std::vector<OC::OCRepresentation>>
+ ("topicList", postTopicArr);
+
+ OC::QueryParamsMap map;
+ map.insert(std::pair<std::string,std::string>(std::string("consumerId"),
+ std::string("123456789012345678901234567890123456")));
+ m_topicResource->post(postRep, map, &onPost, OC::QualityOfService::LowQos);
+ }
}
OCStackResult msgResourceCancelObserve(OC::QualityOfService qos)