mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-30 21:30:04 +00:00 
			
		
		
		
	web_service: stop using std::future + callback style async
This commit is contained in:
		
							parent
							
								
									0a4d338ffa
								
							
						
					
					
						commit
						77c1f647cb
					
				
					 23 changed files with 329 additions and 457 deletions
				
			
		|  | @ -21,7 +21,7 @@ static constexpr std::chrono::seconds announce_time_interval(15); | |||
| 
 | ||||
| AnnounceMultiplayerSession::AnnounceMultiplayerSession() { | ||||
| #ifdef ENABLE_WEB_SERVICE | ||||
|     backend = std::make_unique<WebService::RoomJson>(Settings::values.web_api_url + "/lobby", | ||||
|     backend = std::make_unique<WebService::RoomJson>(Settings::values.web_api_url, | ||||
|                                                      Settings::values.citra_username, | ||||
|                                                      Settings::values.citra_token); | ||||
| #else | ||||
|  | @ -87,22 +87,18 @@ void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() { | |||
|             backend->AddPlayer(member.nickname, member.mac_address, member.game_info.id, | ||||
|                                member.game_info.name); | ||||
|         } | ||||
|         future = backend->Announce(); | ||||
|         if (future.valid()) { | ||||
|             Common::WebResult result = future.get(); | ||||
|             if (result.result_code != Common::WebResult::Code::Success) { | ||||
|                 std::lock_guard<std::mutex> lock(callback_mutex); | ||||
|                 for (auto callback : error_callbacks) { | ||||
|                     (*callback)(result); | ||||
|                 } | ||||
|         Common::WebResult result = backend->Announce(); | ||||
|         if (result.result_code != Common::WebResult::Code::Success) { | ||||
|             std::lock_guard<std::mutex> lock(callback_mutex); | ||||
|             for (auto callback : error_callbacks) { | ||||
|                 (*callback)(result); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| std::future<AnnounceMultiplayerRoom::RoomList> AnnounceMultiplayerSession::GetRoomList( | ||||
|     std::function<void()> func) { | ||||
|     return backend->GetRoomList(func); | ||||
| AnnounceMultiplayerRoom::RoomList AnnounceMultiplayerSession::GetRoomList() { | ||||
|     return backend->GetRoomList(); | ||||
| } | ||||
| 
 | ||||
| } // namespace Core
 | ||||
|  |  | |||
|  | @ -54,7 +54,7 @@ public: | |||
|      * @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 | ||||
|      */ | ||||
|     std::future<AnnounceMultiplayerRoom::RoomList> GetRoomList(std::function<void()> func); | ||||
|     AnnounceMultiplayerRoom::RoomList GetRoomList(); | ||||
| 
 | ||||
| private: | ||||
|     Common::Event shutdown_event; | ||||
|  |  | |||
|  | @ -80,24 +80,20 @@ u64 RegenerateTelemetryId() { | |||
|     return new_telemetry_id; | ||||
| } | ||||
| 
 | ||||
| std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func) { | ||||
| bool VerifyLogin(std::string username, std::string token) { | ||||
| #ifdef ENABLE_WEB_SERVICE | ||||
|     return WebService::VerifyLogin(username, token, Settings::values.web_api_url + "/profile", | ||||
|                                    func); | ||||
|     return WebService::VerifyLogin(Settings::values.web_api_url, username, token); | ||||
| #else | ||||
|     return std::async(std::launch::async, [func{std::move(func)}]() { | ||||
|         func(); | ||||
|         return false; | ||||
|     }); | ||||
|     return false; | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| TelemetrySession::TelemetrySession() { | ||||
| #ifdef ENABLE_WEB_SERVICE | ||||
|     if (Settings::values.enable_telemetry) { | ||||
|         backend = std::make_unique<WebService::TelemetryJson>( | ||||
|             Settings::values.web_api_url + "/telemetry", Settings::values.citra_username, | ||||
|             Settings::values.citra_token); | ||||
|         backend = std::make_unique<WebService::TelemetryJson>(Settings::values.web_api_url, | ||||
|                                                               Settings::values.citra_username, | ||||
|                                                               Settings::values.citra_token); | ||||
|     } else { | ||||
|         backend = std::make_unique<Telemetry::NullVisitor>(); | ||||
|     } | ||||
|  |  | |||
|  | @ -4,7 +4,6 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <future> | ||||
| #include <memory> | ||||
| #include "common/telemetry.h" | ||||
| 
 | ||||
|  | @ -31,6 +30,8 @@ public: | |||
|         field_collection.AddField(type, name, std::move(value)); | ||||
|     } | ||||
| 
 | ||||
|     static void FinalizeAsyncJob(); | ||||
| 
 | ||||
| private: | ||||
|     Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session
 | ||||
|     std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields
 | ||||
|  | @ -55,6 +56,6 @@ u64 RegenerateTelemetryId(); | |||
|  * @param func A function that gets exectued when the verification is finished | ||||
|  * @returns Future with bool indicating whether the verification succeeded | ||||
|  */ | ||||
| std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func); | ||||
| bool VerifyLogin(std::string username, std::string token); | ||||
| 
 | ||||
| } // namespace Core
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue