Exemple #1
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);
            }
        }
        /// <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;
            }
        }