Cute   Learning Hub


  • RemoteObject
  • RemoteObject Class

    class Cute::Client::RemoteObject

    The Cute::Client::RemoteObject class acts as a proxy to a remote object exposed by a server and abstracts away from clients that they are interacting over a network. More...

    Header: #include <CuteClient.h>

    Public Functions

    RemoteObject(const char *className, const QUrl &remoteObjectUrl, const QVariant &sessionData = QVariant(), const QSslConfiguration &sslConfiguration = QSslConfiguration::defaultConfiguration(), const QNetworkProxy &networkProxy = QNetworkProxy::applicationProxy(), const bool exclusiveWebSocketConnection = false)
    virtual ~RemoteObject() override
    QSharedPointer<Cute::Client::IRemoteSlotResponse> callRemoteSlot(const char *remoteSlotName, RemoteSlotArgs... args)

    Signals

    void connected()
    void error(Cute::ErrorInfo errorInfo)

    Static Public Members

    QSharedPointer<Cute::Client::IRemoteObjectConnection> connect(QObject *sender, const char *signal, Cute::Client::RemoteObject *receiver, const char *remoteSlot)
    QSharedPointer<Cute::Client::IRemoteObjectConnection> connect(Cute::Client::RemoteObject *sender, const char *remoteSignal, QObject *receiver, const char *slot)
    void disconnect(QObject *sender, const char *signal, Cute::Client::RemoteObject *receiver, const char *remoteSlot)
    void disconnect(Cute::Client::RemoteObject *sender, const char *remoteSignal, QObject *receiver, const char *slot)

    Detailed Description

    All methods in this class are reentrant.

    The RemoteObject class is the main class used in client-side programming. The RemoteObject abstracts away from clients that they are interacting over a network. The RemoteObject class creates an instance on the server and acts as a proxy to the created instance, enabling clients to interact to remote signals and slots as if they were local and belonged to the RemoteObject class instead. Clients can also call remote slots directly.

    Network interactions are asynchronous by nature. The RemoteObject class emits the connected signal after creating the remote object on the server. If the RemoteObject class fails to instantiate the remote object on the server, it emits the error signal instead.

    Clients can call remote slots and establish remote signal-slot connections before the RemoteObject class emits the connected signal. The RemoteObject class queues all remote slot calls and connections to remote signals/slots and performs them after it instantiates the object on the server.

    Whenever the RemoteObject class reports an error, all connections and calls to remote slots for the RemoteObject class object should be considered invalid. In this case, the queued remote slot calls and remote signal-slot connections will not report any errors. They only report errors specific to the respective call/connection they represent.

    Member Function Documentation

    [default] RemoteObject::RemoteObject(const char *className, const QUrl &remoteObjectUrl, const QVariant &sessionData = QVariant(), const QSslConfiguration &sslConfiguration = QSslConfiguration::defaultConfiguration(), const QNetworkProxy &networkProxy = QNetworkProxy::applicationProxy(), const bool exclusiveWebSocketConnection = false)

    Constructs the className remote object class, exposed at the remoteObjectUrl endpoint on the server. The RemoteObject class passes the sessionData to the remote object created on the server, allowing clients to send authentication information to the server.

    If the sslConfiguration argument is different from the default value, the connection is encrypted. The networkProxy argument specifies the proxy configuration if clients connect to the network through a proxy.

    If exclusiveWebSocketConnection is false, the default value, all remote objects created with the same URL host, port, SSL configuration, and network proxy settings, shares the same WebSocket connection. Otherwise, if exclusiveWebSocketConnection is true, an exclusive WebSocket connection is created for the remote object.

    [signal] void RemoteObject::connected()

    This signal is emitted after the connection has been successfully established.

    [signal] void RemoteObject::error(Cute::ErrorInfo errorInfo)

    This signal is emitted after an error occurred. The errorInfo parameter describes the type of error that occurred.

    [override virtual] RemoteObject::~RemoteObject()

    Destroys the object. All connections to the remote object are disconnected and the network connection to the server is terminated if this is the last remote object on the WebSocket connection.

    template <typename RemoteSlotArgs> QSharedPointer<Cute::Client::IRemoteSlotResponse> RemoteObject::callRemoteSlot(const char *remoteSlotName, RemoteSlotArgs... args)

    Calls the remoteSlotName remote slot with args arguments. Information regarding the call can be obtained by the returned response.

    The returned value informs clients when the remote slot responds or if the remote slot call failed.

    [static] QSharedPointer<Cute::Client::IRemoteObjectConnection> RemoteObject::connect(QObject *sender, const char *signal, Cute::Client::RemoteObject *receiver, const char *remoteSlot)

    Initiates a remote connection from the signal in the sender object to the remoteSlot in the remote object depicted by the receiver object. Clients must enclose the signal and remote slot signatures using the SIGNAL and SLOT macros.

    The returned value allows clients to take action when they connect to the remote slot or disconnect from it. Clients can also take action if errors occur while connecting to the remote slot.

    [static] QSharedPointer<Cute::Client::IRemoteObjectConnection> RemoteObject::connect(Cute::Client::RemoteObject *sender, const char *remoteSignal, QObject *receiver, const char *slot)

    Initiates a remote connection from the remoteSignal in the remote object depicted by sender to the slot in the receiver object. Clients must enclose the remote signal and slot signatures using the SIGNAL and SLOT macros.

    The returned value allows clients to take action when they connect to the remote signal or disconnect from it. Clients can also take action if errors occur while connecting to the remote signal.

    [static] void RemoteObject::disconnect(QObject *sender, const char *signal, Cute::Client::RemoteObject *receiver, const char *remoteSlot)

    Removes all remote connections from the signal in the sender object to the remoteSlot in the remote object depicted by the receiver object. Clients must enclose the signal and remote slot signatures using the SIGNAL and SLOT macros.

    [static] void RemoteObject::disconnect(Cute::Client::RemoteObject *sender, const char *remoteSignal, QObject *receiver, const char *slot)

    Removes all remote connections from the remoteSignal in the remote object depicted by the sender object to the slot in the receiver object. Clients must enclose the remote signal and slot signatures using the SIGNAL and SLOT macros.