<commit_before>#include <iostream>
#include <unistd.h>
#include <sstream>
#include "StreamMan.h"
#include "zmq.h"

using namespace std;

StreamMan::StreamMan()
    :DataMan()
{
}

StreamMan::~StreamMan(){
    if(zmq_meta) zmq_close(zmq_meta);
    if(zmq_context) zmq_ctx_destroy(zmq_context);
    zmq_meta_rep_thread_active = false;
    if(zmq_meta_rep_thread){
        if(zmq_meta_rep_thread->joinable())
            zmq_meta_rep_thread->join();
        delete zmq_meta_rep_thread;
    }
}

int StreamMan::init(json p_jmsg){
    if(check_json(p_jmsg, {"stream_mode", "remote_ip", "local_ip", "remote_port", "local_port" }, "StreamMan")){
        m_stream_mode = p_jmsg["stream_mode"];
        m_local_ip = p_jmsg["local_ip"];
        m_remote_ip = p_jmsg["remote_ip"];
        m_local_port = p_jmsg["local_port"];
        m_remote_port = p_jmsg["remote_port"];
        string remote_address = make_address(m_remote_ip, m_remote_port, "tcp");
        string local_address = make_address(m_local_ip, m_local_port, "tcp");

        if(p_jmsg["num_channels"] != nullptr) m_num_channels = p_jmsg["num_channels"];
        if(p_jmsg["tolerance"] != nullptr) m_tolerance = p_jmsg["tolerance"].get<vector<int>>();
        if(p_jmsg["priority"] != nullptr) m_priority = p_jmsg["priority"].get<vector<int>>();

        if(!zmq_context){
            zmq_context = zmq_ctx_new ();
            zmq_meta = zmq_socket (zmq_context, ZMQ_PAIR);
            if(m_stream_mode == "sender"){
                zmq_connect (zmq_meta, remote_address.c_str());
                cout << "StreamMan::init " << remote_address << " connected" << endl;
            }
            else if(m_stream_mode == "receiver"){
                zmq_bind (zmq_meta, local_address.c_str());
                cout << "StreamMan::init " << local_address << " bound" << endl;
            }
            zmq_meta_rep_thread_active = true;
            zmq_meta_rep_thread = new thread(&StreamMan::zmq_meta_rep_thread_func, this);
        }
        return 0;
    }
    else{
        return -1;
    }
}

void StreamMan::callback(){
    if(get_callback){
        vector<string> do_list = m_cache.get_do_list();
        for(string i : do_list){
            vector<string> var_list = m_cache.get_var_list(i);
            for(string j : var_list){
                get_callback(m_cache.get_buffer(i,j),<commit_msg>added default numbers for tolerance and priority in StreamMan<commit_after>#include <iostream>
#include <unistd.h>
#include <sstream>
#include "StreamMan.h"
#include "zmq.h"

using namespace std;

StreamMan::StreamMan()
    :DataMan()
{
}

StreamMan::~StreamMan(){
    if(zmq_meta) zmq_close(zmq_meta);
    if(zmq_context) zmq_ctx_destroy(zmq_context);
    zmq_meta_rep_thread_active = false;
    if(zmq_meta_rep_thread){
        if(zmq_meta_rep_thread->joinable())
            zmq_meta_rep_thread->join();
        delete zmq_meta_rep_thread;
    }
}

int StreamMan::init(json p_jmsg){
    if(check_json(p_jmsg, {"stream_mode", "remote_ip", "local_ip", "remote_port", "local_port" }, "StreamMan")){
        m_stream_mode = p_jmsg["stream_mode"];
        m_local_ip = p_jmsg["local_ip"];
        m_remote_ip = p_jmsg["remote_ip"];
        m_local_port = p_jmsg["local_port"];
        m_remote_port = p_jmsg["remote_port"];
        string remote_address = make_address(m_remote_ip, m_remote_port, "tcp");
        string local_address = make_address(m_local_ip, m_local_port, "tcp");

        if(p_jmsg["num_channels"] != nullptr) m_num_channels = p_jmsg["num_channels"];
        if(p_jmsg["tolerance"] != nullptr) m_tolerance = p_jmsg["tolerance"].get<vector<int>>();
        else m_tolerance.assign(m_num_channels, 0);
        if(p_jmsg["priority"] != nullptr) m_priority = p_jmsg["priority"].get<vector<int>>();
        else m_priority.assign(m_num_channels, 100);

        if(!zmq_context){
            zmq_context = zmq_ctx_new ();
            zmq_meta = zmq_socket (zmq_context, ZMQ_PAIR);
            if(m_stream_mode == "sender"){
                zmq_connect (zmq_meta, remote_address.c_str());
                cout << "StreamMan::init " << remote_address << " connected" << endl;
            }
            else if(m_stream_mode == "receiver"){
                zmq_bind (zmq_meta, local_address.c_str());
                cout << "StreamMan::init " << local_address << " bound" << endl;
            }
            zmq_meta_rep_thread_active = true;
            zmq_meta_rep_thread = new thread(&StreamMan::zmq_meta_rep_thread_func, this);
        }
        return 0;
    }
    else{
        return -1;
    }
}

void StreamMan::callback(){
    if(get_callback){
        vector<string> do_list = m_cache.get_do_list();
        for(string i : do_list){
            vector<string> var_list = m_cache.get_var_list(i);
            for(string j : var_list){
                get_callback(m_cache.get_buffer(i,j),
{'fraction_non_alphanumeric': 0.13577453198930262, 'fraction_numerical': 0.0016457519029006377, 'mean_word_length': 3.0016460905349795, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 25, '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': '1628751', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1684, 'n_words': 261}