Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::protocols::grpc::generic_service Class Reference

A service that allows dynamic method registration. More...

#include <service_registry.h>

Inheritance diagram for kcenon::network::protocols::grpc::generic_service:
Inheritance graph
Collaboration diagram for kcenon::network::protocols::grpc::generic_service:
Collaboration graph

Classes

class  impl
 

Public Member Functions

 generic_service (std::string service_name)
 Construct a generic service.
 
 ~generic_service () override
 
 generic_service (const generic_service &)=delete
 
generic_serviceoperator= (const generic_service &)=delete
 
 generic_service (generic_service &&) noexcept
 
generic_serviceoperator= (generic_service &&) noexcept
 
auto descriptor () const -> const service_descriptor &override
 Get the service descriptor.
 
auto register_unary_method (const std::string &method_name, unary_handler handler, const std::string &input_type="", const std::string &output_type="") -> VoidResult
 Register a unary method handler.
 
auto register_server_streaming_method (const std::string &method_name, server_streaming_handler handler, const std::string &input_type="", const std::string &output_type="") -> VoidResult
 Register a server streaming method handler.
 
auto register_client_streaming_method (const std::string &method_name, client_streaming_handler handler, const std::string &input_type="", const std::string &output_type="") -> VoidResult
 Register a client streaming method handler.
 
auto register_bidi_streaming_method (const std::string &method_name, bidi_streaming_handler handler, const std::string &input_type="", const std::string &output_type="") -> VoidResult
 Register a bidirectional streaming method handler.
 
auto get_unary_handler (const std::string &method_name) const -> const unary_handler *
 Get unary handler for a method.
 
auto get_server_streaming_handler (const std::string &method_name) const -> const server_streaming_handler *
 Get server streaming handler for a method.
 
auto get_client_streaming_handler (const std::string &method_name) const -> const client_streaming_handler *
 Get client streaming handler for a method.
 
auto get_bidi_streaming_handler (const std::string &method_name) const -> const bidi_streaming_handler *
 Get bidirectional streaming handler for a method.
 
- Public Member Functions inherited from kcenon::network::protocols::grpc::service_base
virtual ~service_base ()=default
 
virtual auto is_ready () const -> bool
 Check if this service is ready to handle requests.
 

Private Attributes

std::unique_ptr< implimpl_
 

Detailed Description

A service that allows dynamic method registration.

Use this class when you need to register methods at runtime without protobuf definitions. Supports all RPC types.

Example:

generic_service service("mypackage.MyService");
service.register_unary_method("Echo",
[](server_context& ctx, const std::vector<uint8_t>& request)
-> std::pair<grpc_status, std::vector<uint8_t>> {
return {grpc_status::ok_status(), request};
});
registry.register_service(&service);
A service that allows dynamic method registration.
Context for handling a single RPC request.
Definition server.h:77
gRPC status with code, message, and optional details
Definition status.h:95
static auto ok_status() -> grpc_status
Create OK status.
Definition status.h:154

Definition at line 212 of file service_registry.h.

Constructor & Destructor Documentation

◆ generic_service() [1/3]

kcenon::network::protocols::grpc::generic_service::generic_service ( std::string service_name)
explicit

Construct a generic service.

Parameters
service_nameFull service name (e.g., "package.ServiceName")

Definition at line 256 of file service_registry.cpp.

257 : impl_(std::make_unique<impl>(std::move(service_name)))
258{
259}

◆ ~generic_service()

kcenon::network::protocols::grpc::generic_service::~generic_service ( )
overridedefault

◆ generic_service() [2/3]

kcenon::network::protocols::grpc::generic_service::generic_service ( const generic_service & )
delete

◆ generic_service() [3/3]

kcenon::network::protocols::grpc::generic_service::generic_service ( generic_service && )
defaultnoexcept

Member Function Documentation

◆ descriptor()

auto kcenon::network::protocols::grpc::generic_service::descriptor ( ) const -> const service_descriptor&
overridevirtual

Get the service descriptor.

Returns
Reference to service descriptor

Implements kcenon::network::protocols::grpc::service_base.

Definition at line 266 of file service_registry.cpp.

267{
268 return impl_->descriptor();
269}
auto descriptor() const -> const service_descriptor &

◆ get_bidi_streaming_handler()

auto kcenon::network::protocols::grpc::generic_service::get_bidi_streaming_handler ( const std::string & method_name) const -> const bidi_streaming_handler*

Get bidirectional streaming handler for a method.

Parameters
method_nameMethod name
Returns
Handler or nullptr

Definition at line 329 of file service_registry.cpp.

331{
332 return impl_->get_bidi_streaming_handler(method_name);
333}
auto get_bidi_streaming_handler(const std::string &method_name) const -> const bidi_streaming_handler *

◆ get_client_streaming_handler()

auto kcenon::network::protocols::grpc::generic_service::get_client_streaming_handler ( const std::string & method_name) const -> const client_streaming_handler*

Get client streaming handler for a method.

Parameters
method_nameMethod name
Returns
Handler or nullptr

Definition at line 323 of file service_registry.cpp.

325{
326 return impl_->get_client_streaming_handler(method_name);
327}
auto get_client_streaming_handler(const std::string &method_name) const -> const client_streaming_handler *

◆ get_server_streaming_handler()

auto kcenon::network::protocols::grpc::generic_service::get_server_streaming_handler ( const std::string & method_name) const -> const server_streaming_handler*

Get server streaming handler for a method.

Parameters
method_nameMethod name
Returns
Handler or nullptr

Definition at line 317 of file service_registry.cpp.

319{
320 return impl_->get_server_streaming_handler(method_name);
321}
auto get_server_streaming_handler(const std::string &method_name) const -> const server_streaming_handler *

◆ get_unary_handler()

auto kcenon::network::protocols::grpc::generic_service::get_unary_handler ( const std::string & method_name) const -> const unary_handler*

Get unary handler for a method.

Parameters
method_nameMethod name
Returns
Handler or nullptr

Definition at line 311 of file service_registry.cpp.

313{
314 return impl_->get_unary_handler(method_name);
315}
auto get_unary_handler(const std::string &method_name) const -> const unary_handler *

◆ operator=() [1/2]

generic_service & kcenon::network::protocols::grpc::generic_service::operator= ( const generic_service & )
delete

◆ operator=() [2/2]

generic_service & kcenon::network::protocols::grpc::generic_service::operator= ( generic_service && )
defaultnoexcept

◆ register_bidi_streaming_method()

auto kcenon::network::protocols::grpc::generic_service::register_bidi_streaming_method ( const std::string & method_name,
bidi_streaming_handler handler,
const std::string & input_type = "",
const std::string & output_type = "" ) -> VoidResult

Register a bidirectional streaming method handler.

Parameters
method_nameMethod name
handlerHandler function
input_typeOptional input type name for reflection
output_typeOptional output type name for reflection
Returns
Success or error

Definition at line 301 of file service_registry.cpp.

306{
307 return impl_->register_bidi_streaming_method(method_name, std::move(handler),
308 input_type, output_type);
309}
auto register_bidi_streaming_method(const std::string &method_name, bidi_streaming_handler handler, const std::string &input_type, const std::string &output_type) -> VoidResult

◆ register_client_streaming_method()

auto kcenon::network::protocols::grpc::generic_service::register_client_streaming_method ( const std::string & method_name,
client_streaming_handler handler,
const std::string & input_type = "",
const std::string & output_type = "" ) -> VoidResult

Register a client streaming method handler.

Parameters
method_nameMethod name
handlerHandler function
input_typeOptional input type name for reflection
output_typeOptional output type name for reflection
Returns
Success or error

Definition at line 291 of file service_registry.cpp.

296{
297 return impl_->register_client_streaming_method(method_name, std::move(handler),
298 input_type, output_type);
299}
auto register_client_streaming_method(const std::string &method_name, client_streaming_handler handler, const std::string &input_type, const std::string &output_type) -> VoidResult

◆ register_server_streaming_method()

auto kcenon::network::protocols::grpc::generic_service::register_server_streaming_method ( const std::string & method_name,
server_streaming_handler handler,
const std::string & input_type = "",
const std::string & output_type = "" ) -> VoidResult

Register a server streaming method handler.

Parameters
method_nameMethod name
handlerHandler function
input_typeOptional input type name for reflection
output_typeOptional output type name for reflection
Returns
Success or error

Definition at line 281 of file service_registry.cpp.

286{
287 return impl_->register_server_streaming_method(method_name, std::move(handler),
288 input_type, output_type);
289}
auto register_server_streaming_method(const std::string &method_name, server_streaming_handler handler, const std::string &input_type, const std::string &output_type) -> VoidResult

◆ register_unary_method()

auto kcenon::network::protocols::grpc::generic_service::register_unary_method ( const std::string & method_name,
unary_handler handler,
const std::string & input_type = "",
const std::string & output_type = "" ) -> VoidResult

Register a unary method handler.

Parameters
method_nameMethod name (without service prefix)
handlerHandler function
input_typeOptional input type name for reflection
output_typeOptional output type name for reflection
Returns
Success or error

Definition at line 271 of file service_registry.cpp.

276{
277 return impl_->register_unary_method(method_name, std::move(handler),
278 input_type, output_type);
279}
auto register_unary_method(const std::string &method_name, unary_handler handler, const std::string &input_type, const std::string &output_type) -> VoidResult

Member Data Documentation

◆ impl_

std::unique_ptr<impl> kcenon::network::protocols::grpc::generic_service::impl_
private

Definition at line 331 of file service_registry.h.


The documentation for this class was generated from the following files: