pica/server/server.h
2023-12-31 14:10:04 -03:00

59 lines
1.5 KiB
C++

//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
//SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <iostream>
#include <string>
#include <sstream>
#include <optional>
#include <string_view>
#include <vector>
#include <memory>
#include <map>
#include <fcgiapp.h>
#include <fcgio.h>
#include <stdint.h>
#include <argon2.h>
#include "request/request.h"
#include "response/response.h"
#include "router.h"
#include "session.h"
#include "database/pool.h"
#include "utils/helpers.h"
#include "config.h"
#include "taskmanager/manager.h"
#include "taskmanager/scheduler.h"
class Server : public std::enable_shared_from_this<Server> {
public:
Server();
~Server();
void run(int socketDescriptor);
unsigned int registerAccount(const std::string& login, const std::string& password);
bool validatePassword(const std::string& login, const std::string& password);
Session& openSession(const std::string& login);
Session& getSession(const std::string& accessToken);
private:
void handleRequest(std::unique_ptr<Request> request);
static std::string generateRandomString(std::size_t length);
private:
using Sessions = std::map<std::string, std::unique_ptr<Session>>;
bool terminating;
uint64_t requestCount;
std::optional<std::string> serverName;
std::shared_ptr<Router> router;
std::shared_ptr<DB::Pool> pool;
std::shared_ptr<TM::Manager> taskManager;
std::shared_ptr<TM::Scheduler> scheduler;
Sessions sessions;
};