Skip to main content

Mountain/RPC/CocoonService/Task/
RegisterTaskProvider.rs

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