<commit_before>#include "utils/logoutput.h"
#include "commandSocket.h"
#include "FffProcessor.h"
#include "Progress.h"

#include <thread>
#include <cinttypes>

#include <Arcus/Socket.h>

#ifdef _WIN32
#include <windows.h>
#endif

namespace cura {

#define BYTES_PER_FLOAT 4
#define FLOATS_PER_VECTOR 3
#define VECTORS_PER_FACE 3
    
class CommandSocket::Private
{
public:
    Private()
        : socket(nullptr)
        , object_count(0)
        , current_sliced_object(nullptr)
        , sliced_objects(0)
        , current_layer_count(0)
        , current_layer_offset(0)
    { }

    cura::proto::Layer* getLayerById(int id);

    Arcus::Socket* socket;
    
    // Number of objects that need to be sliced
    int object_count;
    
    // Message that holds a list of sliced objects
    std::shared_ptr<cura::proto::SlicedObjectList> sliced_object_list;
    
    // Message that holds the currently sliced object (to be added to sliced_object_list)
    cura::proto::SlicedObject* current_sliced_object;
    
    // Number of sliced objects for this sliced object list
    int sliced_objects;

    // Number of layers sent to the front end so far
    // Used for incrementing the current layer in one at a time mode
    int current_layer_count;
    int current_layer_offset;
    
    // Ids of the sliced objects
    std::vector<int64_t> object_ids;

    std::string temp_gcode_file;
    std::ostringstream gcode_output_stream;
    
    // Print object that olds one or more meshes that need to be sliced. 
    std::vector< std::shared_ptr<MeshGroup> > objects_to_slice;
};

CommandSocket::CommandSocket()
    : d(new Private)
{
    FffProcessor::getInstance()->setCommandSocket(this);
}

void CommandSocket::connect(const std::string& ip, int port)
{
    d->socket = new Arcus::Socket();
    //d->socket->registerMessageType(1, &Cura::ObjectList::default_instance());
    d->socket->registerMessageType(1, &cura::proto::Slice::default_instance());
    d->socket->registerMessageType(2, &cura::proto::SlicedObjectList::default_instance());
    d->socket->registerMessageType(3, &cura::proto::Progress::default_instance());
    d->socket->registerMessageType(4, &cura::proto::GCodeLayer::default_instance());
    d->socket->registerMessageType(5, &cura::proto::ObjectPrintTime::default_instance());
    d->socket->registerMessageType(6, &cura::proto::SettingList::default_instance());
    d->socket->registerMessageType(7, &cura::proto::GCodePrefix::default_instance());

    d->socket->connect(ip, port);
    
    // Start & continue listening as long as socket is not closed and there is no error.
    while(d->socket->state() != Arcus::SocketState::Closed && d->socket->state() != Arcus::SocketState::Error)
    {
        //If there is an object to slice, do so.
        if(d->objects_to_slice.size())
        {
            FffProcessor::getInstance()->resetFileNumber();
            for(auto object : d->objects_to_slice)
            {
                FffProcessor::getInstance()->processMeshGroup(object.get());
            }
            d->objects_to_slice.clear();
            FffProcessor::getInstance()->finalize();
            sendGCodeLayer();
            sendPrintTime();
            //TODO: Support all-at-once/one-at-a-time printing
            //d->processor->processModel(d->object_to_slice.get());
            //d->object_to_slice.reset();
            //d->processor->resetFileNumber();

            //sendPrintTime();
        }<commit_msg>Log an error when slicing failed<commit_after>#include "utils/logoutput.h"
#include "commandSocket.h"
#include "FffProcessor.h"
#include "Progress.h"

#include <thread>
#include <cinttypes>

#include <Arcus/Socket.h>

#ifdef _WIN32
#include <windows.h>
#endif

namespace cura {

#define BYTES_PER_FLOAT 4
#define FLOATS_PER_VECTOR 3
#define VECTORS_PER_FACE 3
    
class CommandSocket::Private
{
public:
    Private()
        : socket(nullptr)
        , object_count(0)
        , current_sliced_object(nullptr)
        , sliced_objects(0)
        , current_layer_count(0)
        , current_layer_offset(0)
    { }

    cura::proto::Layer* getLayerById(int id);

    Arcus::Socket* socket;
    
    // Number of objects that need to be sliced
    int object_count;
    
    // Message that holds a list of sliced objects
    std::shared_ptr<cura::proto::SlicedObjectList> sliced_object_list;
    
    // Message that holds the currently sliced object (to be added to sliced_object_list)
    cura::proto::SlicedObject* current_sliced_object;
    
    // Number of sliced objects for this sliced object list
    int sliced_objects;

    // Number of layers sent to the front end so far
    // Used for incrementing the current layer in one at a time mode
    int current_layer_count;
    int current_layer_offset;
    
    // Ids of the sliced objects
    std::vector<int64_t> object_ids;

    std::string temp_gcode_file;
    std::ostringstream gcode_output_stream;
    
    // Print object that olds one or more meshes that need to be sliced. 
    std::vector< std::shared_ptr<MeshGroup> > objects_to_slice;
};

CommandSocket::CommandSocket()
    : d(new Private)
{
    FffProcessor::getInstance()->setCommandSocket(this);
}

void CommandSocket::connect(const std::string& ip, int port)
{
    d->socket = new Arcus::Socket();
    //d->socket->registerMessageType(1, &Cura::ObjectList::default_instance());
    d->socket->registerMessageType(1, &cura::proto::Slice::default_instance());
    d->socket->registerMessageType(2, &cura::proto::SlicedObjectList::default_instance());
    d->socket->registerMessageType(3, &cura::proto::Progress::default_instance());
    d->socket->registerMessageType(4, &cura::proto::GCodeLayer::default_instance());
    d->socket->registerMessageType(5, &cura::proto::ObjectPrintTime::default_instance());
    d->socket->registerMessageType(6, &cura::proto::SettingList::default_instance());
    d->socket->registerMessageType(7, &cura::proto::GCodePrefix::default_instance());

    d->socket->connect(ip, port);
    
    // Start & continue listening as long as socket is not closed and there is no error.
    while(d->socket->state() != Arcus::SocketState::Closed && d->socket->state() != Arcus::SocketState::Error)
    {
        //If there is an object to slice, do so.
        if(d->objects_to_slice.size())
        {
            FffProcessor::getInstance()->resetFileNumber();
            for(auto object : d->objects_to_slice)
            {
                if(!FffProcessor::getInstance()->processMeshGroup(object.get()))
                {
                    logError("Slicing mesh group failed!");
                }
            }
            d->objects_to_slice.clear();
            FffProcessor::getInstance()->finalize();
            sendGCodeLayer();
            sendPrintTime();
            //TODO: Support all-at-once/one-at-a-time printing
            //d->processor->processModel(d->object_to_slice.get());
            //d->object_to_slice.reset();
            //d->processor->resetFileNumber();

            //sendPrintTime();
        }
{'fraction_non_alphanumeric': 0.13151540974293424, 'fraction_numerical': 0.005396960658997301, 'mean_word_length': 3.237063778580024, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 91, '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': '5592297', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2097, 'n_words': 449}