]> git.basschouten.com Git - openhab-addons.git/blob
f15d4e4d96496eec6172d8f365163ae8aa95f934
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.teleinfo.internal.handler;
14
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Set;
18 import java.util.concurrent.CopyOnWriteArraySet;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.teleinfo.internal.TeleinfoDiscoveryService;
22 import org.openhab.binding.teleinfo.internal.data.Frame;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.binding.BaseBridgeHandler;
25 import org.openhab.core.thing.binding.ThingHandlerService;
26
27 /**
28  * The {@link TeleinfoAbstractControllerHandler} class defines a skeleton for controller handlers.
29  *
30  * @author Nicolas SIBERIL - Initial contribution
31  */
32 @NonNullByDefault
33 public abstract class TeleinfoAbstractControllerHandler extends BaseBridgeHandler {
34
35     private Set<TeleinfoControllerHandlerListener> listeners = new CopyOnWriteArraySet<>();
36
37     protected TeleinfoAbstractControllerHandler(Bridge bridge) {
38         super(bridge);
39     }
40
41     public void addListener(final TeleinfoControllerHandlerListener listener) {
42         listeners.add(listener);
43     }
44
45     public void removeListener(final TeleinfoControllerHandlerListener listener) {
46         listeners.remove(listener);
47     }
48
49     protected void fireOnFrameReceivedEvent(final Frame frame) {
50         listeners.forEach(l -> l.onFrameReceived(frame));
51     }
52
53     @Override
54     public Collection<Class<? extends ThingHandlerService>> getServices() {
55         return Collections.singleton(TeleinfoDiscoveryService.class);
56     }
57 }