-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[arcam] Added polling option and fixed a couple of bugs
Signed-off-by: Joep Admiraal <joep@groovytunes.nl>
- Loading branch information
1 parent
b18df00
commit 84ab2e9
Showing
24 changed files
with
382 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...am/src/main/java/org/openhab/binding/arcam/internal/connection/ArcamCommandInTransit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) 2010-2022 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.arcam.internal.connection; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This class allows thread safe access to a command that is currently being executed on the Arcam device. | ||
* | ||
* @author Joep Admiraal - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class ArcamCommandInTransit { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(ArcamCommandInTransit.class); | ||
|
||
@Nullable | ||
private ArcamCommandCode commandInTransit; | ||
|
||
public void waitFor() { | ||
int counter = 0; | ||
while (hasCommand()) { | ||
counter++; | ||
if (counter > 20) { | ||
synchronized (this) { | ||
logger.debug("Stop waiting for a command to finish, command: {}", commandInTransit); | ||
commandInTransit = null; | ||
} | ||
return; | ||
} | ||
|
||
try { | ||
Thread.sleep(10); | ||
} catch (InterruptedException e) { | ||
} | ||
} | ||
} | ||
|
||
public synchronized void set(ArcamCommandCode commandCode) { | ||
commandInTransit = commandCode; | ||
} | ||
|
||
public synchronized void finish(ArcamCommandCode commandCode) { | ||
if (commandCode.equals(commandInTransit)) { | ||
commandInTransit = null; | ||
} | ||
} | ||
|
||
public synchronized boolean hasCommand() { | ||
return commandInTransit != null; | ||
} | ||
} |
Oops, something went wrong.