Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Task/
RegisterTaskProvider.rs

1//! Register a Cocoon-contributed task provider in `ApplicationState`. The
2//! gRPC proto carries no handle, so we hash the task `type` string for
3//! the registration handle.
4
5use serde_json::json;
6use tonic::{Response, Status};
7use CommonLibrary::LanguageFeature::DTO::ProviderType::ProviderType;
8
9use crate::{
10	ApplicationState::DTO::ProviderRegistrationDTO::ProviderRegistrationDTO,
11	RPC::CocoonService::CocoonServiceImpl,
12	Vine::Generated::{Empty, RegisterTaskProviderRequest},
13	dev_log,
14};
15
16pub async fn Fn(Service:&CocoonServiceImpl, Request:RegisterTaskProviderRequest) -> Result<Response<Empty>, Status> {
17	dev_log!("cocoon", "[CocoonService] Registering Task Provider: type={}", Request.r#type);
18
19	let Handle = Request
20		.r#type
21		.as_bytes()
22		.iter()
23		.fold(0u32, |Acc, B| Acc.wrapping_mul(31).wrapping_add(*B as u32));
24
25	let DTO = ProviderRegistrationDTO {
26		Handle,
27
28		ProviderType:ProviderType::Task,
29
30		Selector:json!([{ "language": "*" }]),
31
32		SideCarIdentifier:"cocoon-main".to_string(),
33
34		ExtensionIdentifier:json!(Request.extension_id),
35
36		Options:Some(json!({ "type": Request.r#type })),
37	};
38
39	Service
40		.environment
41		.ApplicationState
42		.Extension
43		.ProviderRegistration
44		.RegisterProvider(Handle, DTO);
45
46	Ok(Response::new(Empty {}))
47}