diff options
| author | 2022-08-16 23:13:05 +0200 | |
|---|---|---|
| committer | 2022-08-27 03:02:21 +0200 | |
| commit | b904652d69fb3d3bf1918a7dd7f04bc049c9f460 (patch) | |
| tree | 4a252395a2a51d8998ef088e446c1f9a7f238aa3 /src/network/announce_multiplayer_session.h | |
| parent | Merge pull request #8566 from german77/galaxy (diff) | |
| download | yuzu-b904652d69fb3d3bf1918a7dd7f04bc049c9f460.tar.gz yuzu-b904652d69fb3d3bf1918a7dd7f04bc049c9f460.tar.xz yuzu-b904652d69fb3d3bf1918a7dd7f04bc049c9f460.zip | |
yuzu_room: Remove dependency on core
Diffstat (limited to 'src/network/announce_multiplayer_session.h')
| -rw-r--r-- | src/network/announce_multiplayer_session.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/network/announce_multiplayer_session.h b/src/network/announce_multiplayer_session.h new file mode 100644 index 000000000..db790f7d2 --- /dev/null +++ b/src/network/announce_multiplayer_session.h | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2017 Citra Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <atomic> | ||
| 7 | #include <functional> | ||
| 8 | #include <memory> | ||
| 9 | #include <mutex> | ||
| 10 | #include <set> | ||
| 11 | #include <thread> | ||
| 12 | #include "common/announce_multiplayer_room.h" | ||
| 13 | #include "common/common_types.h" | ||
| 14 | #include "common/thread.h" | ||
| 15 | |||
| 16 | namespace Network { | ||
| 17 | class Room; | ||
| 18 | class RoomNetwork; | ||
| 19 | } // namespace Network | ||
| 20 | |||
| 21 | namespace Core { | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Instruments AnnounceMultiplayerRoom::Backend. | ||
| 25 | * Creates a thread that regularly updates the room information and submits them | ||
| 26 | * An async get of room information is also possible | ||
| 27 | */ | ||
| 28 | class AnnounceMultiplayerSession { | ||
| 29 | public: | ||
| 30 | using CallbackHandle = std::shared_ptr<std::function<void(const WebService::WebResult&)>>; | ||
| 31 | AnnounceMultiplayerSession(Network::RoomNetwork& room_network_); | ||
| 32 | ~AnnounceMultiplayerSession(); | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Allows to bind a function that will get called if the announce encounters an error | ||
| 36 | * @param function The function that gets called | ||
| 37 | * @return A handle that can be used the unbind the function | ||
| 38 | */ | ||
| 39 | CallbackHandle BindErrorCallback(std::function<void(const WebService::WebResult&)> function); | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Unbind a function from the error callbacks | ||
| 43 | * @param handle The handle for the function that should get unbind | ||
| 44 | */ | ||
| 45 | void UnbindErrorCallback(CallbackHandle handle); | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Registers a room to web services | ||
| 49 | * @return The result of the registration attempt. | ||
| 50 | */ | ||
| 51 | WebService::WebResult Register(); | ||
| 52 | |||
| 53 | /** | ||
| 54 | * Starts the announce of a room to web services | ||
| 55 | */ | ||
| 56 | void Start(); | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Stops the announce to web services | ||
| 60 | */ | ||
| 61 | void Stop(); | ||
| 62 | |||
| 63 | /** | ||
| 64 | * Returns a list of all room information the backend got | ||
| 65 | * @param func A function that gets executed when the async get finished, e.g. a signal | ||
| 66 | * @return a list of rooms received from the web service | ||
| 67 | */ | ||
| 68 | AnnounceMultiplayerRoom::RoomList GetRoomList(); | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Whether the announce session is still running | ||
| 72 | */ | ||
| 73 | bool IsRunning() const; | ||
| 74 | |||
| 75 | /** | ||
| 76 | * Recreates the backend, updating the credentials. | ||
| 77 | * This can only be used when the announce session is not running. | ||
| 78 | */ | ||
| 79 | void UpdateCredentials(); | ||
| 80 | |||
| 81 | private: | ||
| 82 | void UpdateBackendData(std::shared_ptr<Network::Room> room); | ||
| 83 | void AnnounceMultiplayerLoop(); | ||
| 84 | |||
| 85 | Common::Event shutdown_event; | ||
| 86 | std::mutex callback_mutex; | ||
| 87 | std::set<CallbackHandle> error_callbacks; | ||
| 88 | std::unique_ptr<std::thread> announce_multiplayer_thread; | ||
| 89 | |||
| 90 | /// Backend interface that logs fields | ||
| 91 | std::unique_ptr<AnnounceMultiplayerRoom::Backend> backend; | ||
| 92 | |||
| 93 | std::atomic_bool registered = false; ///< Whether the room has been registered | ||
| 94 | |||
| 95 | Network::RoomNetwork& room_network; | ||
| 96 | }; | ||
| 97 | |||
| 98 | } // namespace Core | ||