libivon 0.1.0
Voice-over-IP library
Loading...
Searching...
No Matches
ivon::ServerWrapper Class Reference

RAII wrapper around the libivon server C ABI. More...

#include <ivon_server_wrapper.hpp>

Inheritance diagram for ivon::ServerWrapper:
ivon::IServer

Classes

class  Config
 Server configuration. More...
 

Public Member Functions

 ServerWrapper (const Config &cfg)
 Construct a server from the given configuration.
 
 ~ServerWrapper () override
 
 ServerWrapper (const ServerWrapper &)=delete
 
ServerWrapperoperator= (const ServerWrapper &)=delete
 
 ServerWrapper (ServerWrapper &&)=delete
 
ServerWrapperoperator= (ServerWrapper &&)=delete
 
void run () override
 Run the server (blocks until stop() is called from another thread).
 
void stop () override
 Stop the server (thread-safe, causes run() to return).
 
bool create_group (const std::string &group_id) override
 Create a new group at runtime. Returns false if it already exists.
 
void delete_group (const std::string &group_id, std::function< void(bool)> callback=nullptr) override
 Delete a group (asynchronous). Optional completion callback.
 
bool has_group (const std::string &group_id) const override
 Check if a group exists.
 
std::vector< std::string > group_ids () const override
 Get all group IDs as a vector.
 
std::optional< uint32_t > rotate_group_key (const std::string &group_id) override
 Rotate the encryption key for a group.
 
void kick_client (const std::string &client_id, const std::string &reason="") override
 Kick a client from the server entirely.
 
void kick_client_from_group (const std::string &group_id, const std::string &client_id, const std::string &reason="", std::function< void(bool)> callback=nullptr) override
 Kick a client from a specific group (asynchronous). Optional completion callback.
 
void send_message_to_client (const std::string &client_id, const std::string &data_type, const uint8_t *data, size_t data_len) override
 Send a message from the server to a specific client.
 
void send_message_to_group (const std::string &group_id, const std::string &data_type, const uint8_t *data, size_t data_len) override
 Send a message from the server to all members of a group.
 
void send_message_to_all (const std::string &data_type, const uint8_t *data, size_t data_len) override
 Broadcast a message from the server to all connected clients.
 
void send_message_to_client (const std::string &client_id, const std::string &data_type, std::span< const uint8_t > data)
 Convenience: send to client from a span.
 
void send_message_to_group (const std::string &group_id, const std::string &data_type, std::span< const uint8_t > data)
 Convenience: send to group from a span.
 
void send_message_to_all (const std::string &data_type, std::span< const uint8_t > data)
 Convenience: broadcast to all from a span.
 
void set_property (const std::string &key, const uint8_t *value, size_t value_len) override
 Set a server-level property (pushed to all connected clients).
 
void set_group_property (const std::string &group_id, const std::string &key, const uint8_t *value, size_t value_len) override
 Set a group-level property (pushed to all group members).
 
void on_connection_admission (ConnectionAdmissionCallback cb) override
 Gate: accept/reject raw TCP connections by IP and port.
 
void on_client_id_check (ClientIdCheckCallback cb) override
 Gate: validate a client's self-declared ID.
 
void on_password_validate (PasswordValidateCallback cb) override
 Gate: custom password validation (replaces built-in == check).
 
void on_client_approve (ClientApproveCallback cb) override
 Gate: final approval before a client becomes visible to peers.
 
void on_client_connected (ClientConnectedCallback cb) override
 Event: fired when a client is registered and visible.
 
void on_client_disconnected (ClientDisconnectedCallback cb) override
 Event: fired when a client is removed from the session.
 
void on_group_join_authorize (GroupJoinAuthorizeCallback cb) override
 Gate: authorize a group join request.
 
ivon_server_t handle () const noexcept
 
- Public Member Functions inherited from ivon::IServer
virtual ~IServer ()=default
 

Additional Inherited Members

- Public Types inherited from ivon::IServer
using ConnectionAdmissionCallback = std::function< bool(const std::string &remote_ip, uint16_t remote_port)>
 Gate: accept/reject raw TCP connections by IP and port.
 
using ClientIdCheckCallback = std::function< bool(const std::string &client_id)>
 Gate: validate a client's self-declared ID.
 
using PasswordValidateCallback = std::function< bool(const std::string &client_id, const std::string &password)>
 Gate: custom password validation (replaces built-in == check).
 
using ClientApproveCallback = std::function< bool(const std::string &client_id, const std::string &remote_ip)>
 Gate: final approval before a client becomes visible to peers.
 
using ClientConnectedCallback = std::function< void(const std::string &client_id, uint64_t session_id)>
 Event: fired when a client is registered and visible.
 
using ClientDisconnectedCallback = std::function< void(const std::string &client_id, uint64_t session_id, bool graceful)>
 Event: fired when a client is removed from the session.
 
using GroupJoinAuthorizeCallback = std::function< bool(const std::string &client_id, const std::string &group_id)>
 Gate: authorize a group join request.
 

Detailed Description

RAII wrapper around the libivon server C ABI.

Non-copyable, non-moveable. Owns an ivon_server_t handle and destroys it on destruction. Use std::unique_ptr for deferred initialization or ownership transfer. All methods delegate to the corresponding ivon_server_* C functions.

Constructor & Destructor Documentation

◆ ServerWrapper() [1/3]

ivon::ServerWrapper::ServerWrapper ( const Config cfg)
inlineexplicit

Construct a server from the given configuration.

Callbacks set via the on_*() methods are installed during construction. Set them before calling this constructor.

Exceptions
std::runtime_errorif config or server creation fails.

◆ ~ServerWrapper()

ivon::ServerWrapper::~ServerWrapper ( )
inlineoverride

◆ ServerWrapper() [2/3]

ivon::ServerWrapper::ServerWrapper ( const ServerWrapper )
delete

◆ ServerWrapper() [3/3]

ivon::ServerWrapper::ServerWrapper ( ServerWrapper &&  )
delete

Member Function Documentation

◆ create_group()

bool ivon::ServerWrapper::create_group ( const std::string &  group_id)
inlineoverridevirtual

Create a new group at runtime. Returns false if it already exists.

Implements ivon::IServer.

◆ delete_group()

void ivon::ServerWrapper::delete_group ( const std::string &  group_id,
std::function< void(bool)>  callback = nullptr 
)
inlineoverridevirtual

Delete a group (asynchronous). Optional completion callback.

Implements ivon::IServer.

◆ group_ids()

std::vector< std::string > ivon::ServerWrapper::group_ids ( ) const
inlineoverridevirtual

Get all group IDs as a vector.

Implements ivon::IServer.

◆ handle()

ivon_server_t ivon::ServerWrapper::handle ( ) const
inlinenoexcept

◆ has_group()

bool ivon::ServerWrapper::has_group ( const std::string &  group_id) const
inlineoverridevirtual

Check if a group exists.

Implements ivon::IServer.

◆ kick_client()

void ivon::ServerWrapper::kick_client ( const std::string &  client_id,
const std::string &  reason = "" 
)
inlineoverridevirtual

Kick a client from the server entirely.

Implements ivon::IServer.

◆ kick_client_from_group()

void ivon::ServerWrapper::kick_client_from_group ( const std::string &  group_id,
const std::string &  client_id,
const std::string &  reason = "",
std::function< void(bool)>  callback = nullptr 
)
inlineoverridevirtual

Kick a client from a specific group (asynchronous). Optional completion callback.

Implements ivon::IServer.

◆ on_client_approve()

void ivon::ServerWrapper::on_client_approve ( ClientApproveCallback  cb)
inlineoverridevirtual

Gate: final approval before a client becomes visible to peers.

Implements ivon::IServer.

◆ on_client_connected()

void ivon::ServerWrapper::on_client_connected ( ClientConnectedCallback  cb)
inlineoverridevirtual

Event: fired when a client is registered and visible.

Implements ivon::IServer.

◆ on_client_disconnected()

void ivon::ServerWrapper::on_client_disconnected ( ClientDisconnectedCallback  cb)
inlineoverridevirtual

Event: fired when a client is removed from the session.

Implements ivon::IServer.

◆ on_client_id_check()

void ivon::ServerWrapper::on_client_id_check ( ClientIdCheckCallback  cb)
inlineoverridevirtual

Gate: validate a client's self-declared ID.

Implements ivon::IServer.

◆ on_connection_admission()

void ivon::ServerWrapper::on_connection_admission ( ConnectionAdmissionCallback  cb)
inlineoverridevirtual

Gate: accept/reject raw TCP connections by IP and port.

Implements ivon::IServer.

◆ on_group_join_authorize()

void ivon::ServerWrapper::on_group_join_authorize ( GroupJoinAuthorizeCallback  cb)
inlineoverridevirtual

Gate: authorize a group join request.

Implements ivon::IServer.

◆ on_password_validate()

void ivon::ServerWrapper::on_password_validate ( PasswordValidateCallback  cb)
inlineoverridevirtual

Gate: custom password validation (replaces built-in == check).

Implements ivon::IServer.

◆ operator=() [1/2]

ServerWrapper & ivon::ServerWrapper::operator= ( const ServerWrapper )
delete

◆ operator=() [2/2]

ServerWrapper & ivon::ServerWrapper::operator= ( ServerWrapper &&  )
delete

◆ rotate_group_key()

std::optional< uint32_t > ivon::ServerWrapper::rotate_group_key ( const std::string &  group_id)
inlineoverridevirtual

Rotate the encryption key for a group.

Returns
The new epoch on success, std::nullopt on failure.

Implements ivon::IServer.

◆ run()

void ivon::ServerWrapper::run ( )
inlineoverridevirtual

Run the server (blocks until stop() is called from another thread).

Implements ivon::IServer.

◆ send_message_to_all() [1/2]

void ivon::ServerWrapper::send_message_to_all ( const std::string &  data_type,
const uint8_t *  data,
size_t  data_len 
)
inlineoverridevirtual

Broadcast a message from the server to all connected clients.

Implements ivon::IServer.

◆ send_message_to_all() [2/2]

void ivon::ServerWrapper::send_message_to_all ( const std::string &  data_type,
std::span< const uint8_t >  data 
)
inline

Convenience: broadcast to all from a span.

◆ send_message_to_client() [1/2]

void ivon::ServerWrapper::send_message_to_client ( const std::string &  client_id,
const std::string &  data_type,
const uint8_t *  data,
size_t  data_len 
)
inlineoverridevirtual

Send a message from the server to a specific client.

Implements ivon::IServer.

◆ send_message_to_client() [2/2]

void ivon::ServerWrapper::send_message_to_client ( const std::string &  client_id,
const std::string &  data_type,
std::span< const uint8_t >  data 
)
inline

Convenience: send to client from a span.

◆ send_message_to_group() [1/2]

void ivon::ServerWrapper::send_message_to_group ( const std::string &  group_id,
const std::string &  data_type,
const uint8_t *  data,
size_t  data_len 
)
inlineoverridevirtual

Send a message from the server to all members of a group.

Implements ivon::IServer.

◆ send_message_to_group() [2/2]

void ivon::ServerWrapper::send_message_to_group ( const std::string &  group_id,
const std::string &  data_type,
std::span< const uint8_t >  data 
)
inline

Convenience: send to group from a span.

◆ set_group_property()

void ivon::ServerWrapper::set_group_property ( const std::string &  group_id,
const std::string &  key,
const uint8_t *  value,
size_t  value_len 
)
inlineoverridevirtual

Set a group-level property (pushed to all group members).

Implements ivon::IServer.

◆ set_property()

void ivon::ServerWrapper::set_property ( const std::string &  key,
const uint8_t *  value,
size_t  value_len 
)
inlineoverridevirtual

Set a server-level property (pushed to all connected clients).

Implements ivon::IServer.

◆ stop()

void ivon::ServerWrapper::stop ( )
inlineoverridevirtual

Stop the server (thread-safe, causes run() to return).

Implements ivon::IServer.


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