mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
This commit replaces the old ForumSharingManagerImpl with a new one which is based on state machines and the ProtocolEngine. There is a SharerEngine and a InviteeEngine that take care of state transitions, messages, events and trigger actions to be carried out by the ForumSharingManagerImpl. This is all very similar to the Introduction Client. The general sharing paradigm has been changed from sharing as a state to sharing as an action. Now the UI can allow users to invite contacts to forums. The contacts can accept or decline the invitiation. Also, the Forum Sharing Manger is notified when users leave a forum. Closes #322
63 lines
1.5 KiB
Java
63 lines
1.5 KiB
Java
package org.briarproject.api.forum;
|
|
|
|
import static org.briarproject.api.forum.InviteeAction.LOCAL_ACCEPT;
|
|
import static org.briarproject.api.forum.InviteeAction.LOCAL_DECLINE;
|
|
import static org.briarproject.api.forum.InviteeAction.LOCAL_LEAVE;
|
|
import static org.briarproject.api.forum.InviteeAction.REMOTE_INVITATION;
|
|
import static org.briarproject.api.forum.InviteeAction.REMOTE_LEAVE;
|
|
|
|
public enum InviteeProtocolState {
|
|
|
|
ERROR(0),
|
|
AWAIT_INVITATION(1) {
|
|
@Override
|
|
public InviteeProtocolState next(InviteeAction a) {
|
|
if (a == REMOTE_INVITATION) return AWAIT_LOCAL_RESPONSE;
|
|
return ERROR;
|
|
}
|
|
},
|
|
AWAIT_LOCAL_RESPONSE(2) {
|
|
@Override
|
|
public InviteeProtocolState next(InviteeAction a) {
|
|
if (a == LOCAL_ACCEPT || a == LOCAL_DECLINE) return FINISHED;
|
|
if (a == REMOTE_LEAVE) return LEFT;
|
|
return ERROR;
|
|
}
|
|
},
|
|
FINISHED(3) {
|
|
@Override
|
|
public InviteeProtocolState next(InviteeAction a) {
|
|
if (a == LOCAL_LEAVE || a == REMOTE_LEAVE) return LEFT;
|
|
return FINISHED;
|
|
}
|
|
},
|
|
LEFT(4) {
|
|
@Override
|
|
public InviteeProtocolState next(InviteeAction a) {
|
|
if (a == LOCAL_LEAVE) return ERROR;
|
|
return LEFT;
|
|
}
|
|
};
|
|
|
|
private final int value;
|
|
|
|
InviteeProtocolState(int value) {
|
|
this.value = value;
|
|
}
|
|
|
|
public int getValue() {
|
|
return value;
|
|
}
|
|
|
|
public static InviteeProtocolState fromValue(int value) {
|
|
for (InviteeProtocolState s : values()) {
|
|
if (s.value == value) return s;
|
|
}
|
|
throw new IllegalArgumentException();
|
|
}
|
|
|
|
public InviteeProtocolState next(InviteeAction a) {
|
|
return this;
|
|
}
|
|
}
|