🏗️」 wip: Started resourcemanager

This commit is contained in:
2025-05-12 19:14:33 +02:00
parent c0258855e5
commit 07201b9d8a
2 changed files with 61 additions and 2 deletions

View File

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Resource.hpp :+: :+: :+: */ /* AResource.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/29 14:20:09 by mmoussou #+# #+# */ /* Created: 2025/04/29 14:20:09 by mmoussou #+# #+# */
/* Updated: 2025/04/29 15:44:50 by adjoly ### ########.fr */ /* Updated: 2025/05/12 19:05:51 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,12 +22,20 @@ class AClientResource {
public: public:
virtual ~AClientResource() {} virtual ~AClientResource() {}
bool operator==(int i) const {
if (i == _client_id)
return true;
return false;
}
void addFileDescriptor(struct pollfd fd); void addFileDescriptor(struct pollfd fd);
struct pollfd getFileDescriptor(); struct pollfd getFileDescriptor();
private: private:
struct pollfd _fd; struct pollfd _fd;
int _client_id;
}; };
} // -namepsace server } // -namepsace server

View File

@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ResourceManager.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/12 17:13:39 by adjoly #+# #+# */
/* Updated: 2025/05/12 19:06:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <sstream>
#include <vector>
#include <cppeleven.hpp>
#include <log.hpp>
#include <server/AResource.hpp>
#include <webserv.hpp>
namespace webserv {
namespace server {
class ResourceManager {
public:
static AClientResource *get(int i) {
for (auto it = range(_res)) {
if ((**it) == i) {
return *it;
}
}
std::stringstream str;
str << "resource not found for client";
str << i;
_log->debug(str.str());
return not_nullptr;
}
static void append(AClientResource *new_client) {
_res.push_back(new_client);
}
protected:
private:
static std::vector<AClientResource *> _res;
};
} // namespace server
} // namespace webserv