<commit_before>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2017.  All rights reserved
 */
#include "../StroikaPreComp.h"

#include "../../Foundation/Characters/ToString.h"
#include "../../Foundation/IO/Network/HTTP/Exception.h"

#include "LoggingInterceptor.h"

using namespace Stroika::Foundation;
using namespace Stroika::Foundation::Containers;
using namespace Stroika::Foundation::Memory;

using namespace Stroika::Frameworks;
using namespace Stroika::Frameworks::WebServer;

struct LoggingInterceptor::Rep_ : Interceptor::_IRep {
    Rep_ (const shared_ptr<ILogHandler>& logger)
        : fLogger_ (logger)
    {
    }
    virtual void HandleFault (Message* m, const exception_ptr& e) noexcept override
    {
        RequireNotNull (m);
        shared_ptr<ILogHandler::MessageInstance> logID;
        {
            auto rwLock = fOngoingMessages_.rwget ();
            Assert (rwLock->Lookup (m));
            logID = *rwLock->Lookup (m);
            rwLock->Remove (m);
        }
        fLogger_->Completed (logID);
    }
    virtual void HandleMessage (Message* m) override
    {
        shared_ptr<ILogHandler::MessageInstance> logID = fLogger_->Started (m);
        Assert (fOngoingMessages_->Lookup (m).IsMissing ());
        fOngoingMessages_.rwget ().rwref ().Add (m, logID);
    }
    virtual void CompleteNormally (Message* m) override
    {
        shared_ptr<ILogHandler::MessageInstance> logID;
        {
            auto rwLock = fOngoingMessages_.rwget ();
            Assert (rwLock->Lookup (m));
            logID = *rwLock->Lookup (m);
            rwLock->Remove (m);
        }
        fLogger_->Completed (logID);
    }
    shared_ptr<ILogHandler> fLogger_;
    Execution::Synchronized<Mapping<Message*, shared_ptr<ILogHandler::MessageInstance>>> fOngoingMessages_;
};

/*
 ********************************************************************************
 *********************** WebServer::LoggingInterceptor **************************
 ********************************************************************************
 */
LoggingInterceptor::LoggingInterceptor (const shared_ptr<ILogHandler>& logger)
    : inherited (make_shared<Rep_> (logger))
{
}<commit_msg>WebServer::ILogHandler missing<commit_after>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2017.  All rights reserved
 */
#include "../StroikaPreComp.h"

#include "../../Foundation/Characters/ToString.h"
#include "../../Foundation/IO/Network/HTTP/Exception.h"

#include "LoggingInterceptor.h"

using namespace Stroika::Foundation;
using namespace Stroika::Foundation::Containers;
using namespace Stroika::Foundation::Memory;

using namespace Stroika::Frameworks;
using namespace Stroika::Frameworks::WebServer;

/*
 ********************************************************************************
 ******************************* WebServer::ILogHandler *************************
 ********************************************************************************
 */
shared_ptr<ILogHandler::MessageInstance> ILogHandler::Started (Message* m)
{
    return make_shared<MessageInstance> (m, Time::GetTickCount ());
}

/*
 ********************************************************************************
 *********************** WebServer::LoggingInterceptor **************************
 ********************************************************************************
 */
struct LoggingInterceptor::Rep_ : Interceptor::_IRep {
    Rep_ (const shared_ptr<ILogHandler>& logger)
        : fLogger_ (logger)
    {
    }
    virtual void HandleFault (Message* m, const exception_ptr& e) noexcept override
    {
        RequireNotNull (m);
        shared_ptr<ILogHandler::MessageInstance> logID;
        {
            auto rwLock = fOngoingMessages_.rwget ();
            Assert (rwLock->Lookup (m));
            logID = *rwLock->Lookup (m);
            rwLock->Remove (m);
        }
        fLogger_->Completed (logID);
    }
    virtual void HandleMessage (Message* m) override
    {
        shared_ptr<ILogHandler::MessageInstance> logID = fLogger_->Started (m);
        Assert (fOngoingMessages_->Lookup (m).IsMissing ());
        fOngoingMessages_.rwget ().rwref ().Add (m, logID);
    }
    virtual void CompleteNormally (Message* m) override
    {
        shared_ptr<ILogHandler::MessageInstance> logID;
        {
            auto rwLock = fOngoingMessages_.rwget ();
            Assert (rwLock->Lookup (m));
            logID = *rwLock->Lookup (m);
            rwLock->Remove (m);
        }
        fLogger_->Completed (logID);
    }
    shared_ptr<ILogHandler> fLogger_;
    Execution::Synchronized<Mapping<Message*, shared_ptr<ILogHandler::MessageInstance>>> fOngoingMessages_;
};

LoggingInterceptor::LoggingInterceptor (const shared_ptr<ILogHandler>& logger)
    : inherited (make_shared<Rep_> (logger))
{
}
{'fraction_non_alphanumeric': 0.24280950395998332, 'fraction_numerical': 0.003334722801167153, 'mean_word_length': 3.891946992864424, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1373177', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1283, 'n_words': 250}