Esempio n. 1
0
        /// <summary>
        /// Deactivates TET C# Client and all under lying routines. Should be called when
        /// a application closes down.
        /// </summary>
        public void Deactivate()
        {
            if (null != heartbeatHandler)
            {
                heartbeatHandler.Stop();
                heartbeatHandler = null;
            }

            if (null != apiManager)
            {
                apiManager.Close();
                apiManager = null;
            }

            //clearing listeners will stop heartbeat and broadcasting threads
            ClearListeners();

            isActive = false;
        }
Esempio n. 2
0
        /// <summary>
        /// Activates TET C# Client and all underlying routines. Should be called _only_ 
        /// once when an application starts up. Calling thread will be locked during
        /// initialization.
        /// </summary>
        /// <param name="apiVersion"/>Version number of the Tracker API that this client will be compliant to</param>
        /// <param name="mode"/>Mode though which the client will receive GazeData. Either ClientMode.Push or ClientMode.Pull</param>
        /// <param name="hostname"/>The host name or IP address where the eye tracking server is running.</param>
        /// <param name="portnumber"/>The port number used for the eye tracking server</param>
        /// <returns>True is succesfully activated, false otherwise</returns>
        public bool Activate(ApiVersion apiVersion, ClientMode mode, string hostname, int portnumber)
        {
            //if already running, deactivate before starting anew
            if (isActive)
                Deactivate();

            //lock calling thread while initializing
            initializationLock = Thread.CurrentThread;
            lock (initializationLock)
            {
                apiManager = new GazeApiManager(this);
                apiManager.Connect(hostname, portnumber);

                if (apiManager.IsConnected())
                {
                    apiManager.RequestTracker(mode, apiVersion);
                    apiManager.RequestAllStates();

                    //We wait untill above requests have been handled by server or timeout occours
                    bool waitSuccess = Monitor.Wait(initializationLock, TimeSpan.FromSeconds(20));

                    if (waitSuccess == false)
                    {
                        Debug.WriteLine("Error initializing GazeManager");
                        return false;
                    }

                    //init heartbeat
                    heartbeatHandler = new Heartbeat(apiManager);
                    heartbeatHandler.Start();

                    isActive = true;
                }
                else
                    Debug.WriteLine("Error initializing GazeManager");

                return isActive;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Activates TET C# Client and all underlying routines. Should be called _only_ 
        /// once when an application starts up. Calling thread will be locked during
        /// initialization.
        /// </summary>
        /// <param name="apiVersion">Version number of the Tracker API that this client will be compliant to</param>
        /// <param name="mode">Mode though which the client will receive GazeData. Either ClientMode.Push or ClientMode.Pull</param>
        /// <param name="hostname">The host name or IP address where the eye tracking server is running.</param>
        /// <param name="portnumber">The port number used for the eye tracking server</param>
        /// <returns>True if succesfully activated, false otherwise</returns>
        public bool Activate(ApiVersion apiVersion, ClientMode mode, string hostname, int portnumber)
        {
            //lock to ensure that state changing method calls are synchronous
            lock (Instance)
            {
                Object threadLock = Thread.CurrentThread;

                //lock calling thread while initializing
                lock (threadLock)
                {
                    //only one entity can initialize at the time
                    lock (initializationLock)
                    {
                        if (!IsActivated)
                        {
                            isInizializing = true;

                            try
                            {
                                //establish connection in seperate thread
                                apiManager = new GazeApiManager(this, this);
                                ThreadPool.QueueUserWorkItem(new WaitCallback(HandleServerConnect), new Object[] { apiManager, mode, apiVersion, hostname, portnumber });

                                //We wait untill above requests have been handled by server or timeout occurs
                                bool waitSuccess = Monitor.Wait(initializationLock, TimeSpan.FromSeconds(INIT_TIME_DELAY_SECONDS));

                                if (!waitSuccess)
                                {
                                    HandleInitFailure();

                                    Console.Write("Error initializing GazeManager, is EyeTribe Server running?");
                                }
                                else
                                {
                                    //init heartbeat
                                    heartbeatHandler = new Heartbeat(apiManager);
                                    heartbeatHandler.Start();

                                    isActive = true;

                                    //notify connection listeners
                                    OnGazeApiConnectionStateChanged(IsActivated);
                                }
                            }
                            catch (Exception e)
                            {
                                HandleInitFailure();

                                Console.Write("Error initializing GazeManager: " + e.StackTrace);
                            }
                        }

                        return IsActivated;
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Deactivates TET C# Client and all under lying routines. Should be called when
        /// a application closes down.
        /// </summary>
        public void Deactivate()
        {
            //lock to ensure that state changing method calls are synchronous
            lock (Instance)
            {
                if (null != heartbeatHandler)
                {
                    heartbeatHandler.Stop();
                    heartbeatHandler = null;
                }

                if (null != apiManager)
                {
                    apiManager.Close();
                    apiManager = null;
                }

                //clearing listeners will stop broadcasting threads
                ClearListeners();

                //Handle initialization
                if (isInizializing)
                {
                    lock (initializationLock)
                    {
                        isInizializing = false;
                        Monitor.Pulse(initializationLock);
                    }
                }

                isActive = false;
                isInizializing = false;
            }
        }
Esempio n. 5
0
        internal void HandleInitFailure()
        {
            lock (Instance)
            {
                if (null != heartbeatHandler)
                {
                    heartbeatHandler.Stop();
                    heartbeatHandler = null;
                }

                if (null != apiManager)
                {
                    apiManager.Close();
                    apiManager = null;
                }
            }
        }