<commit_before>#include "admiral_macros.h"

#include "logbook.h"

#define ADDON_NS                        adm
#define ADD_ADDON_NS_TO_ID(M,ID)        M##ID
#define FNC_ADD_EVENT_HANDLER           ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_addEventHandler)
#define FNC_REMOVE_EVENT_HANDLER        ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_removeEventHandler)
#define FNC_ADD_EVENT                   ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_addEvent)
#define FNC_EMIT_EVENT                  ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_emitEvent)
#define FNC_FIND_EVENT                  ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_findEvent)
#define FNC_ADD_ALL_EVENTS              ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_addAllEvents)
#define FNC_INIT                        ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_init)
#define EVENTS_ARRAY                    ADD_ADDON_NS_TO_ID(ADDON_NS,_event_events)

//#define LOGGING_LEVEL_TRACE
//#define LOGGING_TO_RPT

FNC_ADD_EVENT_HANDLER = {
    FUN_ARGS_2(_eventName,_code);

    private ["_eventIndex", "_handlerId"];
    _eventIndex = [_eventName] call FNC_FIND_EVENT;
    _handlerId = -1;
    if (_eventIndex != -1) then {
        DECLARE(_handlerArray) = EVENTS_ARRAY select _eventIndex select 2;
        _handlerId = count _handlerArray;
        PUSH(_handlerArray,_code);
    };

    _handlerId;
};

FNC_REMOVE_EVENT_HANDLER = {
    FUN_ARGS_2(_eventName,_handlerId);

    private ["_eventIndex", "_handlerArray"];
    _eventIndex = [_eventName] call FNC_FIND_EVENT;
    _handlerArray = EVENTS_ARRAY select _eventIndex select 2;
    if (_eventIndex != -1 && {_handlerId >= 0} && {count _handlerArray >= _handlerId + 1}) then {
        _handlerArray set [_handlerId, {}];
    };
};

FNC_ADD_EVENT = {
    FUN_ARGS_2(_eventName,_eventConfigName);

    if ([_eventName] call FNC_FIND_EVENT == -1) then {
        PUSH(EVENTS_ARRAY,AS_ARRAY_3(_eventName,_eventConfigName,[]));
    };
};

FNC_EMIT_EVENT = {
    FUN_ARGS_2(_eventName,_arguments);

    DECLARE(_eventIndex) = [_eventName] call FNC_FIND_EVENT;
    TRACE("admiral.event.emit",FMT_3("Emiting event '%1' with arguments '%2' and found index '%3'.",_eventName,_arguments,_eventIndex));
    if (_eventIndex != -1) then {
        {
            _arguments call _x;
        } foreach (EVENTS_ARRAY select _eventIndex select 2);
        [EVENTS_ARRAY select _eventIndex select 1, _arguments] call adm_common_fnc_callEventFile;
        TRACE("admiral.event.emit",FMT_2("Emitted event '%1' with arguments '%2'.",_eventName,_arguments));
    };
};

FNC_FIND_EVENT = {
    FUN_ARGS_1(_eventName);

    DECLARE(_eventIndex) = -1;
    {<commit_msg>Added more logging and fixed the setting of log level.<commit_after>#include "admiral_macros.h"

//#define LOGGING_LEVEL_DEBUG
//#define LOGGING_TO_RPT
#include "logbook.h"

#define ADDON_NS                        adm
#define ADD_ADDON_NS_TO_ID(M,ID)        M##ID
#define FNC_ADD_EVENT_HANDLER           ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_addEventHandler)
#define FNC_REMOVE_EVENT_HANDLER        ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_removeEventHandler)
#define FNC_ADD_EVENT                   ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_addEvent)
#define FNC_EMIT_EVENT                  ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_emitEvent)
#define FNC_FIND_EVENT                  ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_findEvent)
#define FNC_ADD_ALL_EVENTS              ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_addAllEvents)
#define FNC_INIT                        ADD_ADDON_NS_TO_ID(ADDON_NS,_event_fnc_init)
#define EVENTS_ARRAY                    ADD_ADDON_NS_TO_ID(ADDON_NS,_event_events)


FNC_ADD_EVENT_HANDLER = {
    FUN_ARGS_2(_eventName,_code);

    private ["_eventIndex", "_handlerId"];
    _eventIndex = [_eventName] call FNC_FIND_EVENT;
    _handlerId = -1;
    if (_eventIndex != -1) then {
        DECLARE(_handlerArray) = EVENTS_ARRAY select _eventIndex select 2;
        _handlerId = count _handlerArray;
        PUSH(_handlerArray,_code);
    };

    _handlerId;
};

FNC_REMOVE_EVENT_HANDLER = {
    FUN_ARGS_2(_eventName,_handlerId);

    private ["_eventIndex", "_handlerArray"];
    _eventIndex = [_eventName] call FNC_FIND_EVENT;
    _handlerArray = EVENTS_ARRAY select _eventIndex select 2;
    if (_eventIndex != -1 && {_handlerId >= 0} && {count _handlerArray >= _handlerId + 1}) then {
        _handlerArray set [_handlerId, {}];
    };
};

FNC_ADD_EVENT = {
    FUN_ARGS_2(_eventName,_eventConfigName);

    if ([_eventName] call FNC_FIND_EVENT == -1) then {
        PUSH(EVENTS_ARRAY,AS_ARRAY_3(_eventName,_eventConfigName,[]));
    };
};

FNC_EMIT_EVENT = {
    FUN_ARGS_2(_eventName,_arguments);

    DECLARE(_eventIndex) = [_eventName] call FNC_FIND_EVENT;
    DEBUG("admiral.event.emit",FMT_2("Emiting event '%1' with found index '%2'.",_eventName,_eventIndex));
    TRACE("admiral.event.emit",FMT_3("Emiting event '%1' with arguments '%2' and found index '%3'.",_eventName,_arguments,_eventIndex));
    if (_eventIndex != -1) then {
        {
            _arguments call _x;
        } foreach (EVENTS_ARRAY select _eventIndex select 2);
        [EVENTS_ARRAY select _eventIndex select 1, _arguments] call adm_common_fnc_callEventFile;
        TRACE("admiral.event.emit",FMT_2("Emitted event '%1' with arguments '%2'.",_eventName,_arguments));
    };
};

FNC_FIND_EVENT = {
    FUN_ARGS_1(_eventName);

    DECLARE(_eventIndex) = -1;
    {
{'fraction_non_alphanumeric': 0.10207869339272457, 'fraction_numerical': 0.00983667409057164, 'mean_word_length': 3.7396657871591907, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7219026', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1898, 'n_words': 312}