当前位置: 首页>>代码示例>>C++>>正文


C++ OCRepresentation::getJSONRepresentation方法代码示例

本文整理汇总了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;
}
开发者ID:MCherifiOSS,项目名称:iotivity,代码行数:89,代码来源:SampleProvider.cpp


注:本文中的OCRepresentation::getJSONRepresentation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。