/* This file is part of FlashMQ (https://www.flashmq.org) Copyright (C) 2021 Wiebe Cazemier FlashMQ is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3. FlashMQ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with FlashMQ. If not, see . */ #ifndef THREADDATA_H #define THREADDATA_H #include #include #include #include #include #include #include #include #include #include "forward_declarations.h" #include "client.h" #include "subscriptionstore.h" #include "utils.h" #include "configfileparser.h" #include "authplugin.h" #include "logger.h" typedef void (*thread_f)(ThreadData *); class ThreadData { std::unordered_map clients_by_fd; std::mutex clients_by_fd_mutex; std::shared_ptr subscriptionStore; Logger *logger; void reload(std::shared_ptr settings); void wakeUpThread(); void doKeepAliveCheck(); void quit(); public: Settings settingsLocalCopy; // Is updated on reload, within the thread loop. AuthPlugin authPlugin; bool running = true; std::thread thread; int threadnr = 0; int epollfd = 0; int taskEventFd = 0; std::mutex taskQueueMutex; std::forward_list> taskQueue; ThreadData(int threadnr, std::shared_ptr &subscriptionStore, std::shared_ptr settings); ThreadData(const ThreadData &other) = delete; ThreadData(ThreadData &&other) = delete; void start(thread_f f); void giveClient(Client_p client); Client_p getClient(int fd); void removeClient(Client_p client); void removeClient(int fd); std::shared_ptr &getSubscriptionStore(); void initAuthPlugin(); void queueReload(std::shared_ptr settings); void queueDoKeepAliveCheck(); void queueQuit(); void waitForQuit(); }; #endif // THREADDATA_H