task manager, license formatting
This commit is contained in:
parent
fe2fbb9ad0
commit
f1a2006b4b
69 changed files with 380 additions and 122 deletions
|
@ -1,3 +1,6 @@
|
|||
#SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
#SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
set(HEADERS
|
||||
server.h
|
||||
router.h
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "router.h"
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "server.h"
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
|||
#include "handler/register.h"
|
||||
#include "handler/login.h"
|
||||
|
||||
#include "taskmanager/route.h"
|
||||
|
||||
constexpr const char* pepper = "well, not much of a secret, huh?";
|
||||
constexpr const char* dbLogin = "pica";
|
||||
constexpr const char* dbPassword = "pica";
|
||||
|
@ -29,11 +31,13 @@ constexpr uint32_t hashMemoryCost = 65536;
|
|||
constexpr uint8_t currentDbVesion = 1;
|
||||
|
||||
Server::Server():
|
||||
std::enable_shared_from_this<Server>(),
|
||||
terminating(false),
|
||||
requestCount(0),
|
||||
serverName(std::nullopt),
|
||||
router(),
|
||||
router(std::make_shared<Router>()),
|
||||
pool(DB::Pool::create()),
|
||||
taskManager(std::make_shared<TM::Manager>()),
|
||||
sessions()
|
||||
{
|
||||
std::cout << "Startig pica..." << std::endl;
|
||||
|
@ -50,16 +54,18 @@ Server::Server():
|
|||
DB::Resource db = pool->request();
|
||||
|
||||
db->migrate(currentDbVesion);
|
||||
|
||||
router.addRoute(std::make_unique<Handler::Info>());
|
||||
router.addRoute(std::make_unique<Handler::Env>());
|
||||
router.addRoute(std::make_unique<Handler::Register>(this));
|
||||
router.addRoute(std::make_unique<Handler::Login>(this));
|
||||
}
|
||||
|
||||
Server::~Server() {}
|
||||
|
||||
void Server::run(int socketDescriptor) {
|
||||
router->addRoute(std::make_unique<Handler::Info>());
|
||||
router->addRoute(std::make_unique<Handler::Env>());
|
||||
router->addRoute(std::make_unique<Handler::Register>(shared_from_this()));
|
||||
router->addRoute(std::make_unique<Handler::Login>(shared_from_this()));
|
||||
|
||||
taskManager->start();
|
||||
|
||||
while (!terminating) {
|
||||
std::unique_ptr<Request> request = std::make_unique<Request>();
|
||||
bool result = request->wait(socketDescriptor);
|
||||
|
@ -86,7 +92,9 @@ void Server::handleRequest(std::unique_ptr<Request> request) {
|
|||
}
|
||||
|
||||
request->readPath(serverName.value());
|
||||
router.route(std::move(request));
|
||||
|
||||
auto route = std::make_unique<TM::Route>(router, std::move(request));
|
||||
taskManager->schedule(std::move(route));
|
||||
}
|
||||
|
||||
std::string Server::generateRandomString(std::size_t length) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -25,8 +25,9 @@
|
|||
#include "database/pool.h"
|
||||
#include "utils/helpers.h"
|
||||
#include "config.h"
|
||||
#include "taskmanager/manager.h"
|
||||
|
||||
class Server {
|
||||
class Server : public std::enable_shared_from_this<Server> {
|
||||
public:
|
||||
Server();
|
||||
~Server();
|
||||
|
@ -48,7 +49,8 @@ private:
|
|||
bool terminating;
|
||||
uint64_t requestCount;
|
||||
std::optional<std::string> serverName;
|
||||
Router router;
|
||||
std::shared_ptr<Router> router;
|
||||
std::shared_ptr<DB::Pool> pool;
|
||||
std::shared_ptr<TM::Manager> taskManager;
|
||||
Sessions sessions;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "session.h"
|
||||
|
||||
|
@ -31,4 +31,4 @@ void Session::accept(std::unique_ptr<Request> request) {
|
|||
}
|
||||
|
||||
polling = std::move(request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
||||
//SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue