001/*
002 * Copyright (C) Photon Vision.
003 *
004 * This program is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package org.photonvision.common.dataflow.events;
019
020import io.javalin.websocket.WsContext;
021import java.util.HashMap;
022import org.photonvision.common.dataflow.DataChangeDestination;
023import org.photonvision.common.dataflow.DataChangeSource;
024
025public class IncomingWebSocketEvent<T> extends DataChangeEvent<T> {
026    public final String cameraUniqueName;
027    public final WsContext originContext;
028
029    public IncomingWebSocketEvent(DataChangeDestination destType, String propertyName, T newValue) {
030        this(destType, propertyName, newValue, null, null);
031    }
032
033    public IncomingWebSocketEvent(
034            DataChangeDestination destType,
035            String propertyName,
036            T newValue,
037            String cameraUniqueName,
038            WsContext originContext) {
039        super(DataChangeSource.DCS_WEBSOCKET, destType, propertyName, newValue);
040        this.cameraUniqueName = cameraUniqueName;
041        this.originContext = originContext;
042    }
043
044    @SuppressWarnings("unchecked")
045    public IncomingWebSocketEvent(
046            DataChangeDestination destType, String dataKey, HashMap<String, Object> data) {
047        this(destType, dataKey, (T) data.get(dataKey));
048    }
049
050    @Override
051    public String toString() {
052        return "IncomingWebSocketEvent{"
053                + "cameraUniqueName="
054                + cameraUniqueName
055                + ", sourceType="
056                + sourceType
057                + ", destType="
058                + destType
059                + ", propertyName='"
060                + propertyName
061                + '\''
062                + ", data="
063                + data
064                + '}';
065    }
066}