1+ /*
2+ * Copyright (c) 2013-present, The Eye Tribe.
3+ * All rights reserved.
4+ *
5+ * This source code is licensed under the BSD-style license found in the LICENSE file in the root directory of this source tree.
6+ *
7+ */
8+
19package com .theeyetribe .client ;
210
311import java .net .HttpURLConnection ;
@@ -133,23 +141,23 @@ public boolean activate(final ApiVersion version, final ClientMode mode, final S
133141 //if already running, deactivate before starting anew
134142 if (isActivated ())
135143 deactivate ();
136-
144+
137145 //lock calling thread while initializing
138146 Object threadLock = Thread .currentThread ();
139-
147+
140148 synchronized (threadLock )
141149 {
142150 synchronized (initializationLock )
143151 {
144152 if (!isActivated ())
145153 {
146154 isInitializing = true ;
147-
155+
148156 try
149157 {
150158 //threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
151159 threadPool = Executors .newCachedThreadPool ();
152-
160+
153161 //make sure we do not init networking on calling thread
154162 threadPool .execute (new Runnable ()
155163 {
@@ -160,7 +168,7 @@ public void run()
160168 {
161169 apiManager = new GazeApiManager (GazeManager .this , GazeManager .this );
162170 apiManager .connect (hostname , portnumber );
163-
171+
164172 if (apiManager .isConnected ())
165173 {
166174 apiManager .requestTracker ( mode , version );
@@ -173,10 +181,10 @@ public void run()
173181 }
174182 }
175183 });
176-
184+
177185 //We wait until above requests have been handled by server or timeout occurs
178186 initializationLock .wait ( INIT_TIME_DELAY_SECONDS * 1000 );
179-
187+
180188 if (!isInitialized )
181189 {
182190 deactivate ();
@@ -186,7 +194,7 @@ public void run()
186194 {
187195 if (!heartbeatHandler .isAlive ())
188196 heartbeatHandler .start ();
189-
197+
190198 isActive = true ;
191199 }
192200 }
@@ -198,7 +206,7 @@ public void run()
198206 }
199207 }
200208 }
201-
209+
202210 return isActivated ();
203211 }
204212 }
@@ -354,17 +362,17 @@ public ClientMode getClientMode()
354362 {
355363 return clientMode ;
356364 }
357-
365+
358366 /**
359367 * Initiate a new calibration process. Must be called before any call to {@link #calibrationPointStart(int, int) CalibrationPointStart}
360368 * or {@link #calibrationPointEnd() calibrationPointEnd}.
361- * <p>
362- * Any previous (and possible running) calibration process must be completed or aborted before calling this.
363- * <p>
364- * A full calibration process consists of a number of calls to {@link #calibrationPointStart(int, int) calibrationPointStart} and
365- * {@link #calibrationPointEnd() calibrationPointEnd} matching the total number of calibration points set by the numCalibrationPoints
366- * parameter.
367- *
369+ * <p>
370+ * Any previous (and possible running) calibration process must be completed or aborted before calling this.
371+ * <p>
372+ * A full calibration process consists of a number of calls to {@link #calibrationPointStart(int, int) calibrationPointStart} and
373+ * {@link #calibrationPointEnd() calibrationPointEnd} matching the total number of calibration points set by the numCalibrationPoints
374+ * parameter.
375+ *
368376 * @param numCalibrationPoints The number of calibration points that will be used in this calibration
369377 * @param listener The {@link com.theeyetribe.client.ICalibrationProcessHandler} instance that will receive callbacks during the
370378 * calibration process
@@ -381,14 +389,14 @@ public void calibrationStart(int numCalibrationPoints, ICalibrationProcessHandle
381389 else
382390 System .out .println ("TET Java Client not activated!" );
383391 }
384-
392+
385393 /**
386394 * Called for every calibration point during a calibration process. This call should be followed by a call to
387395 * {@link #calibrationPointEnd() calibrationPointEnd} 1-2 seconds later.
388396 * <p>
389397 * The calibration process must be initiated by a call to {@link #calibrationStart(int, ICalibrationProcessHandler) calibrationStart} before
390398 * calling this.
391- *
399+ *
392400 * @param x X coordinate of the calibration point
393401 * @param y Y coordinate of the calibration point
394402 */
@@ -406,7 +414,7 @@ public void calibrationPointStart(int x, int y)
406414 else
407415 System .out .println ("TET Java Client not activated!" );
408416 }
409-
417+
410418 /**
411419 * Called for every calibration point during a calibration process. This should be called 1-2 seconds after
412420 * {@link #calibrationPointStart(int, int) calibrationPointStart}.
@@ -545,7 +553,7 @@ public int getNumGazeListeners()
545553
546554 return -1 ;
547555 }
548-
556+
549557 /**
550558 * Checks if a given instance of {@link com.theeyetribe.client.IGazeListener} is currently attached.
551559 *
@@ -807,9 +815,6 @@ public void clearListeners()
807815 gazeBroadcaster .stop ();
808816 }
809817
810- long total ;
811- long frameCount ;
812-
813818 @ Override
814819 public void onGazeApiResponse (final String response )
815820 {
@@ -827,10 +832,6 @@ public void run()
827832 {
828833 if (reply .request .compareTo (Protocol .TRACKER_REQUEST_GET ) == 0 )
829834 {
830- frameCount ++;
831-
832- long timeStamp = System .currentTimeMillis ();
833-
834835 JsonParser jsonParser = new JsonParser ();
835836 JsonObject jo = (JsonObject )jsonParser .parse (response );
836837 TrackerGetReply tgr = gson .fromJson (jo , TrackerGetReply .class );
@@ -888,15 +889,15 @@ public void run()
888889 isCalibrating = tgr .values .isCalibrating ;
889890 if (null != tgr .values .isCalibrated )
890891 isCalibrated = tgr .values .isCalibrated ;
891-
892+
892893 //if defined in json response, then set
893894 if (((JsonObject )jo .get (Protocol .KEY_VALUES )).has (Protocol .TRACKER_CALIBRATIONRESULT ))
894895 {
895896 //is calibration result different from current?
896897 if (null == lastCalibrationResult || !lastCalibrationResult .equals (tgr .values .calibrationResult ) )
897898 {
898899 lastCalibrationResult = tgr .values .calibrationResult ;
899-
900+
900901 synchronized (calibrationResultListeners )
901902 {
902903 for (final ICalibrationResultListener listener : calibrationResultListeners )
@@ -993,8 +994,6 @@ public void run()
993994 initializationLock .notify ();
994995 }
995996 }
996-
997- total += System .currentTimeMillis () - timeStamp ;
998997 }
999998 else if (reply .request .compareTo (Protocol .TRACKER_REQUEST_SET ) == 0 )
1000999 {
@@ -1009,14 +1008,14 @@ else if(reply.category.compareTo(Protocol.CATEGORY_CALIBRATION) == 0)
10091008
10101009 if (null != calibrationListener )
10111010 try
1012- {
1013- calibrationListener .onCalibrationStarted ();
1014- }
1015- catch (Exception e )
1016- {
1017- System .out .println ("Exception while calling ICalibrationProcessHandler.onCalibrationStarted() " +
1018- "on listener " + calibrationListener + ": " + e .getLocalizedMessage ());
1019- }
1011+ {
1012+ calibrationListener .onCalibrationStarted ();
1013+ }
1014+ catch (Exception e )
1015+ {
1016+ System .out .println ("Exception while calling ICalibrationProcessHandler.onCalibrationStarted() " +
1017+ "on listener " + calibrationListener + ": " + e .getLocalizedMessage ());
1018+ }
10201019 }
10211020 else if (reply .request .compareTo (Protocol .CALIBRATION_REQUEST_POINTSTART ) == 0 )
10221021 {
@@ -1043,14 +1042,14 @@ else if(reply.request.compareTo(Protocol.CALIBRATION_REQUEST_POINTEND) == 0)
10431042 if (sampledCalibrationPoints == totalCalibrationPoints )
10441043 //Notify calibration listener that all calibration points have been sampled and the analysis of the calibration results has begun
10451044 try
1046- {
1047- calibrationListener .onCalibrationProcessing ();
1048- }
1049- catch (Exception e )
1050- {
1051- System .out .println ("Exception while calling ICalibrationProcessHandler.OnCalibrationProcessing() on listener " +
1052- calibrationListener + ": " + e .getLocalizedMessage ());
1053- }
1045+ {
1046+ calibrationListener .onCalibrationProcessing ();
1047+ }
1048+ catch (Exception e )
1049+ {
1050+ System .out .println ("Exception while calling ICalibrationProcessHandler.OnCalibrationProcessing() on listener " +
1051+ calibrationListener + ": " + e .getLocalizedMessage ());
1052+ }
10541053 }
10551054
10561055 final CalibrationPointEndReply cper = gson .fromJson (response , CalibrationPointEndReply .class );
0 commit comments