if (!message->Get("id", &vid))
return;
- String id = vid;
-
- ApiCallbackInfo aci;
-
- {
- boost::mutex::scoped_lock lock(m_ApiCallbacksMutex);
- auto it = m_ApiCallbacks.find(id);
-
- if (it == m_ApiCallbacks.end())
- return;
-
- aci = it->second;
- m_ApiCallbacks.erase(it);
- }
-
- try {
- aci.Callback(message);
- } catch (const std::exception& ex) {
- Log(LogWarning, "JsonRpcConnection")
- << "Error while processing message for identity '" << m_Identity << "'\n" << DiagnosticInformation(ex);
- }
+ Log(LogWarning, "JsonRpcConnection",
+ "We received a JSON-RPC response message. This should never happen because we're only ever sending notifications.");
return;
}
return Empty;
}
-bool ApiCallbackInfo::IsExpired(void) const
-{
- return Timestamp < Utility::GetTime() - 300;
-}
-
void JsonRpcConnection::CheckLiveness(void)
{
if (m_Seen < Utility::GetTime() - 60 && (!m_Endpoint || !m_Endpoint->GetSyncing())) {
<< "No messages for identity '" << m_Identity << "' have been received in the last 60 seconds.";
Disconnect();
}
-
- {
- boost::mutex::scoped_lock lock(m_ApiCallbacksMutex);
-
- for (auto it = m_ApiCallbacks.begin(), last = m_ApiCallbacks.end(); it != last; ) {
- if (it->second.IsExpired()) {
- it = m_ApiCallbacks.erase(it);
- } else {
- ++it;
- }
- }
- }
}
void JsonRpcConnection::TimeoutTimerHandler(void)
return rate / count;
}
-void JsonRpcConnection::RegisterCallback(const String& id, const boost::function<void (const Dictionary::Ptr&)>& callback)
-{
- ApiCallbackInfo aci;
- aci.Timestamp = Utility::GetTime();
- aci.Callback = callback;
-
- {
- boost::mutex::scoped_lock lock(m_ApiCallbacksMutex);
- m_ApiCallbacks[id] = aci;
- }
-}
class MessageOrigin;
-struct ApiCallbackInfo
-{
- double Timestamp;
- boost::function<void (const Dictionary::Ptr&)> Callback;
-
- bool IsExpired(void) const;
-};
-
/**
* An API client connection.
*
double m_NextHeartbeat;
double m_HeartbeatTimeout;
boost::mutex m_DataHandlerMutex;
- std::map<String, ApiCallbackInfo> m_ApiCallbacks;
- boost::mutex m_ApiCallbacksMutex;
StreamReadContext m_Context;
static void TimeoutTimerHandler(void);
void CheckLiveness(void);
- void RegisterCallback(const String& id, const boost::function<void (const Dictionary::Ptr&)>& callback);
-
void CertificateRequestResponseHandler(const Dictionary::Ptr& message);
};