Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e4fc8d3
Pref draft
kbrddestroyer May 28, 2025
a43f928
MemoryGuard added for memleak tests
kbrddestroyer May 29, 2025
84f291e
MemoryGuard added for memleak tests
kbrddestroyer May 29, 2025
6f76e72
MemoryGuard added for memleak tests. Hooks moved to C, Memguard is no…
kbrddestroyer May 30, 2025
142fca1
Added performance checks
kbrddestroyer May 30, 2025
fd95501
Fix TCP multiplexing
kbrddestroyer May 30, 2025
f45c94f
Fix TCP multiplexing - checked on example
kbrddestroyer May 30, 2025
c07c423
Fix message split algorythm, fix multiplexing issues
kbrddestroyer May 31, 2025
5b462ed
Formatted examples folder sources
kbrddestroyer Jun 1, 2025
35ed5d9
Added comment section in CONTRIBUTING.md
kbrddestroyer Jun 1, 2025
9ae798a
Merge pull request #114 from kbrddestroyer/wip/common/refactors-and-t…
kbrddestroyer Jun 1, 2025
98ba9cc
Commented include/ folder
kbrddestroyer Jun 1, 2025
5591021
Slightly changed backend.hpp definitions
kbrddestroyer Jun 1, 2025
781b845
Commented and documented tcp
kbrddestroyer Jun 1, 2025
0633d81
Commented and formatted udp backend file
kbrddestroyer Jun 1, 2025
a800ef1
Removed pragma region from UDP file
kbrddestroyer Jun 1, 2025
7e825ee
EventSystem refactored
kbrddestroyer Jun 1, 2025
3fcdffb
Commented on AxonMessage
kbrddestroyer Jun 1, 2025
8f47e19
Fix build issues
kbrddestroyer Jun 1, 2025
98d14db
Fix build
kbrddestroyer Jun 1, 2025
6b3f90f
Merge pull request #115 from kbrddestroyer/wip/common/refactoring
kbrddestroyer Jun 1, 2025
a63622d
added draft on network pointer
kbrddestroyer Jun 1, 2025
9122391
fix build issue
kbrddestroyer Jun 1, 2025
e4c39bb
Replace event - this->event
kbrddestroyer Jun 2, 2025
98656cd
Replace event - this->event
kbrddestroyer Jun 2, 2025
1c0da41
Merge pull request #116 from kbrddestroyer/wip/common/refactoring
kbrddestroyer Jun 2, 2025
0f1bc4e
Merge remote-tracking branch 'origin/feature/refactoring' into wip/co…
kbrddestroyer Jun 2, 2025
ea64310
Fixed includes
kbrddestroyer Jun 2, 2025
871791d
Merge branch 'wip/common/patch-includes' into wip/common/merge-from-main
kbrddestroyer Jun 2, 2025
06edfb6
Merge pull request #120 from kbrddestroyer/wip/common/merge-from-main
kbrddestroyer Jun 2, 2025
a8d5246
Moved message to separate library
kbrddestroyer Jun 3, 2025
4e0bf2d
Moved networking logic to low-level controller
kbrddestroyer Jun 3, 2025
8d64cda
Removed deprecates
kbrddestroyer Jun 3, 2025
8791f1b
Added cxx standart to libnetworking
kbrddestroyer Jun 3, 2025
52c2a82
Added common LIBD_DIR variable in CMake
kbrddestroyer Jun 3, 2025
92a70af
Windows build required -std=c++17, event if it's passed manually in c…
kbrddestroyer Jun 3, 2025
19f2e57
Merge pull request #122 from kbrddestroyer/wip/global/libnetwork-rede…
kbrddestroyer Jun 3, 2025
a0e24b1
dev/global/synapse_refactor (#127)
kbrddestroyer Jun 7, 2025
531aa45
Refactored headers, added inlines, moved all gtests under common entr…
kbrddestroyer Jun 8, 2025
a3e5b89
Added unsubscribe method, which utilises some hacks, but still works …
kbrddestroyer Jun 9, 2025
00cd43c
Merge pull request #130 from kbrddestroyer/dev/global/backmerge-from-…
kbrddestroyer Jun 9, 2025
53b8028
Merge pull request #132 from kbrddestroyer/dev/actions/patch-1
kbrddestroyer Jun 9, 2025
b6d4497
Added unsubscribe method to AxonNetworkObject destructor
kbrddestroyer Jun 9, 2025
52ab55b
Migrated SerializedAxonMessage to the rule of 0
kbrddestroyer Jun 9, 2025
2cfc59d
Removed deprecated construction from ConnectionInfo struct - using ho…
kbrddestroyer Jun 9, 2025
3e87a1e
Removed deprecated construction
kbrddestroyer Jun 9, 2025
3e52e44
Revert "Migrated SerializedAxonMessage to the rule of 0"
kbrddestroyer Jun 9, 2025
bbcb533
Merge pull request #133 from kbrddestroyer/dev/refactor/libnetwork-re…
kbrddestroyer Jun 9, 2025
629af6a
Removed alloc from cpps
kbrddestroyer Jun 9, 2025
76cd156
Remove deprecated cast
kbrddestroyer Jun 11, 2025
673485b
Test assert
kbrddestroyer Jun 11, 2025
55129e3
Should be equal, but I replaced sizeof with strlen
kbrddestroyer Jun 11, 2025
c51806f
Should be equal, but I replaced sizeof with strlen
kbrddestroyer Jun 11, 2025
88deef2
Revert "Removed alloc from cpps"
kbrddestroyer Jun 11, 2025
5e6b97a
Merge pull request #134 from kbrddestroyer/dev/refactoring/message-re…
kbrddestroyer Jun 11, 2025
ce979d5
Slight changes in AxonMessage protocol before refactoring
kbrddestroyer Jun 13, 2025
397413a
Merge pull request #138 from kbrddestroyer/dev/refactor/message-2
kbrddestroyer Jun 13, 2025
b7f4a55
Added the rule of 5 to message class (#142)
kbrddestroyer Jun 14, 2025
93f9bd8
Wip/refactor/message refactor (#143)
kbrddestroyer Jun 14, 2025
3835058
Merge branch 'main' into feature/refactoring
kbrddestroyer Jun 14, 2025
bde4099
Merge pull request #144 from kbrddestroyer/dev/refactor/main-backmerge
kbrddestroyer Jun 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ Functions like `malloc`, `calloc`, and `free` are forbidden in C++ code.

Speaking of class layout, [*the rule of zero*](https://en.cppreference.com/w/cpp/language/rule_of_three.html) is preferred

### Code documenting

Comments in code are preferred, but not always necessary. There are some basic rules of proper code documentation,
which can be found [here](https://developer.lsst.io/cpp/api-docs.html).

---

If you find code that doesn’t follow these guidelines, [open an issue](https://github.com/kbrddestroyer/AxonEngine/issues/new) with the `refactoring` label.
19 changes: 18 additions & 1 deletion cmake/build-utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function(add_all_subdirs)
endforeach()
endfunction()

function(list_all_tests name_pattern)
function(list_all_tests_separate name_pattern)
file (GLOB_RECURSE TEST_SOURCES ${name_pattern})

foreach (TEST_SRC ${TEST_SOURCES})
Expand All @@ -31,3 +31,20 @@ function(list_all_tests name_pattern)
message ("Loaded test sequence: ${FILENAME}")
endforeach ()
endfunction()

function(list_all_tests name_pattern)
file (GLOB_RECURSE TEST_SOURCES ${name_pattern})
get_filename_component(FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME_WE)
string (TOUPPER ${FOLDER} FOLDER)

add_executable(TEST_${FOLDER}_TARGET ${TEST_SOURCES} "entry.cpp")
add_test(NAME TEST_${FOLDER} COMMAND $<TARGET_FILE:TEST_${FOLDER}_TARGET>)
target_link_libraries(TEST_${FOLDER}_TARGET PRIVATE ${ARGN})

add_custom_command(TARGET TEST_${FOLDER}_TARGET POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:TEST_${FOLDER}_TARGET> $<TARGET_RUNTIME_DLLS:TEST_${FOLDER}_TARGET>
COMMAND_EXPAND_LISTS
)

message ("Loaded test folder: TEST_${FOLDER}")
endfunction()
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Examples

27 changes: 15 additions & 12 deletions examples/basics/basic-synapse/client.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* This example shows basic connection, using Axon internal tools
* Synapse provides connection between two points
* This example shows basic client connection, using Axon internal tools.
* Synapse provides connection between two points, this one is created in client mode.
*
* This file defined basic client logic, with AxonMessage forming and sending with Synapse tool
* This file defined basic client logic. It creates Message package and sends it to server. Also, it is capable of
* server messages handling, displaying response packages.
*/

#include <networking/AxonNetwork.hpp>
#include <cstring>
#include <networking/AxonLibrary.hpp>
#include <iostream>

#include <chrono>
Expand Down Expand Up @@ -34,12 +34,12 @@ void onMessageReceived(const Networking::SynapseMessageReceivedEvent& event)

int main()
{
Networking::ConnectionInfo connection = { "localhost", 10423 };

Networking::AsyncSynapse<Networking::ConnectionMode::UDP, Networking::SynapseMode::CLIENT> clientConnection(connection);
Networking::AsyncSynapse<
Networking::BerkeleyAxonNetworkController<Networking::TCP, Networking::SynapseMode::CLIENT>
> clientConnection("localhost", 10423);
clientConnection.getEventManager().subscribe<Networking::SynapseMessageReceivedEvent>(onMessageReceived);

clientConnection.start();

time_t startTimestamp = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());

Networking::AxonMessage msg(nullptr, 0);
Expand All @@ -50,12 +50,15 @@ int main()
{
std::this_thread::sleep_for(std::chrono::seconds(1));

std::stringstream sstream;
std::stringstream stream;

sstream <<
stream <<
"Sending message on " <<
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()) - startTimestamp;
Networking::AxonMessage message_(const_cast<char*>(sstream.str().c_str()), sstream.str().length() + 1, 0, Networking::TAG_FLAGS::VALIDATE);

std::cout << "Sending: " << stream.str() << std::endl;

Networking::AxonMessage message_(const_cast<char*>(stream.str().c_str()), stream.str().length() + 2, 0, Networking::TAG_FLAGS::VALIDATE);

clientConnection.send(message_);
}
Expand Down
12 changes: 7 additions & 5 deletions examples/basics/basic-synapse/server.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* This example shows basic connection, using Axon internal tools
* Synapse provides connection between two points
* This example shows basic server, using Axon internal tools.
* Synapse provides connection between two points, this one is created in server mode.
*
* This file defines basic server logic, with message handling using Synapse event system
* This file shows basic server logic and message handling using asynchronous Synapse with event system.
*/

#include <networking/AxonNetwork.hpp>
#include <networking/AxonLibrary.hpp>
#include <iostream>
#include <iomanip>

Expand All @@ -31,7 +31,9 @@ void onMessageReceived(const Networking::SynapseMessageReceivedEvent& event)

int main()
{
Networking::Synapse<Networking::ConnectionMode::UDP, Networking::SynapseMode::SERVER> serverConnection(10423);
Networking::Synapse<
Networking::BerkeleyAxonNetworkController<Networking::ConnectionMode::TCP, Networking::SynapseMode::SERVER>
> serverConnection(10423);
serverConnection.getEventManager().subscribe<Networking::SynapseMessageReceivedEvent>(onMessageReceived);

std::cout << "Starting Synapse connection" << std::endl;
Expand Down
4 changes: 4 additions & 0 deletions include/common_macro.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Defines some useful macro, mostly for C code and backends.
*/

#ifndef AXONENGINE_COMMON_MACRO_H
#define AXONENGINE_COMMON_MACRO_H

Expand Down
18 changes: 16 additions & 2 deletions include/custom_utility.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Contains utility types, functions, etc.
*/

#ifndef CUSTOM_UTILITY_H
#define CUSTOM_UTILITY_H

Expand All @@ -6,8 +10,18 @@
#else
#include <stdint.h>
#endif
// Define alias for uint64_t to be used instead of size_t
// as size_t may have different size on different machines (i.e. x86 vs x64)

#include "common_macro.h"

/**
* Define alias for uint64_t to be used instead of size_t
* as size_t may have different size on different machines (i.e. x86 vs x64)
*/
typedef uint64_t size64_t;
struct Socket
{
SOCKET_T socket;
SOCKADDR_IN_T conn;
};

#endif //CUSTOM_UTILITY_H
2 changes: 1 addition & 1 deletion include/netconfig.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#define SYNAPSE_PAYLOAD_SIZE_MAX 16
#define SYNAPSE_MESSAGE_SIZE_MAX SYNAPSE_PAYLOAD_SIZE_MAX + 16 + 64
#define SYNAPSE_MESSAGE_SIZE_MAX (SYNAPSE_PAYLOAD_SIZE_MAX + 16 + 64)
8 changes: 6 additions & 2 deletions libraries/AxonUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@

#include <common_macro.h>

#if defined(MSVC) || defined(__GNUC__) || defined(__clang__)
#if defined(MSVC) || defined(__GNUC__) || defined(__clang__) || defined(WINDOWS_PLATFORM)
#define GETTER [[nodiscard("Ignoring getter return value is not allowed. For god's sake, have some respect!")]]
#else
#define GETTER
#endif

#if defined(WINDOWS_PLATFORM)
#define GETTER
#if defined(AXON_LIB)
#if defined(AXON_STATIC)
#define AXON_DECLSPEC
#else
#define AXON_DECLSPEC __declspec(dllexport)
#endif
#else
#define AXON_DECLSPEC __declspec(dllimport)
#endif
Expand All @@ -30,3 +33,4 @@

#define WGETTER GETTER_WNE
#endif

1 change: 1 addition & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ message(STATUS "Searching for build config in ${V_GLOB}")

set (CMAKE_POSITION_INDEPENDENT_CODE ON)
set (COMMON_SRC "AxonUtility.h" PARENT_SCOPE)
set (LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR})

add_all_subdirs()
5 changes: 3 additions & 2 deletions libraries/backends/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
project ("AxonEngine.libraries")
project ("AxonEngine.libraries.backends")

file(GLOB_RECURSE SOURCES "*.c" "*.h" "*.cpp" "*.hpp")
add_library(backends STATIC ${SOURCES})

target_include_directories(backends PUBLIC "${CMAKE_HOME_DIRECTORY}/libraries")
target_include_directories(backends PUBLIC ${LIBS_DIR})
target_include_directories(backends PUBLIC "${CMAKE_HOME_DIRECTORY}/common")
target_compile_definitions(backends PUBLIC AXON_LIB)
4 changes: 2 additions & 2 deletions libraries/backends/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ template <> uint8_t initialize_server<SOCK_DGRAM>(Socket& socket, uint32_t port)
return create_udp_server(&socket.conn, &socket.socket, port);
}

template <> uint8_t initialize_client<SOCK_STREAM>(Socket& socket, const char* hostname, uint32_t port)
template <> uint8_t initialize_client<SOCK_STREAM>(Socket& socket, const char* hostname, const uint32_t port)
{
return connect_tcp_client(&socket.conn, &socket.socket, hostname, port);
}

template <> uint8_t initialize_client<SOCK_DGRAM>(Socket& socket, const char* hostname, uint32_t port)
template <> uint8_t initialize_client<SOCK_DGRAM>(Socket& socket, const char* hostname, const uint32_t port)
{
return connect_udp_client(&socket.conn, &socket.socket, hostname, port);
}
Expand Down
26 changes: 12 additions & 14 deletions libraries/backends/backend.hpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
/**
* backend library.
* Contains functions for protocol-independent socket functions usage. Works with Berkeley sockets.
*/

#pragma once

#ifdef __cplusplus
extern "C" {
#endif
#if defined(USE_BERKELEY)
#include "berkeley/basic_networking.h"
#else
/* DEFAULT */
#endif

#include "berkeley/basic_networking.h"
#include "custom_utility.h"
#ifdef __cplusplus
}
#endif

template <uint8_t> int32_t send_message(const Socket& socket, const void* message, size_t size);

template <uint8_t> int32_t recv_message(Socket& socket, void* buffer, size_t size_allocated);

template <uint8_t> uint8_t initialize_server(Socket& socket, uint32_t port);

template <uint8_t> uint8_t initialize_client(Socket& socket, const char* hostname, uint32_t port);

template <uint8_t> int32_t send_message(const Socket& socket, const void* message, size_t size) = delete;
template <uint8_t> int32_t recv_message(Socket& socket, void* buffer, size_t size_allocated) = delete;
template <uint8_t> uint8_t initialize_server(Socket& socket, uint32_t port) = delete;
template <uint8_t> uint8_t initialize_client(Socket& socket, const char* hostname, uint32_t port) = delete;
template <uint8_t> void finalize(Socket& socket);

template <> int32_t send_message<SOCK_STREAM>(const Socket&, const void*, size_t);
Expand All @@ -33,6 +29,8 @@ template <> int32_t recv_message<SOCK_DGRAM>(Socket&, void*, size_t);
template <> uint8_t initialize_server<SOCK_STREAM>(Socket&, uint32_t);
template <> uint8_t initialize_server<SOCK_DGRAM>(Socket&, uint32_t);

template <> uint8_t initialize_client<SOCK_STREAM>(Socket&, const char*, uint32_t);
template <> uint8_t initialize_client<SOCK_DGRAM>(Socket&, const char*, uint32_t);

template <> void finalize<SOCK_STREAM>(Socket &);
template <> void finalize<SOCK_DGRAM>(Socket &);
8 changes: 1 addition & 7 deletions libraries/backends/berkeley/basic_networking.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* Can be used as template for any other backends
*
* Defines some low-level socket logic. Direct usage is not recommended
Expand All @@ -12,12 +12,6 @@
#include "udp/udp_connection.h"
#include "tcp/tcp_connection.h"

struct Socket
{
SOCKET_T socket;
SOCKADDR_IN_T conn;
};

#endif

/* basic_networking.h */
16 changes: 13 additions & 3 deletions libraries/backends/berkeley/master_include.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
/**
* Header, that aggregates some includes for every other berkeley backend source file
*/

#ifndef MASTER_INCLUDE_H
#define MASTER_INCLUDE_H

#ifdef __cplusplus
extern "C" {
#endif

#include <common_macro.h>
#include <netconfig.h>

/* common */

#include <stdio.h>
#include <stdlib.h>

#ifdef __cplusplus
}
#endif

#endif
Loading