score/message_passing/i_server.h
Line | Count | Source |
1 | | /******************************************************************************** |
2 | | * Copyright (c) 2025 Contributors to the Eclipse Foundation |
3 | | * |
4 | | * See the NOTICE file(s) distributed with this work for additional |
5 | | * information regarding copyright ownership. |
6 | | * |
7 | | * This program and the accompanying materials are made available under the |
8 | | * terms of the Apache License Version 2.0 which is available at |
9 | | * https://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * SPDX-License-Identifier: Apache-2.0 |
12 | | ********************************************************************************/ |
13 | | #ifndef SCORE_LIB_MESSAGE_PASSING_I_SERVER_H |
14 | | #define SCORE_LIB_MESSAGE_PASSING_I_SERVER_H |
15 | | |
16 | | #include "score/message_passing/server_types.h" |
17 | | |
18 | | #include "score/os/errno.h" |
19 | | |
20 | | namespace score::message_passing |
21 | | { |
22 | | |
23 | | /// \brief Interface of a Message Passing Server. |
24 | | /// \details The interface is providing the server side of asynchronous client-server IPC communication. |
25 | | /// One server can communicate with multiple clients, each in its own associated session. Multiple |
26 | | /// sessions from multiple clients per one client process (pid) toward the same server are possible. |
27 | | /// The callbacks are called on unspecified threads, but it's guaranteed that all the callbacks belonging to |
28 | | /// the same session are serialized. |
29 | | class IServer |
30 | | { |
31 | | public: |
32 | 227 | virtual ~IServer() = default; |
33 | | |
34 | | /// \brief An IServer shall not be copyable or movable |
35 | | IServer(const IServer&) = delete; |
36 | | IServer(IServer&&) = delete; |
37 | | IServer& operator=(const IServer&) = delete; |
38 | | IServer& operator=(IServer&&) = delete; |
39 | | |
40 | | /// \brief Sets up the callbacks for connection, disconnection and message reception notifications. |
41 | | /// \details The callbacks lifetime (or rather the lifetime of the system state captured in the callbacks by |
42 | | /// reference) needs to end not earlier than after StopListening() (or the destructor) has returned. |
43 | | /// The callbacks other than the ConnectCallback are only used for the connections where UserData |
44 | | /// is not an instance of score::cpp::pmr::unique_ptr<IConnectionHandler>. |
45 | | /// For score::cpp::pmr::unique_ptr<IConnectionHandler> connection, the corresponding IConnectionHandler's |
46 | | /// callback methods are used instead. |
47 | | // NOLINTNEXTLINE(google-default-arguments) TODO: |
48 | | virtual score::cpp::expected_blank<score::os::Error> StartListening( |
49 | | ConnectCallback connect_callback, |
50 | | DisconnectCallback disconnect_callback = DisconnectCallback{}, |
51 | | MessageCallback sent_callback = MessageCallback{}, |
52 | | MessageCallback sent_with_reply_callback = MessageCallback{}) noexcept = 0; |
53 | | /// \brief Releases the callbacks abd closes all the still running server connections. |
54 | | /// \details The resources associated with the callbacks can be released/reused after the function returns. |
55 | | /// The function may block until a currently running callback finishes, so it shall not be called from |
56 | | /// any of the server callbacks. |
57 | | virtual void StopListening() noexcept = 0; |
58 | | |
59 | | protected: |
60 | 229 | IServer() noexcept = default; |
61 | | }; |
62 | | |
63 | | } // namespace score::message_passing |
64 | | |
65 | | #endif // SCORE_LIB_MESSAGE_PASSING_I_SERVER_H |