001/*
002 * Copyright (c) 2011, Kustaa Nyholm / SpareTimeLabs
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification, 
006 * are permitted provided that the following conditions are met:
007 *
008 * Redistributions of source code must retain the above copyright notice, this list 
009 * of conditions and the following disclaimer.
010 * 
011 * Redistributions in binary form must reproduce the above copyright notice, this 
012 * list of conditions and the following disclaimer in the documentation and/or other
013 * materials provided with the distribution.
014 *  
015 * Neither the name of the Kustaa Nyholm or SpareTimeLabs nor the names of its 
016 * contributors may be used to endorse or promote products derived from this software 
017 * without specific prior written permission.
018 * 
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
025 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
028 * OF SUCH DAMAGE.
029 */
030
031package jmri.jmrix.purejavacomm;
032
033import java.util.EventObject;
034
035public class SerialPortEvent extends EventObject {
036    /**
037     * Data available at the serial port.
038     */
039    public static final int DATA_AVAILABLE = 1;
040    /**
041     * Output buffer is empty.
042     */
043    public static final int OUTPUT_BUFFER_EMPTY = 2;
044    /**
045     * Clear to send.
046     */
047    public static final int CTS = 3;
048    /**
049     * Data set ready.
050     */
051    public static final int DSR = 4;
052    /**
053     * Ring indicator.
054     */
055    public static final int RI = 5;
056    /**
057     * Carrier detect.
058     */
059    public static final int CD = 6;
060    /**
061     * Overrun error.
062     */
063    public static final int OE = 7;
064    /**
065     * Parity error.
066     */
067    public static final int PE = 8;
068    /**
069     * Framing error.
070     */
071    public static final int FE = 9;
072    /**
073     * Break interrupt.
074     */
075    public static final int BI = 10;
076
077    private final int eventType;
078    private final boolean newValue;
079    private final boolean oldValue;
080
081    /**
082     * Constructs a <CODE>SerialPortEvent</CODE> with the specified serial port,
083     * event type, old and new values. Application programs should not directly
084     * create <CODE>SerialPortEvent</CODE> objects.
085     * 
086     * @param source     the source
087     * @param eventType  the event type
088     * @param oldValue   the old value
089     * @param newValue   the new value
090     */
091    public SerialPortEvent(SerialPort source, int eventType, boolean oldValue, boolean newValue) {
092        super(source);
093        this.eventType = eventType;
094        this.newValue = newValue;
095        this.oldValue = oldValue;
096    }
097
098    /**
099     * Returns the type of this event.
100     * 
101     * @return The type of this event.
102     */
103    public int getEventType() {
104        return this.eventType;
105    }
106
107    /**
108     * Returns the new value of the state change that caused the
109     * <CODE>SerialPortEvent</CODE> to be propagated.
110     * 
111     * @return The new value of the state change.
112     */
113    public boolean getNewValue() {
114        return this.newValue;
115    }
116
117    /**
118     * Returns the old value of the state change that caused the
119     * <CODE>SerialPortEvent</CODE> to be propagated.
120     * 
121     * @return The old value of the state change.
122     */
123    public boolean getOldValue() {
124        return this.oldValue;
125    }
126}