// Do callbacks for expired outstanding requests.
std::vector<CallbackInfo::Ptr> expiredCallbacks;
app->m_callback->CompleteAndRemoveExpiredCallbackInfo(expiredCallbacks);
+ expiredCallbacks.clear(); // no use of the expired callbacks.
// Get oustanding Observe requests and ping the device every PingPeriodMS.
std::vector<CallbackInfo::Ptr> observeCallbacks;
status = device->ObserveResource(cbInfo);
+ if (status == IPCA_OK)
+ {
+ cbInfo->inObserve = true;
+ }
+
if ((status != IPCA_OK) && (cbInfo != nullptr))
{
if (handle != nullptr)
m_discoveryList.erase(cbInfo->mapKey);
}
else
- if (cbInfo->type == CallbackType_ResourceChange)
+ if ((cbInfo->type == CallbackType_ResourceChange) && cbInfo->inObserve)
{
cbInfo->device->StopObserve(cbInfo);
+ cbInfo->inObserve = false;
}
}
cbInfo->markedToBeRemoved = false;
cbInfo->requestSentTimestamp = 0;
cbInfo->closeHandleCompleteCallback = nullptr;
+ cbInfo->inObserve = false;
}
CallbackInfo::Ptr Callback::CreatePasswordCallbackInfo(
{
const int RequestTimeoutMs = 247000; // This is EXCHANGE_LIFETIME defined in RFC7252.
+ // Separate list for callbacks that are already completed.
+ std::vector<CallbackInfo::Ptr> completedCallbacks;
+
uint64_t currentTime = OICGetCurrentTime(TIME_IN_MS);
{
if ((entry.second->markedToBeRemoved == true) &&
(entry.second->callbackInProgressCount == 0))
{
- m_expiredCallbacksInProgress++;
- cbInfoList.push_back(entry.second);
+ completedCallbacks.push_back(entry.second);
continue;
}
}
// Remove them from the list.
+ for (auto const& entry : completedCallbacks)
+ {
+ m_callbackInfoList.erase(entry->mapKey);
+ }
+
for (auto const& entry : cbInfoList)
{
m_callbackInfoList.erase(entry->mapKey);
std::shared_ptr<OC::OCResource> ocResource; // The OCResource this callback works with.
uint64_t requestSentTimestamp; // when the request was sent to the server.
+
+ bool inObserve; // set to true when observe request is sent for this callback.
};
// Represent IPCAResourceChangeCallback, IPCAGetPropertiesComplete, IPCASetPropertiesComplete.
if (m_observeHandle)
{
IPCACloseHandle(m_observeHandle, nullptr, 0);
+ m_observeHandle = nullptr;
}
}
m_ipcaAppHandle = nullptr;
m_deviceDiscoveryHandle = nullptr;
m_deviceHandle = nullptr;
+ m_observeHandle = nullptr;
m_newResourcePath = "";
IPCAAppInfo ipcaAppInfo = { IPCATestAppUuid, IPCATestAppName, "1.0.0", "Microsoft" };
ContextForCloseHandleTest* testContext = reinterpret_cast<ContextForCloseHandleTest*>(context);
testContext->isInCallback = true;
- if (result != IPCA_OK)
+ if ((result != IPCA_OK) && (result != IPCA_RESOURCE_CREATED) && (result != IPCA_RESOURCE_DELETED))
{
std::cout << "C_ControlledRequestCompleteCallback(): unsuccessful. result = " << result;
std::cout << std::endl;