Пример #1
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
        /// <summary>
        /// Start the session, if possible.
        /// </summary>
        private void HandleSessionStart()
        {
            // Check if the KCD has already sent us the end session event.
            if (SessionIDTree.ContainsKey(SessionID))
            {
                HandleSessionTrouble(new Exception("the KCD closed the connection unexpectedly"));
                return;
            }

            // Clear the session ID tree.
            SessionIDTree.Clear();

            // Show the overlay window.
            Overlay = new RunningOverlay();
            Overlay.Relink(this);

            // Configure the inactivity monitor to timeout about 10 minutes.
            InactivityMonitor = MonitorCreator.CreateInstance(MonitorType.GlobalHookMonitor);
            InactivityMonitor.MonitorKeyboardEvents = true;
            InactivityMonitor.MonitorMouseEvents    = true;
            InactivityMonitor.Interval = 600000;
            InactivityMonitor.Elapsed += delegate(Object sender, ElapsedEventArgs args)
            {
                KBase.ExecInUI(OnInactivity);
            };
            InactivityMonitor.Enabled = true;

            // Start the session.
            Status = VncSessionStatus.Started;

            // Notify listeners.
            PostLocalVncSessionEvent(true, null);

            Kws.OnStateChange(WmStateChange.Transient);
        }
Пример #2
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
        /// <summary>
        /// Clean up the state when the session has completed to avoid resource
        /// leaks. This object CANNOT be reused for another session since some
        /// recently cancelled threads may still reference the object and try
        /// to modify its state.
        /// </summary>
        private void Terminate()
        {
            Status = VncSessionStatus.Completed;
            AppVnc.SessionPresentFlag = false;
            App.LocalSession          = null;

            if (Overlay != null)
            {
                Overlay.Terminate();
                Overlay = null;
            }

            if (TicketQuery != null)
            {
                TicketQuery.Terminate();
                TicketQuery = null;
            }

            if (Tunnel != null)
            {
                Tunnel.Terminate();
                Tunnel = null;
            }

            if (TunnelThread != null)
            {
                TunnelThread.RequestCancellation();
                TunnelThread = null;
            }

            if (MainProcess != null)
            {
                MainProcess.Terminate();
                MainProcess = null;
            }

            if (DummyProcess != null)
            {
                DummyProcess.Terminate();
                DummyProcess = null;
            }

            if (Timer != null)
            {
                Timer.WakeMeUp(-1);
                Timer = null;
            }

            if (InactivityMonitor != null)
            {
                InactivityMonitor.Enabled = false;
                InactivityMonitor.Dispose();
                InactivityMonitor = null;
            }
        }
Пример #3
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
        /// <summary>
        /// Request a ticket to the server.
        /// </summary>
        private void RequestTicket()
        {
            Status = VncSessionStatus.Ticket;
            UInt32 t = ServerSessionFlag ? KAnp.KANP_CMD_VNC_START_TICKET : KAnp.KANP_CMD_VNC_CONNECT_TICKET;
            AnpMsg m = Kws.NewKcdCmd(t);

            if (!ServerSessionFlag)
            {
                m.AddUInt64(SessionID);
            }
            TicketQuery = Kws.PostKcdCmd(m, OnTicketReply);
        }
Пример #4
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
        /// <summary>
        /// Start the main process.
        /// </summary>
        private void StartMainProcess()
        {
            Status = VncSessionStatus.MainProcess;

            // Handle server session miscellaneous actions.
            if (ServerSessionFlag)
            {
                // Set the support mode.
                SetSupportSessionMode(SupportSessionFlag);

                // If a window is being shared (not the desktop), set it
                // visible and in foreground.
                if (WindowHandle != 0)
                {
                    IntPtr hWnd = new IntPtr(WindowHandle);
                    if (KSyscalls.IsIconic(hWnd))
                    {
                        KSyscalls.ShowWindowAsync(hWnd, (int)KSyscalls.WindowStatus.SW_RESTORE);
                    }
                    KSyscalls.SetForegroundWindow(hWnd);
                }
            }

            // Remove any indication of previous server's listening port.
            RegistryKey key = null;

            try
            {
                key = KwmReg.GetKwmCURegKey();
                key.DeleteValue(m_portRegItem, false);
                key.DeleteValue(m_portRegItemWritten, false);
            }

            finally
            {
                if (key != null)
                {
                    key.Close();
                }
            }

            // Start the process.
            StartProcess(true);
        }
Пример #5
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
 /// <summary>
 /// Open the tunnel used by the VNC process.
 /// </summary>
 private void OpenTunnel()
 {
     Status       = VncSessionStatus.Tunnel;
     TunnelThread = new VncTunnelThread(this);
     TunnelThread.Start();
 }
Пример #6
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
 /// <summary>
 /// Start the dummy process.
 /// </summary>
 private void StartDummyProcess()
 {
     Status = VncSessionStatus.DummyProcess;
     StartProcess(false);
 }
Пример #7
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
        /// <summary>
        /// Clean up the state when the session has completed to avoid resource
        /// leaks. This object CANNOT be reused for another session since some
        /// recently cancelled threads may still reference the object and try
        /// to modify its state.
        /// </summary>
        private void Terminate()
        {
            Status = VncSessionStatus.Completed;
            AppVnc.SessionPresentFlag = false;
            App.LocalSession = null;

            if (Overlay != null)
            {
                Overlay.Terminate();
                Overlay = null;
            }

            if (TicketQuery != null)
            {
                TicketQuery.Terminate();
                TicketQuery = null;
            }

            if (Tunnel != null)
            {
                Tunnel.Terminate();
                Tunnel = null;
            }

            if (TunnelThread != null)
            {
                TunnelThread.RequestCancellation();
                TunnelThread = null;
            }

            if (MainProcess != null)
            {
                MainProcess.Terminate();
                MainProcess = null;
            }

            if (DummyProcess != null)
            {
                DummyProcess.Terminate();
                DummyProcess = null;
            }

            if (Timer != null)
            {
                Timer.WakeMeUp(-1);
                Timer = null;
            }

            if (InactivityMonitor != null)
            {
                InactivityMonitor.Enabled = false;
                InactivityMonitor.Dispose();
                InactivityMonitor = null;
            }
        }
Пример #8
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
        /// <summary>
        /// Start the main process.
        /// </summary>
        private void StartMainProcess()
        {
            Status = VncSessionStatus.MainProcess;

            // Handle server session miscellaneous actions.
            if (ServerSessionFlag)
            {
                // Set the support mode.
                SetSupportSessionMode(SupportSessionFlag);

                // If a window is being shared (not the desktop), set it
                // visible and in foreground.
                if (WindowHandle != 0)
                {
                    IntPtr hWnd = new IntPtr(WindowHandle);
                    if (KSyscalls.IsIconic(hWnd))
                        KSyscalls.ShowWindowAsync(hWnd, (int)KSyscalls.WindowStatus.SW_RESTORE);
                    KSyscalls.SetForegroundWindow(hWnd);
                }
            }

            // Remove any indication of previous server's listening port.
            RegistryKey key = null;

            try
            {
                key = KwmReg.GetKwmCURegKey();
                key.DeleteValue(m_portRegItem, false);
                key.DeleteValue(m_portRegItemWritten, false);
            }

            finally
            {
                if (key != null) key.Close();
            }

            // Start the process.
            StartProcess(true);
        }
Пример #9
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
 /// <summary>
 /// Start the dummy process.
 /// </summary>
 private void StartDummyProcess()
 {
     Status = VncSessionStatus.DummyProcess;
     StartProcess(false);
 }
Пример #10
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
 /// <summary>
 /// Request a ticket to the server.
 /// </summary>
 private void RequestTicket()
 {
     Status = VncSessionStatus.Ticket;
     UInt32 t = ServerSessionFlag ? KAnp.KANP_CMD_VNC_START_TICKET : KAnp.KANP_CMD_VNC_CONNECT_TICKET;
     AnpMsg m = Kws.NewKcdCmd(t);
     if (!ServerSessionFlag) m.AddUInt64(SessionID);
     TicketQuery = Kws.PostKcdCmd(m, OnTicketReply);
 }
Пример #11
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
 /// <summary>
 /// Open the tunnel used by the VNC process.
 /// </summary>
 private void OpenTunnel()
 {
     Status = VncSessionStatus.Tunnel;
     TunnelThread = new VncTunnelThread(this);
     TunnelThread.Start();
 }
Пример #12
0
Файл: Vnc.cs Проект: tmbx/kwm-ng
        /// <summary>
        /// Start the session, if possible.
        /// </summary>
        private void HandleSessionStart()
        {
            // Check if the KCD has already sent us the end session event.
            if (SessionIDTree.ContainsKey(SessionID))
            {
                HandleSessionTrouble(new Exception("the KCD closed the connection unexpectedly"));
                return;
            }

            // Clear the session ID tree.
            SessionIDTree.Clear();

            // Show the overlay window.
            Overlay = new RunningOverlay();
            Overlay.Relink(this);

            // Configure the inactivity monitor to timeout about 10 minutes.
            InactivityMonitor = MonitorCreator.CreateInstance(MonitorType.GlobalHookMonitor);
            InactivityMonitor.MonitorKeyboardEvents = true;
            InactivityMonitor.MonitorMouseEvents = true;
            InactivityMonitor.Interval = 600000;
            InactivityMonitor.Elapsed += delegate(Object sender, ElapsedEventArgs args)
                {
                    KBase.ExecInUI(OnInactivity);
                };
            InactivityMonitor.Enabled = true;

            // Start the session.
            Status = VncSessionStatus.Started;

            // Notify listeners.
            PostLocalVncSessionEvent(true, null);

            Kws.OnStateChange(WmStateChange.Transient);
        }