/**
 * Copyright (C) 2010-12 Brookhaven National Laboratory
 * All rights reserved. Use is subject to license terms.
 */
package org.epics.pvmanager;

/**
 * An event for the writer.
 * <p>
 * An event can be trigger by:
 * <ul>
 * <li>a connection change; the connection either connected or disconnected</li>
 * <li>an exception; an error either at the datasource or while preparing the write values</li>
 * <li>a write has concluded</li>
 * </ul>
 * One event can have multiple triggers. You can use the mask or the methods to check what condition applies.
 *
 * @param <T> the type of the writer
 * @author carcassi
 */
public class PVWriterEvent<T> {
    
    /**
     * Mask for connection event.
     */
    public static int CONNECTION_MASK      = 0b000001;
    /**
     * Mask for error event.
     */
    public static int EXCEPTION_MASK       = 0b000010;
    /**
     * Mask for a successful write result.
     */
    public static int WRITE_SUCCEEDED_MASK = 0b000100;
    /**
     * Mask for a failed write result.
     */
    public static int WRITE_FAILED_MASK    = 0b001000;
    
    private final int notificationMask;
    private final PVWriter<T> pvWriter;

    PVWriterEvent(int notificationMask, PVWriter<T> pvWriter) {
        this.notificationMask = notificationMask;
        this.pvWriter = pvWriter;
    }

    /**
     * The writer that generated the event.
     *
     * @return the pv writer
     */
    public PVWriter<T> getPvWriter() {
        return pvWriter;
    }

    /**
     * The mask for the event.
     *
     * @return event mask
     */
    public int getNotificationMask() {
        return notificationMask;
    }
    
    /**
     * Whether this event was generated by a connection change.
     *
     * @return true if the connection status changed from the last notification
     */
    public boolean isConnectionChanged() {
        return (notificationMask & CONNECTION_MASK) != 0;
    }
    
    /**
     * Whether this event was generated in response to a successful write operation.
     *
     * @return true if the write operation was concluded successfully
     */
    public boolean isWriteSucceeded() {
        return (notificationMask & WRITE_SUCCEEDED_MASK) != 0;
    }
    
    /**
     * Whether this event waas generated in response to a failed write operation.
     *
     * @return true if the write operation was concluded unsuccessfully
     */
    public boolean isWriteFailed() {
        return (notificationMask & WRITE_FAILED_MASK) != 0;
    }
    
    /**
     * Whether this event was generated in response to an error.
     *
     * @return true if a new exception is available
     */
    public boolean isExceptionChangesd() {
        return (notificationMask & EXCEPTION_MASK) != 0;
    }
    
    
}

@@ -2685,17 +2685,16 @@
 onChange
-s
 d() %7B%0A  
@@ -2754,20 +2754,901 @@
 ;%0A    %7D%0A    
+%0A%0A    @Override%0A    public String toString() %7B%0A        StringBuilder builder = new StringBuilder();%0A        builder.append(%22%5B %22);%0A        boolean first = true;%0A        if (isConnectionChanged()) %7B%0A            builder.append(%22CONN%22);%0A            first = false;%0A        %7D%0A        if (isWriteFailed()) %7B%0A            if (!first) %7B%0A                builder.append(%22 %7C %22);%0A            %7D%0A            builder.append(%22WRITE_FAIL%22);%0A            first = false;%0A        %7D%0A        if (isWriteSucceeded()) %7B%0A            if (!first) %7B%0A                builder.append(%22 %7C %22);%0A            %7D%0A            builder.append(%22WRITE_SUCC%22);%0A            first = false;%0A        %7D%0A        if (isExceptionChanged()) %7B%0A            if (!first) %7B%0A                builder.append(%22 %7C %22);%0A            %7D%0A            builder.append(%22EXC%22);%0A        %7D%0A        builder.append(%22 %5D%22);%0A        return builder.toString();%0A    %7D
 %0A    %0A%7D%0A

update to 2.1-SNAPSHOT