/****************************************************************************
 * Copyright (C) 2012 HS Coburg.
 * All rights reserved.
 * Contact: ecsec GmbH (info@ecsec.de)
 *
 * This file is part of the Open eCard App.
 *
 * GNU General Public License Usage
 * This file may be used under the terms of the GNU General Public
 * License version 3.0 as published by the Free Software Foundation
 * and appearing in the file LICENSE.GPL included in the packaging of
 * this file. Please review the following information to ensure the
 * GNU General Public License version 3.0 requirements will be met:
 * http://www.gnu.org/copyleft/gpl.html.
 *
 * Other Usage
 * Alternatively, this file may be used in accordance with the terms
 * and conditions contained in a signed written agreement between
 * you and ecsec GmbH.
 *
 ***************************************************************************/

package org.openecard.gui.android;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.Exchanger;
import org.openecard.gui.ResultStatus;
import org.openecard.gui.StepResult;
import org.openecard.gui.definition.OutputInfoUnit;
import org.openecard.gui.definition.Step;


/**
 *
 * @author Dirk Petrautzki <petrautzki@hs-coburg.de>
 */
class AndroidStepResult implements StepResult {

    private Exchanger syncPoint = new Exchanger();
    private ResultStatus status;
    private List<OutputInfoUnit> results;
    private AndroidNavigator navigator;

    public AndroidStepResult() {
	navigator = AndroidNavigator.getInstance();
    }

    public Exchanger getSyncPoint() {
	return syncPoint;
    }

    public void setStatus(ResultStatus status) {
	this.status = status;
    }

    public void setResults(List<OutputInfoUnit> results) {
	this.results = results;
    }

    @Override
    public Step getStep() {
	int curStep = navigator.getCurrentStep();
	return navigator.getSteps().get(curStep);
    }

    @Override
    public String getStepID() {
	return getStep().getID();
    }

    @Override
    public ResultStatus getStatus() {
	synchronize();
	return status;
    }

    @Override
    public boolean isOK() {
	// wait until values are present (blocks until triggered
	synchronize();
	synchronized (this) {
	    return getStatus() == ResultStatus.OK;
	}
    }

    @Override
    public boolean isBack() {
	// wait until values are present
	synchronize();
	synchronized (this) {
	    return getStatus() == ResultStatus.BACK;
	}
    }

    @Override
    public boolean isCancelled() {
	// wait until values are present
	synchronize();
	synchronized (this) {
	    return getStatus() == ResultStatus.CANCEL;
	}
    }

    @Override
    public List<OutputInfoUnit> getResults() {
	// wait until values are present
	synchronize();
	synchronized (this) {
	    if (results == null && navigator.getStepResult().getResults() != null) {
		results = Collections.unmodifiableList(navigator.getStepResult().getResults());
	    }
	    return results;
	}
    }

    private void synchronize() {
	if (status == null) {
	    try {
		syncPoint.exchange(null);
	    } catch (InterruptedException ignore) {
		// TODO: maybe setting status to cancel makes sense here
	    }
	}
    }

}

@@ -92,16 +92,21 @@
 (C) 2012
+-2014
  HS Cobu
@@ -109,16 +109,16 @@
 Coburg.%0A
-
  * All r
@@ -1196,16 +1196,73 @@
 n.Step;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 %0A%0A/**%0A *
@@ -1315,16 +1315,62 @@
 urg.de%3E%0A
+ * @author Tobias Wich %3Ctobias.wich@ecsec.de%3E%0A
  */%0Aclas
@@ -1430,45 +1430,189 @@
 ate 
-Exchanger syncPoint = new Exchanger()
+final static Logger logger = LoggerFactory.getLogger(AndroidStepResult.class);%0A%0A    private final Exchanger syncPoint = new Exchanger();%0A    private final AndroidNavigator navigator
 ;%0A  
@@ -1687,48 +1687,8 @@
 lts;
-%0A    private AndroidNavigator navigator;
 %0A%0A  
@@ -2848,32 +2848,209 @@
 NCEL;%0A%09%7D%0A    %7D%0A%0A
+    @Override%0A    public boolean isReload() %7B%0A%09// wait until values are present%0A%09synchronize();%0A%09synchronized (this) %7B%0A%09    return getStatus() == ResultStatus.RELOAD;%0A%09%7D%0A    %7D%0A%0A
     @Override%0A  
@@ -3190,58 +3190,8 @@
 s ==
- null && navigator.getStepResult().getResults() !=
  nul
@@ -3305,16 +3305,16 @@
 esults;%0A
-
 %09%7D%0A    %7D
@@ -3311,24 +3311,204 @@
 ;%0A%09%7D%0A    %7D%0A%0A
+    @Override%0A    public Step getReplacement() %7B%0A%09logger.warn(%22Function AndroidStepResult.getReplacement is not implemented. Returning no replacement step.%22);%0A%09return null;%0A    %7D%0A%0A
     private 

Make Android GUI compatible with new interface