Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 14 additions & 7 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"CMAKE_INSTALL_PREFIX": "/home/edward/projects/rpc2/submodules/c-ares",
"CMAKE_RULE_MESSAGES": "OFF",
"CMAKE_VERBOSE_MAKEFILE": "OFF",
"CANOPY_DEBUG_THREAD": "OFF",
"CANOPY_DEBUG_GEN": "OFF",
"CANOPY_ENABLE_CLANG_TIDY": "OFF",
"LIBCORO_BUILD_EXAMPLES": "OFF",
"LIBCORO_BUILD_TESTS": "OFF",
"LIBCORO_EXTERNAL_DEPENDENCIES": "OFF",
Expand All @@ -34,7 +32,15 @@
"LIBCORO_FEATURE_NETWORKING": "OFF",
"CANOPY_HANG_ON_FAILED_ASSERT": "OFF",
"CANOPY_USE_TELEMETRY_RAII_LOGGING": "OFF",
"CANOPY_BUILD_DEMOS": "OFF"
"CANOPY_BUILD_DEMOS": "OFF",
"CANOPY_DEBUG_LEAK": "OFF",
"CANOPY_DEBUG_ADDRESS": "OFF",
"CANOPY_DEBUG_THREAD": "OFF",
"CANOPY_DEBUG_UNDEFINED": "OFF",
"CANOPY_DEBUG_ALL": "OFF",
"CANOPY_ENABLE_COVERAGE": "OFF",
"CANOPY_ENABLE_CLANG_TIDY": "OFF",
"CANOPY_ENABLE_CLANG_TIDY_FIX": "OFF"
}
},
{
Expand All @@ -48,7 +54,8 @@
"CANOPY_USE_LOGGING": "ON",
"CANOPY_USE_TELEMETRY": "ON",
"CANOPY_USE_CONSOLE_TELEMETRY": "ON",
"CANOPY_USE_TELEMETRY_RAII_LOGGING": "ON"
"CANOPY_USE_TELEMETRY_RAII_LOGGING": "ON",
"CANOPY_DEBUG_DEFAULT_DESTRUCTOR": "ON"
}
},
{
Expand Down Expand Up @@ -277,9 +284,9 @@
"CANOPY_BUILD_COROUTINE": "ON",
"CMAKE_BUILD_TYPE": "Release",
"CANOPY_USE_LOGGING": "OFF",
"CANOPY_USE_TELEMETRY": "ON",
"CANOPY_USE_CONSOLE_TELEMETRY": "ON",
"CANOPY_USE_TELEMETRY_RAII_LOGGING": "ON",
"CANOPY_USE_TELEMETRY": "OFF",
"CANOPY_USE_CONSOLE_TELEMETRY": "OFF",
"CANOPY_USE_TELEMETRY_RAII_LOGGING": "OFF",
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++",
"CANOPY_BUILD_DEMOS": "ON"
Expand Down
9 changes: 9 additions & 0 deletions cmake/Canopy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ if(NOT DEPENDENCIES_LOADED)
option(CANOPY_BUILD_DEMOS "Build demo code" OFF)
option(CANOPY_BUILD_COROUTINE "Include coroutine support" OFF)
option(CANOPY_STANDALONE "Build Canopy stand alone" OFF)
option(CANOPY_DEBUG_GEN "Get the generator produce verbose messages" OFF)
option(CANOPY_DEBUG_DEFAULT_DESTRUCTOR "Get the generator produce verbose messages" OFF)

# SGX Enclave support (disabled by default - most users don't need this)
option(CANOPY_BUILD_ENCLAVE "Build SGX enclave code" OFF)
Expand Down Expand Up @@ -244,6 +246,12 @@ if(NOT DEPENDENCIES_LOADED)
set(CANOPY_BUILD_COROUTINE_FLAG)
endif()

if(${CANOPY_DEBUG_DEFAULT_DESTRUCTOR})
set(CANOPY_DEBUG_DEFAULT_DESTRUCTOR_FLAG CANOPY_DEBUG_DEFAULT_DESTRUCTOR)
else()
set(CANOPY_DEBUG_DEFAULT_DESTRUCTOR_FLAG)
endif()

set(CANOPY_FMT_LIB fmt::fmt-header-only)

# ####################################################################################################################
Expand All @@ -261,6 +269,7 @@ if(NOT DEPENDENCIES_LOADED)
${CANOPY_USE_CONSOLE_TELEMETRY_FLAG}
${CANOPY_USE_TELEMETRY_RAII_LOGGING_FLAG}
${CANOPY_BUILD_TEST_FLAG}
${CANOPY_DEBUG_DEFAULT_DESTRUCTOR_FLAG}
CANOPY_OUT_BUFFER_SIZE=${CANOPY_OUT_BUFFER_SIZE}
CANOPY_DEFAULT_ENCODING=${CANOPY_DEFAULT_ENCODING_VALUE})

Expand Down
7 changes: 1 addition & 6 deletions demos/comprehensive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,8 @@ auto service = std::make_shared<rpc::service>("name", rpc::zone{id}, scheduler);

### Interface Implementation
```cpp
class my_impl : public i_my_interface
class my_impl : public rpc::base<my_impl, i_my_interface>
{
void* get_address() const override { return const_cast<my_impl*>(this); }
const rpc::casting_interface* query_interface(rpc::interface_ordinal id) const override
{
return match<i_my_interface>(id) ? this : nullptr;
}
CORO_TASK(error_code) my_method(...) override { ... }
};
```
Expand Down
56 changes: 6 additions & 50 deletions demos/comprehensive/include/demo_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,13 @@ namespace comprehensive
// ============================================================================
// Callback Receiver Implementation
// ============================================================================
class callback_receiver_impl : public i_callback_receiver
class callback_receiver_impl : public rpc::base<callback_receiver_impl, i_callback_receiver>
{
std::vector<int> received_progress_;
std::vector<std::string> received_data_;
mutable std::mutex mutex_;

public:
void* get_address() const override { return const_cast<callback_receiver_impl*>(this); }

const rpc::casting_interface* query_interface(rpc::interface_ordinal interface_id) const override
{
if (rpc::match<i_callback_receiver>(interface_id))
return static_cast<const i_callback_receiver*>(this);
return nullptr;
}

CORO_TASK(int) on_progress(int percentage) override
{
std::lock_guard<std::mutex> lock(mutex_);
Expand All @@ -149,22 +140,13 @@ namespace comprehensive
// ============================================================================
// Worker Implementation (Callbacks)
// ============================================================================
class worker_impl : public i_worker
class worker_impl : public rpc::base<worker_impl, i_worker>
{
rpc::shared_ptr<i_callback_receiver> parent_callback_;
mutable std::mutex mutex_;
bool running_{false};

public:
void* get_address() const override { return const_cast<worker_impl*>(this); }

const rpc::casting_interface* query_interface(rpc::interface_ordinal interface_id) const override
{
if (rpc::match<i_worker>(interface_id))
return static_cast<const i_worker*>(this);
return nullptr;
}

CORO_TASK(int) set_callback_receiver(rpc::shared_ptr<i_callback_receiver> receiver) override
{
std::lock_guard<std::mutex> lock(mutex_);
Expand Down Expand Up @@ -216,7 +198,7 @@ namespace comprehensive
// ============================================================================
// Managed Object Implementation (Shared Pointer Demo)
// ============================================================================
class managed_object_impl : public i_managed_object
class managed_object_impl : public rpc::base<managed_object_impl, i_managed_object>
{
uint64_t object_id_;
int ref_count_{1};
Expand All @@ -234,15 +216,6 @@ namespace comprehensive

~managed_object_impl() { --live_count_; }

void* get_address() const override { return const_cast<managed_object_impl*>(this); }

const rpc::casting_interface* query_interface(rpc::interface_ordinal interface_id) const override
{
if (rpc::match<i_managed_object>(interface_id))
return static_cast<const i_managed_object*>(this);
return nullptr;
}

CORO_TASK(int) get_object_id(uint64_t& id) override
{
id = object_id_;
Expand Down Expand Up @@ -270,21 +243,12 @@ namespace comprehensive
// ============================================================================
// Object Factory Implementation
// ============================================================================
class object_factory_impl : public i_object_factory
class object_factory_impl : public rpc::base<object_factory_impl, i_object_factory>
{
std::map<uint64_t, rpc::shared_ptr<i_managed_object>> objects_;
mutable std::mutex mutex_;

public:
void* get_address() const override { return const_cast<object_factory_impl*>(this); }

const rpc::casting_interface* query_interface(rpc::interface_ordinal interface_id) const override
{
if (rpc::match<i_object_factory>(interface_id))
return static_cast<const i_object_factory*>(this);
return nullptr;
}

CORO_TASK(int) create_object(rpc::shared_ptr<i_managed_object>& obj) override
{
auto new_obj = rpc::shared_ptr<i_managed_object>(new managed_object_impl());
Expand Down Expand Up @@ -328,7 +292,8 @@ namespace comprehensive
// ============================================================================
// Demo Service Implementation (For transport demos)
// ============================================================================
class demo_service_impl : public i_demo_service, public rpc::enable_shared_from_this<demo_service_impl>
class demo_service_impl : public rpc::base<demo_service_impl, i_demo_service>,
public rpc::enable_shared_from_this<demo_service_impl>
{
std::string name_;
rpc::shared_ptr<i_demo_service> child_service_;
Expand All @@ -347,15 +312,6 @@ namespace comprehensive
{
}

void* get_address() const override { return const_cast<demo_service_impl*>(this); }

const rpc::casting_interface* query_interface(rpc::interface_ordinal interface_id) const override
{
if (rpc::match<i_demo_service>(interface_id))
return static_cast<const i_demo_service*>(this);
return nullptr;
}

CORO_TASK(int) get_zone_id(uint64_t& zone_id) override
{
auto service = this_service_.lock();
Expand Down
9 changes: 2 additions & 7 deletions demos/comprehensive/src/transport/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ namespace comprehensive
std::atomic<uint64_t> zone_gen{0};
auto root_service = std::make_shared<rpc::service>("benchmark_root", rpc::zone{++zone_gen}, scheduler);
root_service->set_default_encoding(enc);
comprehensive_idl_register_stubs(root_service);

rpc::zone child_zone_id{++zone_gen};
auto child_transport
Expand Down Expand Up @@ -280,7 +279,6 @@ namespace comprehensive
{
auto service_1 = std::make_shared<rpc::service>("spsc_client", zone_1, scheduler);
service_1->set_default_encoding(enc);
comprehensive_idl_register_stubs(service_1);

auto on_shutdown_event = std::make_shared<rpc::event>();
service_1->set_shutdown_event(on_shutdown_event);
Expand Down Expand Up @@ -332,10 +330,9 @@ namespace comprehensive
auto service_2 = std::make_shared<rpc::service>("spsc_server", zone_2, scheduler);
service_2->set_shutdown_event(on_shutdown_event);
service_2->set_default_encoding(enc);
comprehensive_idl_register_stubs(service_2);

rpc::event on_connected;
auto handler = [&, enc](const rpc::interface_descriptor& input_interface,
auto handler = [&, enc](const rpc::connection_settings& input_interface,
rpc::interface_descriptor& output_interface,
std::shared_ptr<rpc::service> service,
std::shared_ptr<rpc::spsc::spsc_transport> transport) -> CORO_TASK(int)
Expand Down Expand Up @@ -414,10 +411,9 @@ namespace comprehensive
auto service = std::make_shared<rpc::service>("tcp_server", rpc::zone{++zone_gen}, scheduler);
service->set_default_encoding(enc);
service->set_shutdown_event(on_shutdown_event);
comprehensive_idl_register_stubs(service);

auto listener = std::make_shared<rpc::tcp::listener>(
[enc](const rpc::interface_descriptor& input_descr,
[enc](const rpc::connection_settings& input_descr,
rpc::interface_descriptor& output_interface,
std::shared_ptr<rpc::service> child_service_ptr,
std::shared_ptr<rpc::tcp::tcp_transport> transport) -> CORO_TASK(int)
Expand Down Expand Up @@ -475,7 +471,6 @@ namespace comprehensive
auto peer_zone_id = rpc::zone{1};
auto client_service = std::make_shared<rpc::service>("tcp_client", rpc::zone{++zone_gen}, scheduler);
client_service->set_default_encoding(enc);
comprehensive_idl_register_stubs(client_service);

coro::net::tcp::client client(scheduler,
coro::net::tcp::client::options{.address = coro::net::ip_address::from_string(host), .port = port});
Expand Down
4 changes: 1 addition & 3 deletions demos/comprehensive/src/transport/spsc_transport_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace comprehensive
rpc::event& client_finished)
{
auto service_1 = std::make_shared<rpc::service>("process_1", zone_1, scheduler);
comprehensive_idl_register_stubs(service_1);

auto on_shutdown_event = std::make_shared<rpc::event>();
service_1->set_shutdown_event(on_shutdown_event);
Expand Down Expand Up @@ -120,10 +119,9 @@ namespace comprehensive
auto on_shutdown_event = std::make_shared<rpc::event>();
auto service_2 = std::make_shared<rpc::service>("process_2", zone_2, scheduler);
service_2->set_shutdown_event(on_shutdown_event);
comprehensive_idl_register_stubs(service_2);

rpc::event on_connected;
auto handler = [&, zone_1](const rpc::interface_descriptor& input_interface,
auto handler = [&, zone_1](const rpc::connection_settings& input_interface,
rpc::interface_descriptor& output_interface,
std::shared_ptr<rpc::service> service,
std::shared_ptr<rpc::spsc::spsc_transport> transport) -> CORO_TASK(int)
Expand Down
7 changes: 2 additions & 5 deletions demos/comprehensive/src/transport/tcp_transport_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,17 @@ namespace comprehensive
// Create server service
auto service = std::make_shared<rpc::service>("tcp_server", rpc::zone{++zone_gen}, scheduler);
service->set_shutdown_event(on_shutdown_event);
comprehensive_idl_register_stubs(service);

std::cout << "Server zone ID: " << service->get_zone_id().get_val() << "\n";

// Create TCP listener with connection handler
auto listener = std::make_shared<rpc::tcp::listener>(
[](const rpc::interface_descriptor& input_descr,
[](const rpc::connection_settings& input_descr,
rpc::interface_descriptor& output_interface,
std::shared_ptr<rpc::service> child_service_ptr,
std::shared_ptr<rpc::tcp::tcp_transport> transport) -> CORO_TASK(int)
{
std::cout << "Server: Accepting connection from zone " << input_descr.destination_zone_id.get_val()
<< "\n";
std::cout << "Server: Accepting connection from zone " << input_descr.input_zone_id.get_val() << "\n";

// Use attach_remote_zone to handle the connection
auto ret
Expand Down Expand Up @@ -159,7 +157,6 @@ namespace comprehensive

// Create client service
auto client_service = std::make_shared<rpc::service>("tcp_client", rpc::zone{++zone_gen}, scheduler);
comprehensive_idl_register_stubs(client_service);

std::cout << "Client zone ID: " << client_service->get_zone_id().get_val() << "\n";
std::cout << "Client: Connecting to " << host << ":" << port << "...\n";
Expand Down
4 changes: 2 additions & 2 deletions demos/websocket/server/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace websocket_demo
const std::shared_ptr<std::queue<std::vector<uint8_t>>>& pending_messages,
const std::shared_ptr<std::mutex>& pending_messages_mutex);

virtual ~transport() DEFAULT_DESTRUCTOR;
virtual ~transport() CANOPY_DEFAULT_DESTRUCTOR;

CORO_TASK(int)
inner_connect(rpc::interface_descriptor input_descr, rpc::interface_descriptor& output_descr) override
inner_connect(rpc::connection_settings& input_descr, rpc::interface_descriptor& output_descr) override
{
std::ignore = input_descr;
std::ignore = output_descr;
Expand Down
2 changes: 1 addition & 1 deletion demos/websocket/server/websocket_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace websocket_demo
public:
websocket_service(std::string name, rpc::zone zone_id, std::shared_ptr<coro::io_scheduler> scheduler);

virtual ~websocket_service() DEFAULT_DESTRUCTOR;
virtual ~websocket_service() CANOPY_DEFAULT_DESTRUCTOR;

rpc::shared_ptr<i_calculator> get_demo_instance();
};
Expand Down
5 changes: 3 additions & 2 deletions demos/websocket/server/ws_client_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ namespace websocket_demo
= CO_AWAIT service_->attach_remote_zone<websocket_demo::v1::i_context_event, websocket_demo::v1::i_calculator>(
"websocket",
transport_,
rpc::interface_descriptor{1, 2}, // this magically makes sink
rpc::connection_settings{1,
websocket_demo::v1::i_context_event::get_id(rpc::get_version()),
2}, // this magically makes sink
output_descr,
[](const rpc::shared_ptr<websocket_demo::v1::i_context_event>& sink,
rpc::shared_ptr<websocket_demo::v1::i_calculator>& local,
const std::shared_ptr<rpc::service>& svc) -> coro::task<int>
{
std::cout << "[WS] Inside attach_remote_zone lambda" << std::endl;
secret_llama_idl_register_stubs(svc);

auto wsrvc = std::static_pointer_cast<websocket_service>(svc);

Expand Down
19 changes: 1 addition & 18 deletions documents/02-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,11 @@ Create `include/calculator_impl.h`:

namespace calculator
{

class calculator_impl : public v1::i_calculator
class calculator_impl : public rpc::base<calculator_impl, v1::i_calculator>
{
public:
calculator_impl() = default;

// Required overrides
void* get_address() const override
{
return const_cast<calculator_impl*>(this);
}

const rpc::casting_interface* query_interface(
rpc::interface_ordinal interface_id) const override
{
if (rpc::match<v1::i_calculator>(interface_id))
{
return static_cast<const v1::i_calculator*>(this);
}
return nullptr;
}

// Interface methods
CORO_TASK(error_code) add(int a, int b, int& result) override
{
Expand Down
Loading