return OCPlatform::bindResource(m_handle, childResource->m_handle);
}
- OCStackResult sendRepresentation(std::shared_ptr<OCResourceRequest> pRequest)
+ OCStackResult sendRepresentation(shared_ptr<OCResourceRequest> pRequest)
{
- auto pResponse = std::make_shared<OC::OCResourceResponse>();
+ auto pResponse = make_shared<OC::OCResourceResponse>();
pResponse->setRequestHandle(pRequest->getRequestHandle());
pResponse->setResourceHandle(pRequest->getResourceHandle());
{
if (m_interestedObservers.size() > 0)
{
- std::shared_ptr<OCResourceResponse> resourceResponse =
- { std::make_shared<OCResourceResponse>() };
+ shared_ptr<OCResourceResponse> resourceResponse =
+ { make_shared<OCResourceResponse>() };
resourceResponse->setErrorCode(200);
resourceResponse->setResourceRepresentation(getRepresentation(), DEFAULT_INTERFACE);
return OC_STACK_OK;
}
- virtual OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request) = 0;
+ virtual OCEntityHandlerResult entityHandler(shared_ptr<OCResourceRequest> request) = 0;
protected:
OCRepresentation m_representation;
}
}
- OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
+ OCEntityHandlerResult entityHandler(shared_ptr<OCResourceRequest> request)
{
cout << "\tIn Server Binaryswitch entity handler:\n";
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if (request)
{
// Get the request type and request flag
- std::string requestType = request->getRequestType();
+ string requestType = request->getRequestType();
int requestFlag = request->getRequestHandlerFlag();
if (requestFlag & RequestHandlerFlag::RequestFlag)
}
else if (ObserveAction::ObserveUnregister == observationInfo.action)
{
- m_interestedObservers.erase(std::remove(
+ m_interestedObservers.erase(remove(
m_interestedObservers.begin(),
m_interestedObservers.end(),
observationInfo.obsId),
}
else
{
- std::cout << "Request invalid" << std::endl;
+ cout << "Request invalid" << endl;
}
return ehResult;
}
}
- OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
+ OCEntityHandlerResult entityHandler(shared_ptr<OCResourceRequest> request)
{
cout << "\tIn Server Temperature entity handler:\n";
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if (request)
{
// Get the request type and request flag
- std::string requestType = request->getRequestType();
+ string requestType = request->getRequestType();
int requestFlag = request->getRequestHandlerFlag();
if (requestFlag & RequestHandlerFlag::RequestFlag)
}
else if (ObserveAction::ObserveUnregister == observationInfo.action)
{
- m_interestedObservers.erase(std::remove(
+ m_interestedObservers.erase(remove(
m_interestedObservers.begin(),
m_interestedObservers.end(),
observationInfo.obsId),
}
else
{
- std::cout << "Request invalid" << std::endl;
+ cout << "Request invalid" << endl;
}
return ehResult;
}
- OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
+ OCEntityHandlerResult entityHandler(shared_ptr<OCResourceRequest> request)
{
cout << "\tIn Server Airconditioner entity handler:\n";
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if (request)
{
// Get the request type and request flag
- std::string requestType = request->getRequestType();
+ string requestType = request->getRequestType();
int requestFlag = request->getRequestHandlerFlag();
if (requestFlag & RequestHandlerFlag::RequestFlag)
}
else
{
- std::cout << "Request invalid" << std::endl;
+ cout << "Request invalid" << endl;
}
return ehResult;
}
};
-std::condition_variable g_callbackLock;
-std::string g_uid;
-std::string g_accesstoken;
+condition_variable g_callbackLock;
+string g_uid;
+string g_accesstoken;
void onPublish(const OCRepresentation &, const int &eCode)
{
- std::cout << "Publish resource response received, code: " << eCode << std::endl;
+ cout << "Publish resource response received, code: " << eCode << endl;
g_callbackLock.notify_all();
}
for (auto itr = rep.begin(); itr != rep.end(); ++itr)
{
cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
+ if (itr->type() == AttributeType::Vector)
+ {
+ switch (itr->base_type())
+ {
+ case AttributeType::OCRepresentation:
+ for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
+ {
+ printRepresentation(itr2);
+ }
+ break;
+
+ case AttributeType::Integer:
+ for (auto itr2 : (*itr).getValue<vector<int> >())
+ {
+ cout << "\t\t" << itr2 << endl;
+ }
+ break;
+
+ case AttributeType::String:
+ for (auto itr2 : (*itr).getValue<vector<string> >())
+ {
+ cout << "\t\t" << itr2 << endl;
+ }
+ break;
+
+ default:
+ cout << "Unhandled base type " << itr->base_type() << endl;
+ break;
+ }
+ }
+ else if (itr->type() == AttributeType::OCRepresentation)
+ {
+ printRepresentation((*itr).getValue<OCRepresentation>());
+ }
}
}
CT_ADAPTER_TCP);
mutex blocker;
- unique_lock<std::mutex> lock(blocker);
+ unique_lock<mutex> lock(blocker);
if (argc == 5)
{
uri,
rt,
itf,
- std::bind(&AirConditionerResource::entityHandler
- , &airConditioner, std::placeholders::_1),
+ bind(&AirConditionerResource::entityHandler
+ , &airConditioner, placeholders::_1),
OC_DISCOVERABLE);
if (result != OC_STACK_OK)
uri,
rt,
itf,
- std::bind(&BinarySwitchResource::entityHandler
- , &binarySwitch, std::placeholders::_1),
+ bind(&BinarySwitchResource::entityHandler
+ , &binarySwitch, placeholders::_1),
OC_OBSERVABLE);
uri = temperature.getResourceUri();
uri,
rt,
itf,
- std::bind(&TemperatureResource::entityHandler
- , &temperature, std::placeholders::_1),
+ bind(&TemperatureResource::entityHandler
+ , &temperature, placeholders::_1),
OC_OBSERVABLE);
result = airConditioner.addChildResource(&binarySwitch);
condition_variable g_callbackLock;
-std::string g_uid;
-std::string g_accesstoken;
+string g_uid;
+string g_accesstoken;
string g_host;
OC::OCResource::Ptr g_binaryswitchResource;
for (auto itr = rep.begin(); itr != rep.end(); ++itr)
{
cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
+ if (itr->type() == AttributeType::Vector)
+ {
+ switch (itr->base_type())
+ {
+ case AttributeType::OCRepresentation:
+ for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
+ {
+ printRepresentation(itr2);
+ }
+ break;
+
+ case AttributeType::Integer:
+ for (auto itr2 : (*itr).getValue<vector<int> >())
+ {
+ cout << "\t\t" << itr2 << endl;
+ }
+ break;
+
+ case AttributeType::String:
+ for (auto itr2 : (*itr).getValue<vector<string> >())
+ {
+ cout << "\t\t" << itr2 << endl;
+ }
+ break;
+
+ default:
+ cout << "Unhandled base type " << itr->base_type() << endl;
+ break;
+ }
+ }
+ else if (itr->type() == AttributeType::OCRepresentation)
+ {
+ printRepresentation((*itr).getValue<OCRepresentation>());
+ }
}
}
}
cout << "OBSERVE RESULT:" << endl;
- printResource(rep);
+ printRepresentation(rep);
}
else
{
if (eCode == OC_STACK_OK)
{
- std::cout << "Observe registration failed or de-registration action failed/succeeded" << std::endl;
+ cout << "Observe registration failed or de-registration action failed/succeeded" << endl;
}
else
{
}
}
-void onPut(const HeaderOptions & /*headerOptions*/, const OCRepresentation &rep, const int eCode)
+void onPost(const HeaderOptions & /*headerOptions*/, const OCRepresentation &rep, const int eCode)
{
- cout << "PUT response: " << eCode << endl;
+ cout << "POST response: " << eCode << endl;
- printResource(rep);
+ printRepresentation(rep);
}
void turnOnOffSwitch(bool toTurn)
binarySwitch.setValue("value", toTurn);
QueryParamsMap query;
- g_binaryswitchResource->post("oic.r.switch.binary", DEFAULT_INTERFACE, binarySwitch, query, &onPut);
+ g_binaryswitchResource->post("oic.r.switch.binary", DEFAULT_INTERFACE, binarySwitch, query,
+ &onPost);
}
void getCollectionResource(const HeaderOptions &,
}
}
-void presenceDevice(OCStackResult , const unsigned int i, const std::string &str)
+void presenceDevice(OCStackResult , const unsigned int i, const string &str)
{
cout << "Presence received, i=" << i << " str=" << str << endl;
}
mutex blocker;
- unique_lock<std::mutex> lock(blocker);
+ unique_lock<mutex> lock(blocker);
if (argc == 5)
{
for (auto itr = rep.begin(); itr != rep.end(); ++itr)
{
cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
- }
-}
-
-void onSearchUser(const HeaderOptions & /*headerOptions*/,
- const OCRepresentation &rep, const int eCode)
-{
- if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
- {
- cout << "\tSearchUser request was successful" << endl;
-
- std::vector<OCRepresentation> userList = rep.getValue<std::vector<OCRepresentation>>("ulist");
-
- for (auto user : userList)
+ if (itr->type() == AttributeType::Vector)
{
- // Mandatory field
- cout << "\tuid: " << user.getValue<string>("uid") << endl;
-
- // Optional field
- cout << "\tuinfo: " << endl;
- OCRepresentation uinfo = user.getValue<OCRepresentation>("uinfo");
- for (auto itr = uinfo.begin(); itr != uinfo.end(); ++itr)
+ switch (itr->base_type())
{
- cout << "\t\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
+ case AttributeType::OCRepresentation:
+ for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
+ {
+ printRepresentation(itr2);
+ }
+ break;
+
+ case AttributeType::Integer:
+ for (auto itr2 : (*itr).getValue<vector<int> >())
+ {
+ cout << "\t\t" << itr2 << endl;
+ }
+ break;
+
+ case AttributeType::String:
+ for (auto itr2 : (*itr).getValue<vector<string> >())
+ {
+ cout << "\t\t" << itr2 << endl;
+ }
+ break;
+
+ default:
+ cout << "Unhandled base type " << itr->base_type() << endl;
+ break;
}
- cout << endl;
}
- }
- else
- {
- cout << "\tSearchUser Response error: " << eCode << endl;
+ else if (itr->type() == AttributeType::OCRepresentation)
+ {
+ printRepresentation((*itr).getValue<OCRepresentation>());
+ }
}
}
{
if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
{
- std::cout << "\tRequest was successful: " << eCode << std::endl;
+ cout << "\tRequest was successful: " << eCode << endl;
printRepresentation(rep);
}
else
{
- std::cout << "\tResponse error: " << eCode << std::endl;
+ cout << "\tResponse error: " << eCode << endl;
}
}
{
if (eCode == OC_STACK_OK)
{
- std::cout << "Observe registration failed or de-registration action failed/succeeded" << std::endl;
+ cout << "Observe registration failed or de-registration action failed/succeeded" << endl;
}
else
{
}
}
-std::condition_variable g_callbackLock;
-std::string g_uid;
-std::string g_accesstoken;
+condition_variable g_callbackLock;
+string g_uid;
+string g_accesstoken;
void handleLoginoutCB(const HeaderOptions &,
const OCRepresentation &rep, const int ecode)
CT_ADAPTER_TCP);
mutex blocker;
- unique_lock<std::mutex> lock(blocker);
+ unique_lock<mutex> lock(blocker);
if (argc == 5)
{
}
cout << "---Group & Invite sample---" << endl;
- cout << " 1 - searchUser" << endl;
- cout << " 2 - deleteDevice" << endl;
- cout << " 3 - createGroup" << endl;
- cout << " 4 - observeGroup" << endl;
- cout << " 5 - getGroupList" << endl;
- cout << " 6 - deleteGroup" << endl;
- cout << " 7 - joinGroup" << endl;
- cout << " 8 - addDeviceToGroup" << endl;
- cout << " 9 - getGroupInfo" << endl;
- cout << " 10 - leaveGroup" << endl;
- cout << " 11 - deleteDeviceFromGroup" << endl;
- cout << " 12 - observeInvitation" << endl;
- cout << " 13 - sendInvitation" << endl;
- cout << " 14 - cancelInvitation" << endl;
- cout << " 15 - deleteInvitation" << endl;
- cout << " 16 - cancelObserveGroup" << endl;
- cout << " 17 - cancelObserveInvitation" << endl;
- cout << " 18 - exit" << endl;
+ cout << " 1 - searchUser using user UUID" << endl;
+ cout << " 2 - searchUser using email" << endl;
+ cout << " 3 - searchUser using phone" << endl;
+ cout << " 4 - deleteDevice" << endl;
+ cout << " 5 - createGroup" << endl;
+ cout << " 6 - observeGroup" << endl;
+ cout << " 7 - getGroupList" << endl;
+ cout << " 8 - deleteGroup" << endl;
+ cout << " 9 - joinGroup" << endl;
+ cout << " 10 - addDeviceToGroup" << endl;
+ cout << " 11 - getGroupInfo" << endl;
+ cout << " 12 - leaveGroup" << endl;
+ cout << " 13 - deleteDeviceFromGroup" << endl;
+ cout << " 14 - observeInvitation" << endl;
+ cout << " 15 - sendInvitation" << endl;
+ cout << " 16 - cancelInvitation" << endl;
+ cout << " 17 - deleteInvitation" << endl;
+ cout << " 18 - cancelObserveGroup" << endl;
+ cout << " 19 - cancelObserveInvitation" << endl;
+ cout << " 20 - exit" << endl;
string cmd;
string cmd2;
case 1:
cout << "Put userUUID to search:" << endl;
cin >> cmd;
- result = accountMgr->searchUser(cmd, &onSearchUser);
+ result = accountMgr->searchUser(cmd, &ocPost);
break;
case 2:
+ cout << "Put email to search:" << endl;
+ cin >> cmd;
+ query["email"] = cmd;
+ result = accountMgr->searchUser(query, &ocPost);
+ break;
+
+ case 3:
+ cout << "Put phone number to search:" << endl;
+ cin >> cmd;
+ query["phone"] = cmd;
+ result = accountMgr->searchUser(query, &ocPost);
+ break;
+
+ case 4:
cout << "PUT deviceID to delete:";
cin >> cmd;
result = accountMgr->deleteDevice(cmd, &onDelete);
break;
- case 3:
+ case 5:
result = accountMgr->createGroup(OC::AclGroupType::PUBLIC, &ocPost);
break;
- case 4:
+ case 6:
cout << "PUT groupId to observe:";
cin >> cmd;
result = accountMgr->observeGroup(cmd, &onObserve);
break;
- case 5:
+ case 7:
result = accountMgr->getGroupList(&ocPost);
break;
- case 6:
+ case 8:
cout << "PUT groupId to delete:";
cin >> cmd;
result = accountMgr->deleteGroup(cmd, &onDelete);
break;
- case 7:
+ case 9:
cout << "PUT groupId to join:";
cin >> cmd;
result = accountMgr->joinGroup(cmd, &ocPost);
break;
- case 8:
+ case 10:
cout << "PUT groupId to add device:";
cin >> cmd;
cout << "PUT deviceId to add to group:";
cin >> cmd2;
{
- std::vector<std::string> deviceIds;
+ vector<string> deviceIds;
deviceIds.push_back(cmd2);
result = accountMgr->addDeviceToGroup(cmd, deviceIds, &ocPost);
}
break;
- case 9:
+ case 11:
cout << "PUT groupId to get info:";
cin >> cmd;
result = accountMgr->getGroupInfo(cmd, &ocPost);
break;
- case 10:
+ case 12:
cout << "PUT groupId to leave:";
cin >> cmd;
result = accountMgr->leaveGroup(cmd, &onDelete);
break;
- case 11:
+ case 13:
cout << "PUT groupId to remove device:";
cin >> cmd;
cout << "PUT deviceId to remove from group:";
cin >> cmd2;
{
- std::vector<std::string> deviceIds;
+ vector<string> deviceIds;
deviceIds.push_back(cmd2);
result = accountMgr->deleteDeviceFromGroup(cmd, deviceIds, &onDelete);
}
break;
- case 12:
+ case 14:
result = accountMgr->observeInvitation(&onObserve);
break;
- case 13:
+ case 15:
cout << "PUT groupId to invite:";
cin >> cmd;
cout << "PUT userUUID to invite:";
result = accountMgr->sendInvitation(cmd, cmd2, &ocPost);
break;
- case 14:
+ case 16:
cout << "PUT groupId to cancel invitation:";
cin >> cmd;
cout << "PUT userUUID to cancel invitation:";
result = accountMgr->cancelInvitation(cmd, cmd2, &onDelete);
break;
- case 15:
+ case 17:
cout << "PUT groupId to delete invitation:";
cin >> cmd;
result = accountMgr->deleteInvitation(cmd, &onDelete);
break;
- case 16:
+ case 18:
cout << "PUT groupId to cancel observe:";
cin >> cmd;
result = accountMgr->cancelObserveGroup(cmd);
break;
- case 17:
+ case 19:
result = accountMgr->cancelObserveInvitation();
break;
- //113 is q
- case 18:
+ case 20:
goto exit;
break;
}
for (auto itr = rep.begin(); itr != rep.end(); ++itr)
{
cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
+ if (itr->type() == AttributeType::Vector)
+ {
+ switch (itr->base_type())
+ {
+ case AttributeType::OCRepresentation:
+ for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
+ {
+ printRepresentation(itr2);
+ }
+ break;
+
+ case AttributeType::Integer:
+ for (auto itr2 : (*itr).getValue<vector<int> >())
+ {
+ cout << "\t\t" << itr2 << endl;
+ }
+ break;
+
+ case AttributeType::String:
+ for (auto itr2 : (*itr).getValue<vector<string> >())
+ {
+ cout << "\t\t" << itr2 << endl;
+ }
+ break;
+
+ default:
+ cout << "Unhandled base type " << itr->base_type() << endl;
+ break;
+ }
+ }
+ else if (itr->type() == AttributeType::OCRepresentation)
+ {
+ printRepresentation((*itr).getValue<OCRepresentation>());
+ }
}
}
////////////////////////////////////////Publisher Sample
-void createTopicCB(const int ecode, const std::string &originUri,
- std::shared_ptr<OC::OCResource> topic)
+void createTopicCB(const int ecode, const string &originUri,
+ shared_ptr<OC::OCResource> topic)
{
- std::cout << "Create topic response received, code: " << ecode << std::endl;
+ cout << "Create topic response received, code: " << ecode << endl;
if (ecode == OCStackResult::OC_STACK_RESOURCE_CREATED)
{
- std::cout << "Created topic : " << topic->uri() << std::endl;
+ cout << "Created topic : " << topic->uri() << endl;
}
else
{
- std::cout << "Topic creation failed : " << originUri << std::endl;
+ cout << "Topic creation failed : " << originUri << endl;
}
}
void publishMessageCB(const HeaderOptions &, const OCRepresentation &, const int eCode)
{
- std::cout << "Publish message response received, code: " << eCode << std::endl;
+ cout << "Publish message response received, code: " << eCode << endl;
}
-void discoverTopicCB(const int ecode, const std::string &, std::shared_ptr<OC::OCResource> topic)
+void discoverTopicCB(const int ecode, const string &, shared_ptr<OC::OCResource> topic)
{
cout << "Topic discovered code: " << ecode << endl;
gTopicList.push_back(topic);
}
////////////////////////////////////////End of Publisher Sample
-std::condition_variable g_callbackLock;
-std::string g_uid;
-std::string g_accesstoken;
+condition_variable g_callbackLock;
+string g_uid;
+string g_accesstoken;
void handleLoginoutCB(const HeaderOptions &,
const OCRepresentation &rep, const int ecode)
CT_ADAPTER_TCP);
mutex blocker;
- unique_lock<std::mutex> lock(blocker);
+ unique_lock<mutex> lock(blocker);
if (argc == 5)
{
for (auto itr = rep.begin(); itr != rep.end(); ++itr)
{
cout << "\t" << itr->attrname() << ":\t" << itr->getValueToString() << endl;
+ if (itr->type() == AttributeType::Vector)
+ {
+ switch (itr->base_type())
+ {
+ case AttributeType::OCRepresentation:
+ for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
+ {
+ printRepresentation(itr2);
+ }
+ break;
+
+ case AttributeType::Integer:
+ for (auto itr2 : (*itr).getValue<vector<int> >())
+ {
+ cout << "\t\t" << itr2 << endl;
+ }
+ break;
+
+ case AttributeType::String:
+ for (auto itr2 : (*itr).getValue<vector<string> >())
+ {
+ cout << "\t\t" << itr2 << endl;
+ }
+ break;
+
+ default:
+ cout << "Unhandled base type " << itr->base_type() << endl;
+ break;
+ }
+ }
+ else if (itr->type() == AttributeType::OCRepresentation)
+ {
+ printRepresentation((*itr).getValue<OCRepresentation>());
+ }
}
}
{
if (eCode == OC_STACK_OK)
{
- std::cout << "Observe registration failed or de-registration action failed/succeeded" << std::endl;
+ cout << "Observe registration failed or de-registration action failed/succeeded" << endl;
}
else
{
}
}
-void discoverTopicCB(const int ecode, const std::string &brokerUri,
- std::shared_ptr<OC::OCResource> topic)
+void discoverTopicCB(const int ecode, const string &brokerUri,
+ shared_ptr<OC::OCResource> topic)
{
cout << "Topic discovered from " << brokerUri << " code: " << ecode << endl;
gTopicList.push_back(topic);
////////////////////////////////////////Subscriber Sample
condition_variable g_callbackLock;
-std::string g_uid;
-std::string g_accesstoken;
+string g_uid;
+string g_accesstoken;
void handleLoginoutCB(const HeaderOptions &,
const OCRepresentation &rep, const int ecode)
CT_ADAPTER_TCP);
mutex blocker;
- unique_lock<std::mutex> lock(blocker);
+ unique_lock<mutex> lock(blocker);
if (argc == 5)
{
#include "ocpayload.h"
#include "oicresourcedirectory.h"
+using namespace std;
+
#define DEFAULT_CONTEXT_VALUE 0x99
#define DEFAULT_AUTH_SIGNUP "/oic/account"
#define DEFAULT_AUTH_SESSION "/oic/account/session"
OCRepPayload *payload = OCRepPayloadCreate();
if (!payload)
{
- std::cout << "Failed to allocate Payload" << std::endl;
+ cout << "Failed to allocate Payload" << endl;
return nullptr;
}
{
if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
{
- std::cout << "Incoming payload not a representation" << std::endl;
+ cout << "Incoming payload not a representation" << endl;
return nullptr;
}
OCRepPayload *getResp = constructResponse(ehRequest);
if (!getResp)
{
- std::cout << "constructResponse failed" << std::endl;
+ cout << "constructResponse failed" << endl;
return OC_EH_ERROR;
}
if (!putResp)
{
- std::cout << "Failed to construct Json response" << std::endl;
+ cout << "Failed to construct Json response" << endl;
return OC_EH_ERROR;
}
if (gLightUnderObservation)
{
- std::cout << " =====> Notifying stack of new power level " << gLightInstance[0].power << std::endl;
- std::cout << " =====> Notifying stack of new power level " << gLightInstance[1].power << std::endl;
+ cout << " =====> Notifying stack of new power level " << gLightInstance[0].power << endl;
+ cout << " =====> Notifying stack of new power level " << gLightInstance[1].power << endl;
// Notifying all observers
result = OCNotifyAllObservers(gLightInstance[0].handle, OC_NA_QOS);
result = OCNotifyAllObservers(gLightInstance[1].handle, OC_NA_QOS);
- std::cout << " =====> Notifying result " << result << std::endl;
+ cout << " =====> Notifying result " << result << endl;
}
}
return NULL;
void ProcessObserveRegister(OCEntityHandlerRequest *ehRequest)
{
- std::cout << "Received observation registration request with observation Id " <<
- ehRequest->obsInfo.obsId << std::endl;
+ cout << "Received observation registration request with observation Id " <<
+ ehRequest->obsInfo.obsId << endl;
if (!observeThreadStarted)
{
{
bool clientStillObserving = false;
- std::cout << "Received observation deregistration request for observation Id " <<
- ehRequest->obsInfo.obsId << std::endl;
+ cout << "Received observation deregistration request for observation Id " <<
+ ehRequest->obsInfo.obsId << endl;
for (uint8_t i = 0; i < SAMPLE_MAX_NUM_OBSERVATIONS; i++)
{
if (interestedObservers[i].observationId == ehRequest->obsInfo.obsId)
// Validate pointer
if (!entityHandlerRequest)
{
- std::cout << "Invalid request pointer" << std::endl;
+ cout << "Invalid request pointer" << endl;
return OC_EH_ERROR;
}
if (flag & OC_REQUEST_FLAG)
{
- std::cout << "Flag includes OC_REQUEST_FLAG" << std::endl;
+ cout << "Flag includes OC_REQUEST_FLAG" << endl;
if (OC_REST_GET == entityHandlerRequest->method)
{
- std::cout << "Received OC_REST_GET from client" << std::endl;
+ cout << "Received OC_REST_GET from client" << endl;
ehResult = ProcessGetRequest(entityHandlerRequest, &payload);
}
else if (OC_REST_PUT == entityHandlerRequest->method)
{
- std::cout << "Received OC_REST_PUT from client" << std::endl;
+ cout << "Received OC_REST_PUT from client" << endl;
ehResult = ProcessPutRequest(entityHandlerRequest, &payload);
}
else
{
- std::cout << "Received unsupported method %d from client " << entityHandlerRequest->method <<
- std::endl;
+ cout << "Received unsupported method %d from client " << entityHandlerRequest->method <<
+ endl;
ehResult = OC_EH_ERROR;
}
// If the result isn't an error or forbidden, send response
// Send the response
if (OCDoResponse(&response) != OC_STACK_OK)
{
- std::cout << "Error sending response" << std::endl;
+ cout << "Error sending response" << endl;
ehResult = OC_EH_ERROR;
}
}
if (flag & OC_OBSERVE_FLAG)
{
- std::cout << "Flag includes OC_OBSERVE_FLAG" << std::endl;
+ cout << "Flag includes OC_OBSERVE_FLAG" << endl;
if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo.action)
{
- std::cout << "Received OC_OBSERVE_REGISTER from client" << std::endl;
+ cout << "Received OC_OBSERVE_REGISTER from client" << endl;
ProcessObserveRegister(entityHandlerRequest);
}
else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo.action)
{
- std::cout << "Received OC_OBSERVE_DEREGISTER from client" << std::endl;
+ cout << "Received OC_OBSERVE_DEREGISTER from client" << endl;
ProcessObserveDeregister(entityHandlerRequest);
}
}
{
if (!uri)
{
- std::cout << "Resource URI cannot be NULL" << std::endl;
+ cout << "Resource URI cannot be NULL" << endl;
return -1;
}
OCEntityHandlerCb,
NULL,
OC_DISCOVERABLE | OC_OBSERVABLE);
- std::cout << "Created Light resource with result:" << res << std::endl;
+ cout << "Created Light resource with result:" << res << endl;
return res;
}
{
if (ctx != (void *)DEFAULT_CONTEXT_VALUE)
{
- std::cout << "Invalid Publish callback received" << std::endl;
+ cout << "Invalid Publish callback received" << endl;
}
- std::cout << "Publish resource response received, code: " << clientResponse->result << std::endl;
+ cout << "Publish resource response received, code: " << clientResponse->result << endl;
return OC_STACK_KEEP_TRANSACTION;
}
-void PublishResources(std::string host)
+void PublishResources(string host)
{
- std::cout << "Publishing resources..." << std::endl;
+ cout << "Publishing resources..." << endl;
if (createLightResource((char *)"/a/light/0", &gLightInstance[0]) != 0)
{
- std::cout << "Unable to create sample resource" << std::endl;
+ cout << "Unable to create sample resource" << endl;
}
OCResourceHandle resourceHandles[1] = { gLightInstance[0].handle,
cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- std::cout << "Publish default resources" << std::endl;
+ cout << "Publish default resources" << endl;
OCDeviceInfo devInfoRoomLight;
OCStringLL deviceType;
if (res != OC_STACK_OK)
{
- std::cout << "Setting device info failed" << std::endl;
+ cout << "Setting device info failed" << endl;
}
res = OCRDPublish(host.c_str(), CT_ADAPTER_TCP, NULL, 0, &cbData,
OC_LOW_QOS);
if (res != OC_STACK_OK)
{
- std::cout << "Unable to publish default resources to cloud" << std::endl;
+ cout << "Unable to publish default resources to cloud" << endl;
}
- std::cout << "Publish user resources" << std::endl;
+ cout << "Publish user resources" << endl;
res = OCRDPublish(host.c_str(), CT_ADAPTER_TCP, resourceHandles, 1, &cbData,
OC_LOW_QOS);
if (res != OC_STACK_OK)
{
- std::cout << "Unable to publish user resources to cloud" << std::endl;
+ cout << "Unable to publish user resources to cloud" << endl;
}
}
{
while (value)
{
- std::cout << "Key: " << value->name;
+ cout << "Key: " << value->name;
switch (value->type)
{
case OCREP_PROP_NULL:
- std::cout << " Value: None" << std::endl;
+ cout << " Value: None" << endl;
break;
case OCREP_PROP_INT:
- std::cout << " Value: " << value->i << std::endl;
+ cout << " Value: " << value->i << endl;
break;
case OCREP_PROP_DOUBLE:
- std::cout << " Value: " << value->d << std::endl;
+ cout << " Value: " << value->d << endl;
break;
case OCREP_PROP_BOOL:
- std::cout << " Value: " << value->b << std::endl;
+ cout << " Value: " << value->b << endl;
break;
case OCREP_PROP_STRING:
- std::cout << " Value: " << value->str << std::endl;
+ cout << " Value: " << value->str << endl;
break;
case OCREP_PROP_BYTE_STRING:
- std::cout << " Value: Byte String" << std::endl;
+ cout << " Value: Byte String" << endl;
break;
case OCREP_PROP_OBJECT:
- std::cout << " Value: Object" << std::endl;
+ cout << " Value: Object" << endl;
break;
case OCREP_PROP_ARRAY:
- std::cout << " Value: Array" << std::endl;
+ cout << " Value: Array" << endl;
break;
}
value = value->next;
}
}
-std::string g_host = "coap+tcp://";
+string g_host = "coap+tcp://";
OCStackApplicationResult handleLoginoutCB(void *ctx,
OCDoHandle /*handle*/,
{
if (ctx != (void *)DEFAULT_CONTEXT_VALUE)
{
- std::cout << "Invalid Login/out callback received" << std::endl;
+ cout << "Invalid Login/out callback received" << endl;
}
- std::cout << "Login/out response received code: " << clientResponse->result << std::endl;
+ cout << "Login/out response received code: " << clientResponse->result << endl;
if (clientResponse->payload != NULL &&
clientResponse->payload->type == PAYLOAD_TYPE_REPRESENTATION)
{
- std::cout << "PAYLOAD_TYPE_REPRESENTATION received" << std::endl;
+ cout << "PAYLOAD_TYPE_REPRESENTATION received" << endl;
OCRepPayloadValue *val = ((OCRepPayload *)clientResponse->payload)->values;
{
if (ctx != (void *)DEFAULT_CONTEXT_VALUE)
{
- std::cout << "Invalid Register callback received" << std::endl;
+ cout << "Invalid Register callback received" << endl;
}
- std::cout << "Register response received code: " << clientResponse->result << std::endl;
+ cout << "Register response received code: " << clientResponse->result << endl;
if (clientResponse->payload != NULL &&
clientResponse->payload->type == PAYLOAD_TYPE_REPRESENTATION)
{
- std::cout << "PAYLOAD_TYPE_REPRESENTATION received" << std::endl;
- std::cout << "You can Sign-In using retrieved accesstoken when disconnected or reboot" <<
- std::endl;
+ cout << "PAYLOAD_TYPE_REPRESENTATION received" << endl;
+ cout << "You can Sign-In using retrieved accesstoken when disconnected or reboot" <<
+ endl;
OCRepPayloadValue *val = ((OCRepPayload *)clientResponse->payload)->values;
void PrintUsage()
{
- std::cout << std::endl;
- std::cout << "Usage : thin_cloud_device <addr:port> <uid> <accesstoken>\n";
- std::cout << "<addr:port>: Cloud Address, \"127.0.0.1:5683\"\n";
- std::cout <<
- "<accesstoken>: String value, Provided by response of onboarding scenario\n\tor kind of registration portal\n\n";
- std::cout <<
- "sample: \"cloud_device 127.0.0.1:5683\"\n\t-Sign-Up mode\n\n";
- std::cout <<
- "sample: \"cloud_device 127.0.0.1:5683 abcdefg 1234567890123456\"\n\t-Sign-in and Publish resource to registered account\n\n";
+ cout << endl;
+ cout << "Usage : thin_cloud_device <addr:port> <uid> <accesstoken>\n";
+ cout << "<addr:port>: Cloud Address, \"127.0.0.1:5683\"\n";
+ cout <<
+ "<accesstoken>: String value, Provided by response of onboarding scenario\n\tor kind of registration portal\n\n";
+ cout <<
+ "sample: \"cloud_device 127.0.0.1:5683\"\n\t-Sign-Up mode\n\n";
+ cout <<
+ "sample: \"cloud_device 127.0.0.1:5683 abcdefg 1234567890123456\"\n\t-Sign-in and Publish resource to registered account\n\n";
}
static FILE *client_open(const char * /*path*/, const char *mode)
int main(int argc, char *argv[])
{
- std::string uId;
- std::string accessToken;
+ string uId;
+ string accessToken;
- std::string authProvider;
- std::string authCode;
+ string authProvider;
+ string authCode;
OCMode stackMode = OC_CLIENT_SERVER;
switch (argc)
{
case 2:
- std::cout << "Put auth provider name(ex: github)" << std::endl;
- std::cin >> authProvider;
- std::cout << "Put auth code(provided by auth provider)" << std::endl;
- std::cin >> authCode;
+ cout << "Put auth provider name(ex: github)" << endl;
+ cin >> authProvider;
+ cout << "Put auth code(provided by auth provider)" << endl;
+ cin >> authCode;
break;
case 4:
g_host += argv[1];
- std::cout << "Host " << g_host.c_str() << std::endl;
+ cout << "Host " << g_host.c_str() << endl;
OCPersistentStorage ps{ client_open, fread, fwrite, fclose, unlink };
if (OCRegisterPersistentStorageHandler(&ps) != OC_STACK_OK)
{
- std::cout << "OCStack init persistent storage error" << std::endl;
+ cout << "OCStack init persistent storage error" << endl;
return 0;
}
if (OCInit(NULL, 0, stackMode) != OC_STACK_OK)
{
- std::cout << "OCStack init error" << std::endl;
+ cout << "OCStack init error" << endl;
return 0;
}
switch (argc)
{
case 2:
- std::cout << "Sign-Up to cloud using " << authProvider << " " << authCode << std::endl;
+ cout << "Sign-Up to cloud using " << authProvider << " " << authCode << endl;
res = OCCloudSignup(g_host.c_str(), OCGetServerInstanceIDString(), authProvider.c_str(),
authCode.c_str(), handleRegisterCB);
- std::cout << "OCCloudSignup return " << res << std::endl;
+ cout << "OCCloudSignup return " << res << endl;
break;
case 4:
- std::cout << "Sign-In to cloud using " << accessToken << std::endl;
+ cout << "Sign-In to cloud using " << accessToken << endl;
res = OCCloudLogin(g_host.c_str(), uId.c_str(), OCGetServerInstanceIDString(), accessToken.c_str(),
handleLoginoutCB);
- std::cout << "OCCloudLogin return " << res << std::endl;
+ cout << "OCCloudLogin return " << res << endl;
break;
default:
- std::cout << "Waiting response.." << std::endl;
+ cout << "Waiting response.." << endl;
while (true)
{
if (OCProcess() != OC_STACK_OK)
{
- std::cout << "OCProcess process error" << std::endl;
+ cout << "OCProcess process error" << endl;
}
sleep(1);
if (OCStop() != OC_STACK_OK)
{
- std::cout << "OCStop process error" << std::endl;
+ cout << "OCStop process error" << endl;
}
return 0;