if (false == m_threadRun)
{
m_threadRun = true;
+#ifdef WITH_PROCESS_EVENT
+ m_processEvent = oc_event_new();
+ if (!m_processEvent)
+ {
+ OIC_LOG(INFO, TAG, "oc_event_new failed!");
+ return OC_STACK_ERROR;
+ }
+ OCRegisterProcessEvent(m_processEvent);
+#endif
m_listeningThread = std::thread(&InProcClientWrapper::listeningFunc, this);
}
}
{
OIC_LOG(INFO, TAG, "stop ocplatform");
- if (m_threadRun && m_listeningThread.joinable())
- {
- m_threadRun = false;
- m_listeningThread.join();
- }
-
// only stop if we are the ones who actually called 'start'. We are counting
// on the server to do the stop.
if (m_cfg.mode == ModeType::Client)
{
+ if (m_threadRun && m_listeningThread.joinable())
+ {
+ m_threadRun = false;
+#ifdef WITH_PROCESS_EVENT
+ if (m_processEvent)
+ {
+ oc_event_signal(m_processEvent);
+ }
+#endif
+ m_listeningThread.join();
+ }
+
+#ifdef WITH_PROCESS_EVENT
+ if (m_processEvent)
+ {
+ oc_event_free(m_processEvent);
+ m_processEvent = NULL;
+ }
+#endif
OCStackResult result = OCStop();
if (OC_STACK_OK != result)
while(m_threadRun)
{
OCStackResult result;
+#ifdef WITH_PROCESS_EVENT
+ uint32_t nextEventTime;
+#endif
auto cLock = m_csdkLock.lock();
if (cLock)
{
std::lock_guard<std::recursive_mutex> lock(*cLock);
+#ifdef WITH_PROCESS_EVENT
+ result = OCProcessEvent(&nextEventTime);
+#else
result = OCProcess();
+#endif
}
else
{
// TODO: do something with result if failed?
}
+#ifdef WITH_PROCESS_EVENT
+ oc_event_wait_for(m_processEvent, nextEventTime);
+#else
// To minimize CPU utilization we may wish to do this with sleep
std::this_thread::sleep_for(std::chrono::milliseconds(10));
+#endif
}
}
return result;
}
+#ifdef WITH_PRESENCE
OCStackApplicationResult subscribePresenceCallback(void* ctx,
OCDoHandle /*handle*/,
OCClientResponse* clientResponse)
return OC_STACK_KEEP_TRANSACTION;
}
+#endif
OCStackResult InProcClientWrapper::SubscribePresence(OCDoHandle* handle,
const std::string& host, const std::string& resourceType,
OCConnectivityType connectivityType, SubscribeCallback& presenceHandler)
{
+#ifdef WITH_PRESENCE
if (!presenceHandler)
{
return OC_STACK_INVALID_PARAM;
os.str().c_str(), nullptr,
nullptr, connectivityType,
OC_LOW_QOS, &cbdata, NULL, 0);
+#else
+ return OC_STACK_NOT_IMPLEMENTED;
+#endif
}
OCStackResult InProcClientWrapper::UnsubscribePresence(OCDoHandle handle)
{
+#ifdef WITH_PRESENCE
OCStackResult result;
auto cLock = m_csdkLock.lock();
}
return result;
+#else
+ return OC_STACK_NOT_IMPLEMENTED;
+#endif
}
#ifdef WITH_CLOUD
return nullptr;
}
- OCHeaderOption* options = new OCHeaderOption[headerOptions.size()];
- int i = 0;
+ OCHeaderOption* options = new OCHeaderOption[headerOptions.size()]();
+
+ size_t numOptions = 0;
for (auto it=headerOptions.begin(); it != headerOptions.end(); ++it)
{
- options[i] = OCHeaderOption();
- options[i].protocolID = OC_COAP_ID;
- options[i].optionID = it->getOptionID();
- options[i].optionLength = it->getOptionData().length() + 1;
- strncpy((char*)options[i].optionData, it->getOptionData().c_str(),
- sizeof(options[i].optionLength) -1 );
- options[i].optionData[sizeof(options[i].optionLength) - 1] = 0;
- i++;
+ OCStackResult ret = OCSetHeaderOption(options, &numOptions, it->getOptionID(),
+ it->getOptionData().c_str(), it->getOptionData().length());
+ if (OC_STACK_OK != ret)
+ {
+ OIC_LOG_V(ERROR, TAG, "Failed to convert vnd header options! (error=%d)", ret);
+ delete[] options;
+ return nullptr;
+ }
}
return options;
std::lock_guard<std::recursive_mutex> lock(*cLock);
OCRepPayload *payload = rep.getPayload();
result = OCSendKeepAliveRequest (nullptr, host.c_str(), (OCPayload*)payload, &cbdata);
- if (result != OC_STACK_OK)
- {
- OCRepPayloadDestroy(payload);
- }
}
else
{