1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "InProcClientWrapper.h"
24 #include "OCPlatform.h"
25 #include "OCResource.h"
26 #include <OCSerialization.h>
31 InProcClientWrapper::InProcClientWrapper(
32 std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
33 : m_threadRun(false), m_csdkLock(csdkLock),
36 // if the config type is server, we ought to never get called. If the config type
37 // is both, we count on the server to run the thread and do the initialize
39 if(m_cfg.mode == ModeType::Client)
41 OCStackResult result = OCInit(m_cfg.ipAddress.c_str(), m_cfg.port, OC_CLIENT);
43 if(OC_STACK_OK != result)
45 throw InitializeException(OC::InitException::STACK_INIT_ERROR, result);
49 m_listeningThread = std::thread(&InProcClientWrapper::listeningFunc, this);
53 InProcClientWrapper::~InProcClientWrapper()
55 if(m_threadRun && m_listeningThread.joinable())
58 m_listeningThread.join();
61 // only stop if we are the ones who actually called 'init'. We are counting
62 // on the server to do the stop.
63 if(m_cfg.mode == ModeType::Client)
69 void InProcClientWrapper::listeningFunc()
74 auto cLock = m_csdkLock.lock();
77 std::lock_guard<std::recursive_mutex> lock(*cLock);
82 result = OC_STACK_ERROR;
85 if(result != OC_STACK_OK)
87 // TODO: do something with result if failed?
90 // To minimize CPU utilization we may wish to do this with sleep
91 std::this_thread::sleep_for(std::chrono::milliseconds(10));
95 OCRepresentation parseGetSetCallback(OCClientResponse* clientResponse)
97 if(clientResponse->resJSONPayload == nullptr || clientResponse->resJSONPayload[0] == '\0')
99 return OCRepresentation();
105 oc.setJSONRepresentation(clientResponse->resJSONPayload);
107 catch (cereal::RapidJSONException& ex)
109 oclog() <<"RapidJSON Exception in parseGetSetCallback: "<<ex.what() <<std::endl<<
110 "Data was:"<< clientResponse->resJSONPayload<< ":" << std::flush;
111 throw OCException(OC::Exception::INVALID_REPRESENTATION, OC_STACK_INVALID_JSON);
113 catch (cereal::Exception& ex)
115 oclog() <<"Cereal Exception in parseGetSetCallback: "<<ex.what() <<std::endl<<
116 "Data was:"<< clientResponse->resJSONPayload<< ":" << std::flush;
117 throw OCException(OC::Exception::INVALID_REPRESENTATION, OC_STACK_INVALID_JSON);
120 std::vector<OCRepresentation>::const_iterator it = oc.representations().begin();
121 if(it == oc.representations().end())
123 return OCRepresentation();
126 // first one is considered the root, everything else is considered a child of this one.
127 OCRepresentation root = *it;
130 std::for_each(it, oc.representations().end(),
131 [&root](const OCRepresentation& repItr)
132 {root.addChild(repItr);});
137 OCStackApplicationResult listenCallback(void* ctx, OCDoHandle handle,
138 OCClientResponse* clientResponse)
140 ClientCallbackContext::ListenContext* context =
141 static_cast<ClientCallbackContext::ListenContext*>(ctx);
143 if(clientResponse->result != OC_STACK_OK)
145 oclog() << "listenCallback(): failed to create resource. clientResponse: "
146 << clientResponse->result
149 return OC_STACK_KEEP_TRANSACTION;
152 auto clientWrapper = context->clientWrapper.lock();
156 oclog() << "listenCallback(): failed to get a shared_ptr to the client wrapper"
158 return OC_STACK_KEEP_TRANSACTION;
161 std::stringstream requestStream;
162 requestStream << clientResponse->resJSONPayload;
168 ListenOCContainer container(clientWrapper, *clientResponse->addr,
169 clientResponse->connType, requestStream);
171 ListenOCContainer container(clientWrapper, *clientResponse->addr,
174 // loop to ensure valid construction of all resources
175 for(auto resource : container.Resources())
177 std::thread exec(context->callback, resource);
182 catch(const std::exception& e)
184 oclog() << "listenCallback failed to parse a malformed message: "
187 << clientResponse->resJSONPayload
189 << clientResponse->result
191 return OC_STACK_KEEP_TRANSACTION;
194 return OC_STACK_KEEP_TRANSACTION;
198 OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl,
199 const std::string& resourceType, OCConnectivityType connectivityType,
200 FindCallback& callback, QualityOfService QoS)
202 OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl,
203 const std::string& resourceType, FindCallback& callback, QualityOfService QoS)
206 OCStackResult result;
208 OCCallbackData cbdata = {0};
210 ClientCallbackContext::ListenContext* context = new ClientCallbackContext::ListenContext();
211 context->callback = callback;
212 context->clientWrapper = shared_from_this();
214 cbdata.context = static_cast<void*>(context);
215 cbdata.cb = listenCallback;
216 cbdata.cd = [](void* c){delete static_cast<ClientCallbackContext::ListenContext*>(c);};
218 auto cLock = m_csdkLock.lock();
221 std::lock_guard<std::recursive_mutex> lock(*cLock);
224 result = OCDoResource(&handle, OC_REST_GET,
225 resourceType.c_str(),
226 nullptr, nullptr, connectivityType,
227 static_cast<OCQualityOfService>(QoS),
231 result = OCDoResource(&handle, OC_REST_GET,
232 resourceType.c_str(),
234 static_cast<OCQualityOfService>(QoS),
242 result = OC_STACK_ERROR;
247 OCStackApplicationResult listenDeviceCallback(void* ctx, OCDoHandle handle,
248 OCClientResponse* clientResponse)
250 ClientCallbackContext::DeviceListenContext* context =
251 static_cast<ClientCallbackContext::DeviceListenContext*>(ctx);
255 OCRepresentation rep = parseGetSetCallback(clientResponse);
256 std::thread exec(context->callback, rep);
259 catch(OC::OCException& e)
261 oclog() <<"Exception in listenDeviceCallback, ignoring response: "
262 <<e.what() <<std::flush;
265 return OC_STACK_KEEP_TRANSACTION;
269 OCStackResult InProcClientWrapper::ListenForDevice(const std::string& serviceUrl,
270 const std::string& deviceURI, OCConnectivityType connectivityType,
271 FindDeviceCallback& callback, QualityOfService QoS)
273 OCStackResult InProcClientWrapper::ListenForDevice(const std::string& serviceUrl,
274 const std::string& deviceURI, FindDeviceCallback& callback, QualityOfService QoS)
277 OCStackResult result;
279 OCCallbackData cbdata = {0};
280 ClientCallbackContext::DeviceListenContext* context =
281 new ClientCallbackContext::DeviceListenContext();
282 context->callback = callback;
283 context->clientWrapper = shared_from_this();
284 cbdata.context = static_cast<void*>(context);
285 cbdata.cb = listenDeviceCallback;
286 cbdata.cd = [](void* c){delete static_cast<ClientCallbackContext::DeviceListenContext*>(c);};
288 auto cLock = m_csdkLock.lock();
291 std::lock_guard<std::recursive_mutex> lock(*cLock);
294 result = OCDoResource(&handle, OC_REST_GET,
296 nullptr, nullptr, connectivityType,
297 static_cast<OCQualityOfService>(QoS),
301 result = OCDoResource(&handle, OC_REST_GET,
304 static_cast<OCQualityOfService>(QoS),
312 result = OC_STACK_ERROR;
317 void parseServerHeaderOptions(OCClientResponse* clientResponse,
318 HeaderOptions& serverHeaderOptions)
322 // Parse header options from server
324 std::string optionData;
326 for(int i = 0; i < clientResponse->numRcvdVendorSpecificHeaderOptions; i++)
328 optionID = clientResponse->rcvdVendorSpecificHeaderOptions[i].optionID;
329 optionData = reinterpret_cast<const char*>
330 (clientResponse->rcvdVendorSpecificHeaderOptions[i].optionData);
331 HeaderOption::OCHeaderOption headerOption(optionID, optionData);
332 serverHeaderOptions.push_back(headerOption);
337 // clientResponse is invalid
338 // TODO check proper logging
339 std::cout << " Invalid response " << std::endl;
343 OCStackApplicationResult getResourceCallback(void* ctx, OCDoHandle handle,
344 OCClientResponse* clientResponse)
346 ClientCallbackContext::GetContext* context =
347 static_cast<ClientCallbackContext::GetContext*>(ctx);
349 OCRepresentation rep;
350 HeaderOptions serverHeaderOptions;
351 OCStackResult result = clientResponse->result;
352 if(result == OC_STACK_OK)
354 parseServerHeaderOptions(clientResponse, serverHeaderOptions);
357 rep = parseGetSetCallback(clientResponse);
359 catch(OC::OCException& e)
365 std::thread exec(context->callback, serverHeaderOptions, rep, result);
367 return OC_STACK_DELETE_TRANSACTION;
371 OCStackResult InProcClientWrapper::GetResourceRepresentation(const std::string& host,
372 const std::string& uri, OCConnectivityType connectivityType,
373 const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
374 GetCallback& callback, QualityOfService QoS)
376 OCStackResult InProcClientWrapper::GetResourceRepresentation(const std::string& host,
377 const std::string& uri, const QueryParamsMap& queryParams,
378 const HeaderOptions& headerOptions, GetCallback& callback,
379 QualityOfService QoS)
382 OCStackResult result;
383 OCCallbackData cbdata = {0};
385 ClientCallbackContext::GetContext* ctx = new ClientCallbackContext::GetContext();
386 ctx->callback = callback;
387 cbdata.context = static_cast<void*>(ctx);
388 cbdata.cb = &getResourceCallback;
389 cbdata.cd = [](void* c){delete static_cast<ClientCallbackContext::GetContext*>(c);};
391 auto cLock = m_csdkLock.lock();
395 std::ostringstream os;
396 os << host << assembleSetResourceUri(uri, queryParams).c_str();
398 std::lock_guard<std::recursive_mutex> lock(*cLock);
400 OCHeaderOption options[MAX_HEADER_OPTIONS];
402 assembleHeaderOptions(options, headerOptions);
404 result = OCDoResource(&handle, OC_REST_GET, os.str().c_str(),
405 nullptr, nullptr, connectivityType,
406 static_cast<OCQualityOfService>(QoS),
408 options, headerOptions.size());
410 result = OCDoResource(&handle, OC_REST_GET, os.str().c_str(),
412 static_cast<OCQualityOfService>(QoS),
414 options, headerOptions.size());
420 result = OC_STACK_ERROR;
426 OCStackApplicationResult setResourceCallback(void* ctx, OCDoHandle handle,
427 OCClientResponse* clientResponse)
429 ClientCallbackContext::SetContext* context =
430 static_cast<ClientCallbackContext::SetContext*>(ctx);
431 OCRepresentation attrs;
432 HeaderOptions serverHeaderOptions;
434 OCStackResult result = clientResponse->result;
435 if (OC_STACK_OK == result ||
436 OC_STACK_RESOURCE_CREATED == result ||
437 OC_STACK_RESOURCE_DELETED == result)
439 parseServerHeaderOptions(clientResponse, serverHeaderOptions);
442 attrs = parseGetSetCallback(clientResponse);
444 catch(OC::OCException& e)
450 std::thread exec(context->callback, serverHeaderOptions, attrs, result);
452 return OC_STACK_DELETE_TRANSACTION;
455 std::string InProcClientWrapper::assembleSetResourceUri(std::string uri,
456 const QueryParamsMap& queryParams)
458 if(uri.back() == '/')
460 uri.resize(uri.size()-1);
463 ostringstream paramsList;
464 if(queryParams.size() > 0)
469 for(auto& param : queryParams)
471 paramsList << param.first <<'='<<param.second<<'&';
474 std::string queryString = paramsList.str();
475 if(queryString.back() == '&')
477 queryString.resize(queryString.size() - 1);
480 std::string ret = uri + queryString;
484 std::string InProcClientWrapper::assembleSetResourcePayload(const OCRepresentation& rep)
486 MessageContainer ocInfo;
487 ocInfo.addRepresentation(rep);
488 return ocInfo.getJSONRepresentation(OCInfoFormat::IncludeOC);
492 OCStackResult InProcClientWrapper::PostResourceRepresentation(const std::string& host,
493 const std::string& uri, OCConnectivityType connectivityType, const OCRepresentation& rep,
494 const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
495 PostCallback& callback, QualityOfService QoS)
497 OCStackResult InProcClientWrapper::PostResourceRepresentation(const std::string& host,
498 const std::string& uri, const OCRepresentation& rep,
499 const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
500 PostCallback& callback, QualityOfService QoS)
503 OCStackResult result;
504 OCCallbackData cbdata = {0};
506 ClientCallbackContext::SetContext* ctx = new ClientCallbackContext::SetContext();
507 ctx->callback = callback;
508 cbdata.cb = &setResourceCallback;
509 cbdata.cd = [](void* c){delete static_cast<ClientCallbackContext::SetContext*>(c);};
510 cbdata.context = static_cast<void*>(ctx);
512 // TODO: in the future the cstack should be combining these two strings!
514 os << host << assembleSetResourceUri(uri, queryParams).c_str();
515 // TODO: end of above
517 auto cLock = m_csdkLock.lock();
521 std::lock_guard<std::recursive_mutex> lock(*cLock);
522 OCHeaderOption options[MAX_HEADER_OPTIONS];
525 assembleHeaderOptions(options, headerOptions);
527 result = OCDoResource(&handle, OC_REST_POST,
528 os.str().c_str(), nullptr,
529 assembleSetResourcePayload(rep).c_str(), connectivityType,
530 static_cast<OCQualityOfService>(QoS),
531 &cbdata, options, headerOptions.size());
533 result = OCDoResource(&handle, OC_REST_POST,
534 os.str().c_str(), nullptr,
535 assembleSetResourcePayload(rep).c_str(),
536 static_cast<OCQualityOfService>(QoS),
537 &cbdata, options, headerOptions.size());
543 result = OC_STACK_ERROR;
550 OCStackResult InProcClientWrapper::PutResourceRepresentation(const std::string& host,
551 const std::string& uri, OCConnectivityType connectivityType, const OCRepresentation& rep,
552 const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
553 PutCallback& callback, QualityOfService QoS)
555 OCStackResult InProcClientWrapper::PutResourceRepresentation(const std::string& host,
556 const std::string& uri, const OCRepresentation& rep,
557 const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
558 PutCallback& callback, QualityOfService QoS)
561 OCStackResult result;
562 OCCallbackData cbdata = {0};
564 ClientCallbackContext::SetContext* ctx = new ClientCallbackContext::SetContext();
565 ctx->callback = callback;
566 cbdata.cb = &setResourceCallback;
567 cbdata.cd = [](void* c){delete static_cast<ClientCallbackContext::SetContext*>(c);};
568 cbdata.context = static_cast<void*>(ctx);
570 // TODO: in the future the cstack should be combining these two strings!
572 os << host << assembleSetResourceUri(uri, queryParams).c_str();
573 // TODO: end of above
575 auto cLock = m_csdkLock.lock();
579 std::lock_guard<std::recursive_mutex> lock(*cLock);
581 OCHeaderOption options[MAX_HEADER_OPTIONS];
583 assembleHeaderOptions(options, headerOptions);
585 result = OCDoResource(&handle, OC_REST_PUT,
586 os.str().c_str(), nullptr,
587 assembleSetResourcePayload(rep).c_str(), connectivityType,
588 static_cast<OCQualityOfService>(QoS),
590 options, headerOptions.size());
592 result = OCDoResource(&handle, OC_REST_PUT,
593 os.str().c_str(), nullptr,
594 assembleSetResourcePayload(rep).c_str(),
595 static_cast<OCQualityOfService>(QoS),
597 options, headerOptions.size());
603 result = OC_STACK_ERROR;
609 OCStackApplicationResult deleteResourceCallback(void* ctx, OCDoHandle handle,
610 OCClientResponse* clientResponse)
612 ClientCallbackContext::DeleteContext* context =
613 static_cast<ClientCallbackContext::DeleteContext*>(ctx);
614 HeaderOptions serverHeaderOptions;
616 if(clientResponse->result == OC_STACK_OK)
618 parseServerHeaderOptions(clientResponse, serverHeaderOptions);
620 std::thread exec(context->callback, serverHeaderOptions, clientResponse->result);
622 return OC_STACK_DELETE_TRANSACTION;
626 OCStackResult InProcClientWrapper::DeleteResource(const std::string& host,
627 const std::string& uri, OCConnectivityType connectivityType,
628 const HeaderOptions& headerOptions, DeleteCallback& callback, QualityOfService QoS)
630 OCStackResult InProcClientWrapper::DeleteResource(const std::string& host,
631 const std::string& uri, const HeaderOptions& headerOptions,
632 DeleteCallback& callback, QualityOfService QoS)
635 OCStackResult result;
636 OCCallbackData cbdata = {0};
638 ClientCallbackContext::DeleteContext* ctx = new ClientCallbackContext::DeleteContext();
639 ctx->callback = callback;
640 cbdata.cb = &deleteResourceCallback;
641 cbdata.cd = [](void* c){delete static_cast<ClientCallbackContext::DeleteContext*>(c);};
642 cbdata.context = static_cast<void*>(ctx);
647 auto cLock = m_csdkLock.lock();
651 OCHeaderOption options[MAX_HEADER_OPTIONS];
654 assembleHeaderOptions(options, headerOptions);
656 std::lock_guard<std::recursive_mutex> lock(*cLock);
658 result = OCDoResource(&handle, OC_REST_DELETE,
659 os.str().c_str(), nullptr,
660 nullptr, connectivityType,
661 static_cast<OCQualityOfService>(m_cfg.QoS),
662 &cbdata, options, headerOptions.size());
664 result = OCDoResource(&handle, OC_REST_DELETE,
665 os.str().c_str(), nullptr,
666 nullptr, static_cast<OCQualityOfService>(m_cfg.QoS),
667 &cbdata, options, headerOptions.size());
673 result = OC_STACK_ERROR;
679 OCStackApplicationResult observeResourceCallback(void* ctx, OCDoHandle handle,
680 OCClientResponse* clientResponse)
682 ClientCallbackContext::ObserveContext* context =
683 static_cast<ClientCallbackContext::ObserveContext*>(ctx);
684 OCRepresentation attrs;
685 HeaderOptions serverHeaderOptions;
686 uint32_t sequenceNumber = clientResponse->sequenceNumber;
687 OCStackResult result = clientResponse->result;
688 if(clientResponse->result == OC_STACK_OK)
690 parseServerHeaderOptions(clientResponse, serverHeaderOptions);
693 attrs = parseGetSetCallback(clientResponse);
695 catch(OC::OCException& e)
700 std::thread exec(context->callback, serverHeaderOptions, attrs,
701 result, sequenceNumber);
703 if(sequenceNumber == OC_OBSERVE_DEREGISTER)
705 return OC_STACK_DELETE_TRANSACTION;
707 return OC_STACK_KEEP_TRANSACTION;
711 OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle,
712 const std::string& host, const std::string& uri, OCConnectivityType connectivityType,
713 const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
714 ObserveCallback& callback, QualityOfService QoS)
716 OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle,
717 const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
718 const HeaderOptions& headerOptions, ObserveCallback& callback, QualityOfService QoS)
721 OCStackResult result;
722 OCCallbackData cbdata = {0};
724 ClientCallbackContext::ObserveContext* ctx = new ClientCallbackContext::ObserveContext();
725 ctx->callback = callback;
726 cbdata.context = static_cast<void*>(ctx);
727 cbdata.cb = &observeResourceCallback;
728 cbdata.cd = [](void* c){delete static_cast<ClientCallbackContext::ObserveContext*>(c);};
731 if (observeType == ObserveType::Observe)
733 method = OC_REST_OBSERVE;
735 else if (observeType == ObserveType::ObserveAll)
737 method = OC_REST_OBSERVE_ALL;
741 method = OC_REST_OBSERVE_ALL;
744 auto cLock = m_csdkLock.lock();
748 std::ostringstream os;
749 os << host << assembleSetResourceUri(uri, queryParams).c_str();
751 std::lock_guard<std::recursive_mutex> lock(*cLock);
752 OCHeaderOption options[MAX_HEADER_OPTIONS];
754 assembleHeaderOptions(options, headerOptions);
756 result = OCDoResource(handle, method,
757 os.str().c_str(), nullptr,
758 nullptr, connectivityType,
759 static_cast<OCQualityOfService>(QoS),
761 options, headerOptions.size());
763 result = OCDoResource(handle, method,
764 os.str().c_str(), nullptr,
766 static_cast<OCQualityOfService>(QoS),
768 options, headerOptions.size());
774 return OC_STACK_ERROR;
780 OCStackResult InProcClientWrapper::CancelObserveResource(OCDoHandle handle,
781 const std::string& host, const std::string& uri, const HeaderOptions& headerOptions,
782 QualityOfService QoS)
784 OCStackResult result;
785 auto cLock = m_csdkLock.lock();
789 std::lock_guard<std::recursive_mutex> lock(*cLock);
790 OCHeaderOption options[MAX_HEADER_OPTIONS];
792 assembleHeaderOptions(options, headerOptions);
793 result = OCCancel(handle, static_cast<OCQualityOfService>(QoS), options,
794 headerOptions.size());
798 result = OC_STACK_ERROR;
804 OCStackApplicationResult subscribePresenceCallback(void* ctx, OCDoHandle handle,
805 OCClientResponse* clientResponse)
807 char stringAddress[DEV_ADDR_SIZE_MAX];
811 if(OCDevAddrToString(clientResponse->addr, stringAddress) == 0 &&
812 OCDevAddrToPort(clientResponse->addr, &port) == 0)
814 os<<stringAddress<<":"<<port;
816 ClientCallbackContext::SubscribePresenceContext* context =
817 static_cast<ClientCallbackContext::SubscribePresenceContext*>(ctx);
819 std::thread exec(context->callback, clientResponse->result,
820 clientResponse->sequenceNumber, os.str());
826 oclog() << "subscribePresenceCallback(): OCDevAddrToString() or OCDevAddrToPort() "
827 <<"failed"<< std::flush;
829 return OC_STACK_KEEP_TRANSACTION;
833 OCStackResult InProcClientWrapper::SubscribePresence(OCDoHandle* handle,
834 const std::string& host, const std::string& resourceType,
835 OCConnectivityType connectivityType, SubscribeCallback& presenceHandler)
837 OCStackResult InProcClientWrapper::SubscribePresence(OCDoHandle* handle,
838 const std::string& host, const std::string& resourceType,
839 SubscribeCallback& presenceHandler)
842 OCCallbackData cbdata = {0};
844 ClientCallbackContext::SubscribePresenceContext* ctx =
845 new ClientCallbackContext::SubscribePresenceContext();
846 ctx->callback = presenceHandler;
847 cbdata.cb = &subscribePresenceCallback;
848 cbdata.context = static_cast<void*>(ctx);
849 cbdata.cd = [](void* c)
850 {delete static_cast<ClientCallbackContext::SubscribePresenceContext*>(c);};
851 auto cLock = m_csdkLock.lock();
853 std::ostringstream os;
854 os << host << "/oc/presence";
856 if(!resourceType.empty())
858 os << "?rt=" << resourceType;
864 return OC_STACK_ERROR;
868 return OCDoResource(handle, OC_REST_PRESENCE, os.str().c_str(), nullptr, nullptr,
869 connectivityType, OC_LOW_QOS, &cbdata, NULL, 0);
871 return OCDoResource(handle, OC_REST_PRESENCE, os.str().c_str(), nullptr, nullptr,
872 OC_LOW_QOS, &cbdata, NULL, 0);
876 OCStackResult InProcClientWrapper::UnsubscribePresence(OCDoHandle handle)
878 OCStackResult result;
879 auto cLock = m_csdkLock.lock();
883 std::lock_guard<std::recursive_mutex> lock(*cLock);
884 result = OCCancel(handle, OC_LOW_QOS, NULL, 0);
888 result = OC_STACK_ERROR;
894 OCStackResult InProcClientWrapper::GetDefaultQos(QualityOfService& qos)
900 void InProcClientWrapper::assembleHeaderOptions(OCHeaderOption options[],
901 const HeaderOptions& headerOptions)
905 for (auto it=headerOptions.begin(); it != headerOptions.end(); ++it)
907 options[i].protocolID = OC_COAP_ID;
908 options[i].optionID = static_cast<uint16_t>(it->getOptionID());
909 options[i].optionLength = (it->getOptionData()).length() + 1;
910 memcpy(options[i].optionData, (it->getOptionData()).c_str(),
911 (it->getOptionData()).length() + 1);