Bläddra i källkod

Move POSIX socket class to core API submodule

- moved POSIX socket class to core API submodule
- moved POSIX socket mock class to associated test location
- adjusted bundled header files
- adjusted Socket class dependencies
Patrick-Christopher Mattulat 1 år sedan
förälder
incheckning
13d07c3b8b

+ 1 - 1
CMakeLists.txt

@@ -150,6 +150,7 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
         ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
     set(SOURCE_FILES_CORE
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/api/io/PosixReader.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/api/socket/PosixSocket.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/Class.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/Version.cpp)
 endif()
@@ -196,7 +197,6 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
     set(SOURCE_FILES_NETWORK
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/network/core/ProtocolFamilyMapper.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/network/core/ProtocolMapper.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/network/socket/PosixSocket.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/network/socket/Socket.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/network/socket/SocketAddressMapper.cpp)
 endif()

+ 2 - 2
include/ls_std/network/socket/PosixSocket.hpp → include/ls_std/core/api/socket/PosixSocket.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-12-09
- * Changed:         2022-12-12
+ * Changed:         2022-12-16
  *
  * */
 
@@ -12,7 +12,7 @@
 
 #include <ls_std/core/interface/IPosixSocket.hpp>
 
-namespace ls::std::network
+namespace ls::std::core::api
 {
   class PosixSocket : public ls::std::core::interface_type::IPosixSocket
   {

+ 2 - 0
include/ls_std/ls_std_core.hpp

@@ -12,6 +12,7 @@
 
 #if defined(unix) || defined(__APPLE__)
 #include <ls_std/core/api/io/PosixReader.hpp>
+#include <ls_std/core/api/socket/PosixSocket.hpp>
 #endif
 
 #include <ls_std/core/exception/EventNotHandledException.hpp>
@@ -28,6 +29,7 @@
 #include <ls_std/core/interface/IEncoding.hpp>
 #include <ls_std/core/interface/IEventSubscriber.hpp>
 #include <ls_std/core/interface/IListener.hpp>
+#include <ls_std/core/interface/IPosixReader.hpp>
 #include <ls_std/core/interface/IPosixSocket.hpp>
 #include <ls_std/core/interface/IReader.hpp>
 #include <ls_std/core/interface/ISerializable.hpp>

+ 1 - 3
include/ls_std/ls_std_network.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-11-16
- * Changed:         2022-12-10
+ * Changed:         2022-12-16
  *
  * */
 
@@ -18,8 +18,6 @@
 #include <ls_std/network/core/ProtocolType.hpp>
 
 #include <ls_std/network/socket/ConvertedSocketAddress.hpp>
-#include <ls_std/network/socket/MockPosixSocket.hpp>
-#include <ls_std/network/socket/PosixSocket.hpp>
 #include <ls_std/network/socket/Socket.hpp>
 #include <ls_std/network/socket/SocketAddress.hpp>
 #include <ls_std/network/socket/SocketAddressMapper.hpp>

+ 0 - 3
include/ls_std/network/socket/Socket.hpp

@@ -12,9 +12,6 @@
 
 #include <ls_std/os/dynamic_goal.hpp>
 #include <ls_std/core/Class.hpp>
-#if defined(unix) || defined(__APPLE__)
-#include "PosixSocket.hpp"
-#endif
 #include "SocketParameter.hpp"
 #include "SocketAddressMapperParameter.hpp"
 #include <memory>

+ 42 - 0
source/ls_std/core/api/socket/PosixSocket.cpp

@@ -0,0 +1,42 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-12-09
+ * Changed:         2022-12-16
+ *
+ * */
+
+#include <ls_std/core/api/socket/PosixSocket.hpp>
+#include <sys/socket.h>
+#include <unistd.h>
+
+int ls::std::core::api::PosixSocket::accept(int _socketFileDescriptor, struct sockaddr *_address, socklen_t* _addressLength)
+{
+  return ::accept(_socketFileDescriptor, _address, _addressLength);
+}
+
+int ls::std::core::api::PosixSocket::bind(int _socketFileDescriptor, const struct sockaddr *_address, socklen_t _addressLength)
+{
+  return ::bind(_socketFileDescriptor, _address, _addressLength);
+}
+
+int ls::std::core::api::PosixSocket::close(int _socketFileDescriptor)
+{
+  return ::close(_socketFileDescriptor);
+}
+
+int ls::std::core::api::PosixSocket::connect(int _socketFileDescriptor, const struct sockaddr *_address, socklen_t _addressLength)
+{
+  return ::connect(_socketFileDescriptor, _address, _addressLength);
+}
+
+int ls::std::core::api::PosixSocket::create(int _domain, int _type, int _protocol)
+{
+  return ::socket(_domain, _type, _protocol);
+}
+
+int ls::std::core::api::PosixSocket::listen(int _socketFileDescriptor, int _backlog)
+{
+  return ::listen(_socketFileDescriptor, _backlog);
+}

+ 0 - 42
source/ls_std/network/socket/PosixSocket.cpp

@@ -1,42 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2022-12-09
- * Changed:         2022-12-12
- *
- * */
-
-#include <ls_std/network/socket/PosixSocket.hpp>
-#include <sys/socket.h>
-#include <unistd.h>
-
-int ls::std::network::PosixSocket::accept(int _socketFileDescriptor, struct sockaddr *_address, socklen_t* _addressLength)
-{
-  return ::accept(_socketFileDescriptor, _address, _addressLength);
-}
-
-int ls::std::network::PosixSocket::bind(int _socketFileDescriptor, const struct sockaddr *_address, socklen_t _addressLength)
-{
-  return ::bind(_socketFileDescriptor, _address, _addressLength);
-}
-
-int ls::std::network::PosixSocket::close(int _socketFileDescriptor)
-{
-  return ::close(_socketFileDescriptor);
-}
-
-int ls::std::network::PosixSocket::connect(int _socketFileDescriptor, const struct sockaddr *_address, socklen_t _addressLength)
-{
-  return ::connect(_socketFileDescriptor, _address, _addressLength);
-}
-
-int ls::std::network::PosixSocket::create(int _domain, int _type, int _protocol)
-{
-  return ::socket(_domain, _type, _protocol);
-}
-
-int ls::std::network::PosixSocket::listen(int _socketFileDescriptor, int _backlog)
-{
-  return ::listen(_socketFileDescriptor, _backlog);
-}

+ 4 - 3
source/ls_std/network/socket/Socket.cpp

@@ -12,10 +12,11 @@
 #include <ls_std/network/core/ProtocolMapper.hpp>
 #include <ls_std/network/socket/ConvertedSocketAddress.hpp>
 #include <ls_std/network/socket/SocketAddressMapper.hpp>
-#include <ls_std/network/socket/MockPosixSocket.hpp>
-#include <ls_std/network/socket/PosixSocket.hpp>
+#include <ls_std/core/api/socket/PosixSocket.hpp>
 #include <ls_std/core/api/io/PosixReader.hpp>
 #include <ls_std/core/exception/WrongProtocolException.hpp>
+#include <ls_std/core/exception/IllegalArgumentException.hpp>
+#include <ls_std/core/exception/FileOperationException.hpp>
 #include <memory>
 
 ls::std::network::Socket::Socket(ls::std::network::SocketParameter _parameter) : ls::std::core::Class("Socket"),
@@ -194,7 +195,7 @@ void ls::std::network::Socket::_setUnixSocketApi()
 {
   if (this->parameter.posixSocket == nullptr)
   {
-    this->parameter.posixSocket = ::std::make_shared<ls::std::network::PosixSocket>();
+    this->parameter.posixSocket = ::std::make_shared<ls::std::core::api::PosixSocket>();
   }
 }
 #endif

+ 4 - 2
test/cases/network/socket/SocketTest.cpp

@@ -3,18 +3,20 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-16
- * Changed:         2022-12-12
+ * Changed:         2022-12-16
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls_std/ls_std_network.hpp>
+#include <ls_std/ls_std_core.hpp>
+#include <ls_std_core_test.hpp>
 
 using namespace ls::std::network;
 using namespace ::testing;
-using namespace ls_std_network_test;
 using namespace ::std;
 using namespace ls::std::core;
+using namespace ls_std_core_test;
 
 namespace
 {

+ 1 - 1
include/ls_std/network/socket/MockPosixSocket.hpp → test/classes/core/api/socket/MockPosixSocket.hpp

@@ -13,7 +13,7 @@
 #include <ls_std/ls_std_core.hpp>
 #include <gmock/gmock.h>
 
-namespace ls_std_network_test // TODO: challenge location
+namespace ls_std_core_test
 {
   class MockPosixSocket : public ls::std::core::interface_type::IPosixSocket
   {

+ 1 - 0
test/ls_std_core_test.hpp

@@ -11,6 +11,7 @@
 #define LS_STD_LS_STD_CORE_TEST_HPP
 
 #include <classes/core/api/io/MockPosixReader.hpp>
+#include <classes/core/api/socket/MockPosixSocket.hpp>
 
 #include <classes/core/MockClass.hpp>