-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e68b82d
commit 7d8b5fe
Showing
11 changed files
with
106 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use gamercade_interface::{ | ||
platform::{ | ||
platform_service_client::PlatformServiceClient, FrontPageRequest, GameSearchRequest, | ||
}, | ||
Session, | ||
}; | ||
use tokio::sync::OnceCell; | ||
use tonic::{transport::Channel, Request}; | ||
|
||
use crate::urls::{WithSession, SERVICE_IP_GRPC}; | ||
|
||
use super::{TaskManager, TaskNotification, TaskRequest}; | ||
|
||
pub type PlatformManager = TaskManager<PlatformManagerState, PlatformRequest>; | ||
|
||
async fn init_platform_client() -> PlatformServiceClient<Channel> { | ||
PlatformServiceClient::connect(SERVICE_IP_GRPC) | ||
.await | ||
.unwrap() | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct PlatformManagerState { | ||
client: OnceCell<PlatformServiceClient<Channel>>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum PlatformRequest { | ||
FrontPage(FrontPageRequest), | ||
Search(GameSearchRequest), | ||
} | ||
|
||
impl TaskRequest<PlatformManagerState> for PlatformRequest { | ||
async fn handle_request( | ||
self, | ||
sender: &tokio::sync::mpsc::Sender<super::TaskNotification>, | ||
state: &tokio::sync::Mutex<PlatformManagerState>, | ||
) { | ||
let mut lock = state.lock().await; | ||
lock.client.get_or_init(init_platform_client).await; | ||
let client = lock.client.get_mut().unwrap(); | ||
|
||
match self { | ||
PlatformRequest::FrontPage(request) => match client.front_page(request).await { | ||
Ok(response) => sender | ||
.try_send(TaskNotification::FrontPageResponse(response.into_inner())) | ||
.unwrap(), | ||
Err(err) => println!("front page response err: {err}"), | ||
}, | ||
PlatformRequest::Search(request) => todo!(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ impl TaskRequest<TagManagerState> for TagRequest { | |
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum TagRequest { | ||
Initialize, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters