All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.bidib.jbidibc.netbidib.client.pairingstates.AbstractPairingState Maven / Gradle / Ivy
package org.bidib.jbidibc.netbidib.client.pairingstates;
import org.bidib.jbidibc.messages.BidibLibrary;
import org.bidib.jbidibc.messages.enums.NetBidibSocketType;
import org.bidib.jbidibc.messages.enums.PairingResult;
import org.bidib.jbidibc.messages.exception.ProtocolException;
import org.bidib.jbidibc.messages.message.BidibCommandMessage;
import org.bidib.jbidibc.messages.message.BidibRequestFactory;
import org.bidib.jbidibc.messages.message.LocalLogoffMessage;
import org.bidib.jbidibc.messages.message.LocalLogonAckMessage;
import org.bidib.jbidibc.messages.message.LocalLogonMessage;
import org.bidib.jbidibc.messages.message.netbidib.BidibLinkData;
import org.bidib.jbidibc.messages.message.netbidib.LocalLinkMessage;
import org.bidib.jbidibc.messages.message.netbidib.LocalProtocolSignatureMessage;
import org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData.PairingStatus;
import org.bidib.jbidibc.messages.utils.ByteUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class AbstractPairingState implements PairingState {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPairingState.class);
/**
* the link data for the remote partner
*/
protected final BidibLinkData remotePartnerLinkData;
/**
* our own link data
*/
protected final ProxyBidibLinkData clientLinkData;
private final DefaultPairingStateHandler pairingStateHandler;
protected AbstractPairingState(final DefaultPairingStateHandler pairingStateHandler,
final BidibLinkData remotePartnerLinkData, final ProxyBidibLinkData clientLinkData) {
this.pairingStateHandler = pairingStateHandler;
this.remotePartnerLinkData = remotePartnerLinkData;
this.clientLinkData = clientLinkData;
}
protected boolean isActiveInitiatedConnection() {
return this.pairingStateHandler.getSocketType() == NetBidibSocketType.clientSocket;
}
protected BidibRequestFactory getRequestFactory() {
return this.pairingStateHandler.getRequestFactory();
}
protected boolean isPaired(BidibLinkData bidibLinkData) {
return this.pairingStateHandler.isPaired(bidibLinkData);
}
protected void setNextPairingState(PairingStateEnum pairingState) {
this.pairingStateHandler.setCurrentPairingState(pairingState);
}
protected void publishMessage(final BidibCommandMessage message) throws ProtocolException {
LOGGER.trace("Publish the message: {}", message);
this.pairingStateHandler.publishMessage(message);
}
protected void publishLocalLogon(int localNodeAddr, long uniqueId) {
LOGGER
.trace("Publish the local logon message was received, localNodeAddr: {}, uniqueId: {}", localNodeAddr,
ByteUtils.formatHexUniqueId(uniqueId));
this.pairingStateHandler.publishLocalLogon(localNodeAddr, uniqueId);
}
protected void publishLocalLogoff() {
LOGGER.trace("Publish the local logoff message was received.");
this.pairingStateHandler.publishLocalLogoff();
}
protected void signalPairingRequest() {
LOGGER.trace("Signal the pairing request, remotePartnerLinkData: {}", remotePartnerLinkData);
this.pairingStateHandler.signalPairingRequest(remotePartnerLinkData);
}
protected void signalPairingResult(PairingStatus pairingStatus) {
LOGGER.info("Signal the pairing result: {}", pairingStatus);
remotePartnerLinkData.setPairingStatus(pairingStatus);
}
public void onLocalProtocolSignature(LocalProtocolSignatureMessage localProtocolSignatureMessage) {
LOGGER
.info("onLocalProtocolSignature, localProtocolSignatureMessage: {}, currentPairingState: {}",
localProtocolSignatureMessage, this.pairingStateHandler.getCurrentPairingState());
}
public void onLocalLogonAck(LocalLogonAckMessage localLogonAckMessage) {
LOGGER
.info("onLocalLogonAck, localLogonAckMessage: {}, currentPairingState: {}", localLogonAckMessage,
this.pairingStateHandler.getCurrentPairingState());
}
public void onLocalLogon(LocalLogonMessage localLogonMessage) {
LOGGER
.info("onLocalLogon, localLogonMessage: {}, currentPairingState: {}", localLogonMessage,
this.pairingStateHandler.getCurrentPairingState());
}
public void onLocalLogoff(LocalLogoffMessage localLogoffMessage) {
LOGGER
.info("onLocalLogoff, localLogoffMessage: {}, currentPairingState: {}", localLogoffMessage,
this.pairingStateHandler.getCurrentPairingState());
}
public void onLocalLink(LocalLinkMessage localLinkMessage) {
LOGGER
.info("onLocalLink, localLinkMessage: {}, currentPairingState: {}", localLinkMessage,
this.pairingStateHandler.getCurrentPairingState());
switch (localLinkMessage.getLinkDescriptor()) {
case BidibLibrary.BIDIB_LINK_DESCRIPTOR_P_VERSION:
LOGGER.info("Received the partner P_VERSION: {}", localLinkMessage.getProtocolVersion());
remotePartnerLinkData.setProtocolVersion(localLinkMessage.getProtocolVersion());
break;
case BidibLibrary.BIDIB_LINK_DESCRIPTOR_PROD_STRING:
LOGGER.info("Received the partner PROD_STRING: {}", localLinkMessage.getProdString());
remotePartnerLinkData.setProdString(localLinkMessage.getProdString());
break;
case BidibLibrary.BIDIB_LINK_DESCRIPTOR_USER_STRING:
LOGGER.info("Received the partner USER_STRING: {}", localLinkMessage.getProdString());
remotePartnerLinkData.setUserString(localLinkMessage.getProdString());
break;
case BidibLibrary.BIDIB_LINK_DESCRIPTOR_ROLE:
LOGGER.info("Received the partner ROLE: {}", localLinkMessage.getNetBidibRole());
remotePartnerLinkData.setNetBidibRole(localLinkMessage.getNetBidibRole());
break;
default:
break;
}
}
@Override
public void initiatePairing(int timeout) {
LOGGER.info("initPairing, timeout: {}", timeout);
}
@Override
public void pairingResult(PairingResult pairingResult) {
LOGGER.info("pairingResult, pairingResult: {}", pairingResult);
}
@Override
public void timeoutPairing() {
LOGGER.info("timeout the pairing.");
}
@Override
public void sendNetBidibStartupSequence() {
LOGGER.info("Send the startup sequence.");
}
}