From ddcb12da07247e75cd1e23f98dd6a2553cdee99f Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 10 Oct 2018 13:09:39 +0300 Subject: [PATCH 01/39] Added net interfaces --- Net/.idea/Net.iml | 2 + Net/.idea/codeStyles/Project.xml | 29 + Net/.idea/misc.xml | 4 + Net/.idea/modules.xml | 8 + Net/.idea/vcs.xml | 6 + Net/.idea/workspace.xml | 313 +++++++++ Net/CMakeLists.txt | 6 + Net/ClientNetObject.cpp | 5 + Net/ClientNetObject.h | 23 + Net/NetObject.cpp | 5 + Net/NetObject.h | 20 + Net/ServerNetObject.cpp | 5 + Net/ServerNetObject.h | 26 + Net/cmake-build-debug/CMakeCache.txt | 358 ++++++++++ .../CMakeFiles/3.9.6/CMakeCCompiler.cmake | 71 ++ .../CMakeFiles/3.9.6/CMakeCXXCompiler.cmake | 73 ++ .../3.9.6/CMakeDetermineCompilerABI_C.bin | Bin 0 -> 8248 bytes .../3.9.6/CMakeDetermineCompilerABI_CXX.bin | Bin 0 -> 8264 bytes .../CMakeFiles/3.9.6/CMakeSystem.cmake | 15 + .../3.9.6/CompilerIdC/CMakeCCompilerId.c | 567 ++++++++++++++++ .../CompilerIdCXX/CMakeCXXCompilerId.cpp | 539 +++++++++++++++ .../CMakeDirectoryInformation.cmake | 16 + .../CMakeFiles/CMakeOutput.log | 633 ++++++++++++++++++ .../CMakeFiles/Makefile.cmake | 49 ++ Net/cmake-build-debug/CMakeFiles/Makefile2 | 108 +++ .../CMakeFiles/Net.dir/CXX.includecache | 40 ++ .../CMakeFiles/Net.dir/DependInfo.cmake | 22 + .../CMakeFiles/Net.dir/build.make | 168 +++++ .../CMakeFiles/Net.dir/cmake_clean.cmake | 12 + .../Net.dir/cmake_clean_target.cmake | 3 + .../CMakeFiles/Net.dir/depend.internal | 20 + .../CMakeFiles/Net.dir/depend.make | 20 + .../CMakeFiles/Net.dir/flags.make | 10 + .../CMakeFiles/Net.dir/link.txt | 2 + .../CMakeFiles/Net.dir/progress.make | 5 + Net/cmake-build-debug/CMakeFiles/Progress/1 | 1 + Net/cmake-build-debug/CMakeFiles/Progress/2 | 1 + .../CMakeFiles/Progress/count.txt | 1 + .../CMakeFiles/TargetDirectories.txt | 3 + .../CMakeFiles/clion-environment.txt | 3 + .../CMakeFiles/clion-log.txt | 4 + .../CMakeFiles/cmake.check_cache | 1 + .../CMakeFiles/feature_tests.bin | Bin 0 -> 12312 bytes .../CMakeFiles/feature_tests.c | 34 + .../CMakeFiles/feature_tests.cxx | 405 +++++++++++ .../CMakeFiles/progress.marks | 1 + Net/cmake-build-debug/Makefile | 238 +++++++ Net/cmake-build-debug/Net.cbp | 109 +++ Net/cmake-build-debug/cmake_install.cmake | 44 ++ 49 files changed, 4028 insertions(+) create mode 100644 Net/.idea/Net.iml create mode 100644 Net/.idea/codeStyles/Project.xml create mode 100644 Net/.idea/misc.xml create mode 100644 Net/.idea/modules.xml create mode 100644 Net/.idea/vcs.xml create mode 100644 Net/.idea/workspace.xml create mode 100644 Net/CMakeLists.txt create mode 100644 Net/ClientNetObject.cpp create mode 100644 Net/ClientNetObject.h create mode 100644 Net/NetObject.cpp create mode 100644 Net/NetObject.h create mode 100644 Net/ServerNetObject.cpp create mode 100644 Net/ServerNetObject.h create mode 100644 Net/cmake-build-debug/CMakeCache.txt create mode 100644 Net/cmake-build-debug/CMakeFiles/3.9.6/CMakeCCompiler.cmake create mode 100644 Net/cmake-build-debug/CMakeFiles/3.9.6/CMakeCXXCompiler.cmake create mode 100755 Net/cmake-build-debug/CMakeFiles/3.9.6/CMakeDetermineCompilerABI_C.bin create mode 100755 Net/cmake-build-debug/CMakeFiles/3.9.6/CMakeDetermineCompilerABI_CXX.bin create mode 100644 Net/cmake-build-debug/CMakeFiles/3.9.6/CMakeSystem.cmake create mode 100644 Net/cmake-build-debug/CMakeFiles/3.9.6/CompilerIdC/CMakeCCompilerId.c create mode 100644 Net/cmake-build-debug/CMakeFiles/3.9.6/CompilerIdCXX/CMakeCXXCompilerId.cpp create mode 100644 Net/cmake-build-debug/CMakeFiles/CMakeDirectoryInformation.cmake create mode 100644 Net/cmake-build-debug/CMakeFiles/CMakeOutput.log create mode 100644 Net/cmake-build-debug/CMakeFiles/Makefile.cmake create mode 100644 Net/cmake-build-debug/CMakeFiles/Makefile2 create mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/CXX.includecache create mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/DependInfo.cmake create mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/build.make create mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/cmake_clean.cmake create mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/cmake_clean_target.cmake create mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/depend.internal create mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/depend.make create mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/flags.make create mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/link.txt create mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/progress.make create mode 100644 Net/cmake-build-debug/CMakeFiles/Progress/1 create mode 100644 Net/cmake-build-debug/CMakeFiles/Progress/2 create mode 100644 Net/cmake-build-debug/CMakeFiles/Progress/count.txt create mode 100644 Net/cmake-build-debug/CMakeFiles/TargetDirectories.txt create mode 100644 Net/cmake-build-debug/CMakeFiles/clion-environment.txt create mode 100644 Net/cmake-build-debug/CMakeFiles/clion-log.txt create mode 100644 Net/cmake-build-debug/CMakeFiles/cmake.check_cache create mode 100755 Net/cmake-build-debug/CMakeFiles/feature_tests.bin create mode 100644 Net/cmake-build-debug/CMakeFiles/feature_tests.c create mode 100644 Net/cmake-build-debug/CMakeFiles/feature_tests.cxx create mode 100644 Net/cmake-build-debug/CMakeFiles/progress.marks create mode 100644 Net/cmake-build-debug/Makefile create mode 100644 Net/cmake-build-debug/Net.cbp create mode 100644 Net/cmake-build-debug/cmake_install.cmake diff --git a/Net/.idea/Net.iml b/Net/.idea/Net.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/Net/.idea/Net.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Net/.idea/codeStyles/Project.xml b/Net/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/Net/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Net/.idea/misc.xml b/Net/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/Net/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Net/.idea/modules.xml b/Net/.idea/modules.xml new file mode 100644 index 0000000..3127853 --- /dev/null +++ b/Net/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Net/.idea/vcs.xml b/Net/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Net/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Net/.idea/workspace.xml b/Net/.idea/workspace.xml new file mode 100644 index 0000000..d0167fc --- /dev/null +++ b/Net/.idea/workspace.xml @@ -0,0 +1,313 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -142,16 +210,20 @@ - - + + + + + - + - + + @@ -168,33 +240,34 @@ - - + - - - - + + + + - - + + - - + + @@ -204,28 +277,61 @@ + + + - + - - + + - + - - + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + @@ -233,78 +339,109 @@ - + - - + + - - - + + + + + + - + - - + + - + - - + + + + + + + + + + + + - - + + - + - - + + + + + + + + + + + + + + + + + + - + - + - - + + - - - + + + + + - + - - + + - + diff --git a/Net/CMakeLists.txt b/Net/CMakeLists.txt index 996ac97..cbcf1f7 100644 --- a/Net/CMakeLists.txt +++ b/Net/CMakeLists.txt @@ -3,4 +3,8 @@ project(Net) set(CMAKE_CXX_STANDARD 11) -add_library(Net NetObject.cpp NetObject.h ServerNetObject.cpp ServerNetObject.h ClientNetObject.cpp ClientNetObject.h) \ No newline at end of file +add_library(Net NetObject.cpp NetObject.h ServerNetObject.cpp ServerNetObject.h Packet.cpp Packet.h) + +include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) + +add_executable(tests test/gtest.cpp test/packet_tests.cpp) \ No newline at end of file diff --git a/Net/ClientNetObject.cpp b/Net/ClientNetObject.cpp deleted file mode 100644 index 40f074e..0000000 --- a/Net/ClientNetObject.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by alex on 09.10.18. -// - -#include "ClientNetObject.h" diff --git a/Net/ClientNetObject.h b/Net/ClientNetObject.h deleted file mode 100644 index 8eb0b53..0000000 --- a/Net/ClientNetObject.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Created by alex on 09.10.18. -// - -#ifndef NET_CLIENTNETOBJECT_H -#define NET_CLIENTNETOBJECT_H - - -#include -#include "NetObject.h" - -class ClientNetObject: public NetObject -{ -public: - void send(std::queue commands); - Update receive(); -private: - void* command_queue_to_data(std::queue); - Update data_to_update(); -}; - - -#endif //NET_CLIENTNETOBJECT_H diff --git a/Net/NetObject.cpp b/Net/NetObject.cpp index 7b3d524..29cdd55 100644 --- a/Net/NetObject.cpp +++ b/Net/NetObject.cpp @@ -3,3 +3,48 @@ // #include "NetObject.h" + +NetObject::NetObject() +{ + thread=new std::thread(read_sock); +} + +NetObject::~NetObject() +{ + //need to set global variable to let thread know when to finish + thread->join(); + delete thread; +} + +void NetObject::read_sock() +{ + //read from the connection and write to recv_buf +} + +Packet *NetObject::receive() +{ + return nullptr; +} + +void NetObject::send(Packet packet) +{ + +} + +NetObject::NetObject(int port,std::string& ip) + : + port(port), + ip(ip) +{ + thread=new std::thread(read_sock); +} + +void NetObject::set_port(int n_port) +{ + port=n_port; +} + +void NetObject::connect() +{ + +} diff --git a/Net/NetObject.h b/Net/NetObject.h index 56f3001..8bbcb1b 100644 --- a/Net/NetObject.h +++ b/Net/NetObject.h @@ -5,15 +5,32 @@ #ifndef NET_NETOBJECT_H #define NET_NETOBJECT_H +#include +#include "Packet.h" - -virtual class NetObject +class NetObject { public: - virtual void connect() = 0; + NetObject(); + NetObject(int port, std::string& ip); + NetObject(NetObject&)=delete; + NetObject(NetObject&&)=delete; + NetObject& operator=(NetObject&)=delete; + NetObject& operator=(NetObject&&)=delete; + ~NetObject(); + + void set_port(int port); + void send(Packet packet); + Packet* receive(); + void connect(); protected: - void send(void* data); - void* receive(); + static short const BUF_SIZE=1024; + static void read_sock(); + Packet recv_buf[BUF_SIZE]; +private: + int port; + std::string ip; + std::thread* thread; }; diff --git a/Net/Packet.cpp b/Net/Packet.cpp new file mode 100644 index 0000000..0697e6e --- /dev/null +++ b/Net/Packet.cpp @@ -0,0 +1,17 @@ +// +// Created by alex on 29.10.18. +// + +#include "Packet.h" + +template +void Packet::convert(T to_convert) +{ + +} + +template +T Packet::extract() +{ + +} diff --git a/Net/Packet.h b/Net/Packet.h new file mode 100644 index 0000000..7f9ce19 --- /dev/null +++ b/Net/Packet.h @@ -0,0 +1,28 @@ +// +// Created by alex on 29.10.18. +// + +#ifndef NET_PACKET_H +#define NET_PACKET_H + + +class Packet +{ +public: + enum + { + Update, + Command + } data_type; + template + void convert(T to_convert); + + template + T extract(); +private: + int* data; +}; + + + +#endif //NET_PACKET_H diff --git a/Net/ServerNetObject.cpp b/Net/ServerNetObject.cpp index 7a0e9cf..e5a8e8f 100644 --- a/Net/ServerNetObject.cpp +++ b/Net/ServerNetObject.cpp @@ -3,3 +3,43 @@ // #include "ServerNetObject.h" + +void ServerNetObject::set_player_number(short player_number) +{ + ServerNetObject::player_number = player_number; +} + +void ServerNetObject::connect() +{ + +} + +ServerNetObject::ServerNetObject(short player_number) + : player_number(player_number) +{ + +} + +void ServerNetObject::set_player(int port,std::string& ip) +{ + players.push_back(new NetObject(port,ip)); +} + +ServerNetObject::~ServerNetObject() +{ + while(!players.empty()) + { + delete players[players.size()-1]; + players.pop_back(); + } +} + +void ServerNetObject::send(Packet packet) +{ + +} + +std::vector ServerNetObject::recieve() +{ + return std::vector(); +} diff --git a/Net/ServerNetObject.h b/Net/ServerNetObject.h index 571af11..df2d0fd 100644 --- a/Net/ServerNetObject.h +++ b/Net/ServerNetObject.h @@ -6,19 +6,21 @@ #define NET_SERVERNETOBJECT_H -#include +#include #include "NetObject.h" -class ServerNetObject: public NetObject +class ServerNetObject { public: - void set_player_num(); - void send(Update update); - std::vector> receive_all(); + explicit ServerNetObject(short player_number); + void set_player_number(short player_number); + void set_player(int port,std::string& ip); + void connect(); + std::vector recieve(); + void send(Packet packet); + ~ServerNetObject(); private: - std::queue receive(); - void* update_to_data(Update); - std::queue data_to_command_queue(); + std::vector players; short player_number; }; diff --git a/Net/cmake-build-debug/CMakeFiles/Makefile.cmake b/Net/cmake-build-debug/CMakeFiles/Makefile.cmake index c951317..adebcd1 100644 --- a/Net/cmake-build-debug/CMakeFiles/Makefile.cmake +++ b/Net/cmake-build-debug/CMakeFiles/Makefile.cmake @@ -45,5 +45,6 @@ set(CMAKE_MAKEFILE_PRODUCTS # Dependency information for all targets: set(CMAKE_DEPEND_INFO_FILES + "CMakeFiles/tests.dir/DependInfo.cmake" "CMakeFiles/Net.dir/DependInfo.cmake" ) diff --git a/Net/cmake-build-debug/CMakeFiles/Makefile2 b/Net/cmake-build-debug/CMakeFiles/Makefile2 index cf9c277..ff1e2b9 100644 --- a/Net/cmake-build-debug/CMakeFiles/Makefile2 +++ b/Net/cmake-build-debug/CMakeFiles/Makefile2 @@ -59,6 +59,43 @@ CMAKE_SOURCE_DIR = /home/alex/TP-MAIL/CPP1/PROJ/Net # The top-level build directory on which CMake was run. CMAKE_BINARY_DIR = /home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug +#============================================================================= +# Target rules for target CMakeFiles/tests.dir + +# All Build rule for target. +CMakeFiles/tests.dir/all: + $(MAKE) -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/depend + $(MAKE) -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/build + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles --progress-num=5,6,7 "Built target tests" +.PHONY : CMakeFiles/tests.dir/all + +# Include target in all. +all: CMakeFiles/tests.dir/all + +.PHONY : all + +# Build rule for subdir invocation for target. +CMakeFiles/tests.dir/rule: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles 3 + $(MAKE) -f CMakeFiles/Makefile2 CMakeFiles/tests.dir/all + $(CMAKE_COMMAND) -E cmake_progress_start /home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles 0 +.PHONY : CMakeFiles/tests.dir/rule + +# Convenience name for target. +tests: CMakeFiles/tests.dir/rule + +.PHONY : tests + +# clean rule for target. +CMakeFiles/tests.dir/clean: + $(MAKE) -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/clean +.PHONY : CMakeFiles/tests.dir/clean + +# clean rule for target. +clean: CMakeFiles/tests.dir/clean + +.PHONY : clean + #============================================================================= # Target rules for target CMakeFiles/Net.dir diff --git a/Net/cmake-build-debug/CMakeFiles/Net.dir/CXX.includecache b/Net/cmake-build-debug/CMakeFiles/Net.dir/CXX.includecache index 181fdff..30cf593 100644 --- a/Net/cmake-build-debug/CMakeFiles/Net.dir/CXX.includecache +++ b/Net/cmake-build-debug/CMakeFiles/Net.dir/CXX.includecache @@ -6,19 +6,13 @@ #IncludeRegexTransform: -/home/alex/TP-MAIL/CPP1/PROJ/Net/ClientNetObject.cpp -ClientNetObject.h -/home/alex/TP-MAIL/CPP1/PROJ/Net/ClientNetObject.h - -/home/alex/TP-MAIL/CPP1/PROJ/Net/ClientNetObject.h -NetObject.h -/home/alex/TP-MAIL/CPP1/PROJ/Net/NetObject.h - /home/alex/TP-MAIL/CPP1/PROJ/Net/NetObject.cpp NetObject.h /home/alex/TP-MAIL/CPP1/PROJ/Net/NetObject.h /home/alex/TP-MAIL/CPP1/PROJ/Net/NetObject.h +thread +- Packet.h /home/alex/TP-MAIL/CPP1/PROJ/Net/Packet.h @@ -27,14 +21,14 @@ Packet.h /home/alex/TP-MAIL/CPP1/PROJ/Net/Packet.h /home/alex/TP-MAIL/CPP1/PROJ/Net/Packet.h -queue -- /home/alex/TP-MAIL/CPP1/PROJ/Net/ServerNetObject.cpp ServerNetObject.h /home/alex/TP-MAIL/CPP1/PROJ/Net/ServerNetObject.h /home/alex/TP-MAIL/CPP1/PROJ/Net/ServerNetObject.h +vector +- NetObject.h /home/alex/TP-MAIL/CPP1/PROJ/Net/NetObject.h diff --git a/Net/cmake-build-debug/CMakeFiles/Net.dir/DependInfo.cmake b/Net/cmake-build-debug/CMakeFiles/Net.dir/DependInfo.cmake index 0e4502b..35a7862 100644 --- a/Net/cmake-build-debug/CMakeFiles/Net.dir/DependInfo.cmake +++ b/Net/cmake-build-debug/CMakeFiles/Net.dir/DependInfo.cmake @@ -4,14 +4,15 @@ set(CMAKE_DEPENDS_LANGUAGES ) # The set of files for implicit dependencies of each language: set(CMAKE_DEPENDS_CHECK_CXX - "/home/alex/TP-MAIL/CPP1/PROJ/Net/ClientNetObject.cpp" "/home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles/Net.dir/ClientNetObject.cpp.o" "/home/alex/TP-MAIL/CPP1/PROJ/Net/NetObject.cpp" "/home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles/Net.dir/NetObject.cpp.o" + "/home/alex/TP-MAIL/CPP1/PROJ/Net/Packet.cpp" "/home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles/Net.dir/Packet.cpp.o" "/home/alex/TP-MAIL/CPP1/PROJ/Net/ServerNetObject.cpp" "/home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles/Net.dir/ServerNetObject.cpp.o" ) set(CMAKE_CXX_COMPILER_ID "GNU") # The include file search paths: set(CMAKE_CXX_TARGET_INCLUDE_PATH + "/include" ) # Targets to which this target links. diff --git a/Net/cmake-build-debug/CMakeFiles/Net.dir/build.make b/Net/cmake-build-debug/CMakeFiles/Net.dir/build.make index 6b3f68a..7c00fcb 100644 --- a/Net/cmake-build-debug/CMakeFiles/Net.dir/build.make +++ b/Net/cmake-build-debug/CMakeFiles/Net.dir/build.make @@ -105,42 +105,42 @@ CMakeFiles/Net.dir/ServerNetObject.cpp.o.provides: CMakeFiles/Net.dir/ServerNetO CMakeFiles/Net.dir/ServerNetObject.cpp.o.provides.build: CMakeFiles/Net.dir/ServerNetObject.cpp.o -CMakeFiles/Net.dir/ClientNetObject.cpp.o: CMakeFiles/Net.dir/flags.make -CMakeFiles/Net.dir/ClientNetObject.cpp.o: ../ClientNetObject.cpp - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles --progress-num=$(CMAKE_PROGRESS_3) "Building CXX object CMakeFiles/Net.dir/ClientNetObject.cpp.o" - /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/Net.dir/ClientNetObject.cpp.o -c /home/alex/TP-MAIL/CPP1/PROJ/Net/ClientNetObject.cpp +CMakeFiles/Net.dir/Packet.cpp.o: CMakeFiles/Net.dir/flags.make +CMakeFiles/Net.dir/Packet.cpp.o: ../Packet.cpp + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles --progress-num=$(CMAKE_PROGRESS_3) "Building CXX object CMakeFiles/Net.dir/Packet.cpp.o" + /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/Net.dir/Packet.cpp.o -c /home/alex/TP-MAIL/CPP1/PROJ/Net/Packet.cpp -CMakeFiles/Net.dir/ClientNetObject.cpp.i: cmake_force - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/Net.dir/ClientNetObject.cpp.i" - /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/alex/TP-MAIL/CPP1/PROJ/Net/ClientNetObject.cpp > CMakeFiles/Net.dir/ClientNetObject.cpp.i +CMakeFiles/Net.dir/Packet.cpp.i: cmake_force + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/Net.dir/Packet.cpp.i" + /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/alex/TP-MAIL/CPP1/PROJ/Net/Packet.cpp > CMakeFiles/Net.dir/Packet.cpp.i -CMakeFiles/Net.dir/ClientNetObject.cpp.s: cmake_force - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/Net.dir/ClientNetObject.cpp.s" - /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/alex/TP-MAIL/CPP1/PROJ/Net/ClientNetObject.cpp -o CMakeFiles/Net.dir/ClientNetObject.cpp.s +CMakeFiles/Net.dir/Packet.cpp.s: cmake_force + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/Net.dir/Packet.cpp.s" + /usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/alex/TP-MAIL/CPP1/PROJ/Net/Packet.cpp -o CMakeFiles/Net.dir/Packet.cpp.s -CMakeFiles/Net.dir/ClientNetObject.cpp.o.requires: +CMakeFiles/Net.dir/Packet.cpp.o.requires: -.PHONY : CMakeFiles/Net.dir/ClientNetObject.cpp.o.requires +.PHONY : CMakeFiles/Net.dir/Packet.cpp.o.requires -CMakeFiles/Net.dir/ClientNetObject.cpp.o.provides: CMakeFiles/Net.dir/ClientNetObject.cpp.o.requires - $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/ClientNetObject.cpp.o.provides.build -.PHONY : CMakeFiles/Net.dir/ClientNetObject.cpp.o.provides +CMakeFiles/Net.dir/Packet.cpp.o.provides: CMakeFiles/Net.dir/Packet.cpp.o.requires + $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/Packet.cpp.o.provides.build +.PHONY : CMakeFiles/Net.dir/Packet.cpp.o.provides -CMakeFiles/Net.dir/ClientNetObject.cpp.o.provides.build: CMakeFiles/Net.dir/ClientNetObject.cpp.o +CMakeFiles/Net.dir/Packet.cpp.o.provides.build: CMakeFiles/Net.dir/Packet.cpp.o # Object files for target Net Net_OBJECTS = \ "CMakeFiles/Net.dir/NetObject.cpp.o" \ "CMakeFiles/Net.dir/ServerNetObject.cpp.o" \ -"CMakeFiles/Net.dir/ClientNetObject.cpp.o" +"CMakeFiles/Net.dir/Packet.cpp.o" # External object files for target Net Net_EXTERNAL_OBJECTS = libNet.a: CMakeFiles/Net.dir/NetObject.cpp.o libNet.a: CMakeFiles/Net.dir/ServerNetObject.cpp.o -libNet.a: CMakeFiles/Net.dir/ClientNetObject.cpp.o +libNet.a: CMakeFiles/Net.dir/Packet.cpp.o libNet.a: CMakeFiles/Net.dir/build.make libNet.a: CMakeFiles/Net.dir/link.txt @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles --progress-num=$(CMAKE_PROGRESS_4) "Linking CXX static library libNet.a" @@ -154,7 +154,7 @@ CMakeFiles/Net.dir/build: libNet.a CMakeFiles/Net.dir/requires: CMakeFiles/Net.dir/NetObject.cpp.o.requires CMakeFiles/Net.dir/requires: CMakeFiles/Net.dir/ServerNetObject.cpp.o.requires -CMakeFiles/Net.dir/requires: CMakeFiles/Net.dir/ClientNetObject.cpp.o.requires +CMakeFiles/Net.dir/requires: CMakeFiles/Net.dir/Packet.cpp.o.requires .PHONY : CMakeFiles/Net.dir/requires diff --git a/Net/cmake-build-debug/CMakeFiles/Net.dir/cmake_clean.cmake b/Net/cmake-build-debug/CMakeFiles/Net.dir/cmake_clean.cmake index 7412a98..7756c2d 100644 --- a/Net/cmake-build-debug/CMakeFiles/Net.dir/cmake_clean.cmake +++ b/Net/cmake-build-debug/CMakeFiles/Net.dir/cmake_clean.cmake @@ -1,7 +1,7 @@ file(REMOVE_RECURSE "CMakeFiles/Net.dir/NetObject.cpp.o" "CMakeFiles/Net.dir/ServerNetObject.cpp.o" - "CMakeFiles/Net.dir/ClientNetObject.cpp.o" + "CMakeFiles/Net.dir/Packet.cpp.o" "libNet.pdb" "libNet.a" ) diff --git a/Net/cmake-build-debug/CMakeFiles/Net.dir/depend.internal b/Net/cmake-build-debug/CMakeFiles/Net.dir/depend.internal index f52ba9e..e96780c 100644 --- a/Net/cmake-build-debug/CMakeFiles/Net.dir/depend.internal +++ b/Net/cmake-build-debug/CMakeFiles/Net.dir/depend.internal @@ -1,11 +1,6 @@ # CMAKE generated file: DO NOT EDIT! # Generated by "Unix Makefiles" Generator, CMake Version 3.9 -CMakeFiles/Net.dir/ClientNetObject.cpp.o - /home/alex/TP-MAIL/CPP1/PROJ/Net/ClientNetObject.cpp - /home/alex/TP-MAIL/CPP1/PROJ/Net/ClientNetObject.h - /home/alex/TP-MAIL/CPP1/PROJ/Net/NetObject.h - /home/alex/TP-MAIL/CPP1/PROJ/Net/Packet.h CMakeFiles/Net.dir/NetObject.cpp.o /home/alex/TP-MAIL/CPP1/PROJ/Net/NetObject.cpp /home/alex/TP-MAIL/CPP1/PROJ/Net/NetObject.h diff --git a/Net/cmake-build-debug/CMakeFiles/Net.dir/depend.make b/Net/cmake-build-debug/CMakeFiles/Net.dir/depend.make index 53ac9cc..fd7869e 100644 --- a/Net/cmake-build-debug/CMakeFiles/Net.dir/depend.make +++ b/Net/cmake-build-debug/CMakeFiles/Net.dir/depend.make @@ -1,11 +1,6 @@ # CMAKE generated file: DO NOT EDIT! # Generated by "Unix Makefiles" Generator, CMake Version 3.9 -CMakeFiles/Net.dir/ClientNetObject.cpp.o: ../ClientNetObject.cpp -CMakeFiles/Net.dir/ClientNetObject.cpp.o: ../ClientNetObject.h -CMakeFiles/Net.dir/ClientNetObject.cpp.o: ../NetObject.h -CMakeFiles/Net.dir/ClientNetObject.cpp.o: ../Packet.h - CMakeFiles/Net.dir/NetObject.cpp.o: ../NetObject.cpp CMakeFiles/Net.dir/NetObject.cpp.o: ../NetObject.h CMakeFiles/Net.dir/NetObject.cpp.o: ../Packet.h diff --git a/Net/cmake-build-debug/CMakeFiles/Net.dir/flags.make b/Net/cmake-build-debug/CMakeFiles/Net.dir/flags.make index 54ad5d3..c7959c7 100644 --- a/Net/cmake-build-debug/CMakeFiles/Net.dir/flags.make +++ b/Net/cmake-build-debug/CMakeFiles/Net.dir/flags.make @@ -6,5 +6,5 @@ CXX_FLAGS = -g -std=gnu++11 CXX_DEFINES = -CXX_INCLUDES = +CXX_INCLUDES = -I/include diff --git a/Net/cmake-build-debug/CMakeFiles/Net.dir/link.txt b/Net/cmake-build-debug/CMakeFiles/Net.dir/link.txt index b90419e..b3f08bf 100644 --- a/Net/cmake-build-debug/CMakeFiles/Net.dir/link.txt +++ b/Net/cmake-build-debug/CMakeFiles/Net.dir/link.txt @@ -1,2 +1,2 @@ -/usr/bin/ar qc libNet.a CMakeFiles/Net.dir/NetObject.cpp.o CMakeFiles/Net.dir/ServerNetObject.cpp.o CMakeFiles/Net.dir/ClientNetObject.cpp.o +/usr/bin/ar qc libNet.a CMakeFiles/Net.dir/NetObject.cpp.o CMakeFiles/Net.dir/ServerNetObject.cpp.o CMakeFiles/Net.dir/Packet.cpp.o /usr/bin/ranlib libNet.a diff --git a/Net/cmake-build-debug/CMakeFiles/Progress/1 b/Net/cmake-build-debug/CMakeFiles/Progress/1 deleted file mode 100644 index 7b4d68d..0000000 --- a/Net/cmake-build-debug/CMakeFiles/Progress/1 +++ /dev/null @@ -1 +0,0 @@ -empty \ No newline at end of file diff --git a/Net/cmake-build-debug/CMakeFiles/Progress/2 b/Net/cmake-build-debug/CMakeFiles/Progress/2 deleted file mode 100644 index 7b4d68d..0000000 --- a/Net/cmake-build-debug/CMakeFiles/Progress/2 +++ /dev/null @@ -1 +0,0 @@ -empty \ No newline at end of file diff --git a/Net/cmake-build-debug/CMakeFiles/Progress/count.txt b/Net/cmake-build-debug/CMakeFiles/Progress/count.txt index 7ed6ff8..0cfbf08 100644 --- a/Net/cmake-build-debug/CMakeFiles/Progress/count.txt +++ b/Net/cmake-build-debug/CMakeFiles/Progress/count.txt @@ -1 +1 @@ -5 +2 diff --git a/Net/cmake-build-debug/CMakeFiles/TargetDirectories.txt b/Net/cmake-build-debug/CMakeFiles/TargetDirectories.txt index c743079..271ac52 100644 --- a/Net/cmake-build-debug/CMakeFiles/TargetDirectories.txt +++ b/Net/cmake-build-debug/CMakeFiles/TargetDirectories.txt @@ -1,3 +1,4 @@ /home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles/edit_cache.dir +/home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles/tests.dir /home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles/rebuild_cache.dir /home/alex/TP-MAIL/CPP1/PROJ/Net/cmake-build-debug/CMakeFiles/Net.dir diff --git a/Net/cmake-build-debug/CMakeFiles/progress.marks b/Net/cmake-build-debug/CMakeFiles/progress.marks index b8626c4..7f8f011 100644 --- a/Net/cmake-build-debug/CMakeFiles/progress.marks +++ b/Net/cmake-build-debug/CMakeFiles/progress.marks @@ -1 +1 @@ -4 +7 diff --git a/Net/cmake-build-debug/Makefile b/Net/cmake-build-debug/Makefile index 6cbae0b..a507361 100644 --- a/Net/cmake-build-debug/Makefile +++ b/Net/cmake-build-debug/Makefile @@ -110,6 +110,19 @@ depend: $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 .PHONY : depend +#============================================================================= +# Target rules for targets named tests + +# Build rule for target. +tests: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 tests +.PHONY : tests + +# fast build rule for target. +tests/fast: + $(MAKE) -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/build +.PHONY : tests/fast + #============================================================================= # Target rules for targets named Net @@ -123,33 +136,6 @@ Net/fast: $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/build .PHONY : Net/fast -ClientNetObject.o: ClientNetObject.cpp.o - -.PHONY : ClientNetObject.o - -# target to build an object file -ClientNetObject.cpp.o: - $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/ClientNetObject.cpp.o -.PHONY : ClientNetObject.cpp.o - -ClientNetObject.i: ClientNetObject.cpp.i - -.PHONY : ClientNetObject.i - -# target to preprocess a source file -ClientNetObject.cpp.i: - $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/ClientNetObject.cpp.i -.PHONY : ClientNetObject.cpp.i - -ClientNetObject.s: ClientNetObject.cpp.s - -.PHONY : ClientNetObject.s - -# target to generate assembly for a file -ClientNetObject.cpp.s: - $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/ClientNetObject.cpp.s -.PHONY : ClientNetObject.cpp.s - NetObject.o: NetObject.cpp.o .PHONY : NetObject.o @@ -177,6 +163,33 @@ NetObject.cpp.s: $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/NetObject.cpp.s .PHONY : NetObject.cpp.s +Packet.o: Packet.cpp.o + +.PHONY : Packet.o + +# target to build an object file +Packet.cpp.o: + $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/Packet.cpp.o +.PHONY : Packet.cpp.o + +Packet.i: Packet.cpp.i + +.PHONY : Packet.i + +# target to preprocess a source file +Packet.cpp.i: + $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/Packet.cpp.i +.PHONY : Packet.cpp.i + +Packet.s: Packet.cpp.s + +.PHONY : Packet.s + +# target to generate assembly for a file +Packet.cpp.s: + $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/Packet.cpp.s +.PHONY : Packet.cpp.s + ServerNetObject.o: ServerNetObject.cpp.o .PHONY : ServerNetObject.o @@ -204,6 +217,60 @@ ServerNetObject.cpp.s: $(MAKE) -f CMakeFiles/Net.dir/build.make CMakeFiles/Net.dir/ServerNetObject.cpp.s .PHONY : ServerNetObject.cpp.s +test/gtest.o: test/gtest.cpp.o + +.PHONY : test/gtest.o + +# target to build an object file +test/gtest.cpp.o: + $(MAKE) -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/test/gtest.cpp.o +.PHONY : test/gtest.cpp.o + +test/gtest.i: test/gtest.cpp.i + +.PHONY : test/gtest.i + +# target to preprocess a source file +test/gtest.cpp.i: + $(MAKE) -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/test/gtest.cpp.i +.PHONY : test/gtest.cpp.i + +test/gtest.s: test/gtest.cpp.s + +.PHONY : test/gtest.s + +# target to generate assembly for a file +test/gtest.cpp.s: + $(MAKE) -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/test/gtest.cpp.s +.PHONY : test/gtest.cpp.s + +test/packet_tests.o: test/packet_tests.cpp.o + +.PHONY : test/packet_tests.o + +# target to build an object file +test/packet_tests.cpp.o: + $(MAKE) -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/test/packet_tests.cpp.o +.PHONY : test/packet_tests.cpp.o + +test/packet_tests.i: test/packet_tests.cpp.i + +.PHONY : test/packet_tests.i + +# target to preprocess a source file +test/packet_tests.cpp.i: + $(MAKE) -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/test/packet_tests.cpp.i +.PHONY : test/packet_tests.cpp.i + +test/packet_tests.s: test/packet_tests.cpp.s + +.PHONY : test/packet_tests.s + +# target to generate assembly for a file +test/packet_tests.cpp.s: + $(MAKE) -f CMakeFiles/tests.dir/build.make CMakeFiles/tests.dir/test/packet_tests.cpp.s +.PHONY : test/packet_tests.cpp.s + # Help Target help: @echo "The following are some of the valid targets for this Makefile:" @@ -211,17 +278,24 @@ help: @echo "... clean" @echo "... depend" @echo "... edit_cache" + @echo "... tests" @echo "... rebuild_cache" @echo "... Net" - @echo "... ClientNetObject.o" - @echo "... ClientNetObject.i" - @echo "... ClientNetObject.s" @echo "... NetObject.o" @echo "... NetObject.i" @echo "... NetObject.s" + @echo "... Packet.o" + @echo "... Packet.i" + @echo "... Packet.s" @echo "... ServerNetObject.o" @echo "... ServerNetObject.i" @echo "... ServerNetObject.s" + @echo "... test/gtest.o" + @echo "... test/gtest.i" + @echo "... test/gtest.s" + @echo "... test/packet_tests.o" + @echo "... test/packet_tests.i" + @echo "... test/packet_tests.s" .PHONY : help diff --git a/Net/cmake-build-debug/Net.cbp b/Net/cmake-build-debug/Net.cbp index d4b891d..73bcf4a 100644 --- a/Net/cmake-build-debug/Net.cbp +++ b/Net/cmake-build-debug/Net.cbp @@ -27,6 +27,54 @@ + + + + - + - + - + - + @@ -102,6 +152,12 @@ + + + + diff --git a/Net/test/gtest.cpp b/Net/test/gtest.cpp new file mode 100644 index 0000000..6d528bd --- /dev/null +++ b/Net/test/gtest.cpp @@ -0,0 +1,12 @@ +// +// Created by alex on 29.10.18. +// + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/Net/test/packet_tests.cpp b/Net/test/packet_tests.cpp new file mode 100644 index 0000000..edc11c4 --- /dev/null +++ b/Net/test/packet_tests.cpp @@ -0,0 +1,25 @@ +// +// Created by alex on 29.10.18. +// + +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../Packet.h" + +TEST(packet_update_test, convert_extract) +{ + Packet packet; + Update before(); + packet.convert(before); + Update after=packet.extract(); + EXPECT_EQ(before, after); +} + +TEST(packet_command_test, convert_extract) +{ + Packet packet; + Command before(); + packet.convert(before); + Command after=packet.extract(); + EXPECT_EQ(before, after); +} \ No newline at end of file From 22174fa97dd822cdbc98b4efddc89ef300189f1e Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 29 Oct 2018 18:36:56 +0300 Subject: [PATCH 04/39] packet tests repaired --- Net/.idea/workspace.xml | 52 +++++++++++++-------------------------- Net/test/packet_tests.cpp | 14 +++++++++-- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/Net/.idea/workspace.xml b/Net/.idea/workspace.xml index 8928b28..755631a 100644 --- a/Net/.idea/workspace.xml +++ b/Net/.idea/workspace.xml @@ -12,36 +12,9 @@ - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - + - @@ -328,6 +309,7 @@ + @@ -438,8 +420,8 @@ - - + + diff --git a/Net/test/packet_tests.cpp b/Net/test/packet_tests.cpp index edc11c4..a3fa50c 100644 --- a/Net/test/packet_tests.cpp +++ b/Net/test/packet_tests.cpp @@ -6,10 +6,20 @@ #include "gmock/gmock.h" #include "../Packet.h" +//to delete after taking real commands and updates! +struct Update { + +}; + +struct Command { + +}; +// + TEST(packet_update_test, convert_extract) { Packet packet; - Update before(); + Update before; packet.convert(before); Update after=packet.extract(); EXPECT_EQ(before, after); @@ -18,7 +28,7 @@ TEST(packet_update_test, convert_extract) TEST(packet_command_test, convert_extract) { Packet packet; - Command before(); + Command before; packet.convert(before); Command after=packet.extract(); EXPECT_EQ(before, after); From b9b8902a71abc20d9a0955f2b22244cdd24d3de5 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 19 Nov 2018 11:08:08 +0300 Subject: [PATCH 05/39] modified architecture --- Net/AbstractClientNetObject.cpp | 5 ++++ Net/AbstractClientNetObject.h | 17 ++++++++++++ Net/AbstractServerNetObject.cpp | 5 ++++ Net/AbstractServerNetObject.h | 17 ++++++++++++ Net/CMakeLists.txt | 4 +-- Net/ClientNetObject.cpp | 44 ++++++++++++++++++++++++++++++ Net/ClientNetObject.h | 29 ++++++++++++++++++++ Net/NetObject.cpp | 47 +-------------------------------- Net/NetObject.h | 30 ++++++--------------- Net/Packet.cpp | 17 ------------ Net/Packet.h | 28 -------------------- Net/Serializable.cpp | 5 ++++ Net/Serializable.h | 18 +++++++++++++ Net/ServerNetObject.cpp | 37 +++++++++++++------------- Net/ServerNetObject.h | 29 +++++++++++--------- Net/test/packet_tests.cpp | 35 ------------------------ 16 files changed, 185 insertions(+), 182 deletions(-) create mode 100644 Net/AbstractClientNetObject.cpp create mode 100644 Net/AbstractClientNetObject.h create mode 100644 Net/AbstractServerNetObject.cpp create mode 100644 Net/AbstractServerNetObject.h create mode 100644 Net/ClientNetObject.cpp create mode 100644 Net/ClientNetObject.h delete mode 100644 Net/Packet.cpp delete mode 100644 Net/Packet.h create mode 100644 Net/Serializable.cpp create mode 100644 Net/Serializable.h delete mode 100644 Net/test/packet_tests.cpp diff --git a/Net/AbstractClientNetObject.cpp b/Net/AbstractClientNetObject.cpp new file mode 100644 index 0000000..a15a1be --- /dev/null +++ b/Net/AbstractClientNetObject.cpp @@ -0,0 +1,5 @@ +// +// Created by alex on 12.11.18. +// + +#include "AbstractClientNetObject.h" diff --git a/Net/AbstractClientNetObject.h b/Net/AbstractClientNetObject.h new file mode 100644 index 0000000..e89bced --- /dev/null +++ b/Net/AbstractClientNetObject.h @@ -0,0 +1,17 @@ +// +// Created by alex on 12.11.18. +// + +#ifndef NET_ABSTRACTCLIENTNETOBJECT_H +#define NET_ABSTRACTCLIENTNETOBJECT_H + + +#include "NetObject.h" + +class AbstractClientNetObject:public NetObject +{ + +}; + + +#endif //NET_ABSTRACTCLIENTNETOBJECT_H diff --git a/Net/AbstractServerNetObject.cpp b/Net/AbstractServerNetObject.cpp new file mode 100644 index 0000000..a9660fa --- /dev/null +++ b/Net/AbstractServerNetObject.cpp @@ -0,0 +1,5 @@ +// +// Created by alex on 12.11.18. +// + +#include "AbstractServerNetObject.h" diff --git a/Net/AbstractServerNetObject.h b/Net/AbstractServerNetObject.h new file mode 100644 index 0000000..25f31fa --- /dev/null +++ b/Net/AbstractServerNetObject.h @@ -0,0 +1,17 @@ +// +// Created by alex on 12.11.18. +// + +#ifndef NET_ABSTRACTSERVERNETOBJECT_H +#define NET_ABSTRACTSERVERNETOBJECT_H + + +#include "NetObject.h" + +class AbstractServerNetObject:public NetObject +{ + +}; + + +#endif //NET_ABSTRACTSERVERNETOBJECT_H diff --git a/Net/CMakeLists.txt b/Net/CMakeLists.txt index cbcf1f7..3482c52 100644 --- a/Net/CMakeLists.txt +++ b/Net/CMakeLists.txt @@ -3,8 +3,8 @@ project(Net) set(CMAKE_CXX_STANDARD 11) -add_library(Net NetObject.cpp NetObject.h ServerNetObject.cpp ServerNetObject.h Packet.cpp Packet.h) +add_library(Net NetObject.cpp NetObject.h Serializable.cpp Serializable.h AbstractClientNetObject.cpp AbstractClientNetObject.h AbstractServerNetObject.cpp AbstractServerNetObject.h ServerNetObject.cpp ServerNetObject.h ClientNetObject.cpp ClientNetObject.h) include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) -add_executable(tests test/gtest.cpp test/packet_tests.cpp) \ No newline at end of file +add_executable(tests test/gtest.cpp) \ No newline at end of file diff --git a/Net/ClientNetObject.cpp b/Net/ClientNetObject.cpp new file mode 100644 index 0000000..5c8fbe7 --- /dev/null +++ b/Net/ClientNetObject.cpp @@ -0,0 +1,44 @@ +// +// Created by alex on 12.11.18. +// + +#include "ClientNetObject.h" + +void ClientNetObject::connect() +{ + +} + +void ClientNetObject::send(Serializable *serializable) +{ + +} + +std::vector ClientNetObject::receive() +{ + return nullptr; +} + +ClientNetObject::ClientNetObject(uint _port, std::string& _ip) + : + port(_port), + ip(_ip) +{ + thread=nullptr; +} + +void ClientNetObject::work() +{ + connect(); + thread=new std::thread(read_sock); +} + +ClientNetObject::~ClientNetObject() +{ + delete thread; +} + +void ClientNetObject::read_sock() +{ + +} diff --git a/Net/ClientNetObject.h b/Net/ClientNetObject.h new file mode 100644 index 0000000..f379433 --- /dev/null +++ b/Net/ClientNetObject.h @@ -0,0 +1,29 @@ +// +// Created by alex on 12.11.18. +// + +#ifndef NET_CLIENTNETOBJECT_H +#define NET_CLIENTNETOBJECT_H + + +#include +#include "AbstractClientNetObject.h" + +class ClientNetObject:public AbstractClientNetObject +{ +public: + ClientNetObject(uint _port, std::string& _ip); + void send(Serializable *serializable) override; + std::vector receive() override; + void work(); + ~ClientNetObject(); +private: + void connect() override; + static void read_sock(); + uint port; + std::string ip; + std::thread* thread; +}; + + +#endif //NET_CLIENTNETOBJECT_H diff --git a/Net/NetObject.cpp b/Net/NetObject.cpp index 29cdd55..52e3ed0 100644 --- a/Net/NetObject.cpp +++ b/Net/NetObject.cpp @@ -1,50 +1,5 @@ // -// Created by alex on 09.10.18. +// Created by alex on 12.11.18. // #include "NetObject.h" - -NetObject::NetObject() -{ - thread=new std::thread(read_sock); -} - -NetObject::~NetObject() -{ - //need to set global variable to let thread know when to finish - thread->join(); - delete thread; -} - -void NetObject::read_sock() -{ - //read from the connection and write to recv_buf -} - -Packet *NetObject::receive() -{ - return nullptr; -} - -void NetObject::send(Packet packet) -{ - -} - -NetObject::NetObject(int port,std::string& ip) - : - port(port), - ip(ip) -{ - thread=new std::thread(read_sock); -} - -void NetObject::set_port(int n_port) -{ - port=n_port; -} - -void NetObject::connect() -{ - -} diff --git a/Net/NetObject.h b/Net/NetObject.h index 8bbcb1b..b378034 100644 --- a/Net/NetObject.h +++ b/Net/NetObject.h @@ -1,36 +1,22 @@ // -// Created by alex on 09.10.18. +// Created by alex on 12.11.18. // #ifndef NET_NETOBJECT_H #define NET_NETOBJECT_H -#include -#include "Packet.h" + +#include +#include "Serializable.h" class NetObject { public: - NetObject(); - NetObject(int port, std::string& ip); - NetObject(NetObject&)=delete; - NetObject(NetObject&&)=delete; - NetObject& operator=(NetObject&)=delete; - NetObject& operator=(NetObject&&)=delete; - ~NetObject(); - - void set_port(int port); - void send(Packet packet); - Packet* receive(); - void connect(); -protected: - static short const BUF_SIZE=1024; - static void read_sock(); - Packet recv_buf[BUF_SIZE]; + virtual void connect()=0; + virtual void send(Serializable*)=0; + virtual std::vector receive()=0; private: - int port; - std::string ip; - std::thread* thread; + std::vector buf; }; diff --git a/Net/Packet.cpp b/Net/Packet.cpp deleted file mode 100644 index 0697e6e..0000000 --- a/Net/Packet.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// -// Created by alex on 29.10.18. -// - -#include "Packet.h" - -template -void Packet::convert(T to_convert) -{ - -} - -template -T Packet::extract() -{ - -} diff --git a/Net/Packet.h b/Net/Packet.h deleted file mode 100644 index 7f9ce19..0000000 --- a/Net/Packet.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// Created by alex on 29.10.18. -// - -#ifndef NET_PACKET_H -#define NET_PACKET_H - - -class Packet -{ -public: - enum - { - Update, - Command - } data_type; - template - void convert(T to_convert); - - template - T extract(); -private: - int* data; -}; - - - -#endif //NET_PACKET_H diff --git a/Net/Serializable.cpp b/Net/Serializable.cpp new file mode 100644 index 0000000..acf5833 --- /dev/null +++ b/Net/Serializable.cpp @@ -0,0 +1,5 @@ +// +// Created by alex on 12.11.18. +// + +#include "Serializable.h" diff --git a/Net/Serializable.h b/Net/Serializable.h new file mode 100644 index 0000000..0d4d77b --- /dev/null +++ b/Net/Serializable.h @@ -0,0 +1,18 @@ +// +// Created by alex on 12.11.18. +// + +#ifndef NET_SERIALIZABLE_H +#define NET_SERIALIZABLE_H + +#include + +struct Serializable +{ +public: + virtual std::string serialize()=0; + virtual void deserialize(std::string)=0; +}; + + +#endif //NET_SERIALIZABLE_H diff --git a/Net/ServerNetObject.cpp b/Net/ServerNetObject.cpp index e5a8e8f..c5c2c84 100644 --- a/Net/ServerNetObject.cpp +++ b/Net/ServerNetObject.cpp @@ -1,45 +1,44 @@ // -// Created by alex on 09.10.18. +// Created by alex on 12.11.18. // #include "ServerNetObject.h" -void ServerNetObject::set_player_number(short player_number) -{ - ServerNetObject::player_number = player_number; -} - void ServerNetObject::connect() { } -ServerNetObject::ServerNetObject(short player_number) - : player_number(player_number) +void ServerNetObject::send(Serializable *serializable) { } -void ServerNetObject::set_player(int port,std::string& ip) +std::vector ServerNetObject::receive() { - players.push_back(new NetObject(port,ip)); + return nullptr; } -ServerNetObject::~ServerNetObject() +void ServerNetObject::set_player_number(short player_number) { - while(!players.empty()) - { - delete players[players.size()-1]; - players.pop_back(); - } + ServerNetObject::player_number = player_number; } -void ServerNetObject::send(Packet packet) +void ServerNetObject::set_ip(const std::string &ip) { + ServerNetObject::ip = ip; +} +void ServerNetObject::set_port(uint port) +{ + ServerNetObject::port = port; } -std::vector ServerNetObject::recieve() +ServerNetObject::ServerNetObject(uint _port, const std::string &_ip, short _player_number) + : + port(_port), + ip(_ip), + player_number(_player_number) { - return std::vector(); + } diff --git a/Net/ServerNetObject.h b/Net/ServerNetObject.h index df2d0fd..05c58b3 100644 --- a/Net/ServerNetObject.h +++ b/Net/ServerNetObject.h @@ -1,27 +1,30 @@ // -// Created by alex on 09.10.18. +// Created by alex on 12.11.18. // #ifndef NET_SERVERNETOBJECT_H #define NET_SERVERNETOBJECT_H -#include -#include "NetObject.h" +#include "AbstractServerNetObject.h" +#include "ClientNetObject.h" -class ServerNetObject +class ServerNetObject:public AbstractServerNetObject { public: - explicit ServerNetObject(short player_number); - void set_player_number(short player_number); - void set_player(int port,std::string& ip); - void connect(); - std::vector recieve(); - void send(Packet packet); - ~ServerNetObject(); + ServerNetObject(uint _port=50000,const std::string& _ip, short _player_number); + void connect() override; + void send(Serializable *serializable) override; + std::vector receive() override; + + void set_player_number(short player_number); + void set_ip(const std::string &ip); + void set_port(uint port); private: - std::vector players; - short player_number; + uint port; + std::string ip; + short player_number; + std::vector players; }; diff --git a/Net/test/packet_tests.cpp b/Net/test/packet_tests.cpp deleted file mode 100644 index a3fa50c..0000000 --- a/Net/test/packet_tests.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Created by alex on 29.10.18. -// - -#include "gtest/gtest.h" -#include "gmock/gmock.h" -#include "../Packet.h" - -//to delete after taking real commands and updates! -struct Update { - -}; - -struct Command { - -}; -// - -TEST(packet_update_test, convert_extract) -{ - Packet packet; - Update before; - packet.convert(before); - Update after=packet.extract(); - EXPECT_EQ(before, after); -} - -TEST(packet_command_test, convert_extract) -{ - Packet packet; - Command before; - packet.convert(before); - Command after=packet.extract(); - EXPECT_EQ(before, after); -} \ No newline at end of file From 9c1e54ba477f51ec6415a34ea045117a93c32b48 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 19 Nov 2018 11:11:09 +0300 Subject: [PATCH 06/39] Added gitignore --- Net/.gitignore | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Net/.gitignore diff --git a/Net/.gitignore b/Net/.gitignore new file mode 100644 index 0000000..b810d44 --- /dev/null +++ b/Net/.gitignore @@ -0,0 +1,35 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +Net/cmake-build-debug* +Net/.idea* From eb73346222555267e2ff93592c7a3fc828938091 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 19 Nov 2018 11:14:36 +0300 Subject: [PATCH 07/39] Clean Clion autogenerated --- Net/.gitignore | 35 - Net/.idea/Net.iml | 2 - Net/.idea/codeStyles/Project.xml | 29 - Net/.idea/misc.xml | 4 - Net/.idea/modules.xml | 8 - Net/.idea/vcs.xml | 6 - Net/.idea/workspace.xml | 432 ------------ Net/cmake-build-debug/CMakeCache.txt | 358 ---------- .../CMakeFiles/3.9.6/CMakeCCompiler.cmake | 71 -- .../CMakeFiles/3.9.6/CMakeCXXCompiler.cmake | 73 -- .../3.9.6/CMakeDetermineCompilerABI_C.bin | Bin 8248 -> 0 bytes .../3.9.6/CMakeDetermineCompilerABI_CXX.bin | Bin 8264 -> 0 bytes .../CMakeFiles/3.9.6/CMakeSystem.cmake | 15 - .../3.9.6/CompilerIdC/CMakeCCompilerId.c | 567 ---------------- .../CompilerIdCXX/CMakeCXXCompilerId.cpp | 539 --------------- .../CMakeDirectoryInformation.cmake | 16 - .../CMakeFiles/CMakeOutput.log | 633 ------------------ .../CMakeFiles/Makefile.cmake | 50 -- Net/cmake-build-debug/CMakeFiles/Makefile2 | 145 ---- .../CMakeFiles/Net.dir/CXX.includecache | 34 - .../CMakeFiles/Net.dir/DependInfo.cmake | 23 - .../CMakeFiles/Net.dir/build.make | 168 ----- .../CMakeFiles/Net.dir/cmake_clean.cmake | 12 - .../Net.dir/cmake_clean_target.cmake | 3 - .../CMakeFiles/Net.dir/depend.internal | 15 - .../CMakeFiles/Net.dir/depend.make | 15 - .../CMakeFiles/Net.dir/flags.make | 10 - .../CMakeFiles/Net.dir/link.txt | 2 - .../CMakeFiles/Net.dir/progress.make | 5 - .../CMakeFiles/Progress/count.txt | 1 - .../CMakeFiles/TargetDirectories.txt | 4 - .../CMakeFiles/clion-environment.txt | 3 - .../CMakeFiles/clion-log.txt | 4 - .../CMakeFiles/cmake.check_cache | 1 - .../CMakeFiles/feature_tests.bin | Bin 12312 -> 0 bytes .../CMakeFiles/feature_tests.c | 34 - .../CMakeFiles/feature_tests.cxx | 405 ----------- .../CMakeFiles/progress.marks | 1 - Net/cmake-build-debug/Makefile | 312 --------- Net/cmake-build-debug/Net.cbp | 165 ----- Net/cmake-build-debug/cmake_install.cmake | 44 -- 41 files changed, 4244 deletions(-) delete mode 100644 Net/.gitignore delete mode 100644 Net/.idea/Net.iml delete mode 100644 Net/.idea/codeStyles/Project.xml delete mode 100644 Net/.idea/misc.xml delete mode 100644 Net/.idea/modules.xml delete mode 100644 Net/.idea/vcs.xml delete mode 100644 Net/.idea/workspace.xml delete mode 100644 Net/cmake-build-debug/CMakeCache.txt delete mode 100644 Net/cmake-build-debug/CMakeFiles/3.9.6/CMakeCCompiler.cmake delete mode 100644 Net/cmake-build-debug/CMakeFiles/3.9.6/CMakeCXXCompiler.cmake delete mode 100755 Net/cmake-build-debug/CMakeFiles/3.9.6/CMakeDetermineCompilerABI_C.bin delete mode 100755 Net/cmake-build-debug/CMakeFiles/3.9.6/CMakeDetermineCompilerABI_CXX.bin delete mode 100644 Net/cmake-build-debug/CMakeFiles/3.9.6/CMakeSystem.cmake delete mode 100644 Net/cmake-build-debug/CMakeFiles/3.9.6/CompilerIdC/CMakeCCompilerId.c delete mode 100644 Net/cmake-build-debug/CMakeFiles/3.9.6/CompilerIdCXX/CMakeCXXCompilerId.cpp delete mode 100644 Net/cmake-build-debug/CMakeFiles/CMakeDirectoryInformation.cmake delete mode 100644 Net/cmake-build-debug/CMakeFiles/CMakeOutput.log delete mode 100644 Net/cmake-build-debug/CMakeFiles/Makefile.cmake delete mode 100644 Net/cmake-build-debug/CMakeFiles/Makefile2 delete mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/CXX.includecache delete mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/DependInfo.cmake delete mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/build.make delete mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/cmake_clean.cmake delete mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/cmake_clean_target.cmake delete mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/depend.internal delete mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/depend.make delete mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/flags.make delete mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/link.txt delete mode 100644 Net/cmake-build-debug/CMakeFiles/Net.dir/progress.make delete mode 100644 Net/cmake-build-debug/CMakeFiles/Progress/count.txt delete mode 100644 Net/cmake-build-debug/CMakeFiles/TargetDirectories.txt delete mode 100644 Net/cmake-build-debug/CMakeFiles/clion-environment.txt delete mode 100644 Net/cmake-build-debug/CMakeFiles/clion-log.txt delete mode 100644 Net/cmake-build-debug/CMakeFiles/cmake.check_cache delete mode 100755 Net/cmake-build-debug/CMakeFiles/feature_tests.bin delete mode 100644 Net/cmake-build-debug/CMakeFiles/feature_tests.c delete mode 100644 Net/cmake-build-debug/CMakeFiles/feature_tests.cxx delete mode 100644 Net/cmake-build-debug/CMakeFiles/progress.marks delete mode 100644 Net/cmake-build-debug/Makefile delete mode 100644 Net/cmake-build-debug/Net.cbp delete mode 100644 Net/cmake-build-debug/cmake_install.cmake diff --git a/Net/.gitignore b/Net/.gitignore deleted file mode 100644 index b810d44..0000000 --- a/Net/.gitignore +++ /dev/null @@ -1,35 +0,0 @@ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -Net/cmake-build-debug* -Net/.idea* diff --git a/Net/.idea/Net.iml b/Net/.idea/Net.iml deleted file mode 100644 index f08604b..0000000 --- a/Net/.idea/Net.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Net/.idea/codeStyles/Project.xml b/Net/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/Net/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Net/.idea/misc.xml b/Net/.idea/misc.xml deleted file mode 100644 index 79b3c94..0000000 --- a/Net/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Net/.idea/modules.xml b/Net/.idea/modules.xml deleted file mode 100644 index 3127853..0000000 --- a/Net/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Net/.idea/vcs.xml b/Net/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/Net/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Net/.idea/workspace.xml b/Net/.idea/workspace.xml deleted file mode 100644 index 755631a..0000000 --- a/Net/.idea/workspace.xml +++ /dev/null @@ -1,432 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -