Class GazepointSocket

java.lang.Object
adaptlil.gazepoint.api.GazepointSocket
All Implemented Interfaces:
Component

public class GazepointSocket extends Object implements Component
Connects to GP3 and reads data. Utilizes a thread safe queue to write/read data recieved from the tracker. API specifies that data is sent in the form of XML so we utilize XML Annotations to construct XML objects after receiving API data. This is to simplify the process of interacting with the tracking data.
  • Field Details

    • hostName

      private String hostName
    • port

      private int port
    • socket

      private Socket socket
    • input

      private BufferedReader input
    • output

      private PrintStream output
    • xmlMapper

      private final com.fasterxml.jackson.dataformat.xml.XmlMapper xmlMapper
    • gazeDataBuffer

      private final AsyncBuffer<RecXml> gazeDataBuffer
    • ackBuffer

      private AsyncBuffer<AckXml> ackBuffer
    • gazeBufferThread

      private Thread gazeBufferThread
    • mediator

      private Mediator mediator
  • Constructor Details

    • GazepointSocket

      public GazepointSocket(String hostName, int port)
  • Method Details

    • connect

      public void connect() throws IOException
      Opens socket port to the gazepoint tracker and sets the input, output streams
      Throws:
      IOException
    • startCalibration

      public void startCalibration() throws com.fasterxml.jackson.core.JsonProcessingException
      Initiates calibration on the tracker.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • startGazeDataStream

      public void startGazeDataStream() throws IOException
      Initiates ENABLE_SEND_DATA with the tracker to begin gaze data stream. This method creates a new thread so be careful. The thread will write data into the gaze buffer.
      Throws:
      IOException
    • start

      private void start() throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • writeToBuffer

      private void writeToBuffer(String msg)
      Writes the string to the appropriate buffer. If ACK, ackBuffer, if REC, Gaze buffer.
      Parameters:
      msg -
    • readFromGazepointSocket

      public String readFromGazepointSocket() throws IOException
      Throws:
      IOException
    • readGazeDataFromBuffer

      public RecXml readGazeDataFromBuffer()
      Grabs the head of the gaze data xml object queue (Reference gazepoint API)
      Returns:
      Returns the XML Data Object that details whatever GazeData has been sent from the tracker
    • stopGazeDataStream

      public AckXml stopGazeDataStream() throws IOException
      Pauses the data stream by sending the ENABLE_SEND_DATA command w/ false flag.
      Returns:
      Returns the ACK Xml from the server.
      Throws:
      IOException - If this is thrown, it may be a logic issue where we are reading the wrong input line.
    • getGazeDataQueue

      public AsyncBuffer<RecXml> getGazeDataQueue()
    • writeToGazepointSocket

      public void writeToGazepointSocket(String msg)
    • writeSetCommand

      public void writeSetCommand(SetCommand setCommand) throws com.fasterxml.jackson.core.JsonProcessingException
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • setMediator

      public void setMediator(Mediator mediator)
      Specified by:
      setMediator in interface Component