本文整理汇总了C++中OCRepresentation::getJSONRepresentation方法的典型用法代码示例。如果您正苦于以下问题:C++ OCRepresentation::getJSONRepresentation方法的具体用法?C++ OCRepresentation::getJSONRepresentation怎么用?C++ OCRepresentation::getJSONRepresentation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCRepresentation
的用法示例。
在下文中一共展示了OCRepresentation::getJSONRepresentation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: entityHandler
OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request ,
std::shared_ptr< OCResourceResponse > response)
{
cout << "Sample Provider entityHandler\n";
if (request)
{
cout << "flag : request\n";
std::string requestType = request->getRequestType();
int requestFlag = request->getRequestHandlerFlag();
if (requestFlag == RequestHandlerFlag::InitFlag)
{
cout << "\t\trequestFlag : Init\n";
}
if (requestFlag == RequestHandlerFlag::RequestFlag)
{
cout << "\t\trequestFlag : Request\n";
if (requestType == "GET")
{
cout << "\t\trequestType : GET\n";
try
{
if (response)
{
OCRepresentation rep = myResource.get();
cout << rep.getJSONRepresentation() << endl;
response->setErrorCode(200);
response->setResourceRepresentation(rep, DEFAULT_INTERFACE);
}
else
{
cout << "response is null\n";
}
}
catch (exception &e)
{
cout << e.what() << endl;
}
}
else if (requestType == "PUT")
{
cout << "\t\t\trequestType : PUT\n";
OCRepresentation rep = request->getResourceRepresentation();
myResource.put(rep);
if (response)
{
response->setErrorCode(200);
response->setResourceRepresentation(myResource.get());
}
}
else if (requestType == "POST")
{
}
else if (requestType == "DELETE")
{
}
}
else if (requestFlag & RequestHandlerFlag::ObserverFlag)
{
pthread_t threadId;
cout << request->getResourceUri() << endl;
cout << request->getResourceRepresentation().getUri() << endl;
cout << "========================================================" << endl;
cout << "Receive ObserverFlag : Start Observe\n";
cout << "========================================================" << endl;
g_Observation = 1;
cout << "\t\trequestFlag : Observer\n";
static int startedThread = 0;
if (!startedThread)
{
cout << "\t\tpthrerad_create\n";
pthread_create(&threadId , NULL , ChangeLightRepresentation , (void *) NULL);
startedThread = 1;
}
}
}
else
{
std::cout << "Request invalid" << std::endl;
}
return OC_EH_OK;
}