Example #1
0
RequestMap bridge::InterfaceManager::generateDifferentialRequests(bool killSwitchActive) {
    RequestMap diff;

    for (auto &newRequest : *(interface->getRequestMap())) {
        if (previousRequests.find(newRequest.first) == previousRequests.end()) {
            logger.debug("Key '%s' not in the previous state. Adding.", newRequest.first.c_str());
            diff[newRequest.first] = newRequest.second;
        }
        else {
            if (previousRequests[newRequest.first].equals(newRequest.second)) {
                logger.debug("Key '%s' identical to the previous one. Skipping.", newRequest.first.c_str());
            } else {
                logger.debug("Key '%s' differs from previous state's one. Adding.", newRequest.first.c_str());
                diff[newRequest.first] = newRequest.second;
            }
        }
    }

    previousRequests.clear();

    for (auto req : *(interface->getRequestMap())) {
        previousRequests.insert(req);
    }

    if (killSwitchActive) {
        for (auto &r : *(interface->getRequestMap())) {
            if (r.second.isKillSwitchDependent()) {
                logger.debug("Removing key '%s' because kill switch is active.", r.first.c_str());
                diff.erase(r.first);
                previousRequests.erase(r.first);
            }
        }
    }
    return diff;
}
//-----------------------------------------------------------------------------
/// RemoveRequest
///
/// Provides a way for the Server to remove a request that it will not be
/// responding to. This is typical if the request is passed on to a plugin
/// in a different process which will be sending a response.
///
/// \param requestID a requestID returned by a call to CreateRequest
//-----------------------------------------------------------------------------
void RemoveRequest(CommunicationID requestID)
{
    // protect the maps from being changed by other threads using the mutex
    ScopeLock lock(s_mutex);

    RequestMap::iterator iter = g_requestMap.find(requestID);

    if (iter != g_requestMap.end())
    {
        HTTPRequestHeader* pRequest = iter->second;
        delete pRequest;
        g_requestMap.erase(iter);
    }
}