本文整理汇总了C++中OCRepresentation类的典型用法代码示例。如果您正苦于以下问题:C++ OCRepresentation类的具体用法?C++ OCRepresentation怎么用?C++ OCRepresentation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OCRepresentation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LOGD
/*
* Class: org_iotivity_base_OcRepresentation
* Method: getResourceInterfaces
* Signature: ()Ljava/util/List;
*/
JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceInterfaces
(JNIEnv *env, jobject thiz)
{
LOGD("OcRepresentation_getResourceInterfaces");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
if (!rep) return nullptr;
std::vector<std::string> resourceInterfaces = rep->getResourceInterfaces();
return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
}
示例2: putClientRepresentation
void putClientRepresentation(std::shared_ptr<OCResource> resource, string &key, int value)
{
if(resource)
{
OCRepresentation rep;
std::cout << "Putting representation..."<<std::endl;
rep.setValue(key, value);
resource->put(rep, QueryParamsMap(), &onPut);
}
}
示例3: get
OCRepresentation get()
{
cout << "resource get\n";
m_Rep.setValue("temperature", m_temp);
m_Rep.setValue("humidity", m_humid);
cout << "resource get : done\n";
return m_Rep;
}
示例4: OIC_LOG_V
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);
}
}
示例5: onObserve
void onObserve(const HeaderOptions &headerOption , const OCRepresentation& rep , const int& eCode, const int& sequenceNumber)
{
std::cout << "onObserve" << std::endl;
// if(eCode == SUCCESS_RESPONSE)
if(eCode <= OC_STACK_RESOURCE_DELETED)
{
AttributeMap attributeMap = rep.getAttributeMap();
for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it)
{
if(attributeMap.find(it->first) == attributeMap.end())
{
return;
}
}
if(rep.getUri().empty())
{
cout << "uri is null\n";
return;
}
std::cout << std::endl;
std::cout << "========================================================" << std::endl;
std::cout << "Receive OBSERVE RESULT:" << std::endl;
std::cout << "\tSequenceNumber: " << sequenceNumber << std::endl;
for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it)
{
std::cout << "\tAttribute name: " << it->first << " value: ";
for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr)
{
std::cout << "\t" << *valueItr << " ";
}
std::cout << std::endl;
}
if(observe_count() > 30)
{
std::cout << "Cancelling Observe..." << std::endl;
OCStackResult result = g_curResource->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);
}
}
示例6: 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();
}
}
示例7: LOGD
/*
* Class: org_iotivity_base_OcRepresentation
* Method: getChildrenArray
* Signature: ()[Lorg/iotivity/base/OcRepresentation;
*/
JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcRepresentation_getChildrenArray
(JNIEnv *env, jobject thiz)
{
LOGD("OcRepresentation_getChildrenArray");
OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
if (!rep)
{
return nullptr;
}
return JniUtils::convertRepresentationVectorToJavaArray(env, rep->getChildren());
}
示例8: allBulbOff
void allBulbOff()
{
OCRepresentation rep;
rep.setValue("DoAction", std::string("AllBulbOff"));
if (g_resource)
{
g_resource->post("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(),
&onPost);
}
}
示例9: onPut
void onPut(const OCRepresentation& rep , const int eCode)
{
if(eCode == SUCCESS_RESPONSE)
{
std::cout << "PUT request was successful" << std::endl;
AttributeMap attributeMap = rep.getAttributeMap();
for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it)
{
std::cout << "\tAttribute name: " << it->first << " value: ";
for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr)
{
std::cout << "\t" << *valueItr << " ";
}
std::cout << std::endl;
}
std::vector< OCRepresentation > children = rep.getChildren();
for(auto oit = children.begin() ; oit != children.end() ; ++oit)
{
attributeMap = oit->getAttributeMap();
for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it)
{
std::cout << "\tAttribute name: " << it->first << " value: ";
for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr)
{
std::cout << "\t" << *valueItr << " ";
}
std::cout << 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;
QueryParamsMap test;
g_curResource->observe(ObserveType::Observe , test , &onObserve);
}
else
{
std::cout << "onPut Response error: " << eCode << std::endl;
std::exit(-1);
}
}
示例10: wanIpLock
void WANIpConnection::setConnectionType(string newConnectionType)
{
unique_lock<mutex> wanIpLock(m_mutex);
OCRepresentation rep;
rep.setValue("uri", m_resource->uri());
rep.setValue("type", newConnectionType);
m_setConnectionTypeInfoCB = bind(&WANIpConnection::onSetConnectionType, this, _1, _2, _3);
m_resource->post(rep, QueryParamsMap(), m_setConnectionTypeInfoCB);
if (m_cv.wait_for(wanIpLock, chrono::seconds(MAX_WAIT_TIME_FOR_BLOCKING_CALL)) == cv_status::timeout)
{
cerr << "Remote device failed to respond to the request." << endl;
}
}
示例11: onGet
void onGet(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode)
{
try
{
if(eCode == OC_STACK_OK)
{
dlog_print(DLOG_INFO, LOG_TAG, "GET request was successful %s", rep.getUri().c_str());
std::cout << "Attributes : " << rep.numberOfAttributes() << std::endl;
typedef std::map<std::string, int>::iterator it_type;
for(it_type iterator = intprops.begin(); iterator != intprops.end(); iterator++) {
std::cout << "Key : " << iterator->first << " Value = "<<rep[iterator->first]<<std::endl;
iterator->second = rep[iterator->first];
}
typedef std::map<std::string, double>::iterator itd_type;
for(itd_type iterator = doubleprops.begin(); iterator != doubleprops.end(); iterator++) {
std::cout << "Key : " << iterator->first << " Value = "<<rep[iterator->first]<<std::endl;
iterator->second = rep[iterator->first];
}
rvidata r;
r.lt = rep["leftTemperature"];
r.rt = rep["rightTemperature"];
r.lhs = rep["leftSeatHeat"];
r.rhs = rep["rightSeatHeat"];
r.fs = rep["fanSpeed"];
r.fd = rep["fanDown"];
r.fr = rep["fanRight"];
r.fu = rep["fanUp"];
r.fac = rep["fanAC"];
r.fa = rep["fanAuto"];
r.fr = rep["fanRecirc"];
r.dm = rep["defrostMax"];
r.df = rep["defrostFront"];
r.dr = rep["defrostRear"];
send_message(&r);
}
else
{
dlog_print(DLOG_INFO, LOG_TAG, "GET request was UNsuccessful");
}
}
catch(std::exception& e)
{
std::cout << "Exception: " << e.what() << " in onPut" << std::endl;
}
}
示例12: checkProvInformationCb
void RemoteEnrolleeResource::checkProvInformationCb(const HeaderOptions& /*headerOptions*/,
const OCRepresentation& rep, const int eCode)
{
OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : %s, eCode = %d",
rep.getUri().c_str(),
eCode);
if (eCode != 0)
{
OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
"checkProvInformationCb : 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, "checkProvInformationCb : ps - %d", ps);
//Provisioning status check
if (ps == ES_PS_PROVISIONING_COMPLETED)
{
OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
"checkProvInformationCb : Provisioning is success. "
"Now trigger network connection ");
#ifdef REMOTE_ARDUINO_ENROLEE
std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONING_SUCCESS);
m_provStatusCb(provStatus);
#endif
triggerNetworkConnection();
return;
}
else
{
OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
"checkProvInformationCb : Provisioning is failed ");
std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
m_provStatusCb(provStatus);
return;
}
}
示例13: allBulbOn
void allBulbOn()
{
OCRepresentation rep;
rep.setValue("DoAction", std::string("AllBulbOn"));
if (g_resource)
{
OCStackResult res = g_resource->post("a.collection", GROUP_INTERFACE,
rep, QueryParamsMap(), &onPost);
if( res != OC_STACK_OK )
cout << "failed" << endl;
}
}
示例14: 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;
}
}
示例15: 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;
}