]> git.basschouten.com Git - openhab-addons.git/blob
4af1406abaff8c3a892c3c12d235a6ebac67c652
[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.satel.internal.command;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.satel.internal.event.EventDispatcher;
17 import org.openhab.binding.satel.internal.protocol.SatelMessage;
18
19 /**
20  * Interface for commands sent to communication module.
21  *
22  * @author Krzysztof Goworek - Initial contribution
23  */
24 @NonNullByDefault
25 public interface SatelCommand {
26
27     /**
28      * State of command.
29      * <ul>
30      * <li>NEW - just created</li>
31      * <li>ENQUEUED - currently waiting in the queue</li>
32      * <li>SENT - sent to communication module</li>
33      * <li>SUCCEEDED - response received and successfully handled</li>
34      * <li>FAILED - either send failed or response is invalid</li>
35      * </ul>
36      *
37      * @author Krzysztof Goworek - Initial contribution
38      *
39      */
40     enum State {
41         NEW,
42         ENQUEUED,
43         SENT,
44         SUCCEEDED,
45         FAILED
46     }
47
48     /**
49      * Returns current state of the command.
50      *
51      * @return current state
52      */
53     State getState();
54
55     /**
56      * Sets state of the command.
57      *
58      * @param state new state
59      */
60     void setState(State state);
61
62     /**
63      * Returns request's message object.
64      *
65      * @return {@link SatelMessage} request object
66      */
67     SatelMessage getRequest();
68
69     /**
70      * Checks whether a response message matches request enclosed in this object.
71      *
72      * @param response response message
73      * @return <code>true</code> if given response matches the request
74      */
75     boolean matches(SatelMessage response);
76
77     /**
78      * Handles response received for the command. Usually generates an event with received data.
79      *
80      * @param eventDispatcher event dispatcher
81      * @param response response to handle
82      * @return <code>true</code> if response has been successfully handled
83      */
84     boolean handleResponse(EventDispatcher eventDispatcher, SatelMessage response);
85 }