async fn handle_new_client(
        &self,
        proxy: fthermal::ActorProxy,
        actor_type: fthermal::ActorType,
        trip_points: Vec<u32>,
    ) -> Result<(), fthermal::Error> {
        // TODO(fxb/44484): These strings must live for the duration of the function because the
        // trace macro uses them when the function goes out of scope. Therefore, they must be bound
        // here and not used anonymously at the macro callsite.
        let actor_type_str = format!("{:?}", actor_type);
        let trip_points_str = format!("{:?}", trip_points);
        fuchsia_trace::duration!(
            "power_manager",
            "ThermalLimiter::handle_new_client",
            "proxy" => proxy.as_handle_ref().raw_handle(),
            "actor_type" => actor_type_str.as_str(),
            "trip_points" => trip_points_str.as_str()
        );
        // trip_points must:
        //  - have length in the range [1 - MAX_TRIP_POINT_COUNT]
        //  - have values in the range [1 - MAX_THERMAL_LOAD]
        //  - be monotonically increasing
        let trip_points_len = trip_points.len() as u32;
        if trip_points_len < 1
            || trip_points_len > fthermal::MAX_TRIP_POINT_COUNT
            || !trip_points.windows(2).all(|w| w[0] < w[1])
            || *trip_points.first().unwrap() < 1
            || *trip_points.last().unwrap() > MAX_THERMAL_LOAD.0
        {
            return Err(fthermal::Error::InvalidArguments);
        }

        // Convert trip_points from Vec<u32> to Vec<ThermalLoad>
        let trip_points = trip_points.into_iter().map(ThermalLoad).collect();

        let mut client =
            ClientEntry::new(proxy, actor_type, trip_points, self.inspect.create_client_node());

        // Update the client state based on our last cached thermal load
        client.update_state(self.thermal_load.get());

        // Make a copy of the ClientEntry's proxy and state before ownership is moved into the
        // `clients` vector.
        let proxy = client.proxy.clone();
        let state = client.current_state;

        // Add the new client entry to the client list
        self.clients.borrow_mut().push(client);

        // Send the initial thermal state update to the client
        self.send_thermal_state(proxy, state);

        Ok(())
    }
/// Handle a new client connection. Called each time a client makes the Subscribe call.
Handle a new client connection. Called each time a client makes the Subscribe call.
Handle a new client connection . Called each time a client makes the Subscribe call .
async fn handle_new_client(
        &self,
        proxy: fthermal::ActorProxy,
        actor_type: fthermal::ActorType,
        trip_points: Vec<u32>,
    ) -> Result<(), fthermal::Error> {
        // TODO(fxb/44484): These strings must live for the duration of the function because the
        // trace macro uses them when the function goes out of scope. Therefore, they must be bound
        // here and not used anonymously at the macro callsite.
        let actor_type_str = format!("{:?}", actor_type);
        let trip_points_str = format!("{:?}", trip_points);
        fuchsia_trace::duration!(
            "power_manager",
            "ThermalLimiter::handle_new_client",
            "proxy" => proxy.as_handle_ref().raw_handle(),
            "actor_type" => actor_type_str.as_str(),
            "trip_points" => trip_points_str.as_str()
        );
        // trip_points must:
        //  - have length in the range [1 - MAX_TRIP_POINT_COUNT]
        //  - have values in the range [1 - MAX_THERMAL_LOAD]
        //  - be monotonically increasing
        let trip_points_len = trip_points.len() as u32;
        if trip_points_len < 1
            || trip_points_len > fthermal::MAX_TRIP_POINT_COUNT
            || !trip_points.windows(2).all(|w| w[0] < w[1])
            || *trip_points.first().unwrap() < 1
            || *trip_points.last().unwrap() > MAX_THERMAL_LOAD.0
        {
            return Err(fthermal::Error::InvalidArguments);
        }
        // Convert trip_points from Vec<u32> to Vec<ThermalLoad>
        let trip_points = trip_points.into_iter().map(ThermalLoad).collect();
        let mut client =
            ClientEntry::new(proxy, actor_type, trip_points, self.inspect.create_client_node());
        // Update the client state based on our last cached thermal load
        client.update_state(self.thermal_load.get());
        // Make a copy of the ClientEntry's proxy and state before ownership is moved into the
        // `clients` vector.
        let proxy = client.proxy.clone();
        let state = client.current_state;
        // Add the new client entry to the client list
        self.clients.borrow_mut().push(client);
        // Send the initial thermal state update to the client
        self.send_thermal_state(proxy, state);
        Ok(())
    }
async fn handle_new_client ( & self , proxy : fthermal :: ActorProxy , actor_type : fthermal :: ActorType , trip_points : Vec < u32 > , ) -> Result < ( ) , fthermal :: Error > { // TODO(fxb/44484): These strings must live for the duration of the function because the // trace macro uses them when the function goes out of scope. Therefore, they must be bound // here and not used anonymously at the macro callsite. let actor_type_str = format ! ( " " actor_type ) ; let trip_points_str = format ! ( " " trip_points ) ; fuchsia_trace :: duration ! ( " " " " " " proxy as_handle_ref ( ) raw_handle ( ) " " actor_type_str as_str ( ) " " trip_points_str as_str ( ) ) ; // trip_points must: //  - have length in the range [1 - MAX_TRIP_POINT_COUNT] //  - have values in the range [1 - MAX_THERMAL_LOAD] //  - be monotonically increasing let trip_points_len = trip_points . len ( ) as u32 ; if trip_points_len < 1 || trip_points_len > fthermal :: MAX_TRIP_POINT_COUNT || ! trip_points . windows ( 2 ) . all ( | w | w [ 0 ] < w [ 1 ] ) || * trip_points . first ( ) . unwrap ( ) < 1 || * trip_points . last ( ) . unwrap ( ) > MAX_THERMAL_LOAD . 0 { return Err ( fthermal :: Error :: InvalidArguments ) ; } // Convert trip_points from Vec<u32> to Vec<ThermalLoad> let trip_points = trip_points . into_iter ( ) . map ( ThermalLoad ) . collect ( ) ; let mut client = ClientEntry :: new ( proxy , actor_type , trip_points , self . inspect . create_client_node ( ) ) ; // Update the client state based on our last cached thermal load client . update_state ( self . thermal_load . get ( ) ) ; // Make a copy of the ClientEntry's proxy and state before ownership is moved into the // `clients` vector. let proxy = client . proxy . clone ( ) ; let state = client . current_state ; // Add the new client entry to the client list self . clients . borrow_mut ( ) . push ( client ) ; // Send the initial thermal state update to the client self . send_thermal_state ( proxy , state ) ; Ok ( ( ) ) }
Handle a new client connection.
Handle a new client connection .
&self
proxy
fthermal::ActorProxy
actor_type
fthermal::ActorType
trip_points
Vec<u32>
&self
proxy
fthermal::ActorProxy
actor_type
fthermal::ActorType
trip_points
Vec<u32>