本文整理汇总了C++中OCRepresentation::getValue方法的典型用法代码示例。如果您正苦于以下问题:C++ OCRepresentation::getValue方法的具体用法?C++ OCRepresentation::getValue怎么用?C++ OCRepresentation::getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCRepresentation
的用法示例。
在下文中一共展示了OCRepresentation::getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: put
// 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;
}
}
示例2: putResourceInfo
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();
}
}
示例3: onObserve
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);
}
}
示例4: putResourceInfo
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;
}
}
示例5: setFactorySetRepresentation
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());
}
}
示例6: onGet
// 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;
}
}
示例7: setConfigurationRepresentation
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;
}
}
示例8: onGet
// 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;
}
}
示例9: getResourceInfo
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)));
}
}
示例10: put
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;
}
}
示例11: getResponse
// 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();
}
}
示例12: onObserve
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;
}
}
示例13: setFanRepresentation
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;
}
}
示例14: setResourceRepresentation
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;
}
示例15: setLightRepresentation
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;
}
}