<commit_before>#include <boost/cast.hpp>

#include "messageHandler.h"
#include <libwatcher/messageStatus.h>

using namespace std; 
using namespace watcher;
using namespace watcher::event;
using namespace boost;

INIT_LOGGER(MessageHandler, "MessageHandler");

MessageHandler::MessageHandler()
{
    TRACE_ENTER();
    TRACE_EXIT();
}

MessageHandler::~MessageHandler()
{
    TRACE_ENTER();
    TRACE_EXIT();
}

MessageHandler::ConnectionCommand MessageHandler::produceReply(const MessagePtr &request, MessagePtr &reply)
{
    TRACE_ENTER();
    LOG_DEBUG("Producing reply for message: " << *request);
    reply=MessageStatusPtr(new MessageStatus(MessageStatus::status_ack));
    LOG_DEBUG("Produced reply: " << *reply);

    TRACE_EXIT_RET("writeMessage"); 
    return writeMessage;
}

MessageHandler::ConnectionCommand MessageHandler::handleReply(const MessagePtr &request, const MessagePtr &reply)
{
    TRACE_ENTER();

    LOG_INFO("Recv'd :" << "\n\t" << *reply << endl << "In reply to: " << "\n\t" << *request);

    if (reply->type != MESSAGE_STATUS_TYPE)
    {
        LOG_WARN("Got a non-message status message in reply.");
        TRACE_EXIT_RET("closeConnection");
        return closeConnection;
    }

    MessageStatusPtr mess=boost::dynamic_pointer_cast<MessageStatus>(reply);
    
    if(mess->status!=MessageStatus::status_ack && mess->status!=MessageStatus::status_ok) 
    {
        LOG_WARN("Recv'd non ack reply to request: " << MessageStatus::statusToString(mess->status)); 
    }
    else
    {
        LOG_INFO("Recv'd ack to request, all is well."); 
    }

    TRACE_EXIT_RET("stayConnected");
    return stayConnected;
}

void MessageHandler::handleMessageArrive(const MessagePtr message)
{
    TRACE_ENTER();
    LOG_INFO("Recv'd message: " << message); 
    TRACE_EXIT();
}

<commit_msg>Check return value of dynamic_cast<> of Message reply from server. Currently is NOT casting from base ---> derived. Which is bad.<commit_after>#include <boost/cast.hpp>

#include "messageHandler.h"
#include <libwatcher/messageStatus.h>

using namespace std; 
using namespace watcher;
using namespace watcher::event;
using namespace boost;

INIT_LOGGER(MessageHandler, "MessageHandler");

MessageHandler::MessageHandler()
{
    TRACE_ENTER();
    TRACE_EXIT();
}

MessageHandler::~MessageHandler()
{
    TRACE_ENTER();
    TRACE_EXIT();
}

MessageHandler::ConnectionCommand MessageHandler::produceReply(const MessagePtr &request, MessagePtr &reply)
{
    TRACE_ENTER();
    LOG_DEBUG("Producing reply for message: " << *request);
    reply=MessageStatusPtr(new MessageStatus(MessageStatus::status_ack));
    LOG_DEBUG("Produced reply: " << *reply);

    TRACE_EXIT_RET("writeMessage"); 
    return writeMessage;
}

MessageHandler::ConnectionCommand MessageHandler::handleReply(const MessagePtr &request, const MessagePtr &reply)
{
    TRACE_ENTER();

    LOG_INFO("Recv'd :" << "\n\t" << *reply << endl << "In reply to: " << "\n\t" << *request);

    if (reply->type != MESSAGE_STATUS_TYPE)
    {
        LOG_WARN("Got a non-message status message in reply.");
        TRACE_EXIT_RET("closeConnection");
        return closeConnection;
    }

    MessageStatusPtr mess=boost::dynamic_pointer_cast<MessageStatus>(reply); 

    if(mess)
    {
        if(mess->status!=MessageStatus::status_ack && mess->status!=MessageStatus::status_ok) 
        {
            LOG_WARN("Recv'd non ack reply to request: " << MessageStatus::statusToString(mess->status)); 
        }
        else
        {
            LOG_INFO("Recv'd ack to request, all is well."); 
        }
    }
    else
    {
        LOG_ERROR("Look into this: unable to dynamically cast a shared_ptr<base> to shared_ptr<derived> even though it is the right type"); 
    }

    TRACE_EXIT_RET("closeConnection");
    return closeConnection;
}

void MessageHandler::handleMessageArrive(const MessagePtr message)
{
    TRACE_ENTER();
    LOG_INFO("Recv'd message: " << message); 
    TRACE_EXIT();
}


{'fraction_non_alphanumeric': 0.12985375693393847, 'fraction_numerical': 0.0, 'mean_word_length': 4.131953428201811, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 21, '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': '498826', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1170, 'n_words': 253}