Changes made in the initial interfaces for further code review.
1. Especially tried to fix the callback mechanism I previously used. 2. 'long sessionID' changed to 'int requestId' 3. Introduced a generic class VotingBoothResult 4. Quite some other local changesvbdev2
parent
77f47fe9e1
commit
15453a772d
|
@ -28,7 +28,9 @@ message UIElement {
|
|||
bytes data = 2;
|
||||
}
|
||||
|
||||
// a new data structure for BallotQuestion. Need to delete the old one
|
||||
// A question in the ballot
|
||||
// is_mandatory determines whether the question may be skipped with no answer
|
||||
// description might hold information/guidlines for the voter
|
||||
message BallotQuestion {
|
||||
bool is_mandatory = 1;
|
||||
UIElement question = 2;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package meerkat.voting;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import meerkat.protobuf.Voting.*;
|
||||
|
||||
/**
|
||||
|
@ -7,13 +8,20 @@ import meerkat.protobuf.Voting.*;
|
|||
*/
|
||||
public interface BallotOutputDevice {
|
||||
|
||||
void commitToBallot(long sessionId, EncryptedBallot encryptedBallot, VotingBooth.Callback callback);
|
||||
/**
|
||||
*
|
||||
* @param requestId
|
||||
* @param encryptedBallot
|
||||
* @param callback
|
||||
*/
|
||||
void commitToBallot(int requestId, EncryptedBallot encryptedBallot,
|
||||
FutureCallback<VotingBoothResult<Boolean>> callback);
|
||||
|
||||
void audit(long sessionId, EncryptedBallot encryptedBallot, BallotSecrets ballotSecrets, VotingBooth.Callback callback);
|
||||
void audit(int requestId, EncryptedBallot encryptedBallot, BallotSecrets ballotSecrets,
|
||||
FutureCallback<VotingBoothResult<Boolean>> callback);
|
||||
|
||||
void castBallot(long sessionId, VotingBooth.Callback callback);
|
||||
void castBallot(int requestId, FutureCallback<VotingBoothResult<Boolean>> callback);
|
||||
|
||||
// probably has no difference than cast. Maybe drop this method
|
||||
void cancelBallot(long sessionId, VotingBooth.Callback callback);
|
||||
void cancelBallot(int requestId, FutureCallback<VotingBoothResult<Boolean>> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package meerkat.voting;
|
||||
|
||||
import meerkat.protobuf.Voting;
|
||||
|
||||
/**
|
||||
* Created by hai on 23/02/16.
|
||||
*/
|
||||
public interface StorageManager {
|
||||
|
||||
// should these methods be synchronous or asynchronous? Can we rely on it being immediate?
|
||||
public void detectAdminHardwareKey();
|
||||
boolean detectAdminHardwareKey();
|
||||
|
||||
public void readElectionParams ();
|
||||
Voting.ElectionParams readElectionParams ();
|
||||
}
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
package meerkat.voting;
|
||||
|
||||
import meerkat.protobuf.Voting.*;
|
||||
|
||||
/**
|
||||
* Created by hai on 23/02/16.
|
||||
*/
|
||||
public interface UI {
|
||||
|
||||
|
||||
// Voter scenario methods
|
||||
void introductionToVoter (long sessionId);
|
||||
|
||||
void chooseChannel (long sessionId, BallotQuestion question);
|
||||
|
||||
void askVoterQuestion (long sessionId, int questionNumber, BallotQuestion question);
|
||||
|
||||
void castOrAudit (long sessionId);
|
||||
|
||||
void showWaitForFinishScreen (long sessionId);
|
||||
|
||||
|
||||
// Admin scenario methods
|
||||
//TODO: the admin scenario still needs some more thinking
|
||||
|
||||
|
||||
|
||||
// bad thing happened scenario
|
||||
void showErrorMessageAndHalt (String errorMessage);
|
||||
void showErrorMessageWithCancelButton (long sessionId, String errorMessage);
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package meerkat.voting;
|
||||
|
||||
import meerkat.protobuf.Voting;
|
||||
import meerkat.protobuf.Voting.*;
|
||||
|
||||
/**
|
||||
|
@ -8,75 +7,21 @@ import meerkat.protobuf.Voting.*;
|
|||
*/
|
||||
public interface VotingBooth {
|
||||
|
||||
public enum ErrorID {
|
||||
OUTPUT_DEVICE_OUT_OF_PAPER,
|
||||
OUTPUT_DEVICE_OUT_OF_INK,
|
||||
OUTPUT_DEVICE_NO_CONNECTION,
|
||||
OUTPUT_DEVICE_HARDWARE_NOT_FOUND,
|
||||
void setComponenets (BallotOutputDevice outputDevice,
|
||||
VotingBoothEncryptor vbEncryptor,
|
||||
VotingBoothUI vbUI,
|
||||
StorageManager vbStorageManager);
|
||||
|
||||
UI_HARDWARE_NOT_FOUND
|
||||
}
|
||||
void initBoothParams (BoothParams boothParams);
|
||||
|
||||
|
||||
// keeps track in which state we are
|
||||
// internal state will also include the number of the current question and the answers we got so far,
|
||||
// later it includes the details of the PlaintextBallot and later the Encryption and the secrets
|
||||
public enum State {
|
||||
INITIALIZED,
|
||||
|
||||
VOTER_INTRODUCTION,
|
||||
VOTER_CHOOSE_CHANNEL,
|
||||
VOTER_VOTING,
|
||||
VOTER_ENCRYPTING,
|
||||
VOTER_CAST_OR_AUDIT,
|
||||
VOTER_CASTING,
|
||||
VOTER_AUDITING
|
||||
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
|
||||
// callbacks and messages from BallotOutputDevice
|
||||
|
||||
public void ballotCommitResult (long sessionId, boolean result);
|
||||
public void ballotCastResult (long sessionId, boolean result);
|
||||
public void ballotAuditResult (long sessionId, boolean result);
|
||||
public void ballotCancelResult (long sessionId, boolean result);
|
||||
// other error messages, such as Printer turned-off or out-of-paper
|
||||
public void outputDeviceReportProblem (ErrorID errorId);
|
||||
|
||||
|
||||
// callbacks and messages from UI
|
||||
|
||||
public void introductionFinished (long sessionId);
|
||||
public void choiceOfChannel (long sessionId, int channelNumber);
|
||||
public void skipQuestion (long sessionId, int questionNumber);
|
||||
public void backwardsQuestion (long sessionId, int questionNumber);
|
||||
public void cancelVotingSession (long sessionId);
|
||||
public void answer (long sessionId, int questionNumber, String answer);
|
||||
public void cast (long sessionId);
|
||||
public void audit (long sessionId);
|
||||
// other error messages, such as hardware-not-detected
|
||||
public void uiReportProblem (ErrorID errorId);
|
||||
|
||||
|
||||
// callbacks from encryptor
|
||||
|
||||
public void returnEncryption (long sessionId, EncryptedBallot encryptedBallot, BallotSecrets secrets);
|
||||
|
||||
|
||||
// callbacks from StorageManager
|
||||
|
||||
public void adminHardwareKeyDetected (boolean isKeyInserted);
|
||||
public void loadElectionParams (ElectionParams electionParams);
|
||||
}
|
||||
void initElectionParams (ElectionParams electionParams);
|
||||
|
||||
// this function is synchronous
|
||||
public void start ();
|
||||
void start ();
|
||||
|
||||
|
||||
// messages from Admin Console (If there is such one)
|
||||
// this function is asynchronous
|
||||
public void shutDown();
|
||||
void shutDown();
|
||||
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import meerkat.protobuf.Voting.*;
|
|||
/**
|
||||
* Created by hai on 23/02/16.
|
||||
*/
|
||||
public interface Encryptor {
|
||||
public interface VotingBoothEncryptor {
|
||||
|
||||
public void encrypt (long sessionId, PlaintextBallot plaintextBallot);
|
||||
void encrypt (PlaintextBallot plaintextBallot);
|
||||
|
||||
//TODO: probably needs some key generation methods as well
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package meerkat.voting;
|
||||
|
||||
/**
|
||||
* Created by hai on 02/03/16.
|
||||
*/
|
||||
public class VotingBoothResult<T> {
|
||||
private final int m_requestId;
|
||||
private final T m_result;
|
||||
|
||||
public int getRequestId () { return m_requestId; }
|
||||
public T getResult () { return m_result; }
|
||||
|
||||
public VotingBoothResult (int requestId, T result) {
|
||||
m_requestId = requestId;
|
||||
m_result = result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package meerkat.voting;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import meerkat.protobuf.Voting.*;
|
||||
|
||||
/**
|
||||
* Created by hai on 23/02/16.
|
||||
*/
|
||||
public interface VotingBoothUI {
|
||||
|
||||
enum VoterQuestionChoice {
|
||||
ANSWERED,
|
||||
SKIP,
|
||||
BACK,
|
||||
CANCEL
|
||||
}
|
||||
|
||||
class VoterQuestionResponse {
|
||||
private final VoterQuestionChoice m_choice;
|
||||
private final String m_answer;
|
||||
|
||||
public VoterQuestionResponse(VoterQuestionChoice choice, String answer) {
|
||||
assert ((choice == VoterQuestionChoice.ANSWERED && answer != null) ||
|
||||
(choice != VoterQuestionChoice.ANSWERED && answer == null));
|
||||
m_choice = choice;
|
||||
m_answer = answer;
|
||||
}
|
||||
|
||||
public VoterQuestionChoice getChoice () { return m_choice; }
|
||||
public String getAnswer () { return m_answer; }
|
||||
}
|
||||
|
||||
|
||||
enum FinalizeBallotChoice {
|
||||
CAST,
|
||||
AUDIT
|
||||
}
|
||||
|
||||
// Voter scenario methods
|
||||
void newVoter (int requestId, FutureCallback<VotingBoothResult<Boolean>> callback);
|
||||
|
||||
void chooseChannel (int requestId, BallotQuestion question, FutureCallback<VotingBoothResult<Integer>> callback);
|
||||
|
||||
void askVoterQuestion (int requestId, int questionNumber, BallotQuestion question,
|
||||
FutureCallback<VotingBoothResult<VoterQuestionResponse>> callback);
|
||||
|
||||
void castOrAudit (int requestId, FutureCallback<VotingBoothResult<FinalizeBallotChoice>> callback);
|
||||
|
||||
void showWaitForFinishScreen (int requestId, FutureCallback<VotingBoothResult<Boolean>> callback);
|
||||
|
||||
|
||||
// Admin scenario methods
|
||||
//TODO: the admin scenario still needs some more thinking
|
||||
|
||||
|
||||
|
||||
// bad thing happened scenario
|
||||
void showErrorMessageAndHalt (int requestId, String errorMessage,
|
||||
FutureCallback<VotingBoothResult<Boolean>> callback);
|
||||
|
||||
void showErrorMessageWithButtons (int requestId, String errorMessage, String[] buttonLabels,
|
||||
FutureCallback<VotingBoothResult<Integer>> callback);
|
||||
|
||||
}
|
Loading…
Reference in New Issue