-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Notify about DataBroker Disconnect
Closes: #12 Signed-Off-By: Andre Weber <[email protected]>
- Loading branch information
1 parent
d724aba
commit 47e378b
Showing
8 changed files
with
190 additions
and
2 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
31 changes: 31 additions & 0 deletions
31
kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DisconnectListener.kt
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,31 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.eclipse.kuksa | ||
|
||
/** | ||
* The [DisconnectListener] can be registered to [DataBrokerConnection.disconnectListeners] | ||
* When registered it will notify about manual or unexpected connection disconnects from the DataBroker. | ||
*/ | ||
fun interface DisconnectListener { | ||
/** | ||
* Will be triggered, when the connection to the DataBroker was closed manually or unexpectedly. | ||
*/ | ||
fun onDisconnect() | ||
} |
50 changes: 50 additions & 0 deletions
50
kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/MultiListener.kt
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,50 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.eclipse.kuksa | ||
|
||
/** | ||
* Generic Listener interface, to support multiple listeners. | ||
*/ | ||
class MultiListener<T> { | ||
private var listeners: MutableSet<T> = mutableSetOf() | ||
|
||
/** | ||
* Adds a new [listener] and returns true if the [listener] was successfully added, returns false otherwise. | ||
* A [listener] can only be added once. | ||
*/ | ||
fun register(listener: T): Boolean { | ||
return listeners.add(listener) | ||
} | ||
|
||
/** | ||
* Removes a [listener] and returns true if the [listener] was successfully removed, returns false otherwise. | ||
*/ | ||
fun unregister(listener: T): Boolean { | ||
return listeners.remove(listener) | ||
} | ||
|
||
/** | ||
* Retrieves a defensive copy of the underlying list of listeners. | ||
*/ | ||
@JvmSynthetic | ||
internal fun get(): List<T> { | ||
return listeners.toList() | ||
} | ||
} |
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