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.digitalstrom.internal.lib.manager;
15 import org.openhab.binding.digitalstrom.internal.lib.config.Config;
16 import org.openhab.binding.digitalstrom.internal.lib.listener.ConnectionListener;
17 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.DsAPI;
18 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.HttpTransport;
21 * The {@link ConnectionManager} manages the connection to a digitalSTROM-Server.
23 * @author Michael Ochel - Initial contribution
24 * @author Matthias Siegele - Initial contribution
26 public interface ConnectionManager {
28 public static final int GENERAL_EXCEPTION = -1;
29 public static final int MALFORMED_URL_EXCEPTION = -2;
30 public static final int CONNECTION_EXCEPTION = -3;
31 public static final int SOCKET_TIMEOUT_EXCEPTION = -4;
32 public static final int UNKNOWN_HOST_EXCEPTION = -5;
33 public static final int AUTHENTIFICATION_PROBLEM = -6;
34 public static final int SSL_HANDSHAKE_EXCEPTION = -7;
37 * Returns the {@link HttpTransport} to execute queries or special commands on the digitalSTROM-Server.
39 * @return the HttpTransport
41 HttpTransport getHttpTransport();
44 * Returns the {@link DsAPI} to execute commands on the digitalSTROM-Server.
48 DsAPI getDigitalSTROMAPI();
51 * This method has to be called before each command to check the connection to the digitalSTROM-Server.
52 * It examines the connection to the server, sets a new Session-Token, if it is expired and sets a new
53 * Application-Token, if none it set at the digitalSTROM-Server. It also outputs the specific connection failure.
55 * @return true if the connection is established and false if not
57 boolean checkConnection();
60 * Returns the current Session-Token.
62 * @return Session-Token
64 String getSessionToken();
67 * Returns the auto-generated or user defined Application-Token.
69 * @return Application-Token
71 String getApplicationToken();
74 * Registers a {@link ConnectionListener} to this {@link ConnectionManager}.
76 * @param connectionListener to register
78 void registerConnectionListener(ConnectionListener connectionListener);
81 * Unregisters the {@link ConnectionListener} from this {@link ConnectionManager}.
83 void unregisterConnectionListener();
86 * Revokes the saved Application-Token from the digitalSTROM-Server and returns true if the Application-Token was
87 * revoke successful, otherwise false.
89 * @return successful = true, otherwise false
91 boolean removeApplicationToken();
94 * Updates the login configuration.
96 * @param hostAddress of the digitalSTROM-Server
97 * @param username to login
98 * @param password to login
99 * @param applicationToken to login
101 void updateConfig(String hostAddress, String username, String password, String applicationToken);
104 * Updates the {@link Config} with the given config.
106 * @param config to update
108 void updateConfig(Config config);
111 * Returns the {@link Config}.
118 * Informs this {@link ConnectionManager} that the {@link Config} has been updated.
120 void configHasBeenUpdated();
123 * Generates and returns a new session token.
125 * @return new session token
127 String getNewSessionToken();
130 * Checks the connection through the given HTTP-Response-Code or exception code. If a {@link ConnectionListener} is
131 * registered this method also informs the registered {@link ConnectionListener} if the connection state has
134 * <b>Exception-Codes:</b><br>
135 * <b>{@link #GENERAL_EXCEPTION}</b> general exception<br>
136 * <b>{@link #MALFORMED_URL_EXCEPTION}</b> MalformedURLException<br>
137 * <b>{@link #CONNECTION_EXCEPTION}</b> java.net.ConnectException<br>
138 * <b>{@link #SOCKET_TIMEOUT_EXCEPTION}</b> SocketTimeoutException<br>
139 * <b>{@link #UNKNOWN_HOST_EXCEPTION}</b> java.net.UnknownHostException<br>
141 * <b>Code for authentication problems:</b> {@link #AUTHENTIFICATION_PROBLEM}<br>
144 * @param code exception or HTTP-Response-Code
145 * @return true, if connection is valid
147 boolean checkConnection(int code);
150 * Returns true, if connection is established, otherwise false.
152 * @return true, if connection is established, otherwise false
154 boolean connectionEstablished();