// Typedefs
//-----------------------------------------------------------------------------
typedef enum {
- OC_STACK_UNINITIALIZED = 0, OC_STACK_INITIALIZED
+ OC_STACK_UNINITIALIZED = 0, OC_STACK_INITIALIZED, OC_STACK_UNINIT_IN_PROGRESS
} OCStackState;
#ifdef WITH_PRESENCE
OC_LOG(INFO, TAG, PCF("Entering OCStop"));
- if (stackState != OC_STACK_INITIALIZED)
+ if (stackState == OC_STACK_UNINIT_IN_PROGRESS)
+ {
+ OC_LOG(DEBUG, TAG, PCF("Stack already stopping, exiting"));
+ return OC_STACK_OK;
+ }
+ else if (stackState != OC_STACK_INITIALIZED)
{
OC_LOG(ERROR, TAG, PCF("Stack not initialized"));
return OC_STACK_ERROR;
}
+ stackState = OC_STACK_UNINIT_IN_PROGRESS;
+
#ifdef WITH_PRESENCE
// Ensure that the TTL associated with ANY and ALL presence notifications originating from
// here send with the code "OC_STACK_PRESENCE_STOPPED" result.
stackState = OC_STACK_UNINITIALIZED;
result = OC_STACK_OK;
} else {
+ stackState = OC_STACK_INITIALIZED;
result = OC_STACK_ERROR;
}
m_listeningThread.join();
}
- OCStop();
+ // only stop if we are the ones who actually called 'init'. We are counting
+ // on the server to do the stop.
+ if(m_cfg.mode == ModeType::Client)
+ {
+ OCStop();
+ }
}
void InProcClientWrapper::listeningFunc()
return OC_STACK_KEEP_TRANSACTION;
}
+ auto clientWrapper = context->clientWrapper.lock();
+
+ if(!clientWrapper)
+ {
+ oclog() << "listenCallback(): failed to get a shared_ptr to the client wrapper"
+ << std::flush;
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
std::stringstream requestStream;
requestStream << clientResponse->resJSONPayload;
try
{
- ListenOCContainer container(context->clientWrapper, *clientResponse->addr,
+ ListenOCContainer container(clientWrapper, *clientResponse->addr,
requestStream);
// loop to ensure valid construction of all resources