2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.heos.internal.resources;
16 import java.util.concurrent.CopyOnWriteArraySet;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.heos.internal.json.dto.HeosEventObject;
20 import org.openhab.binding.heos.internal.json.payload.Media;
23 * The {@link HeosSystemEventListener } is used for classes which
24 * wants to inform players or groups about change events
25 * from the HEOS system. Classes which wants to be informed
26 * has to implement the {@link HeosEventListener} and register at
27 * the class which extends this {@link HeosSystemEventListener}
29 * @author Johannes Einig - Initial contribution
30 * @author Martin van Wingerden - change handling of stop/pause depending on playing item type
33 public class HeosSystemEventListener {
34 private final Set<HeosEventListener> listenerList = new CopyOnWriteArraySet<>();
37 * Register a listener from type {@link HeosEventListener} to be notified by
40 * @param listener the lister from type {@link HeosEventListener} for change events
42 public void addListener(HeosEventListener listener) {
43 listenerList.add(listener);
47 * Removes the listener from the notification list
49 * @param listener the listener from type {@link HeosEventListener} to be removed
51 public void removeListener(HeosEventListener listener) {
52 listenerList.remove(listener);
56 * Notifies the registered listener of a changed state type event
58 * @param eventObject the command of the event
60 public void fireStateEvent(HeosEventObject eventObject) {
61 listenerList.forEach(element -> element.playerStateChangeEvent(eventObject));
65 * Notifies the registered listener of a changed media type event
67 * @param pid the ID of the player or group which has changed
68 * @param media the media information
70 public void fireMediaEvent(String pid, Media media) {
71 listenerList.forEach(element -> element.playerMediaChangeEvent(pid, media));
75 * Notifies the registered listener if a change of the bridge state
77 * @param event the event type
78 * @param success the result (success or fail)
79 * @param command the command of the event
81 public void fireBridgeEvent(String event, boolean success, Object command) {
82 for (HeosEventListener heosEventListener : listenerList) {
83 heosEventListener.bridgeChangeEvent(event, success, command);