<commit_before>/**
 *  _____
 * |  __ \
 * | |__) | __ _  _   _
 * |  _  / / _` || | | |
 * | | \ \| (_| || |_| |
 * |_|  \_\\__,_| \__, |
 *                 __/ |
 *                |___/
 *  ______                        _         _    _
 * |  ____|                      | |       | |  (_)
 * | |__  ___   _   _  _ __    __| |  __ _ | |_  _   ___   _ __
 * |  __|/ _ \ | | | || '_ \  / _` | / _` || __|| | / _ \ | '_ \
 * | |  | (_) || |_| || | | || (_| || (_| || |_ | || (_) || | | |
 * |_|   \___/  \__,_||_| |_| \__,_| \__,_| \__||_| \___/ |_| |_|
 *
 **/

#include <RayFoundation/RayFoundation.h>
#include <unistd.h>
#include "Tests.h"

RArray *keysForConnects;
RArray *keysForConnects2;

RData* KeyForConnectionData(RTCPDataStruct *connectionData, pointer context) {
    if(connectionData != nil) {
        if(context == (pointer) 1) {
            return $(keysForConnects, m(objectAtIndex, RArray)), connectionData->identifier);
        } else if(context == (pointer) 2) {
            return $(keysForConnects2, m(objectAtIndex, RArray)), connectionData->identifier);
        }
    }
    return nil;
}

pointer TempExec(RTCPDataStruct *data) {

    RPrintf("%lu connected\n", data->identifier);

    rbool end = no;
    do {
        RData *received = PEConnectionReceive(((RTCPDataStructPE *) data->context)->connection, nil);

        if (received) {
            $(received, m(validateToASCII, RString)));
            RPrintf("%lu -> ", data->identifier);
            p(RData)(received);
            end = $(received, m(isEqualTo, RString)), RS("End"));
            deleter(received, RData);
        } else {
            end = yes;
        }

    } while(!end);

    RPrintf("%lu disconnected\n", data->identifier);

    if(((RTCPDataStructPE*)data->context)->connection != nil) {
        PEConnectionDeleter(((RTCPDataStructPE *) data->context)->connection);
        ((RTCPDataStructPE *) data->context)->connection = nil;
    }
    data->socket = nil;

    return nil;
}

RTCPHandlerPE *globalHandler;
RTCPDelegate  *globalDelegate;
PEKeyGeneratorDelegate *globalKeyGenerator;

RThread clientThread = nil;

void startPEClient();

void startedNotifier(RTCPHandler *handler) {
    if(handler == globalHandler->handler) {
        RPrintf("RTCPHandlerPE server started %p on port %u\n", handler, 3000);

        if(clientThread == nil) {
            clientThread = makeRThread((RThreadFunction) startPEClient);
        }
    } else {
        RPrintf("RTCPHandlerPE connector started %p on port %u\n", handler, 3000);
    }
}

void startPEServer(){
    RTCPHandlerPE **server = &globalHandler;
    RTCPDelegate **delegate = &globalDelegate;
    PEKeyGeneratorDelegate **keyGenerator = &globalKeyGenerator;

    *keyGenerator = allocator(PEKeyGeneratorDelegate);
    (*keyGenerator)->context = (pointer) 1;
    (*keyGenerator)->keyForConnectionData = KeyForConnectionData;

    *server = c(RTCPHandlerPE)(nil);

    if(*server != nil) {

        $((*server), m(set_keyGeneratorDelegate, RTCPHandlerPE)), *keyGenerator);

        (*server)->dataStructContextDestructor = nil;


        *delegate = allocator(RTCPDelegate);
        if(*delegate != nil) {
            (*delegate)->delegateFunction = TempExec;
            (*delegate)->context          = nil;

            (*server)->handler->handlerStartedNotifier = (RThreadFunction) startedNotifier;
            $(*server,  m(set_delegate, RTCPHandlerPE)), *delegate);
            $(*server,  m(startOnPort,  RTCPHandlerPE)), 3000);
        }
    }
}

pointer TempExec2(RTCPDataStruct *data) {
    RPrintf("%lu connecting...\n", data->identifier);

    PEConnectionSend(((RTCPDataStructPE*)data->context)->connection, RS("Hello bro=)"));

    sleep(1);
    PEConnectionSend(((RTCPDataStructPE*)data->context)->connection, RS("Come, get some!"));
    PEConnectionSend(((RTCPDataStructPE*)data->context)->connection, RS("End"));

    return nil;
}

void startPEClient(){
    RTCPHandlerPE *server1;
    RTCPDelegate *delegate1;
    PEKeyGeneratorDelegate *keyGenerator1;

    RTCPHandlerPE **server = &server1;
    RTCPDelegate **delegate = &delegate1;
    PEKeyGeneratorDelegate **keyGenerator = &keyGenerator1;

    *keyGenerator = allocator(PEKeyGeneratorDelegate);
    (*keyGenerator)->keyForConnectionData = KeyForConnectionData;
    (*keyGenerator)->context = (pointer) 2;

    *server = c(RTCPHandlerPE)(nil);<commit_msg>New year greetings commit! =)<commit_after>/**
 *  _____
 * |  __ \
 * | |__) | __ _  _   _
 * |  _  / / _` || | | |
 * | | \ \| (_| || |_| |
 * |_|  \_\\__,_| \__, |
 *                 __/ |
 *                |___/
 *  ______                        _         _    _
 * |  ____|                      | |       | |  (_)
 * | |__  ___   _   _  _ __    __| |  __ _ | |_  _   ___   _ __
 * |  __|/ _ \ | | | || '_ \  / _` | / _` || __|| | / _ \ | '_ \
 * | |  | (_) || |_| || | | || (_| || (_| || |_ | || (_) || | | |
 * |_|   \___/  \__,_||_| |_| \__,_| \__,_| \__||_| \___/ |_| |_|
 *
 **/

#include <RayFoundation/RayFoundation.h>
#include <unistd.h>
#include "Tests.h"

RArray *keysForConnects;
RArray *keysForConnects2;

RData* KeyForConnectionData(RTCPDataStruct *connectionData, pointer context) {
    if(connectionData != nil) {
        if(context == (pointer) 1) {
            return $(keysForConnects, m(objectAtIndex, RArray)), connectionData->identifier);
        } else if(context == (pointer) 2) {
            return $(keysForConnects2, m(objectAtIndex, RArray)), connectionData->identifier);
        }
    }
    return nil;
}

pointer TempExec(RTCPDataStruct *data) {

    RPrintf("%lu connected\n", data->identifier);

    rbool end = no;
    do {
        RData *received = PEConnectionReceive(((RTCPDataStructPE *) data->context)->connection, nil);

        if (received) {
            $(received, m(validateToASCII, RString)));
            RPrintf("%lu -> ", data->identifier);
            p(RData)(received);
            end = $(received, m(isEqualTo, RString)), RS("End"));
            deleter(received, RData);
        } else {
            end = yes;
        }

    } while(!end);

    RPrintf("%lu disconnected\n", data->identifier);

    if(((RTCPDataStructPE*)data->context)->connection != nil) {
        PEConnectionDeleter(((RTCPDataStructPE *) data->context)->connection);
        ((RTCPDataStructPE *) data->context)->connection = nil;
    }
    data->socket = nil;

    return nil;
}

RTCPHandlerPE *globalHandler;
RTCPDelegate  *globalDelegate;
PEKeyGeneratorDelegate *globalKeyGenerator;

RThread clientThread = nil;

void startPEClient();

void startedNotifier(RTCPHandler *handler) {
    if(handler == globalHandler->handler) {
        RPrintf("RTCPHandlerPE server started %p on port %u\n", handler, 3000);

        if(clientThread == nil) {
            clientThread = makeRThread((RThreadFunction) startPEClient);
        }
    } else {
        RPrintf("RTCPHandlerPE connector started %p on port %u\n", handler, 3000);
    }
}

void startPEServer(){
    RTCPHandlerPE **server = &globalHandler;
    RTCPDelegate **delegate = &globalDelegate;
    PEKeyGeneratorDelegate **keyGenerator = &globalKeyGenerator;

    *keyGenerator = allocator(PEKeyGeneratorDelegate);
    (*keyGenerator)->context = (pointer) 1;
    (*keyGenerator)->keyForConnectionData = KeyForConnectionData;

    *server = c(RTCPHandlerPE)(nil);

    if(*server != nil) {

        $((*server), m(set_keyGeneratorDelegate, RTCPHandlerPE)), *keyGenerator);

        (*server)->dataStructContextDestructor = nil;


        *delegate = allocator(RTCPDelegate);
        if(*delegate != nil) {
            (*delegate)->delegateFunction = TempExec;
            (*delegate)->context          = nil;

            (*server)->handler->handlerStartedNotifier = (RThreadFunction) startedNotifier;
            $(*server,  m(set_delegate, RTCPHandlerPE)), *delegate);
            $(*server,  m(startOnPort,  RTCPHandlerPE)), 3000);
        }
    }
}

pointer TempExec2(RTCPDataStruct *data) {
    RPrintf("%lu connecting...\n", data->identifier);

    PEConnectionSend(((RTCPDataStructPE*)data->context)->connection, RS("Happy merry christmas"));
    sleep(1);
    PEConnectionSend(((RTCPDataStructPE*)data->context)->connection, RS("And a happy new year!"));
    PEConnectionSend(((RTCPDataStructPE*)data->context)->connection, RS("2015-End =)"));

    return nil;
}

void startPEClient(){
    RTCPHandlerPE *server1;
    RTCPDelegate *delegate1;
    PEKeyGeneratorDelegate *keyGenerator1;

    RTCPHandlerPE **server = &server1;
    RTCPDelegate **delegate = &delegate1;
    PEKeyGeneratorDelegate **keyGenerator = &keyGenerator1;

    *keyGenerator = allocator(PEKeyGeneratorDelegate);
    (*keyGenerator)->keyForConnectionData = KeyForConnectionData;
    (*keyGenerator)->context = (pointer) 2;

    *server = c(RTCPHandlerPE)(nil);
{'fraction_non_alphanumeric': 0.15994088893941116, 'fraction_numerical': 0.006365806524951688, 'mean_word_length': 2.7971514889943894, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2678573', 'n_tokens_mistral': 2816, 'n_tokens_neox': 2707, 'n_words': 438}