Skip to content

Commit

Permalink
Merge branch '1.0.2.0-develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
borisu committed Jun 22, 2024
2 parents 807b1e8 + e939a91 commit 116745f
Show file tree
Hide file tree
Showing 113 changed files with 3,961 additions and 1,872 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
path = 3rdparty/modules/tinyxml2
url = https://github.com/leethomason/tinyxml2.git
branch = v10.0.0
[submodule "3rdparty/modules/oatpp"]
path = 3rdparty/modules/oatpp
url = https://github.com/oatpp/oatpp.git
branch = 1.3.0-latest
[submodule "3rdparty/modules/base64"]
path = 3rdparty/modules/base64
url = https://github.com/tobiaslocker/base64
Expand Down
1 change: 0 additions & 1 deletion 3rdparty/modules/oatpp
Submodule oatpp deleted from 17ef2a
26 changes: 21 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
cmake_minimum_required(VERSION 3.5)

set (CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

option(NO_KAFKA_PLUGIN "No Kafka plugin" OFF)

option(NO_ZEROMQ_PLUGIN "No ZeroMQ plugin" OFF)

option(NO_OATPP_PLUGIN "No Oatpp plugin" OFF)
option(NO_REDSIPP_PLUGIN "No Redis-plus-plus plugin" OFF)

option(NO_RABBITMQ_PLUGIN "No RabbitMq plugin" OFF)

option(NO_LIBEVENT_PLUGIN "No Libevent plugin" OFF)

enable_testing()

Expand All @@ -32,10 +36,22 @@ else()
add_compile_definitions(NO_ZEROMQ_PLUGIN)
endif()

if (NOT NO_OATPP_PLUGIN)
add_subdirectory(bricks_oatpp)
if (NOT NO_REDSIPP_PLUGIN)
add_subdirectory(bricks_redispp)
else()
add_compile_definitions(NO_REDSIPP_PLUGIN)
endif()

if (NOT NO_RABBITMQ_PLUGIN)
add_subdirectory(bricks_rabbitmq)
else()
add_compile_definitions(NO_RABBITMQ_PLUGIN)
endif()

if (NOT NO_LIBEVENT_PLUGIN)
add_subdirectory(bricks_libevent)
else()
add_compile_definitions(NO_OATPP_PLUGIN)
add_compile_definitions(NO_LIBEVENT_PLUGIN)
endif()

add_subdirectory(bricks_ut)
Expand Down
2 changes: 2 additions & 0 deletions src/bricks_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/include/selector.h
${CMAKE_CURRENT_SOURCE_DIR}/include/utils.h
${CMAKE_CURRENT_SOURCE_DIR}/include/xtree.h
${CMAKE_CURRENT_SOURCE_DIR}/include/timer.h
${CMAKE_CURRENT_SOURCE_DIR}/include/meta.h
)

set (BRICKS_CORE_SRC
Expand Down Expand Up @@ -38,6 +39,7 @@ poller_impl.h
poller_impl.cpp
timer_impl.h
timer_impl.cpp

)

set (BRICKS_CORE_3RD_PARTY
Expand Down
22 changes: 21 additions & 1 deletion src/bricks_core/common.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
#include "pch.h"
#include "bricks.h"
#include "locking_queue.h"
#include "utils.h"

using namespace bricks;

void bricks::brick_destroy(brick_t* ptr) { ptr->release(); };
thread_local std::random_device rd; // Obtain a random number from hardware
thread_local std::mt19937_64 gen(rd()); // Seed the generator (Mersenne Twister for 64-bit numbers)
thread_local std::uniform_int_distribution<uint64_t> distrib(1, UINT64_MAX); // Define the rang
std::mutex mtx;

void
bricks::brick_destroy(brick_t* ptr)
{
ptr->release();
};

void
bricks::generate_random_64hex_str(hex64_str_t hex_buffer)
{
SYNCHRONIZED(mtx);

int64_t req_handle = distrib(gen);

snprintf(hex_buffer, 64, "0x%" PRIx64, req_handle);
}
1 change: 1 addition & 0 deletions src/bricks_core/include/bricks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#include "selector.h"
#include "buffer.h"
#include "plugin.h"
#include "meta.h"


19 changes: 12 additions & 7 deletions src/bricks_core/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <memory>
#include <list>
#include <chrono>
#include <future>

#ifdef WIN32
#ifdef BRICKS_EXPORTS
Expand All @@ -32,7 +33,9 @@ namespace bricks
BRICKS_3RD_PARTY_ERROR = 4,
BRICKS_TIMEOUT = 5,
BRICKS_NOT_SUPPORTED = 6,
BRICKS_REMOTE_ERROR = 3,
BRICKS_REMOTE_ERROR = 7,
BRICKS_OBJECT_DESTROYED = 8,
BRICKS_NOT_IMPLEMENTED = 9,
};

class brick_t
Expand All @@ -41,12 +44,6 @@ namespace bricks
virtual void release() = 0;
};

class startable_brick_t : public brick_t
{
public:
virtual bricks_error_code_e start() = 0;
};

void brick_destroy(brick_t* ptr);

template<class T>
Expand All @@ -62,6 +59,14 @@ namespace bricks
using brick_uptr = std::unique_ptr<B, bricks_destroyer>;

typedef std::vector<char> vector_t;

typedef std::promise<bricks_error_code_e> bricks_promise_t;

typedef std::future<bricks_error_code_e> bricks_future_t;

typedef char hex64_str_t[64];

void BRICKS_API generate_random_64hex_str(hex64_str_t s);

}

Expand Down
6 changes: 4 additions & 2 deletions src/bricks_core/meta.h → src/bricks_core/include/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ namespace bricks
subscriber_plugin_t* subscriber,
timer_t* timer,
const char* request_topic_prefix,
const char* reponse_topic_prefix);
const char* reponse_topic_prefix,
const char* error_topic_prefix);

BRICKS_API server_plugin_t* create_pubsub_server(
publisher_plugin_t* publisher,
subscriber_plugin_t* subscriber,
const char* request_topic_prefix,
const char* reponse_topic_prefix);
const char* reponse_topic_prefix,
const char* error_topic_prefix);

}
30 changes: 19 additions & 11 deletions src/bricks_core/include/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@ namespace bricks {

enum plugin_capabilities_e
{
HIERARCHICAL_SUBSCRIBE
HIERARCHICAL_SUBSCRIBE,
HIERARCHICAL_PUBLISH,
};

class plugin_t : public startable_brick_t {
enum plugin_meta_event_e
{
OBJECT_DESTROYED,
};

typedef function<void(plugin_meta_event_e, xtree_t*)>
meta_cb_t;

class plugin_t : public brick_t
{
public:

virtual bool check_capability(plugin_capabilities_e) = 0;

virtual void set_meta_cb(meta_cb_t) = 0;
};

class publisher_plugin_t : public plugin_t
Expand All @@ -27,7 +40,7 @@ namespace bricks {

virtual bricks_error_code_e init(cb_queue_t *queue, const xtree_t* options = nullptr) = 0;

virtual bricks_error_code_e add_topic(const string& topic, const xtree_t* options = nullptr) = 0;
virtual bricks_error_code_e describe_topic(const string& topic, const xtree_t* options = nullptr) = 0;

virtual bricks_error_code_e publish(const string& topic, const char*, size_t, const xtree_t* options = nullptr) = 0;
};
Expand All @@ -45,8 +58,6 @@ namespace bricks {

virtual bricks_error_code_e unsubscribe(const string& topic, const xtree_t* options = nullptr) = 0;

virtual bricks_error_code_e unsubscribe(const xtree_t* options = nullptr) = 0;

};

typedef function <void(bricks_error_code_e, const char*, size_t, xtree_t*)>
Expand All @@ -59,9 +70,8 @@ namespace bricks {
{
public:

virtual bricks_error_code_e init(cb_queue_t *queue, const xtree_t* options = nullptr) = 0;

virtual bricks_error_code_e register_request_cb(request_cb_t request, const xtree_t* options = nullptr) = 0;
virtual bricks_error_code_e init(cb_queue_t *queue, request_cb_t request, const xtree_t* options = nullptr) = 0;

};

typedef function<void(bricks_error_code_e, buffer_t*, xtree_t*)>
Expand All @@ -83,9 +93,7 @@ namespace bricks {
{
public:

virtual bricks_error_code_e init(cb_queue_t *queue, const xtree_t* options = nullptr) = 0;

virtual bricks_error_code_e register_event_cb(event_cb_t event_cb, const xtree_t* options = nullptr) = 0;
virtual bricks_error_code_e init(cb_queue_t *queue, event_cb_t event_cb, const xtree_t* options = nullptr) = 0;

virtual bricks_error_code_e send_event(const char*, size_t, const xtree_t* options = nullptr) = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions src/bricks_core/include/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace bricks
{
public:

virtual bricks_error_code_e enqueue(callback_t) = 0;
virtual bricks_error_code_e enqueue(callback_t, int* event_id = nullptr) = 0;

virtual bricks_error_code_e try_dequeue(callback_t&, int milliseconds) = 0;
virtual bricks_error_code_e try_dequeue(callback_t&, int milliseconds, int* event_id = nullptr) = 0;

};

Expand Down
2 changes: 1 addition & 1 deletion src/bricks_core/include/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace bricks

typedef clock_t::time_point time_point_t;

class BRICKS_API timer_t : public startable_brick_t
class timer_t : public brick_t
{
public:
virtual bricks_error_code_e init(cb_queue_t* queue, const xtree_t* options = nullptr) = 0;
Expand Down
9 changes: 3 additions & 6 deletions src/bricks_core/include/utils.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#pragma once

#define ASSERT_INITIATED if (!this->initiated) return BRICKS_INVALID_STATE
#define ASSERT_NOT_INITIATED if (this->initiated) return BRICKS_INVALID_STATE

#define ASSERT_STARTED if (!this->started) return BRICKS_INVALID_STATE
#define ASSERT_NOT_STARTED if (this->started) return BRICKS_INVALID_STATE
#define ASSERT_PREINIT do { if (this->destroyed) return BRICKS_OBJECT_DESTROYED; if ( this->initiated) return BRICKS_INVALID_STATE; } while (false)
#define ASSERT_READY do { if (this->destroyed) return BRICKS_OBJECT_DESTROYED; if (!this->initiated) return BRICKS_INVALID_STATE; } while (false)

#define BRICKS_MAP_PAIR(x) {#x,x}

#define SYNCHRONIZED(M) std::lock_guard<std::recursive_mutex> lk__(M);
#define SYNCHRONIZED(M) std::lock_guard lk__(M);

#define BRICKS_DEFAULT_CLIENT_TIMEOUT 1000
9 changes: 8 additions & 1 deletion src/bricks_core/include/xtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,14 @@ namespace bricks
template <typename T1>
T1 get_opt(std::optional<property_value_t> opt, T1 d = T1{})
{
return opt.has_value() ? std::get<T1>(opt.value()) : d;
try
{
return opt.has_value() ? std::get<T1>(opt.value()) : d;
}
catch (std::bad_variant_access const&)
{
return d;
}
}

}
Loading

0 comments on commit 116745f

Please sign in to comment.