<commit_before>//
// Copyright 2016 - 2020 (C). <NAME>. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "mqttsn/gateway/gateway_all.h"

#include <sstream>
#include <fstream>
#include <algorithm>
#include <limits>

#include "mqttsn/gateway/gateway_allpp.h"

namespace
{

typedef mqttsn::gateway::Config Config;
typedef mqttsn::gateway::Gateway Gateway;
typedef mqttsn::gateway::Session Session;

}  // namespace

/*===================== Gateway Object ======================*/

MqttsnGatewayHandle mqttsn_gw_alloc(void)
{
    MqttsnGatewayHandle gw;
    gw.obj = new Gateway();
    return gw;
}

void mqttsn_gw_free(MqttsnGatewayHandle gw)
{
    std::unique_ptr<Gateway>(reinterpret_cast<Gateway*>(gw.obj));
}

void mqttsn_gw_set_advertise_period(
    MqttsnGatewayHandle gw,
    unsigned short value)
{
    if (gw.obj == nullptr) {
        return;
    }

    reinterpret_cast<Gateway*>(gw.obj)->setAdvertisePeriod(value);
}

void mqttsn_gw_set_id(MqttsnGatewayHandle gw, unsigned char id)
{
    if (gw.obj == nullptr) {
        return;
    }

    reinterpret_cast<Gateway*>(gw.obj)->setGatewayId(id);
}

void mqttsn_gw_set_tick_req_cb(MqttsnGatewayHandle gw, MqttsnGwTickReqCb cb, void* data)
{
    if ((gw.obj == nullptr) || (cb == nullptr)) {
        return;
    }

    reinterpret_cast<Gateway*>(gw.obj)->setNextTickProgramReqCb(
        [cb, data](unsigned duration)
        {
            cb(data, duration);
        });
}

void mqttsn_gw_set_advertise_broadcast_req_cb(
    MqttsnGatewayHandle gw,
    MqttsnGwBroadcastReqCb cb,
    void* data)
{
    if ((gw.obj == nullptr) || (cb == nullptr)) {
        return;
    }

    reinterpret_cast<Gateway*>(gw.obj)->setSendDataReqCb(
        [cb, data](const unsigned char* buf, unsigned bufLen)
        {
            cb(data, buf, bufLen);
        });
}

bool mqttsn_gw_start(MqttsnGatewayHandle gw)
{
    if (gw.obj == nullptr) {
        return false;
    }

    return reinterpret_cast<Gateway*>(gw.obj)->start();
}

void mqttsn_gw_stop(MqttsnGatewayHandle gw)
{
    if (gw.obj == nullptr) {
        return;
    }

    reinterpret_cast<Gateway*>(gw.obj)->stop();
}
<commit_msg>Attempt to fix windows build.<commit_after>//
// Copyright 2016 - 2020 (C). <NAME>. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "mqttsn/gateway/gateway_all.h"

#include <sstream>
#include <fstream>
#include <algorithm>
#include <limits>

#include "mqttsn/gateway/gateway_allpp.h"

namespace
{

typedef mqttsn::gateway::Config Config;
typedef mqttsn::gateway::Gateway Gateway;
typedef mqttsn::gateway::Session Session;

}  // namespace

/*===================== Gateway Object ======================*/

MqttsnGatewayHandle mqttsn_gw_alloc(void)
{
    MqttsnGatewayHandle gw;
    gw.obj = new Gateway();
    return gw;
}

void mqttsn_gw_free(MqttsnGatewayHandle gw)
{
    std::unique_ptr<Gateway>(reinterpret_cast<Gateway*>(gw.obj));
}

void mqttsn_gw_set_advertise_period(
    MqttsnGatewayHandle gw,
    unsigned short value)
{
    if (gw.obj == nullptr) {
        return;
    }

    reinterpret_cast<Gateway*>(gw.obj)->setAdvertisePeriod(value);
}

void mqttsn_gw_set_id(MqttsnGatewayHandle gw, unsigned char id)
{
    if (gw.obj == nullptr) {
        return;
    }

    reinterpret_cast<Gateway*>(gw.obj)->setGatewayId(id);
}

void mqttsn_gw_set_tick_req_cb(MqttsnGatewayHandle gw, MqttsnGwTickReqCb cb, void* data)
{
    if ((gw.obj == nullptr) || (cb == nullptr)) {
        return;
    }

    reinterpret_cast<Gateway*>(gw.obj)->setNextTickProgramReqCb(
        [cb, data](unsigned duration)
        {
            cb(data, duration);
        });
}

void mqttsn_gw_set_advertise_broadcast_req_cb(
    MqttsnGatewayHandle gw,
    MqttsnGwBroadcastReqCb cb,
    void* data)
{
    if ((gw.obj == nullptr) || (cb == nullptr)) {
        return;
    }

    reinterpret_cast<Gateway*>(gw.obj)->setSendDataReqCb(
        [cb, data](const unsigned char* buf, std::size_t bufLen)
        {
            cb(data, buf, static_cast<unsigned>(bufLen));
        });
}

bool mqttsn_gw_start(MqttsnGatewayHandle gw)
{
    if (gw.obj == nullptr) {
        return false;
    }

    return reinterpret_cast<Gateway*>(gw.obj)->start();
}

void mqttsn_gw_stop(MqttsnGatewayHandle gw)
{
    if (gw.obj == nullptr) {
        return;
    }

    reinterpret_cast<Gateway*>(gw.obj)->stop();
}

{'fraction_non_alphanumeric': 0.14777587681779297, 'fraction_numerical': 0.0051325919589392645, 'mean_word_length': 3.4122641509433964, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 42, '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': '1858898', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1744, 'n_words': 336}