Realm C++ SDK Version v2.2.0
Classes | Public Types | Public Member Functions | List of all members
realm::networking::sync_socket_provider Class Referenceabstract

#include <websocket.hpp>

Inheritance diagram for realm::networking::sync_socket_provider:
realm::networking::default_socket_provider

Classes

struct  timer
 

Public Types

using FunctionHandler = std::function< void(status)>
 Function handler typedef.
 
using sync_timer = std::unique_ptr< sync_socket_provider::timer >
 Other class typedefs.
 

Public Member Functions

virtual ~sync_socket_provider ()=default
 
virtual std::unique_ptr< websocket_interfaceconnect (std::unique_ptr< websocket_observer > observer, websocket_endpoint &&endpoint)=0
 
virtual void post (FunctionHandler &&handler)=0
 
virtual sync_timer create_timer (std::chrono::milliseconds delay, FunctionHandler &&handler)=0
 

Detailed Description

Sync Socket Provider interface that provides the event loop and WebSocket factory used by the SyncClient.

All callback and event operations in the SyncClient must be completed in the order in which they were issued (via post() or timer) to the event loop and cannot be run in parallel. It is up to the custom event loop implementation to determine if these are run on the same thread or a thread pool as long as it is guaranteed that the callback handler functions are processed in order and not run concurrently.

The implementation of a sync_socket_provider must support the following operations that post handler functions (via by the Sync client) onto the event loop:

The event loop is not required to be a single thread as long as the following requirements are satisfied:

The sync_socket_provider also provides a WebSocket interface for connecting to the server via a WebSocket connection.

Constructor & Destructor Documentation

◆ ~sync_socket_provider()

virtual realm::networking::sync_socket_provider::~sync_socket_provider ( )
virtualdefault

The event loop implementation must ensure the event loop is stopped and flushed when the object is destroyed. If the event loop is processed by a thread, the thread must be joined as part of this operation.

Member Function Documentation

◆ connect()

virtual std::unique_ptr< websocket_interface > realm::networking::sync_socket_provider::connect ( std::unique_ptr< websocket_observer observer,
websocket_endpoint &&  endpoint 
)
pure virtual

Create a new websocket pointed to the server indicated by endpoint and connect to the server. Any events that occur during the execution of the websocket will call directly to the handlers provided by the observer. The web_socket_observer guarantees that the WebSocket object will be closed/destroyed before the observer is terminated/destroyed.

Implemented in realm::networking::default_socket_provider.

◆ create_timer()

virtual sync_timer realm::networking::sync_socket_provider::create_timer ( std::chrono::milliseconds  delay,
FunctionHandler &&  handler 
)
pure virtual

Create and register a new timer whose handler function will be posted to the event loop when the provided delay expires.

This is a one shot timer and the Timer class returned becomes invalid once the timer has expired. A new timer will need to be created to wait again.

Parameters
delayThe duration to wait in ms before the timer expires.
handlerThe handler function to be called on the event loop when the timer expires.
Returns
A pointer to the Timer object that can be used to cancel the timer. The timer will also be canceled if the Timer object returned is destroyed.

Implemented in realm::networking::default_socket_provider.

◆ post()

virtual void realm::networking::sync_socket_provider::post ( FunctionHandler &&  handler)
pure virtual

Submit a handler function to be executed by the event loop (thread).

Register the specified handler function to be queued on the event loop for immediate asynchronous execution. The specified handler will be executed by an expression on the form handler(). If the the handler object is movable, it will never be copied. Otherwise, it will be copied as necessary.

This function is thread-safe and can be called by any thread. It can also be called from other post() handler function.

The handler will never be called as part of the execution of post(). If post() is called on a thread separate from the event loop, the handler may be called before post() returns.

Handler functions added through post() must be executed in the order they are added. More precisely, if post() is called twice to add two handlers, A and B, and the execution of post(A) ends before the beginning of the execution of post(B), then A is guaranteed to execute before B.

Parameters
handlerThe handler function to be queued on the event loop.

Implemented in realm::networking::default_socket_provider.


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