Skip to content

Commit

Permalink
Move files and fix headers
Browse files Browse the repository at this point in the history
  • Loading branch information
kachsheev committed Sep 16, 2024
1 parent 57636fd commit b6b2b99
Show file tree
Hide file tree
Showing 36 changed files with 639 additions and 518 deletions.
116 changes: 89 additions & 27 deletions include/FlameIDE/Handler/Network/Handler.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef FLAMEIDE_OS_NETWORK_HANDLER_HPP
#define FLAMEIDE_OS_NETWORK_HANDLER_HPP

#include <FlameIDE/Common/Constants.hpp>
#include <FlameIDE/Common/Expected.hpp>
#include <FlameIDE/Common/Traits.hpp>

#include <FlameIDE/Os/Types.hpp>
Expand All @@ -13,8 +13,6 @@ namespace flame_ide
{namespace network
{

class NetworkBase;

class UdpServer;
class UdpClient;

Expand All @@ -35,34 +33,78 @@ class Handler
{
public:
class Internal;
class Tcp;
class Udp;

public:
class ServerHandle;
class CommunicationHandle;
class SessionHandle;

using ExpectedServerHandle = Expected<ServerHandle, os::Status>;
using ExpectedSessionHandle = Expected<SessionHandle, os::Status>;

using ExpectedUdpServer = Expected<os::network::UdpServer, os::Status>;
using ExpectedUdpClient = Expected<os::network::UdpClient, os::Status>;

using ExpectedTcpServer = Expected<os::network::TcpServer, os::Status>;
using ExpectedTcpClient = Expected<os::network::TcpClient, os::Status>;

public:
Handler() noexcept;
Handler(const Handler &) noexcept = delete;
Handler(Handler &&handler) noexcept;

~Handler() noexcept;

Handler &operator=(const Handler &) noexcept = delete;
Handler &operator=(Handler &&handler) noexcept;

ServerHandle push(os::network::UdpServer &&server) noexcept;
CommunicationHandle push(os::network::UdpClient &&client) noexcept;

ServerHandle push(os::network::TcpServer &&server) noexcept;
CommunicationHandle push(os::network::TcpClient &&client) noexcept;

os::Status pop(const ServerHandle &, os::network::UdpServer &server) noexcept;
os::Status pop(const CommunicationHandle &, os::network::UdpClient &client) noexcept;

os::Status pop(const ServerHandle &, os::network::TcpServer &server) noexcept;
os::Status pop(const CommunicationHandle &, os::network::TcpClient &client) noexcept;
Handler &operator=(Handler &&handler) noexcept;

/// @brief pushUdp
/// @param server
/// @return
ExpectedServerHandle pushUdp(os::network::UdpServer &&server) noexcept;

/// @brief pushUdp
/// @param client
/// @return
ExpectedSessionHandle pushUdp(os::network::UdpClient &&client) noexcept;

/// @brief pushTcp
/// @param server
/// @return
ExpectedServerHandle pushTcp(os::network::TcpServer &&server) noexcept;

/// @brief pushTcp
/// @param client
/// @return
ExpectedSessionHandle pushTcp(os::network::TcpClient &&client) noexcept;

/// @brief pop
/// @param server
/// @return
ExpectedUdpServer popUdp(ServerHandle &handle) noexcept;

/// @brief pop
/// @param client
/// @return
ExpectedUdpClient popUdp(SessionHandle &handle) noexcept;

/// @brief pop
/// @param server
/// @return
ExpectedTcpServer popTcp(ServerHandle &handle) noexcept;

/// @brief pop
/// @param client
/// @return
ExpectedTcpClient popTcp(SessionHandle &handle) noexcept;

/// @brief start
/// @return
os::Status start() noexcept;

/// @brief stop
/// @return
os::Status stop() noexcept;

private:
Expand All @@ -89,45 +131,65 @@ class Handler::ServerHandle

operator bool() const noexcept;

Handler::CommunicationHandle getCommunicationHandle() noexcept;
///
/// @brief getSessionHandle
/// @return
///
Handler::SessionHandle getSessionHandle() noexcept;

private:
friend class Handler::Internal;
friend class Handler::Udp;
friend class Handler::Tcp;

private:
using CallbackGetCommunicationHandle = Handler::CommunicationHandle (*)(void *);
using CallbackGetSessionHandle = Handler::SessionHandle (*)(void *);

private:
void *data = nullptr;
CallbackGetCommunicationHandle callbackGetCommunicationHandle = nullptr;
CallbackGetSessionHandle callbackGetSessionHandle = nullptr;
};

}}} // namespace flame_ide::handler::network

// Handler::CommunicationHandle
// Handler::SessionHandle
namespace flame_ide
{namespace handler
{namespace network
{

class Handler::CommunicationHandle
class Handler::SessionHandle
{
public:
CommunicationHandle() noexcept = default;
CommunicationHandle(CommunicationHandle &&) noexcept = default;
~CommunicationHandle() noexcept = default;
SessionHandle() noexcept = default;
SessionHandle(SessionHandle &&) noexcept = default;
~SessionHandle() noexcept = default;

CommunicationHandle &operator=(CommunicationHandle &&) noexcept = default;
SessionHandle &operator=(SessionHandle &&) noexcept = default;

operator bool() const noexcept;

///
/// @brief bytesToRead
/// @return
///
Types::ssize_t bytesToRead() const noexcept;

///
/// @brief receive
/// @return
///
Types::ssize_t receive(flame_ide::templates::Range<byte_t *>) noexcept;

///
/// @brief send
/// @return
///
Types::ssize_t send(flame_ide::templates::Range<const byte_t *>) noexcept;

private:
friend class Handler::Internal;
friend class Handler::Udp;
friend class Handler::Tcp;
friend class Handler::ServerHandle;

private:
Expand Down
24 changes: 24 additions & 0 deletions src/Handler/Network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@ set(DEPENDENCY_HEADER_TARGETS
${FLAME_NAMESPACE}::Handler::Network::Headers
)
set(DEPENDENCY_TARGETS_FOR_STATIC
"${FLAME_NAMESPACE}::${NAME_ALIAS}::Udp::Object"
"${FLAME_NAMESPACE}::${NAME_ALIAS}::Tcp::Object"
"${FLAME_NAMESPACE}::Os::Static"
)
set(DEPENDENCY_TARGETS_FOR_SHARED
"${FLAME_NAMESPACE}::${NAME_ALIAS}::Udp::Object::Independ"
"${FLAME_NAMESPACE}::${NAME_ALIAS}::Tcp::Object::Independ"
"${FLAME_NAMESPACE}::Os::Shared"
)

if(FLAME_MAKE_STATIC)
set(MAKE_STATIC MAKE_STATIC)
endif()
if(FLAME_MAKE_SHARED)
set(MAKE_SHARED MAKE_SHARED)
endif()

get_sources(FILE_LIST)
flame_compile_library(
NAME "${NAME}"
Expand All @@ -26,7 +37,20 @@ flame_compile_library(
"${FLAME_NAMESPACE}::${NAME_ALIAS}::Object"
INDEPENDENT_OBJECT_ALIAS_NAME
"${FLAME_NAMESPACE}::${NAME_ALIAS}::Object::Independ"
STATIC_ALIAS_NAME "${FLAME_NAMESPACE}::${NAME_ALIAS}::Static"
SHARED_ALIAS_NAME "${FLAME_NAMESPACE}::${NAME_ALIAS}::Shared"

NO_RTTI
NO_EXCEPTIONS

${MAKE_STATIC}
${MAKE_SHARED}
)

set(SOURCE_MODULES
${CMAKE_CURRENT_LIST_DIR}/Udp
${CMAKE_CURRENT_LIST_DIR}/Tcp
)
foreach(module ${SOURCE_MODULES})
add_subdirectory(${module})
endforeach()
8 changes: 4 additions & 4 deletions src/Handler/Network/CommunicationHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ namespace flame_ide
{namespace network
{

Handler::CommunicationHandle::operator bool() const noexcept
Handler::SessionHandle::operator bool() const noexcept
{
return object && callbackBytesToRead && callbackReceive && callbackSend;
}

Types::ssize_t Handler::CommunicationHandle::bytesToRead() const noexcept
Types::ssize_t Handler::SessionHandle::bytesToRead() const noexcept
{
return callbackBytesToRead(&object);
}

Types::ssize_t
Handler::CommunicationHandle::receive(templates::Range<byte_t *> bytes) noexcept
Handler::SessionHandle::receive(templates::Range<byte_t *> bytes) noexcept
{
return callbackReceive(&object, bytes);
}

Types::ssize_t
Handler::CommunicationHandle::send(templates::Range<const byte_t *> bytes) noexcept
Handler::SessionHandle::send(templates::Range<const byte_t *> bytes) noexcept
{
return callbackSend(&object, bytes);
}
Expand Down
36 changes: 18 additions & 18 deletions src/Handler/Network/Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,54 +50,54 @@ Handler &Handler::operator=(Handler &&handler) noexcept
return *this;
}

Handler::ServerHandle Handler::push(os::network::UdpServer &&server) noexcept
Handler::ExpectedServerHandle Handler::pushUdp(os::network::UdpServer &&server) noexcept
{
return internal->push(flame_ide::move(server));
return internal->udp().push(flame_ide::move(server));
}

Handler::CommunicationHandle Handler::push(os::network::UdpClient &&client) noexcept
Handler::ExpectedSessionHandle Handler::pushUdp(os::network::UdpClient &&client) noexcept
{
return internal->push(flame_ide::move(client));
return internal->udp().push(flame_ide::move(client));
}

Handler::ServerHandle Handler::push(os::network::TcpServer &&server) noexcept
Handler::ExpectedServerHandle Handler::pushTcp(os::network::TcpServer &&server) noexcept
{
return internal->push(flame_ide::move(server));
return internal->tcp().push(flame_ide::move(server));
}

Handler::CommunicationHandle Handler::push(os::network::TcpClient &&client) noexcept
Handler::ExpectedSessionHandle Handler::pushTcp(os::network::TcpClient &&client) noexcept
{
return internal->push(flame_ide::move(client));
return internal->tcp().push(flame_ide::move(client));
}

os::Status Handler::pop(const ServerHandle &, os::network::UdpServer &/*server*/) noexcept
Handler::ExpectedUdpServer Handler::popUdp(ServerHandle &handle) noexcept
{
return os::STATUS_FAILED;
return internal->udp().pop(handle);
}

os::Status Handler::pop(const CommunicationHandle &, os::network::UdpClient &/*client*/) noexcept
Handler::ExpectedUdpClient Handler::popUdp(SessionHandle &handle) noexcept
{
return os::STATUS_FAILED;
return internal->udp().pop(handle);
}

os::Status Handler::pop(const ServerHandle &, os::network::TcpServer &/*server*/) noexcept
Handler::ExpectedTcpServer Handler::popTcp(ServerHandle &handle) noexcept
{
return os::STATUS_FAILED;
return internal->tcp().pop(handle);
}

os::Status Handler::pop(const CommunicationHandle &, os::network::TcpClient &/*client*/) noexcept
Handler::ExpectedTcpClient Handler::popTcp(SessionHandle &handle) noexcept
{
return os::STATUS_FAILED;
return internal->tcp().pop(handle);
}

os::Status Handler::start() noexcept
{
return os::STATUS_FAILED;
return internal->start();
}

os::Status Handler::stop() noexcept
{
return os::STATUS_FAILED;
return internal->stop();
}

}}} // namespace flame_ide::handler::network
Expand Down
10 changes: 0 additions & 10 deletions src/Handler/Network/Headers.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
set (HEADER_LIST
${CMAKE_CURRENT_SOURCE_DIR}/Functions.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Internal.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Tcp.hpp
${CMAKE_CURRENT_SOURCE_DIR}/TcpClient.hpp
${CMAKE_CURRENT_SOURCE_DIR}/TcpConfig.hpp
${CMAKE_CURRENT_SOURCE_DIR}/TcpServer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/TcpTypes.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Udp.hpp
${CMAKE_CURRENT_SOURCE_DIR}/UdpClient.hpp
${CMAKE_CURRENT_SOURCE_DIR}/UdpConfig.hpp
${CMAKE_CURRENT_SOURCE_DIR}/UdpServer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/UdpTypes.hpp
${CMAKE_CURRENT_SOURCE_DIR}/Worker.hpp
)
Loading

0 comments on commit b6b2b99

Please sign in to comment.