Example #1
0
    // Puts representation.
    // Gets values from the representation and
    // updates the internal state
    void put(OCRepresentation& rep)
    {
        try {
            if (rep.getValue("state", m_state))
            {
                cout << "\t\t\t\t" << "state: " << m_state << endl;
            }
            else
            {
                cout << "\t\t\t\t" << "state not found in the representation" << endl;
            }

            if (rep.getValue("power", m_power))
            {
                cout << "\t\t\t\t" << "power: " << m_power << endl;
            }
            else
            {
                cout << "\t\t\t\t" << "power not found in the representation" << endl;
            }
        }
        catch (exception& e)
        {
            cout << e.what() << endl;
        }

    }
    void putResourceInfo(const HeaderOptions& /*headerOptions*/,
            const OCRepresentation rep, const OCRepresentation /*rep2*/, const int eCode)
    {
       std::cout << "In PutResourceInfo" << std::endl;

       std::cout <<"Clientside Put response to get was: "<<std::endl;
       std::cout <<"ErrorCode: "<<eCode <<std::endl;

       if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
       {
            std::cout<<"Successful Put.  Attributes sent were: "<<std::endl;

            rep.getValue("isFoo", m_isFoo);
            rep.getValue("barCount", m_barCount);

            std::cout << "\tisFoo: "<< m_isFoo << std::endl;
            std::cout << "\tbarCount: "<< m_barCount << std::endl;

            std::cout<<"Actual New values are: "<<std::endl;

            rep.getValue("isFoo", m_isFoo);
            rep.getValue("barCount", m_barCount);

            std::cout << "\tisFoo: "<< m_isFoo << std::endl;
            std::cout << "\tbarCount: "<< m_barCount << std::endl;

            m_cv.notify_all();
       }
    }
Example #3
0
void onObserve(const HeaderOptions headerOptions, const OCRepresentation &rep,
               const int &eCode, const int &sequenceNumber)
{
    if (eCode == OC_STACK_OK)
    {
        std::cout << "OBSERVE RESULT:" << std::endl;
        std::cout << "\tSequenceNumber: " << sequenceNumber << std::endl;

        rep.getValue("state", myfan.m_state);
        rep.getValue("power", myfan.m_power);
        rep.getValue("name", myfan.m_name);

        std::cout << "\tstate: " << myfan.m_state << std::endl;
        std::cout << "\tpower: " << myfan.m_power << std::endl;
        std::cout << "\tname: " << myfan.m_name << std::endl;

        if (observe_count() > 30)
        {
            std::cout << "Cancelling Observe..." << std::endl;
            OCStackResult result = curFanResource->cancelObserve();

            std::cout << "Cancel result: " << result << std::endl;
            sleep(10);
            std::cout << "DONE" << std::endl;
            std::exit(0);
        }
    }
    else
    {
        std::cout << "onObserve Response error: " << eCode << std::endl;
        std::exit(-1);
    }
}
Example #4
0
void putResourceInfo(const HeaderOptions& headerOptions,
        const OCRepresentation rep, const OCRepresentation rep2, const int eCode)
{
   bool m_isFoo = false;
   int m_barCount = 0;
   std::cout << "In PutResourceInfo" << std::endl;

   std::cout <<"Clientside Put response to get was: "<<std::endl;
   std::cout <<"ErrorCode: "<<eCode <<std::endl;

   if(eCode == 0)
   {
        std::cout<<"Successful Put.  Attributes sent were: "<<std::endl;

        rep.getValue("isFoo", m_isFoo);
        rep.getValue("barCount", m_barCount);

        std::cout << "\tisFoo: "<< m_isFoo << std::endl;
        std::cout << "\tbarCount: "<< m_barCount << std::endl;

        std::cout<<"Actual New values are: "<<std::endl;

        rep.getValue("isFoo", m_isFoo);
        rep.getValue("barCount", m_barCount);

        std::cout << "\tisFoo: "<< m_isFoo << std::endl;
        std::cout << "\tbarCount: "<< m_barCount << std::endl;
   }
}
void FactorySetResource::setFactorySetRepresentation(OCRepresentation &rep)
{
    string value;

    if (rep.getValue("loc", value))
    {
        m_location = value;
        dlog_print(DLOG_INFO, "FactorySetResource", "#### m_location: %s",
                   m_location.c_str());
    }

    if (rep.getValue("st", value))
    {
        dlog_print(DLOG_INFO, "FactorySetResource", "#### SystemTime is not"
                   "allowed to be written");
    }

    if (rep.getValue("c", value))
    {
        m_currency = value;
        dlog_print(DLOG_INFO, "FactorySetResource", "#### m_currency: %s",
                   m_currency.c_str());
    }

    if (rep.getValue("r", value))
    {
        m_region = value;
        dlog_print(DLOG_INFO, "FactorySetResource", "#### m_region: %s",
                   m_region.c_str());
    }
}
// Callback handler on GET request
void onGet(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
{
    (void)headerOptions;
    try
    {
        if (eCode == OC_STACK_OK)
        {
            std::cout << "GET request was successful" << std::endl;
            std::cout << "Resource URI: " << rep.getUri() << std::endl;

            std::cout << "Payload: " << rep.getPayload() << std::endl;

            rep.getValue("on-off", mylight.m_on_off);
            rep.getValue("dim", mylight.m_dim);
            rep.getValue("color", mylight.m_color);

            std::cout << "\ton-off: " << mylight.m_on_off << std::endl;
            std::cout << "\tcolor: " << mylight.m_color << std::endl;
            std::cout << "\tdim: " << mylight.m_dim << std::endl;

            putLightRepresentation(curResource);
        }
        else
        {
            std::cout << "onGET Response error: " << eCode << std::endl;
        }
    }
    catch (std::exception &e)
    {
        std::cout << "Exception: " << e.what() << " in onGet" << std::endl;
    }
}
void ConfigurationResource::setConfigurationRepresentation(OCRepresentation& rep)
{
    string value;

    if (rep.getValue("n", value))
    {
        m_deviceName = value;
        std::cout << "\t\t\t\t" << "m_deviceName: " << m_deviceName << std::endl;
    }

    if (rep.getValue("loc", value))
    {
        m_location = value;
        std::cout << "\t\t\t\t" << "m_location: " << m_location << std::endl;
    }

    if (rep.getValue("locn", value))
    {
        m_locationName = value;
        std::cout << "\t\t\t\t" << "m_locationName: " << m_locationName << std::endl;
    }

    if (rep.getValue("c", value))
    {
        m_currency = value;
        std::cout << "\t\t\t\t" << "m_currency: " << m_currency << std::endl;
    }

    if (rep.getValue("r", value))
    {
        m_region = value;
        std::cout << "\t\t\t\t" << "m_region: " << m_region << std::endl;
    }
}
// Callback handler on GET request
void onGet(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode)
{
    try
    {
        if(eCode == OC_STACK_OK)
        {
            std::cout << "GET request was successful" << std::endl;
            //std::cout << "Resource URI: " << rep.getUri() << std::endl;

            rep.getValue("state", mylight.m_state);
            rep.getValue("power", mylight.m_power);
            rep.getValue("name", mylight.m_name);

            //std::cout << "\tstate: " << mylight.m_state << std::endl;
            //std::cout << "\tpower: " << mylight.m_power << std::endl;
            //std::cout << "\tname: " << mylight.m_name << std::endl;

            putLightRepresentation(curResource);
        }
        else
        {
            std::cout << "onGET Response error: " << eCode << std::endl;
            std::exit(-1);
        }
    }
    catch(std::exception& e)
    {
        std::cout << "Exception: " << e.what() << " in onGet" << std::endl;
    }
}
Example #9
0
void getResourceInfo(std::shared_ptr<OCResource> resource, const HeaderOptions& headerOptions,
            const OCRepresentation rep,
            const int eCode)
{
    bool m_isFoo = false;
    int m_barCount = 0;
    std::cout << "In getResourceInfo" << std::endl;

    std::cout<<"Clientside response to get was: "<<std::endl;
    std::cout<<"Error Code: "<<eCode<<std::endl;

    if(eCode == 0)
    {
        std::cout <<"Successful Get.  Attributes are: "<<std::endl;

        rep.getValue("isFoo", m_isFoo);
        rep.getValue("barCount", m_barCount);

        std::cout << "\tisFoo: "<< m_isFoo << std::endl;
        std::cout << "\tbarCount: "<< m_barCount << std::endl;

        std::cout << "Doing a put on q/foo" <<std::endl;
        OCRepresentation rep2(rep);
        m_isFoo = false;
        m_barCount = 211;

        rep2.setValue("isFoo", m_isFoo);
        rep2.setValue("barCount", m_barCount);

        resource->put(rep2, QueryParamsMap(),
            PutCallback(std::bind(putResourceInfo, std::placeholders::_1,
                 rep2, std::placeholders::_2, std::placeholders::_3)));
    }
}
Example #10
0
        void put(OCRepresentation &rep)
        {
            try
            {
                if (rep.getValue("temperature", m_temp))
                {
                    cout << "\t\t\t\t" << "temperature: " << m_temp << endl;
                }
                else
                {
                    cout << "\t\t\t\t" << "temperature not found in the representation" << endl;
                }

                if (rep.getValue("humidity", m_humid))
                {
                    cout << "\t\t\t\t" << "humidity: " << m_humid << endl;
                }
                else
                {
                    cout << "\t\t\t\t" << "humidity not found in the representation" << endl;
                }
            }
            catch (exception &e)
            {
                cout << e.what() << endl;
            }

        }
Example #11
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();
        }
    }
Example #12
0
void SensorResource::onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
	const int& eCode, const int& sequenceNumber)
{
	int density = 0;
	int ledColor = 0;
	bool motion = false;
	try
	{
		if(eCode == OC_STACK_OK) {
			if (rep.hasAttribute("density")) {
				m_gas.s_active = true;
				rep.getValue("density", density);
				std::cout << "\tdensity: " << density << std::endl;

				if (m_rr->m_kitchenMonitor) {
					std::cout << "Kitchen Monitor is enabled" << std::endl;
					executeGasRule(density);
				}
			}

			if (rep.hasAttribute("fanstate")) {
				m_fan.s_active = true;
				std::string state = rep.getValue<std::string>("fanstate");
				m_fanState = (state == "on" ? true:false);
				std::cout << "\tfanstate: " << m_fanState << std::endl;
			}

			if (rep.hasAttribute("ledColor")) {
				m_led.s_active = true;
				rep.getValue("ledColor", ledColor);
				std::cout << "\tledColor: " << ledColor << std::endl;
			}
			if (rep.hasAttribute("motion")) {
				m_pri.s_active = true;
				rep.getValue("motion", motion);
				std::cout << "\tmotion: " << motion << std::endl;
				PutCallback p (std::bind(&SensorResource::onPut, this, PH::_1, PH::_2, PH::_3));
				if ((motion == true) && (m_led.s_active == true)) {
					OCRepresentation ledrep;
					ledrep.setValue("ledColor", BLUE);
					m_led.s_resource->put(ledrep, QueryParamsMap(), p);
				}
			}
		}
		else {
			std::cout << "onObserve Response error: " << eCode << std::endl;
		}
	}
	catch(std::exception& e) {
		std::cout << "Exception: " << e.what() << " in onObserve" << std::endl;
	}
}
Example #13
0
    void setFanRepresentation(OCRepresentation& rep)
    {
        bool tempState = false;
        int tempSpeed = 0;

        // If both entries exist
        if(rep.getValue("state", tempState) && rep.getValue("speed", tempSpeed))
        {
            m_fanState = tempState;
            m_fanSpeed = tempSpeed;

            cout << "\t\t\t\t" << "state: " << m_fanState << endl;
            cout << "\t\t\t\t" << "speed: " << m_fanSpeed << endl;
        }
    }
void TemphumidResource::setResourceRepresentation(OCRepresentation &rep)
{
    int tempHumid = 0;
    int tempTemp = 0;

    rep.getValue("humidity", tempTemp);
    rep.getValue("temperature", tempHumid);

    m_humid = tempHumid;
    m_temp = tempTemp;

    cout << "\t\t\t" << "Received representation: " << endl;
    cout << "\t\t\t\t" << "temp: " << m_humid << endl;
    cout << "\t\t\t\t" << "humid: " << m_temp << endl;
}
Example #15
0
    void setLightRepresentation(OCRepresentation& rep)
    {
        bool tempState = false;
        int tempColor = 0;

        // If both entries exist
        if(rep.getValue("state", tempState) && rep.getValue("color", tempColor))
        {
            m_lightState = tempState;
            m_lightColor= tempColor;

            cout << "\t\t\t\t" << "state: " << m_lightState << endl;
            cout << "\t\t\t\t" << "color: " << m_lightColor << endl;
        }
    }
void onPost(const HeaderOptions& /*headerOptions*/,
        const OCRepresentation& rep, const int eCode)
{
    try
    {
        if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED)
        {
            std::cout << "POST request was successful" << std::endl;

            if(rep.hasAttribute("createduri"))
            {
                std::cout << "\tUri of the created resource: "
                    << rep.getValue<std::string>("createduri") << std::endl;
            }
            else
            {
                rep.getValue("state", mylight.m_state);
                rep.getValue("power", mylight.m_power);
                rep.getValue("name", mylight.m_name);

                //std::cout << "\tstate: " << mylight.m_state << std::endl;
                //std::cout << "\tpower: " << mylight.m_power << std::endl;
                //std::cout << "\tname: " << mylight.m_name << std::endl;
            }

            OCRepresentation rep2;

            std::cout << "Posting light representation..."<<std::endl;

            mylight.m_state = true;
            mylight.m_power = 55;

            rep2.setValue("state", mylight.m_state);
            rep2.setValue("power", mylight.m_power);

            curResource->post(rep2, QueryParamsMap(), &onPost2);
        }
        else
        {
            std::cout << "onPost Response error: " << eCode << std::endl;
            std::exit(-1);
        }
    }
    catch(std::exception& e)
    {
        std::cout << "Exception: " << e.what() << " in onPost" << std::endl;
    }
}
Example #17
0
void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep,
        const int eCode)
{
    printf("\nonPost\n");

    if (rep.hasAttribute("ActionSet"))
    {
        std::string plainText;

        if (rep.getValue("ActionSet", plainText))
        {
            ActionSet *actionset = groupMgr->getActionSetfromString(plainText);
            if (actionset != NULL)
            {
                cout << endl << "\tACTIONSET NAME :: "
                        << actionset->actionsetName << endl;
                for (auto actIter = actionset->listOfAction.begin();
                        actIter != actionset->listOfAction.end(); ++actIter)
                {
                    cout << "\t\tTARGET :: " << (*actIter)->target << endl;

                    for (auto capaIter = (*actIter)->listOfCapability.begin();
                            capaIter != (*actIter)->listOfCapability.end();
                            ++capaIter)
                    {
                        cout << "\t\t\t" << (*capaIter)->capability << " :: "
                                << (*capaIter)->status << endl;
                    }
                }
            }
            delete actionset;
        }

        // printf( "\tPlain Text :: %s\n", plainText.c_str() );
    }
    else if (rep.hasAttribute("DoAction"))
    {
        std::string plainText;
        if (rep.getValue("DoAction", plainText))
        {
            cout << "\t" << plainText << endl;
        }
    }
    else
    {

    }
}
Example #18
0
void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
        const int& eCode, const int& sequenceNumber)
{
    if (eCode == OC_STACK_OK)
    {
        int level;

        std::cout << "OBSERVE RESULT:" << std::endl;
        std::cout << "\tSequenceNumber: " << sequenceNumber << endl;

        if (rep.getValue("level", level))
        {
            if (level == 0)
            {
                allBulbOn();
            }
            else
            {
                allBulbOff();
            }
        }
        std::cout << "\tlevel: " << level << std::endl;
    }
    else
    {
        std::cout << "onObserve Response error: " << eCode << std::endl;
        std::exit(-1);
    }
}
Example #19
0
void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
{
    printf("\nonPost\n");

    std::vector< OCRepresentation > children = rep.getChildren();

    cout << "\n\n\nCHILD RESOURCE OF GROUP" << endl;
    for (auto iter = children.begin(); iter != children.end(); ++iter)
    {
        std::string power;
        (*iter).getValue("power", power);

        cout << "\tURI :: " << (*iter).getUri() << endl;
        cout << "\t\tpower :: " << power << endl;
    }

    if (rep.hasAttribute("ActionSet"))
    {
        std::string plainText;

        rep.getValue("ActionSet", plainText);

        printf("\tPlain Text :: %s\n", plainText.c_str());
    }
    else
    {
        printf("Not found ActionSet\n");
    }
}
void WANIpConnection::onGetConnectionTypeInfo(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
{
    (void) headerOptions;
    if (eCode == OC_STACK_OK)
    {
        string uri;
        rep.getValue("uri", uri);
        if (uri == m_resource->uri())
        {
            OCRepresentation connectionTypeInfoRep;
            rep.getValue("connectionTypeInfo", connectionTypeInfoRep);
            connectionTypeInfoRep.getValue("type", m_connectionTypeInfo.type);
            connectionTypeInfoRep.getValue("allTypes", m_connectionTypeInfo.possibleTypes);
        }
    }
    m_cv.notify_one();
}
void onPost(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
{
    (void)headerOptions;
    try
    {
        if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED)
        {
            std::cout << "POST request was successful" << std::endl;

            if (rep.hasAttribute("createduri"))
            {
                std::cout << "\tUri of the created resource: "
                          << rep.getValue<std::string>("createduri") << std::endl;
            }
            else
            {
                rep.getValue("on-off", mylight.m_on_off);
                rep.getValue("color", mylight.m_color);
                rep.getValue("dim", mylight.m_dim);

                std::cout << "\ton-off: " << mylight.m_on_off << std::endl;
                std::cout << "\tcolor: " << mylight.m_color << std::endl;
                std::cout << "\tdim: " << mylight.m_dim << std::endl;
            }

            OCRepresentation rep2;

            std::cout << "Posting light representation..." << std::endl;

            mylight.m_on_off = true;

            rep2.setValue("on-off", mylight.m_on_off);

            curResource->post(rep2, QueryParamsMap(), &onPost2);
        }
        else
        {
            std::cout << "onPost Response error: " << eCode << std::endl;
        }
    }
    catch (std::exception &e)
    {
        std::cout << "Exception: " << e.what() << " in onPost" << std::endl;
    }
}
void onPost2(const HeaderOptions& /*headerOptions*/,
        const OCRepresentation& rep, const int eCode)
{
    try
    {
        if(eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED)
        {
            std::cout << "POST request was successful" << std::endl;

            if(rep.hasAttribute("createduri"))
            {
                std::cout << "\tUri of the created resource: "
                    << rep.getValue<std::string>("createduri") << std::endl;
            }
            else
            {
                rep.getValue("state", mylight.m_state);
                rep.getValue("power", mylight.m_power);
                rep.getValue("name", mylight.m_name);

                //std::cout << "\tstate: " << mylight.m_state << std::endl;
                //std::cout << "\tpower: " << mylight.m_power << std::endl;
                //std::cout << "\tname: " << mylight.m_name << std::endl;
            }

            if (OBSERVE_TYPE_TO_USE == ObserveType::Observe)
                std::cout << std::endl << "Observe is used." << std::endl << std::endl;
            else if (OBSERVE_TYPE_TO_USE == ObserveType::ObserveAll)
                std::cout << std::endl << "ObserveAll is used." << std::endl << std::endl;

            curResource->observe(OBSERVE_TYPE_TO_USE, QueryParamsMap(), &onObserve);

        }
        else
        {
            std::cout << "onPost2 Response error: " << eCode << std::endl;
            std::exit(-1);
        }
    }
    catch(std::exception& e)
    {
        std::cout << "Exception: " << e.what() << " in onPost2" << std::endl;
    }

}
void WANIpConnection::onGetWarnDisconnectTime(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
{
    (void) headerOptions;
    if (eCode == OC_STACK_OK)
    {
        string uri;
        rep.getValue("uri", uri);
        if (uri == m_resource->uri())
        {
            rep.getValue("warnDiscoTime", m_warnDisconnectTime);
        }
    }
    else
    {
        std::cerr << "GET request failure." << std::endl;
    }
    m_cv.notify_one();
}
void WANIpConnection::onGetExternalIPAddress(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
{
    (void) headerOptions;
    if (eCode == OC_STACK_OK)
    {
        string uri;
        rep.getValue("uri", uri);
        if (uri == m_resource->uri())
        {
            rep.getValue("externAddr", m_externalIpAddress);
        }
    }
    else
    {
        std::cerr << "GET request failure." << std::endl;
    }
    m_cv.notify_one();
}
Example #25
0
void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& rep,
                    const int& eCode, const int& sequenceNumber)
{
    if(eCode == SUCCESS_RESPONSE)
    {
        std::cout << "OBSERVE RESULT:"<<std::endl;
        if(sequenceNumber == (int) ObserveAction::ObserveRegister)
        {
            std::cout << "\tObserve Registration Confirmed: "<< std::endl;
        }
        else if (sequenceNumber == (int) ObserveAction::ObserveUnregister)
        {
            std::cout << "\tObserve Cancel Confirmed: "<< std::endl;
            sleep(10);
            std::cout << "DONE"<<std::endl;
            std::exit(0);
        }
        else
        {
            std::cout << "\tSequenceNumber: "<< sequenceNumber << std::endl;
        }

        rep.getValue("state", mylight.m_state);
        rep.getValue("power", mylight.m_power);
        rep.getValue("name", mylight.m_name);

        std::cout << "\tstate: " << mylight.m_state << std::endl;
        std::cout << "\tpower: " << mylight.m_power << std::endl;
        std::cout << "\tname: " << mylight.m_name << std::endl;

        if(observe_count() == 11)
        {
            std::cout<<"Cancelling Observe..."<<std::endl;
            OCStackResult result = curResource->cancelObserve(OC::QualityOfService::HighQos);

            std::cout << "Cancel result: "<< result << " waiting for confirmation ..." <<std::endl;
        }
    }
    else
    {
        std::cout << "onObserve Response error: " << eCode << std::endl;
        std::exit(-1);
    }
}
void onPost2(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
{
    (void)headerOptions;
    try
    {
        if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED)
        {
            std::cout << "POST request was successful" << std::endl;

            if (rep.hasAttribute("createduri"))
            {
                std::cout << "\tUri of the created resource: "
                          << rep.getValue<std::string>("createduri") << std::endl;
            }
            else
            {
                rep.getValue("on-off", mylight.m_on_off);
                rep.getValue("color", mylight.m_color);
                rep.getValue("dim", mylight.m_dim);

                std::cout << "\ton-off: " << mylight.m_on_off << std::endl;
                std::cout << "\tcolor: " << mylight.m_color << std::endl;
                std::cout << "\tdim: " << mylight.m_dim << std::endl;
            }

            if (OBSERVE_TYPE_TO_USE == ObserveType::Observe)
                std::cout << std::endl << "Observe is used." << std::endl << std::endl;
            else if (OBSERVE_TYPE_TO_USE == ObserveType::ObserveAll)
                std::cout << std::endl << "ObserveAll is used." << std::endl << std::endl;

            curResource->observe(OBSERVE_TYPE_TO_USE, QueryParamsMap(), &onObserve);

        }
        else
        {
            std::cout << "onPost2 Response error: " << eCode << std::endl;
        }
    }
    catch (std::exception &e)
    {
        std::cout << "Exception: " << e.what() << " in onPost2" << std::endl;
    }

}
        void RemoteEnrolleeResource::getProvStatusResponse(const HeaderOptions& /*headerOptions*/,
                const OCRepresentation& rep, const int eCode)
        {
            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : %s, eCode = %d",
                    rep.getUri().c_str(),
                    eCode);

            if (eCode != 0)
            {
                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
                        "getProvStatusResponse : Provisioning is failed ");
                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
                m_provStatusCb(provStatus);
                return;
            }

            int ps = -1;

            rep.getValue(OC_RSRVD_ES_PS, ps);

            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ps - %d",
                    ps);

            if (ps == ES_PS_NEED_PROVISIONING) //Indicates the need for provisioning
            {
                OCRepresentation provisioningRepresentation;

                provisioningRepresentation.setValue(OC_RSRVD_ES_TNN,
                std::string(m_ProvConfig.provData.WIFI.ssid));
                provisioningRepresentation.setValue(OC_RSRVD_ES_CD,
                std::string(m_ProvConfig.provData.WIFI.pwd));

                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ssid - %s",
                        m_ProvConfig.provData.WIFI.ssid);
                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : pwd - %s",
                        m_ProvConfig.provData.WIFI.pwd);

                m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
                        std::function<
                                void(const HeaderOptions& headerOptions,
                                        const OCRepresentation& rep, const int eCode) >(
                        std::bind(&RemoteEnrolleeResource::checkProvInformationCb, this,
                        std::placeholders::_1, std::placeholders::_2,
                        std::placeholders::_3)));
            }
            else if (ps == ES_PS_PROVISIONING_COMPLETED) //Indicates that provisioning is completed
            {
                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
                        "getProvStatusResponse : Provisioning is successful");
                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
                        ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONED_ALREADY);
                m_provStatusCb(provStatus);
            }
        }
void SecurityCollection::setModeRepresentation(OCRepresentation& rep)
{
    string value;

    if (rep.getValue("mode", value))
    {
        m_modeValue = value;

        std::cout << "\t\t\t\t" << "value: " << m_modeValue << std::endl;
    }
}
void NetworkCollection::setNetworkRepresentation(OCRepresentation& rep)
{
    string value;

    if (rep.getValue("value", value))
    {
        m_networkValue = value;

        std::cout << "\t\t\t\t" << "m_networkValue: " << m_networkValue << std::endl;
    }
}
void NetworkCollection::setIPAddressRepresentation(OCRepresentation& rep)
{
    string value;

    if (rep.getValue("IPAddress", value))
    {
        m_IPAddressValue = value;

        std::cout << "\t\t\t\t" << "value: " << m_IPAddressValue << std::endl;
    }
}