Skip to content

Commit

Permalink
chore: recover from bad merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rhwood committed May 23, 2020
1 parent 42f806c commit be4ded7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 37 deletions.
21 changes: 12 additions & 9 deletions java/src/jmri/jmrix/srcp/SRCPSystemConnectionMemo.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package jmri.jmrix.srcp;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.ResourceBundle;
import jmri.InstanceManager;
import jmri.NamedBean;
import jmri.ShutDownManager;
import jmri.jmrix.SystemConnectionMemo;
import jmri.jmrix.srcp.swing.SRCPComponentFactory;
import jmri.jmrix.swing.ComponentFactory;
import jmri.util.NamedBeanComparator;

/**
Expand All @@ -17,7 +21,7 @@
* @author Bob Jacobsen Copyright (C) 2010
* @author Paul Bender Copyright (C) 2015-2016
*/
public class SRCPSystemConnectionMemo extends jmri.jmrix.SystemConnectionMemo {
public class SRCPSystemConnectionMemo extends SystemConnectionMemo {

public SRCPSystemConnectionMemo(String prefix, String name, SRCPTrafficController et) {
super(prefix, name);
Expand All @@ -26,8 +30,7 @@ public SRCPSystemConnectionMemo(String prefix, String name, SRCPTrafficControlle
}
register();
InstanceManager.store(this, SRCPSystemConnectionMemo.class); // also register as specific type
InstanceManager.store(cf = new jmri.jmrix.srcp.swing.SRCPComponentFactory(this),
jmri.jmrix.swing.ComponentFactory.class);
InstanceManager.store(cf = new SRCPComponentFactory(this), ComponentFactory.class);
}

public SRCPSystemConnectionMemo(SRCPTrafficController et) {
Expand Down Expand Up @@ -95,7 +98,7 @@ public <T> T get(Class<?> T) {
}

/**
* Tells which managers this class provides.
* {@inheritDoc}
*/
@Override
public boolean provides(Class<?> type) {
Expand All @@ -114,28 +117,28 @@ public <B extends NamedBean> Comparator<B> getNamedBeanComparator(Class<B> type)

@Override
public void dispose() {
InstanceManager.getDefault(ShutDownManager.class).deregister(et);
InstanceManager.getDefault(ShutDownManager.class).deregister(et.shutDownTask);
et = null;
InstanceManager.deregister(this, SRCPSystemConnectionMemo.class);
if (cf != null) {
InstanceManager.deregister(cf, jmri.jmrix.swing.ComponentFactory.class);
InstanceManager.deregister(cf, ComponentFactory.class);
}
super.dispose();
}

// private list of busMemos, so the parser visitor can pass information
// to the bus representation.
private java.util.ArrayList<SRCPBusConnectionMemo> busMemos = null;
private ArrayList<SRCPBusConnectionMemo> busMemos = null;

public SRCPBusConnectionMemo getMemo(int i) {
if (busMemos == null) {
busMemos = new java.util.ArrayList<SRCPBusConnectionMemo>();
busMemos = new ArrayList<>();
// there is always a bus 0, so add it now.
busMemos.add(0, new SRCPBusConnectionMemo(getTrafficController(), getSystemPrefix(), 0));
}
try {
return busMemos.get(i);
} catch (java.lang.IndexOutOfBoundsException ie) {
} catch (IndexOutOfBoundsException ie) {
// this memo must not exist in the list, add it and return it.
busMemos.add(i, new SRCPBusConnectionMemo(getTrafficController(), getSystemPrefix(), i));
return busMemos.get(i);
Expand Down
48 changes: 20 additions & 28 deletions java/src/jmri/jmrix/srcp/SRCPTrafficController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.lang.reflect.InvocationTargetException;
import java.util.Vector;
import jmri.InstanceManager;
import jmri.ShutDownManager;
import jmri.jmrix.AbstractMRListener;
import jmri.jmrix.AbstractMRMessage;
import jmri.jmrix.AbstractMRReply;
Expand Down Expand Up @@ -30,14 +32,14 @@ public class SRCPTrafficController extends AbstractMRTrafficController
implements SRCPInterface {

protected SRCPSystemConnectionMemo _memo = null;
final Runnable shutDownTask = () -> sendSRCPMessage(new SRCPMessage("TERM 0 SESSION"), null);

/**
* Create a new SRCPTrafficController instance.
*/
public SRCPTrafficController() {
super();
jmri.InstanceManager.getDefault(jmri.ShutDownManager.class)
.register(() -> this.sendSRCPMessage(new SRCPMessage("TERM 0 SESSION"), null));
InstanceManager.getDefault(ShutDownManager.class).register(shutDownTask);
}

// The methods to implement the SRCPInterface
Expand Down Expand Up @@ -77,9 +79,7 @@ SRCPSystemConnectionMemo getSystemConnectionMemo() {
*/
@Override
public void receiveLoop() {
if (log.isDebugEnabled()) {
log.debug("SRCP receiveLoop starts");
}
log.debug("SRCP receiveLoop starts");
SRCPClientParser parser = new SRCPClientParser(istream);
while (true) {
try {
Expand All @@ -99,9 +99,7 @@ public void receiveLoop() {
} catch (InterruptedException | InvocationTargetException ex) {
log.error("Unexpected exception in invokeAndWait:", ex);
}
if (log.isDebugEnabled()) {
log.debug("dispatch thread invoked");
}
log.debug("dispatch thread invoked");

log.debug("Mode {} child contains {}", mode, ((SimpleNode) e.jjtGetChild(1)).jjtGetValue());
//if (mode==HANDSHAKEMODE && ((String)((SimpleNode)e.jjtGetChild(1)).jjtGetValue()).contains("GO")) mode=RUNMODE;
Expand Down Expand Up @@ -161,9 +159,7 @@ public void receiveLoop() {
default: {
replyInDispatch = false;
if (allowUnexpectedReply == true) {
if (log.isDebugEnabled()) {
log.debug("Allowed unexpected reply received in state: {} was {}", mCurrentState, e.toString());
}
log.debug("Allowed unexpected reply received in state: {} was {}", mCurrentState, e);

synchronized (xmtRunnable) {
// The transmit thread sometimes gets stuck
Expand All @@ -173,12 +169,13 @@ public void receiveLoop() {
xmtRunnable.notify();
}
} else {
unexpectedReplyStateError(mCurrentState,e.toString());
unexpectedReplyStateError(mCurrentState, e.toString());
}
}
}

} catch (ParseException pe) {
}
catch (ParseException pe) {
rcvException = true;
reportReceiveLoopException(pe);
break;
Expand All @@ -204,8 +201,9 @@ protected void forwardReply(AbstractMRListener client, AbstractMRReply m) {

/**
* Forward a SRCPReply to all registered SRCPInterface listeners.
*
* @param client WHo should receive the reply
* @param n relevant node
* @param n relevant node
*/
protected void forwardReply(AbstractMRListener client, SimpleNode n) {
((SRCPListener) client).reply(n);
Expand All @@ -225,7 +223,7 @@ protected AbstractMRListener pollReplyHandler() {
}

/**
* Forward a preformatted message to the actual interface.
* {@inheritDoc}
*/
@Override
public void sendSRCPMessage(SRCPMessage m, SRCPListener reply) {
Expand All @@ -252,13 +250,12 @@ protected AbstractMRReply newReply() {
@Override
protected boolean endOfMessage(AbstractMRReply msg) {
int index = msg.getNumDataElements() - 1;
if (msg.getElement(index) == 0x0D) {
return true;
}
if (msg.getElement(index) == 0x0A) {
return true;
} else {
return false;
switch (msg.getElement(index)) {
case 0x0D:
case 0x0A:
return true;
default:
return false;
}
}

Expand All @@ -281,9 +278,7 @@ protected void notifyReply(SimpleNode r, AbstractMRListener dest) {
int cnt = v.size();
for (int i = 0; i < cnt; i++) {
AbstractMRListener client = v.elementAt(i);
if (log.isDebugEnabled()) {
log.debug("notify client: {}", client);
}
log.debug("notify client: {}", client);
try {
//skip dest for now, we'll send the message to there last.
if (dest != client) {
Expand Down Expand Up @@ -330,6 +325,3 @@ public void run() {

private final static Logger log = LoggerFactory.getLogger(SRCPTrafficController.class);
}



0 comments on commit be4ded7

Please sign in to comment.