2017-10-31 14:32:42 +05:30
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-10-27 13:10:15 +05:30
|
|
|
#include <atomic>
|
2017-10-31 14:32:42 +05:30
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2017-11-08 02:21:11 +05:30
|
|
|
#include <mutex>
|
2017-10-31 14:32:42 +05:30
|
|
|
#include <set>
|
|
|
|
#include <thread>
|
|
|
|
#include "common/announce_multiplayer_room.h"
|
|
|
|
#include "common/common_types.h"
|
2017-11-11 00:07:26 +05:30
|
|
|
#include "common/thread.h"
|
2017-10-31 14:32:42 +05:30
|
|
|
|
2018-10-27 13:10:15 +05:30
|
|
|
namespace Network {
|
|
|
|
class Room;
|
|
|
|
}
|
|
|
|
|
2017-10-31 14:32:42 +05:30
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instruments AnnounceMultiplayerRoom::Backend.
|
|
|
|
* Creates a thread that regularly updates the room information and submits them
|
|
|
|
* An async get of room information is also possible
|
|
|
|
*/
|
|
|
|
class AnnounceMultiplayerSession : NonCopyable {
|
|
|
|
public:
|
2017-11-08 02:21:11 +05:30
|
|
|
using CallbackHandle = std::shared_ptr<std::function<void(const Common::WebResult&)>>;
|
2017-10-31 14:32:42 +05:30
|
|
|
AnnounceMultiplayerSession();
|
|
|
|
~AnnounceMultiplayerSession();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows to bind a function that will get called if the announce encounters an error
|
|
|
|
* @param function The function that gets called
|
|
|
|
* @return A handle that can be used the unbind the function
|
|
|
|
*/
|
2017-11-08 02:21:11 +05:30
|
|
|
CallbackHandle BindErrorCallback(std::function<void(const Common::WebResult&)> function);
|
2017-10-31 14:32:42 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind a function from the error callbacks
|
|
|
|
* @param handle The handle for the function that should get unbind
|
|
|
|
*/
|
2017-11-08 02:21:11 +05:30
|
|
|
void UnbindErrorCallback(CallbackHandle handle);
|
2017-10-31 14:32:42 +05:30
|
|
|
|
2018-10-27 13:10:15 +05:30
|
|
|
/// Registers a room to web services
|
|
|
|
void Register();
|
|
|
|
|
2017-10-31 14:32:42 +05:30
|
|
|
/**
|
|
|
|
* Starts the announce of a room to web services
|
|
|
|
*/
|
|
|
|
void Start();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the announce to web services
|
|
|
|
*/
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of all room information the backend got
|
|
|
|
* @param func A function that gets executed when the async get finished, e.g. a signal
|
|
|
|
* @return a list of rooms received from the web service
|
|
|
|
*/
|
2018-09-12 21:52:48 +05:30
|
|
|
AnnounceMultiplayerRoom::RoomList GetRoomList();
|
2017-10-31 14:32:42 +05:30
|
|
|
|
|
|
|
private:
|
2017-11-11 00:07:26 +05:30
|
|
|
Common::Event shutdown_event;
|
2017-10-31 14:32:42 +05:30
|
|
|
std::mutex callback_mutex;
|
2017-11-08 02:21:11 +05:30
|
|
|
std::set<CallbackHandle> error_callbacks;
|
2017-10-31 14:32:42 +05:30
|
|
|
std::unique_ptr<std::thread> announce_multiplayer_thread;
|
|
|
|
|
2017-11-08 02:21:11 +05:30
|
|
|
/// Backend interface that logs fields
|
|
|
|
std::unique_ptr<AnnounceMultiplayerRoom::Backend> backend;
|
2017-10-31 14:32:42 +05:30
|
|
|
|
2018-10-27 13:10:15 +05:30
|
|
|
std::atomic_bool registered = false; ///< Whether the room has been registered
|
|
|
|
|
|
|
|
void UpdateBackendData(std::shared_ptr<Network::Room> room);
|
2017-10-31 14:32:42 +05:30
|
|
|
void AnnounceMultiplayerLoop();
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Core
|