aboutsummaryrefslogtreecommitdiff
path: root/include/client/web_socket_client.hpp
blob: f676e59f6ac93689036c4daed5c97e5c382b9bd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include <functional>
#include <string>

namespace client
{
/**
 * @brief An interface for a WebSocket client singleton.
 */
class IWebSocketClient
{
public:
    /**
     * @brief Starts the client.
     * @remark This method must be called before any other client methods.
     */
    virtual void start() = 0;

    /**
     * @brief Stops the client.
     * @remark This method should be called when the client is no longer needed, before it is
     * destroyed.
     */
    virtual void stop() = 0;

    /**
     * @brief Opens a connection to the given server.
     */
    virtual void openConnection(std::string uri) = 0;

    /**
     * @brief Indicates whether the client is connected to the given server.
     * @returns True if the client is connected, false otherwise.
     */
    virtual bool isConnected(std::string uri) = 0;

    /**
     * @brief Sends the given message to the given server.
     * @returns A tuple indicating the server URI and whether the message was successfully
     * sent.
     */
    virtual std::tuple<std::string, bool> send(std::string message, std::string uri) = 0;

    /**
     * @brief Sets up a message handler for the given server.
     * @param uri The URI of the server to which the message handler should be attached.
     * @param messageHandler A callable object that will be invoked with the subscription ID and
     * the message contents when the client receives a message from the server.
     */
    virtual void receive(std::string uri, std::function<void(const std::string&, const std::string&)> messageHandler) = 0;

    /**
     * @brief Closes the connection to the given server.
     */
    virtual void closeConnection(std::string uri) = 0;
};
} // namespace client