pub async fn run(self) -> Result<(), Error> {
        async fn perform(
            request: CoapRequest<SocketAddr>,
            mut in_send: mpsc::Sender<(SkillRegisterMessage, oneshot::Sender<Response>)>,
            pending_requests: &SharedPending<(
                Vec<PlainCapability>,
                oneshot::Sender<RequestResponse>,
            )>,
            pending_can_you: &SharedPending<f32>,
            current_skills: Arc<SyncMutex<HashMap<String, ()>>>,
            mut self_send: mpsc::Sender<(String, Vec<u8>)>,
        ) -> Option<CoapResponse> {
            match *request.get_method() {
                Method::Get => method_handlers::on_get(request, &mut in_send, current_skills).await,
                Method::Post => {
                    method_handlers::on_post(
                        request,
                        &mut in_send,
                        &mut self_send,
                        &current_skills,
                        pending_can_you,
                        pending_requests,
                    )
                    .await
                }
                Method::Delete => {
                    method_handlers::on_delete(request, &mut in_send, current_skills).await
                }
                Method::Put =>
                // Puts are needed so that an observe update is produced
                {
                    if request.get_path().starts_with("vap/skillRegistry/skill") {
                        respond(request.response, coap_lite::ResponseType::Valid, vec![])
                    }
                    else {
                        respond(request.response, coap_lite::ResponseType::MethodNotAllowed, vec![])
                    }
                }

                _ => {
                    println!("request by other method");
                    respond(
                        request.response,
                        coap_lite::ResponseType::MethodNotAllowed,
                        vec![],
                    )
                }
            }
        }

        let mut server = Server::new(&self.ip_address).unwrap();
        server.enable_all_coap(0);

        // The server is ready, we can start to send requests to itself
        // This is added because of an issue with the client trying to acces the
        // server too soon on Linux.
        self.barrier.wait();
        server
            .run(|request| {
                perform(
                    request,
                    self.in_send.clone(),
                    &self.pending_requests,
                    &self.pending_can_you,
                    self.current_skills.clone(),
                    self.self_send.clone(),
                )
            })
            .await
            .unwrap();
        Ok(())
    }
/// Call this function and await it for the rest of the program, this handles
/// sending and receiving messages from the skills. Stopping this means no more
/// communication, and even dropped channels.
Call this function and await it for the rest of the program, this handles
sending and receiving messages from the skills. Stopping this means no more
communication, and even dropped channels.
Call this function and await it for the rest of the program this handles sending and receiving messages from the skills . Stopping this means no more communication and even dropped channels .
pub async fn run(self) -> Result<(), Error> {
        async fn perform(
            request: CoapRequest<SocketAddr>,
            mut in_send: mpsc::Sender<(SkillRegisterMessage, oneshot::Sender<Response>)>,
            pending_requests: &SharedPending<(
                Vec<PlainCapability>,
                oneshot::Sender<RequestResponse>,
            )>,
            pending_can_you: &SharedPending<f32>,
            current_skills: Arc<SyncMutex<HashMap<String, ()>>>,
            mut self_send: mpsc::Sender<(String, Vec<u8>)>,
        ) -> Option<CoapResponse> {
            match *request.get_method() {
                Method::Get => method_handlers::on_get(request, &mut in_send, current_skills).await,
                Method::Post => {
                    method_handlers::on_post(
                        request,
                        &mut in_send,
                        &mut self_send,
                        &current_skills,
                        pending_can_you,
                        pending_requests,
                    )
                    .await
                }
                Method::Delete => {
                    method_handlers::on_delete(request, &mut in_send, current_skills).await
                }
                Method::Put =>
                // Puts are needed so that an observe update is produced
                {
                    if request.get_path().starts_with("vap/skillRegistry/skill") {
                        respond(request.response, coap_lite::ResponseType::Valid, vec![])
                    }
                    else {
                        respond(request.response, coap_lite::ResponseType::MethodNotAllowed, vec![])
                    }
                }
                _ => {
                    println!("request by other method");
                    respond(
                        request.response,
                        coap_lite::ResponseType::MethodNotAllowed,
                        vec![],
                    )
                }
            }
        }
        let mut server = Server::new(&self.ip_address).unwrap();
        server.enable_all_coap(0);
        // The server is ready, we can start to send requests to itself
        // This is added because of an issue with the client trying to acces the
        // server too soon on Linux.
        self.barrier.wait();
        server
            .run(|request| {
                perform(
                    request,
                    self.in_send.clone(),
                    &self.pending_requests,
                    &self.pending_can_you,
                    self.current_skills.clone(),
                    self.self_send.clone(),
                )
            })
            .await
            .unwrap();
        Ok(())
    }
pub async fn run ( self ) -> Result < ( ) , Error > { async fn perform ( request : CoapRequest < SocketAddr > , mut in_send : mpsc :: Sender < ( SkillRegisterMessage , oneshot :: Sender < Response > ) > , pending_requests : & SharedPending < ( Vec < PlainCapability > , oneshot :: Sender < RequestResponse > , ) > , pending_can_you : & SharedPending < f32 > , current_skills : Arc < SyncMutex < HashMap < String , ( ) > > > , mut self_send : mpsc :: Sender < ( String , Vec < u8 > ) > , ) -> Option < CoapResponse > { match * request . get_method ( ) { Method :: Get => method_handlers :: on_get ( request , & mut in_send , current_skills ) . await , Method :: Post => { method_handlers :: on_post ( request , & mut in_send , & mut self_send , & current_skills , pending_can_you , pending_requests , ) . await } Method :: Delete => { method_handlers :: on_delete ( request , & mut in_send , current_skills ) . await } Method :: Put => // Puts are needed so that an observe update is produced { if request . get_path ( ) . starts_with ( " " ) { respond ( request . response , coap_lite :: ResponseType :: Valid , vec ! [ ] ) } else { respond ( request . response , coap_lite :: ResponseType :: MethodNotAllowed , vec ! [ ] ) } } _ => { println ! ( " " ) ; respond ( request . response , coap_lite :: ResponseType :: MethodNotAllowed , vec ! [ ] , ) } } } let mut server = Server :: new ( & self . ip_address ) . unwrap ( ) ; server . enable_all_coap ( 0 ) ; // The server is ready, we can start to send requests to itself // This is added because of an issue with the client trying to acces the // server too soon on Linux. self . barrier . wait ( ) ; server . run ( | request | { perform ( request , self . in_send . clone ( ) , & self . pending_requests , & self . pending_can_you , self . current_skills . clone ( ) , self . self_send . clone ( ) , ) } ) . await . unwrap ( ) ; Ok ( ( ) ) }
Call this function and await it for the rest of the program, this handles
sending and receiving messages from the skills.
Call this function and await it for the rest of the program this handles sending and receiving messages from the skills .
self