fn paused(&mut self) -> StateMachine<Self> {
        match self.event_receiver.recv() {
            // Paused ---- Resume ----> Running
            Ok(VcpuEvent::Resume) => {
                // Nothing special to do.
                self.response_sender
                    .send(VcpuResponse::Resumed)
                    .expect("vcpu channel unexpectedly closed");
                // Move to 'running' state.
                StateMachine::next(Self::running)
            }
            Ok(VcpuEvent::Pause) => {
                self.response_sender
                    .send(VcpuResponse::Paused)
                    .expect("vcpu channel unexpectedly closed");
                StateMachine::next(Self::paused)
            }
            Ok(VcpuEvent::SaveState) => {
                // Save vcpu state.
                self.kvm_vcpu
                    .save_state()
                    .map(|vcpu_state| {
                        self.response_sender
                            .send(VcpuResponse::SavedState(Box::new(vcpu_state)))
                            .expect("vcpu channel unexpectedly closed");
                    })
                    .unwrap_or_else(|e| {
                        self.response_sender
                            .send(VcpuResponse::Error(Error::VcpuResponse(e)))
                            .expect("vcpu channel unexpectedly closed");
                    });

                StateMachine::next(Self::paused)
            }
            Ok(VcpuEvent::RestoreState(vcpu_state)) => {
                self.kvm_vcpu
                    .restore_state(&vcpu_state)
                    .map(|()| {
                        self.response_sender
                            .send(VcpuResponse::RestoredState)
                            .expect("vcpu channel unexpectedly closed");
                    })
                    .unwrap_or_else(|e| {
                        self.response_sender
                            .send(VcpuResponse::Error(Error::VcpuResponse(e)))
                            .expect("vcpu channel unexpectedly closed")
                    });

                StateMachine::next(Self::paused)
            }
            Ok(VcpuEvent::Finish) => StateMachine::finish(),
            // Unhandled exit of the other end.
            Err(_) => {
                // Move to 'exited' state.
                self.exit(FC_EXIT_CODE_GENERIC_ERROR)
            }
        }
    }
// This is the main loop of the `Paused` state.
This is the main loop of the `Paused` state.
This is the main loop of the ` Paused ` state .
fn paused(&mut self) -> StateMachine<Self> {
        match self.event_receiver.recv() {
            // Paused ---- Resume ----> Running
            Ok(VcpuEvent::Resume) => {
                // Nothing special to do.
                self.response_sender
                    .send(VcpuResponse::Resumed)
                    .expect("vcpu channel unexpectedly closed");
                // Move to 'running' state.
                StateMachine::next(Self::running)
            }
            Ok(VcpuEvent::Pause) => {
                self.response_sender
                    .send(VcpuResponse::Paused)
                    .expect("vcpu channel unexpectedly closed");
                StateMachine::next(Self::paused)
            }
            Ok(VcpuEvent::SaveState) => {
                // Save vcpu state.
                self.kvm_vcpu
                    .save_state()
                    .map(|vcpu_state| {
                        self.response_sender
                            .send(VcpuResponse::SavedState(Box::new(vcpu_state)))
                            .expect("vcpu channel unexpectedly closed");
                    })
                    .unwrap_or_else(|e| {
                        self.response_sender
                            .send(VcpuResponse::Error(Error::VcpuResponse(e)))
                            .expect("vcpu channel unexpectedly closed");
                    });
                StateMachine::next(Self::paused)
            }
            Ok(VcpuEvent::RestoreState(vcpu_state)) => {
                self.kvm_vcpu
                    .restore_state(&vcpu_state)
                    .map(|()| {
                        self.response_sender
                            .send(VcpuResponse::RestoredState)
                            .expect("vcpu channel unexpectedly closed");
                    })
                    .unwrap_or_else(|e| {
                        self.response_sender
                            .send(VcpuResponse::Error(Error::VcpuResponse(e)))
                            .expect("vcpu channel unexpectedly closed")
                    });
                StateMachine::next(Self::paused)
            }
            Ok(VcpuEvent::Finish) => StateMachine::finish(),
            // Unhandled exit of the other end.
            Err(_) => {
                // Move to 'exited' state.
                self.exit(FC_EXIT_CODE_GENERIC_ERROR)
            }
        }
    }
fn paused ( & mut self ) -> StateMachine < Self > { match self . event_receiver . recv ( ) { // Paused ---- Resume ----> Running Ok ( VcpuEvent :: Resume ) => { // Nothing special to do. self . response_sender . send ( VcpuResponse :: Resumed ) . expect ( " " ) ; // Move to 'running' state. StateMachine :: next ( Self :: running ) } Ok ( VcpuEvent :: Pause ) => { self . response_sender . send ( VcpuResponse :: Paused ) . expect ( " " ) ; StateMachine :: next ( Self :: paused ) } Ok ( VcpuEvent :: SaveState ) => { // Save vcpu state. self . kvm_vcpu . save_state ( ) . map ( | vcpu_state | { self . response_sender . send ( VcpuResponse :: SavedState ( Box :: new ( vcpu_state ) ) ) . expect ( " " ) ; } ) . unwrap_or_else ( | e | { self . response_sender . send ( VcpuResponse :: Error ( Error :: VcpuResponse ( e ) ) ) . expect ( " " ) ; } ) ; StateMachine :: next ( Self :: paused ) } Ok ( VcpuEvent :: RestoreState ( vcpu_state ) ) => { self . kvm_vcpu . restore_state ( & vcpu_state ) . map ( | ( ) | { self . response_sender . send ( VcpuResponse :: RestoredState ) . expect ( " " ) ; } ) . unwrap_or_else ( | e | { self . response_sender . send ( VcpuResponse :: Error ( Error :: VcpuResponse ( e ) ) ) . expect ( " " ) } ) ; StateMachine :: next ( Self :: paused ) } Ok ( VcpuEvent :: Finish ) => StateMachine :: finish ( ) , // Unhandled exit of the other end. Err ( _ ) => { // Move to 'exited' state. self . exit ( FC_EXIT_CODE_GENERIC_ERROR ) } } }
This is the main loop of the `Paused` state.
This is the main loop of the ` Paused ` state .
&mut self
&mut self