/// Create a new session context for a given service and session IDs.
Create a new session context for a given service and session IDs.
Create a new session context for a given service and session IDs .
fn create_session_context(
        &mut self, 
        service_id: u16, 
        session_id: u32, 
        event_loop: &mut EventLoop<Self>) -> Option<&mut SessionContext<L>> {
        if !self.sessions.contains_key(&session_id) {
            let app_context = self.app_context.lock()
                .unwrap();
            let config = &app_context.config;
            if let Some(svc) = config.get(service_id) {
                if let Some(addr) = svc.address() {
                    log_info!(self.logger, "connecting to remote service: {}, service ID: {:04x}, session ID: {:08x}", addr, service_id, session_id);
                    match SessionContext::new(self.logger.clone(),
                        service_id, session_id, addr, event_loop) {
                        Err(err) => log_warn!(self.logger, "unable to open connection to a remote service (address: {}, service ID: {:04x}, session ID: {:08x}): {}", addr, service_id, session_id, err.description()),
                        Ok(ctx)  => {
                            let token_id = session2token(session_id);
                            let tevent   = TimerEvent::TimeoutCheck(token_id);
                            self.sessions.insert(session_id, ctx);
                            self.session_queue.push_back(session_id);
                            event_loop.timeout_ms(tevent, TIMEOUT_CHECK_PERIOD)
                                .unwrap();
                        }
                    }
                } else {
                    log_warn!(self.logger, "requested service ID belongs to a Control Protocol service (session ID: {:08x})", session_id);
                }
            } else {
                log_warn!(self.logger, "non-existing service requested (service ID: {}, session ID: {:08x})", service_id, session_id);
            }
        }
        self.sessions.get_mut(&session_id)
    }
fn create_session_context ( & mut self , service_id : u16 , session_id : u32 , event_loop : & mut EventLoop < Self > ) -> Option < & mut SessionContext < L > > { if ! self . sessions . contains_key ( & session_id ) { let app_context = self . app_context . lock ( ) . unwrap ( ) ; let config = & app_context . config ; if let Some ( svc ) = config . get ( service_id ) { if let Some ( addr ) = svc . address ( ) { log_info ! ( self logger " " addr service_id session_id ) ; match SessionContext :: new ( self . logger . clone ( ) , service_id , session_id , addr , event_loop ) { Err ( err ) => log_warn ! ( self logger " " addr service_id session_id err description ( ) ) , Ok ( ctx ) => { let token_id = session2token ( session_id ) ; let tevent = TimerEvent :: TimeoutCheck ( token_id ) ; self . sessions . insert ( session_id , ctx ) ; self . session_queue . push_back ( session_id ) ; event_loop . timeout_ms ( tevent , TIMEOUT_CHECK_PERIOD ) . unwrap ( ) ; } } } else { log_warn ! ( self logger " " session_id ) ; } } else { log_warn ! ( self logger " " service_id session_id ) ; } } self . sessions . get_mut ( & session_id ) }
Create a new session context for a given service and session IDs.
Create a new session context for a given service and session IDs .
&mut self
service_id
u16
session_id
u32
event_loop
&mut EventLoop<Self>