Пример #1
0
    // Note that resourceName, resource, and getId are all bound via the std::bind mechanism.
    // it is possible to attach ANY arbitrary data to do whatever you would like here.  It may,
    // however be a better fit to wrap each call in an object so a fuller context (and additional
    // requests) can be easily made inside of a simple context
    void getResponse(const std::string& resourceName, const HeaderOptions& headerOptions,
                const OCRepresentation rep, const int eCode, OCResource::Ptr resource, int getId)
    {
        std::cout << "Got a response from get from the " << resourceName << std::endl;
        std::cout << "Get ID is "<<getId<<" and resource URI is " << resource->uri() << std::endl;

        printHeaderOptions(headerOptions);

        std::cout << "The Attribute Data is: "<<std::endl;

        switch(getId)
        {
            case 0:
                {
                    // Get on device
                    std::string name;
                    rep.getValue("device_name", name);
                    std::cout << "Name of device: "<< name << std::endl;
                    break;
                }
            case 1:
                {
                    bool isOn = false;
                    rep.getValue("on",isOn);
                    std::cout<<"The fridge light is "<< ((isOn)?"":"not ") <<"on"<<std::endl;
                }
                break;
            case 2:
            case 3:
                {
                    bool isOpen = false;
                    std::string side;
                    rep.getValue("open", isOpen);
                    rep.getValue("side", side);
                    std::cout << "Door is "<<isOpen<<" and is on the "<<side<<std::endl;
                }
                break;
            case 4:
                {
                    // Get on random resource called.
                    std::string name;
                    rep.getValue("device_name", name);
                    std::cout << "Name of fridge: "<< name << std::endl;
                    break;
                }
        }
        ++m_callbackCount;

        if(m_callbackCount == m_callsMade)
        {
            m_cv.notify_all();
        }
    }
Пример #2
0
    //Callback function to handle response for deleteResource call.
    void deleteResponse(const std::string& resourceName, const HeaderOptions& headerOptions,
                const int eCode, OCResource::Ptr resource, int deleteId)
    {
        std::cout << "Got a response from delete from the "<< resourceName << std::endl;
        std::cout << "Delete ID is "<<deleteId<<" and resource URI is "<<resource->uri()<<std::endl;
        printHeaderOptions(headerOptions);

        ++m_callbackCount;

        if(m_callbackCount == m_callsMade)
        {
            m_cv.notify_all();
        }
    }