<commit_before>/// Implementation of devices_manager.hpp
///
/// (c) Koheron

#include "devices_manager.hpp"
#include "kserver.hpp"
#include "commands.hpp"

#if KSERVER_HAS_THREADS
#  include <thread>
#endif

namespace kserver {

DeviceManager::DeviceManager(KServer *kserver_)
: device_list(device_num)
,  kserver(kserver_)
#if KSERVER_HAS_DEVMEM
,  dev_mem(kserver_->config->addr_limit_down, kserver_->config->addr_limit_up)
#endif
{
    device_list[KSERVER] = static_cast<KDeviceAbstract*>(kserver);
    is_started[KSERVER] = 1;
}

DeviceManager::~DeviceManager()
{
    Reset();
}

int DeviceManager::Init()
{
#if KSERVER_HAS_DEVMEM
    if (dev_mem.Open() < 0) {
        kserver->syslog.print(SysLog::CRITICAL,
                              "Can't start DevMem\n");
        return -1;
    }
#endif

    return 0;
}

// X Macro: Start new device
#if KSERVER_HAS_DEVMEM
#define EXPAND_AS_START_DEVICE(num, name, operations ...)                 \
        case num:                                                         \
            device_list[num]                                              \
                = new name (static_cast<KServer*>(device_list[KSERVER]),  \
                            dev_mem);                                     \
            break;
#else
#define EXPAND_AS_START_DEVICE(num, name, operations ...)                 \
        case num:                                                         \
            device_list[num]                                              \
                = new name (static_cast<KServer*>(device_list[KSERVER])); \
            break;
#endif

int DeviceManager::StartDev(device_t dev)
{
#if KSERVER_HAS_THREADS
    std::lock_guard<std::mutex> lock(mutex);
#endif

    assert(dev < device_num);
    assert(!is_started[dev]);

    if (dev == NO_DEVICE) {
        is_started[dev] = 1;
        return 0;
    }

    if (dev == KSERVER)
        if (!is_started[dev]) {
            kserver->syslog.print(SysLog::CRITICAL,
                                  "KServer must always be started !\n");
            return -1;   <commit_msg>Fic start dev (#113)<commit_after>/// Implementation of devices_manager.hpp
///
/// (c) Koheron

#include "devices_manager.hpp"
#include "kserver.hpp"
#include "commands.hpp"

#if KSERVER_HAS_THREADS
#  include <thread>
#endif

namespace kserver {

DeviceManager::DeviceManager(KServer *kserver_)
: device_list(device_num)
,  kserver(kserver_)
#if KSERVER_HAS_DEVMEM
,  dev_mem(kserver_->config->addr_limit_down, kserver_->config->addr_limit_up)
#endif
{
    device_list[KSERVER] = static_cast<KDeviceAbstract*>(kserver);
    is_started[KSERVER] = 1;
}

DeviceManager::~DeviceManager()
{
    Reset();
}

int DeviceManager::Init()
{
#if KSERVER_HAS_DEVMEM
    if (dev_mem.Open() < 0) {
        kserver->syslog.print(SysLog::CRITICAL,
                              "Can't start DevMem\n");
        return -1;
    }
#endif

    return 0;
}

// X Macro: Start new device
#if KSERVER_HAS_DEVMEM
#define EXPAND_AS_START_DEVICE(num, name, operations ...)                 \
        case num:                                                         \
            device_list[num]                                              \
                = new name (static_cast<KServer*>(device_list[KSERVER]),  \
                            dev_mem);                                     \
            break;
#else
#define EXPAND_AS_START_DEVICE(num, name, operations ...)                 \
        case num:                                                         \
            device_list[num]                                              \
                = new name (static_cast<KServer*>(device_list[KSERVER])); \
            break;
#endif

int DeviceManager::StartDev(device_t dev)
{
#if KSERVER_HAS_THREADS
    std::lock_guard<std::mutex> lock(mutex);
#endif

    assert(dev < device_num);

    if (is_started[dev])
        return 0;

    if (dev == NO_DEVICE) {
        is_started[dev] = 1;
        return 0;
    }

    if (dev == KSERVER)
        if (!is_started[dev]) {
            kserver->syslog.print(SysLog::CRITICAL,
                                  "KServer must always be started !\n");
            return -1;   
{'fraction_non_alphanumeric': 0.11431293165039295, 'fraction_numerical': 0.0042867349368897354, 'mean_word_length': 1.648171500630517, 'pattern_counts': {'":': 0, '<': 17, '<?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': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6166564', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1232, 'n_words': 234}