Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/listener/ChannelStateChangeListener.java')
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/listener/ChannelStateChangeListener.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/listener/ChannelStateChangeListener.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/listener/ChannelStateChangeListener.java
new file mode 100644
index 000000000..99353b7d6
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.locator/src/org/eclipse/tm/te/tcf/locator/listener/ChannelStateChangeListener.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Uwe Stieber (Wind River) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tm.te.tcf.locator.listener;
+
+import org.eclipse.tm.tcf.protocol.IChannel;
+import org.eclipse.tm.tcf.protocol.IPeer;
+import org.eclipse.tm.tcf.protocol.Protocol;
+import org.eclipse.tm.te.tcf.core.interfaces.listeners.IChannelStateChangeListener;
+import org.eclipse.tm.te.tcf.locator.interfaces.nodes.ILocatorModel;
+import org.eclipse.tm.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tm.te.tcf.locator.interfaces.nodes.IPeerModelProperties;
+import org.eclipse.tm.te.tcf.locator.interfaces.services.ILocatorModelLookupService;
+
+
+/**
+ * Channel state change listener implementation.
+ */
+public class ChannelStateChangeListener implements IChannelStateChangeListener {
+ // Reference to the parent model
+ private final ILocatorModel fModel;
+
+ /**
+ * Constructor.
+ *
+ * @param model The parent locator model. Must be not <code>null</code>.
+ */
+ public ChannelStateChangeListener(ILocatorModel model) {
+ assert model != null;
+ fModel = model;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.tcf.tcf.core.interfaces.listeners.IChannelStateChangeListener#stateChanged(org.eclipse.tm.tcf.protocol.IChannel, int)
+ */
+ public void stateChanged(IChannel channel, int state) {
+ assert Protocol.isDispatchThread() && channel != null;
+
+ switch (state) {
+ case IChannel.STATE_OPEN:
+ IPeer peer = channel.getRemotePeer();
+ // Find the corresponding model node
+ IPeerModel node = fModel.getService(ILocatorModelLookupService.class).lkupPeerModelById(peer.getID());
+ if (node != null) {
+ // Increase the channel reference counter by 1
+ int counter = node.getIntProperty(IPeerModelProperties.PROP_CHANNEL_REF_COUNTER);
+ if (counter < 0) counter = 0;
+ counter++;
+ node.setProperty(IPeerModelProperties.PROP_CHANNEL_REF_COUNTER, counter);
+ if (counter > 0) node.setProperty(IPeerModelProperties.PROP_STATE, IPeerModelProperties.STATE_CONNECTED);
+ }
+ break;
+ case IChannel.STATE_CLOSED:
+ peer = channel.getRemotePeer();
+ // Find the corresponding model node
+ node = fModel.getService(ILocatorModelLookupService.class).lkupPeerModelById(peer.getID());
+ if (node != null) {
+ // Decrease the channel reference counter by 1
+ int counter = node.getIntProperty(IPeerModelProperties.PROP_CHANNEL_REF_COUNTER);
+ counter--;
+ if (counter < 0) counter = 0;
+ node.setProperty(IPeerModelProperties.PROP_CHANNEL_REF_COUNTER, counter);
+ if (counter == 0) node.setProperty(IPeerModelProperties.PROP_STATE, IPeerModelProperties.STATE_REACHABLE);
+ }
+ break;
+ }
+ }
+
+}

Back to the top