Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/feature/WWM-91' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JinmuGo committed Nov 6, 2023
2 parents e269224 + c02586a commit 03b6bba
Show file tree
Hide file tree
Showing 32 changed files with 116 additions and 36 deletions.
16 changes: 1 addition & 15 deletions src/Reactor/AEventHandler/AEventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@
#define AEVENTHANDLER_H

#include <sys/socket.h>
#include "enum.h"
#include "shared_ptr.hpp"
#include "types.h"

struct sharedData {
const fd_t fd;
const enum EventType type;
std::vector<char> buffer;
enum AsyncState state;

sharedData(const fd_t fd, const enum EventType type, std::vector<char> buffer)
: fd(fd), type(type), buffer(buffer), state(PENDING){};
};

typedef utils::shared_ptr<struct sharedData> sharedData_t;
#include "SharedData.hpp"

#endif
10 changes: 5 additions & 5 deletions src/Reactor/AEventHandler/AEventHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace reactor {
AEventHandler(sharedData_t& sharedData) : _sharedData(sharedData){};
virtual ~AEventHandler(){};
sharedData_t getData() const { return this->_sharedData; };
handle_t getHandle() const { return this->_sharedData.get()->fd; };
std::vector<char>& getBuffer() { return this->_sharedData.get()->buffer; };
enum EventType getType() const { return this->_sharedData.get()->type; };
enum AsyncState getState() const { return this->_sharedData.get()->state; };
void setState(const enum AsyncState state) { this->_sharedData.get()->state = state; };
handle_t getHandle() const { return this->_sharedData.get()->getFd(); };
std::vector<char>& getBuffer() { return this->_sharedData.get()->getBuffer(); };
enum EventType getType() const { return this->_sharedData.get()->getType(); };
enum AsyncState getState() const { return this->_sharedData.get()->getState(); };
void setState(const enum AsyncState state) { this->_sharedData->setState(state); };
virtual void handleEvent() = 0;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace reactor {
ClientRequestHandler::ClientRequestHandler(sharedData_t& sharedData, va_list args)
: AExeHandler(sharedData), _request(ServerManager::getInstance()->getServerConfig(sharedData.get()->fd)) {
: AExeHandler(sharedData), _request(ServerManager::getInstance()->getServerConfig(sharedData.get()->getFd())) {
Dispatcher::getInstance()->registerIOHandler<ClientReadHandlerFactory>(sharedData);
va_end(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace reactor {
throw;
}
Dispatcher::getInstance()->registerExeHandler<ClientRequestHandlerFactory>(
sharedData_t(new sharedData(clientFd, EVENT_READ, std::vector<char>())));
sharedData_t(new SharedData(clientFd, EVENT_READ, std::vector<char>())));
this->setState(PENDING);
// Dispatcher::getInstance()->removeExeHandler(u::shared_ptr<AEventHandler>(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ifndef TOPDIR
endif

ifndef DSTDIR
DSTDIR := $(abspath ../../)
DSTDIR := $(abspath ../../../)
endif

include $(TOPDIR)/config/makefile/common.mk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ifndef TOPDIR
endif

ifndef DSTDIR
DSTDIR := $(abspath ../../)
DSTDIR := $(abspath ../../../)
endif

include $(TOPDIR)/config/makefile/common.mk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ifndef TOPDIR
endif

ifndef DSTDIR
DSTDIR := $(abspath ../../)
DSTDIR := $(abspath ../../../)
endif

include $(TOPDIR)/config/makefile/common.mk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ifndef TOPDIR
endif

ifndef DSTDIR
DSTDIR := $(abspath ../../)
DSTDIR := $(abspath ../../../)
endif

include $(TOPDIR)/config/makefile/common.mk
Expand Down
17 changes: 17 additions & 0 deletions src/Reactor/AEventHandler/IOHandler/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ifndef TOPDIR
TOPDIR := $(abspath ../../../../)
endif

ifndef DSTDIR
DSTDIR := $(abspath ../../)
endif

include $(TOPDIR)/config/makefile/common.mk

DIRS := ClientReadHandler \
ClientWriteHandler \
FileReadHandler \
FileWriteHandler \
ServerReadHandler

include $(TOPDIR)/config/makefile/objRecipes.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ifndef TOPDIR
endif

ifndef DSTDIR
DSTDIR := $(abspath ../../)
DSTDIR := $(abspath ../../../)
endif

include $(TOPDIR)/config/makefile/common.mk
Expand Down
7 changes: 2 additions & 5 deletions src/Reactor/AEventHandler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ endif
include $(TOPDIR)/config/makefile/common.mk

DIRS := AExeHandler \
ClientReadHandler \
ClientWriteHandler \
FileReadHandler \
FileWriteHandler \
ServerReadHandler \
IOHandler \
SharedData \
TestAcceptHandler

include $(TOPDIR)/config/makefile/objRecipes.mk
18 changes: 18 additions & 0 deletions src/Reactor/AEventHandler/SharedData/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ifndef TOPDIR
TOPDIR := $(abspath ../../../../)
endif

ifndef DSTDIR
DSTDIR := $(abspath ../../)
endif

include $(TOPDIR)/config/makefile/common.mk

SRCS := $(addprefix $(DSTDIR)/objs/, SharedData.cpp)

OBJS := $(SRCS:.cpp=.o)
DEPS := $(SRCS:.cpp=.d)

-include $(DEPS)erverReadHandler

include $(TOPDIR)/config/makefile/objRecipes.mk
22 changes: 22 additions & 0 deletions src/Reactor/AEventHandler/SharedData/SharedData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "SharedData.hpp"

namespace reactor {
SharedData::SharedData(const fd_t fd, const enum EventType type, std::vector<char> buffer)
: _fd(fd), _type(type), _buffer(buffer), _state(PENDING){};

SharedData::SharedData(const SharedData& obj)
: _fd(obj._fd), _type(obj._type), _buffer(obj._buffer), _state(obj._state){};

SharedData::~SharedData(){};

SharedData& SharedData::operator=(const SharedData& obj) {
if (this != &obj) {
const_cast<fd_t&>(this->_fd) = obj._fd;
const_cast<enum EventType&>(this->_type) = obj._type;
this->_buffer = obj._buffer;
this->_state = obj._state;
}
return *this;
};

} // namespace reactor
9 changes: 9 additions & 0 deletions src/Reactor/AEventHandler/SharedData/SharedData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#ifndef SHAREDDATA_H
#define SHAREDDATA_H

#include "enum.h"
#include "shared_ptr.hpp"
#include "types.h"

#endif
31 changes: 31 additions & 0 deletions src/Reactor/AEventHandler/SharedData/SharedData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
#ifndef SHAREDDATA_HPP
#define SHAREDDATA_HPP

#include "SharedData.h"

namespace reactor {
class SharedData {
private:
const fd_t _fd;
const enum EventType _type;
std::vector<char> _buffer;
enum AsyncState _state;

public:
SharedData(const fd_t fd, const enum EventType type, std::vector<char> buffer);
SharedData(const SharedData& obj);
~SharedData();
SharedData& operator=(const SharedData& obj);

fd_t getFd() const { return this->_fd; };
enum EventType getType() const { return this->_type; };
std::vector<char>& getBuffer() { return this->_buffer; };
enum AsyncState getState() const { return this->_state; };
void setState(const enum AsyncState state) { this->_state = state; };
};

typedef utils::shared_ptr<SharedData> sharedData_t;
}; // namespace reactor

#endif
6 changes: 3 additions & 3 deletions src/Reactor/Dispatcher/Dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ namespace reactor {
~Dispatcher();
template <class Factory>
void registerIOHandler(sharedData_t& sharedData) {
const handle_t handle = sharedData.get()->fd;
const handle_t handle = sharedData.get()->getFd();
Factory factory;
u::shared_ptr<AEventHandler> handler = factory.createIOHandler(sharedData);

this->_ioHandlers[handle].push_back(handler);
this->_handlerIndices[handler] = this->_ioHandlers[handle].size() - 1;
this->_demultiplexer->requestEvent(handler.get(), sharedData.get()->type);
this->_demultiplexer->requestEvent(handler.get(), sharedData.get()->getType());
}

template <class Factory>
void registerExeHandler(sharedData_t sharedData, ...) {
const handle_t handle = sharedData->fd;
const handle_t handle = sharedData->getFd();
Factory factory;
va_list args;
va_start(args, sharedData);
Expand Down
2 changes: 1 addition & 1 deletion src/ServerManager/ServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ ServerManager::~ServerManager() {

void ServerManager::registerReadEvent(fd_t fd) {
reactor::Dispatcher::getInstance()->registerExeHandler<reactor::ServerAcceptHandlerFactory>(
sharedData_t(new sharedData(fd, EVENT_READ, std::vector<char>())), NULL);
reactor::sharedData_t(new reactor::SharedData(fd, EVENT_READ, std::vector<char>())), NULL);
}

0 comments on commit 03b6bba

Please sign in to comment.