Ver código fonte

Remove network module

- remove network module and move it to another
branch for feature development
Patrick-Christopher Mattulat 3 anos atrás
pai
commit
b76ce3f77a

+ 0 - 2
CMakeLists.txt

@@ -92,7 +92,6 @@ set(SOURCE_FILES
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/Event.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/EventHandler.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/EventManager.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/network/Socket.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/serialization/json/event/SerializableJSONEvent.cpp)
 
 if (${LS_STD_BUILD_WITH_TESTS})
@@ -148,7 +147,6 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/GossipNewsAgency.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/EventHandlerTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/EventManagerTest.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/network/SocketTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/event/SerializableJSONEventTest.cpp)
 endif ()
 

+ 1 - 3
include/ls_std/ls_std.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-10-29
- * Changed:         2020-12-20
+ * Changed:         2020-12-25
  *
  * */
 
@@ -85,6 +85,4 @@
 #include "event/IEventSubscriber.hpp"
 #include "event/EventManager.hpp"
 
-#include "network/Socket.hpp"
-
 #endif

+ 0 - 20
include/ls_std/network/AddressFamily.hpp

@@ -1,20 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2020-12-06
- * Changed:         2020-12-06
- *
- * */
-
-#ifndef LS_STD_ADDRESS_FAMILY_HPP
-#define LS_STD_ADDRESS_FAMILY_HPP
-
-namespace ls_std {
-  enum AddressFamily {
-    ADDRESS_FAMILY_IP_V4 = 0,
-    ADDRESS_FAMILY_IP_V6
-  };
-}
-
-#endif

+ 0 - 20
include/ls_std/network/NetworkProtocol.hpp

@@ -1,20 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2020-12-06
- * Changed:         2020-12-06
- *
- * */
-
-#ifndef LS_STD_NETWORK_PROTOCOL_HPP
-#define LS_STD_NETWORK_PROTOCOL_HPP
-
-namespace ls_std {
-  enum NetworkProtocol {
-    NETWORK_PROTOCOL_TCP_IP = 0,
-    NETWORK_PROTOCOL_UDP_IP
-  };
-}
-
-#endif

+ 0 - 62
include/ls_std/network/Socket.hpp

@@ -1,62 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2020-12-06
- * Changed:         2020-12-06
- *
- * */
-
-#ifndef LS_STD_SOCKET_HPP
-#define LS_STD_SOCKET_HPP
-
-#include <ls_std/base/Class.hpp>
-#include "AddressFamily.hpp"
-#include "SocketType.hpp"
-#include "NetworkProtocol.hpp"
-
-#if defined(unix) || defined(__APPLE__)
-#include <sys/types.h>
-#include <sys/socket.h>
-#endif
-
-#ifdef _WIN32
-#include <winsock2.h>
-#endif
-
-namespace ls_std {
-  class Socket : public ls_std::Class {
-    public:
-
-      Socket();
-      ~Socket() override;
-
-      bool close();
-      bool create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
-
-    private:
-
-      #if defined(unix) || defined(__APPLE__)
-        int descriptor {};
-      #endif
-      #ifdef _WIN32
-        SOCKET descriptor {};
-      #endif
-
-      bool _close();
-      #ifdef _WIN32
-        bool _closeOnWindows() const;
-      #endif
-      static int _convertAddressFamily(ls_std::AddressFamily _addressFamily);
-      static int _convertNetworkProtocol(ls_std::NetworkProtocol _networkProtocol);
-      static int _convertSocketType(ls_std::SocketType _socketType);
-      #if defined(unix) || defined(__APPLE__)
-        static int _create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
-      #endif
-      #ifdef _WIN32
-        static SOCKET _create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
-      #endif
-  };
-}
-
-#endif

+ 0 - 20
include/ls_std/network/SocketType.hpp

@@ -1,20 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2020-12-06
- * Changed:         2020-12-06
- *
- * */
-
-#ifndef LS_STD_SOCKET_TYPE_HPP
-#define LS_STD_SOCKET_TYPE_HPP
-
-namespace ls_std {
-  enum SocketType {
-    SOCKET_TYPE_STREAM = 0,
-    SOCKET_TYPE_DATAGRAM
-  };
-}
-
-#endif

+ 0 - 165
source/ls_std/network/Socket.cpp

@@ -1,165 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2020-12-06
- * Changed:         2020-12-21
- *
- * */
-
-#include <ls_std/network/Socket.hpp>
-#include <ls_std/base/Types.hpp>
-
-#if defined(unix) || defined(__APPLE__)
-#include <sys/socket.h>
-#include <resolv.h>
-#include <unistd.h>
-#endif
-#ifdef _WIN32
-#include <http.h>
-#include <iostream>
-#include <ls_std/utils/WindowsUtils.hpp>
-#endif
-
-ls_std::Socket::Socket() : ls_std::Class("Socket")
-{}
-
-ls_std::Socket::~Socket()
-{
-  this->_close();
-}
-
-bool ls_std::Socket::close()
-{
-  bool closed;
-
-  #if defined(unix) || defined(__APPLE__)
-    int result = ::close(this->descriptor);
-    closed = result == 0;
-  #endif
-  #ifdef _WIN32
-    closed = this->_close();
-  #endif
-
-  return closed;
-}
-
-bool ls_std::Socket::create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol)
-{
-  bool created;
-
-  #if defined(unix) || defined(__APPLE__)
-    this->descriptor = ls_std::Socket::_create(_addressFamily, _socketType, _networkProtocol);
-    created = this->descriptor >= 0;
-  #endif
-  #ifdef _WIN32
-    this->descriptor = ls_std::Socket::_create(_addressFamily, _socketType, _networkProtocol);
-    created = this->descriptor >= 0;
-  #endif
-
-  return created;
-}
-
-bool ls_std::Socket::_close()
-{
-  bool closed;
-
-  #ifdef _WIN32
-    closed = this->_closeOnWindows();
-  #endif
-
-  return closed;
-}
-
-#ifdef _WIN32
-bool ls_std::Socket::_closeOnWindows() const
-{
-  int result = closesocket(this->descriptor);
-  bool closed = result == 0;
-
-  if(!closed) {
-    std::cout << ls_std::WindowsUtils::getMessageFromErrorCode(WSAGetLastError()) << std::endl; // TODO: use logger
-  }
-
-  return closed;
-}
-#endif
-
-int ls_std::Socket::_convertAddressFamily(ls_std::AddressFamily _addressFamily)
-{
-  int addressFamily;
-
-  switch(_addressFamily)
-  {
-    case ls_std::ADDRESS_FAMILY_IP_V4:
-    {
-      addressFamily = AF_INET;
-    } break;
-    case ls_std::ADDRESS_FAMILY_IP_V6:
-    {
-      addressFamily = AF_INET6;
-    } break;
-  }
-
-  return addressFamily;
-}
-
-int ls_std::Socket::_convertNetworkProtocol(ls_std::NetworkProtocol _networkProtocol)
-{
-  int networkProtocol;
-
-  switch(_networkProtocol)
-  {
-    case ls_std::NETWORK_PROTOCOL_TCP_IP:
-    {
-      networkProtocol = IPPROTO_TCP;
-    } break;
-    case ls_std::NETWORK_PROTOCOL_UDP_IP:
-    {
-      networkProtocol = IPPROTO_UDP;
-    } break;
-  }
-
-  return networkProtocol;
-}
-
-int ls_std::Socket::_convertSocketType(ls_std::SocketType _socketType)
-{
-  int socketType;
-
-  switch(_socketType)
-  {
-    case ls_std::SOCKET_TYPE_STREAM:
-    {
-      socketType = SOCK_STREAM;
-    } break;
-    case ls_std::SOCKET_TYPE_DATAGRAM:
-    {
-      socketType = SOCK_DGRAM;
-    } break;
-  }
-
-  return socketType;
-}
-
-#if defined(unix) || defined(__APPLE__)
-  int ls_std::Socket::_create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol)
-  {
-    int addressFamily = ls_std::Socket::_convertAddressFamily(_addressFamily);
-    int socketType = ls_std::Socket::_convertSocketType(_socketType);
-    int networkProtocol = ls_std::Socket::_convertNetworkProtocol(_networkProtocol);
-
-    return socket(addressFamily, socketType, networkProtocol);
-  }
-#endif
-
-#ifdef _WIN32
-  SOCKET ls_std::Socket::_create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol)
-  {
-    int addressFamily = ls_std::Socket::_convertAddressFamily(_addressFamily);
-    int socketType = ls_std::Socket::_convertSocketType(_socketType);
-    int networkProtocol = ls_std::Socket::_convertNetworkProtocol(_networkProtocol);
-
-    return socket(addressFamily, socketType, networkProtocol);
-  }
-#endif

+ 0 - 39
test/cases/network/SocketTest.cpp

@@ -1,39 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2020-12-06
- * Changed:         2020-12-06
- *
- * */
-
-#include <gtest/gtest.h>
-#include <ls_std/ls_std.hpp>
-
-namespace {
-  class SocketTest : public ::testing::Test {
-    protected:
-
-      SocketTest() = default;
-      ~SocketTest() override = default;
-
-      void SetUp() override {}
-      void TearDown() override {}
-  };
-
-  TEST_F(SocketTest, close)
-  {
-    ls_std::Socket socket {};
-    ASSERT_TRUE(socket.create(ls_std::ADDRESS_FAMILY_IP_V4, ls_std::SOCKET_TYPE_STREAM, ls_std::NETWORK_PROTOCOL_TCP_IP));
-    ASSERT_TRUE(socket.close());
-
-    ls_std::Socket anotherSocket {};
-    ASSERT_TRUE(anotherSocket.close());
-  }
-
-  TEST_F(SocketTest, create)
-  {
-    ls_std::Socket socket {};
-    ASSERT_TRUE(socket.create(ls_std::ADDRESS_FAMILY_IP_V4, ls_std::SOCKET_TYPE_STREAM, ls_std::NETWORK_PROTOCOL_TCP_IP));
-  }
-}