| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2011, 2013 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Bernd Hufmann - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader; |
| 13 | |
| 14 | import org.eclipse.linuxtools.tmf.core.component.TmfComponent; |
| 15 | import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal; |
| 16 | import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; |
| 17 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; |
| 18 | import org.eclipse.linuxtools.tmf.core.signal.TmfStartSynchSignal; |
| 19 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; |
| 20 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; |
| 21 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; |
| 22 | |
| 23 | /** |
| 24 | * Class to implement that certain signals are sent as well as are sent with correct content. |
| 25 | * |
| 26 | * @author Bernd Hufmann |
| 27 | */ |
| 28 | public class Uml2SDSignalValidator extends TmfComponent implements IUml2SdSignalValidator { |
| 29 | |
| 30 | // ------------------------------------------------------------------------ |
| 31 | // Attributes |
| 32 | // ------------------------------------------------------------------------ |
| 33 | private int fSignalDepth = 0; |
| 34 | private boolean fIsSignalReceived = false; |
| 35 | private boolean fIsSignalError = false; |
| 36 | private boolean fIsSourceError = false; |
| 37 | private boolean fIsCurrentTimeError = false; |
| 38 | private boolean fIsRangeError = false; |
| 39 | |
| 40 | private Object fSource = null; |
| 41 | private TmfTimestamp fCurrentTimestamp = null; |
| 42 | private TmfTimeRange fCurrentTimeRange = null; |
| 43 | |
| 44 | // ------------------------------------------------------------------------ |
| 45 | // Constructor |
| 46 | // ------------------------------------------------------------------------ |
| 47 | /** |
| 48 | * Constructor |
| 49 | */ |
| 50 | public Uml2SDSignalValidator() { |
| 51 | } |
| 52 | |
| 53 | // ------------------------------------------------------------------------ |
| 54 | // Operations |
| 55 | // ------------------------------------------------------------------------ |
| 56 | /** |
| 57 | * Signal handler for time synch signal. |
| 58 | * @param signal the signal to handle. |
| 59 | */ |
| 60 | @TmfSignalHandler |
| 61 | public void synchToTime(TmfTimeSynchSignal signal) { |
| 62 | // Set results so that it can be validated in the test case |
| 63 | setSignalReceived(true); |
| 64 | setSourceError(getSource() != signal.getSource()); |
| 65 | setCurrentTimeError(!getCurrentTime().equals(signal.getCurrentTime())); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Signal handler for time range synch signal. |
| 70 | * @param signal the signal to handle. |
| 71 | */ |
| 72 | @TmfSignalHandler |
| 73 | public void synchToTimeRange(TmfRangeSynchSignal signal) { |
| 74 | // Set results so that it can be validated in the test case |
| 75 | setSignalReceived(true); |
| 76 | setSourceError(getSource() != signal.getSource()); |
| 77 | setCurrentTimeError(!getCurrentTime().equals(signal.getCurrentTime())); |
| 78 | setRangeError(!getCurrentRange().equals(signal.getCurrentRange())); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Signal handler for handling start synch signal. |
| 83 | * @param signal the signal to handle. |
| 84 | */ |
| 85 | @TmfSignalHandler |
| 86 | public void startSynch(TmfStartSynchSignal signal) { |
| 87 | fSignalDepth++; |
| 88 | // make sure that the signal which is send by the loader class is not handled by the loader class |
| 89 | // after receiving it. i.e. it must not trigger a another signal |
| 90 | |
| 91 | // Set results so that it can be validated in the test case |
| 92 | setSignalError(fSignalDepth > 1); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Signal handler for handling end synch signal. |
| 97 | * @param signal the signal to handle. |
| 98 | */ |
| 99 | @TmfSignalHandler |
| 100 | public void endSynch(TmfEndSynchSignal signal) { |
| 101 | fSignalDepth = fSignalDepth > 0 ? fSignalDepth - 1 : 0; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public boolean isSignalReceived() { |
| 106 | return fIsSignalReceived; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void setSignalReceived(boolean received) { |
| 111 | fIsSignalReceived = received; |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public boolean isSourceError() { |
| 116 | return fIsSourceError; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void setSourceError(boolean fIsSourceError) { |
| 121 | this.fIsSourceError = fIsSourceError; |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public boolean isCurrentTimeError() { |
| 126 | return fIsCurrentTimeError; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void setCurrentTimeError(boolean fIsCurrentTimeError) { |
| 131 | this.fIsCurrentTimeError = fIsCurrentTimeError; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public boolean isRangeError() { |
| 136 | return fIsRangeError; |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public void setRangeError(boolean fIsRangeError) { |
| 141 | this.fIsRangeError = fIsRangeError; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public boolean isSignalError() { |
| 146 | return fIsSignalError; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void setSignalError(boolean fIsSignalError) { |
| 151 | this.fIsSignalError = fIsSignalError; |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public Object getSource() { |
| 156 | return fSource; |
| 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public void setSource(Object source) { |
| 161 | fSource = source; |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public TmfTimestamp getCurrentTime() { |
| 166 | return fCurrentTimestamp; |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void setCurrentTime(TmfTimestamp currentTime) { |
| 171 | fCurrentTimestamp = currentTime == null ? null : new TmfTimestamp(currentTime); |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public TmfTimeRange getCurrentRange() { |
| 176 | return fCurrentTimeRange; |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public void setCurrentRange(TmfTimeRange currentRange) { |
| 181 | fCurrentTimeRange = currentRange == null ? null : new TmfTimeRange(currentRange); |
| 182 | } |
| 183 | } |
| 184 | |