diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/commons/Errors.kt b/app/src/main/kotlin/kaist/iclab/abclogger/commons/Errors.kt index eaba0ee..501ce76 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/commons/Errors.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/commons/Errors.kt @@ -285,8 +285,14 @@ open class CollectorError( qualifiedName = qualifiedName ) + class TurningOnRequestWhenUnavailable(override val qualifiedName: String) : CollectorError( + R.string.error_collector_turning_on_request_when_unavailable, + qualifiedName = qualifiedName + ) + companion object { fun notFound(qualifiedName: String) = NotFound(qualifiedName) + fun turningOnRequestWhenUnavaiable(qualifiedName: String) = TurningOnRequestWhenUnavailable(qualifiedName) fun changeSettingDuringOperating(qualifiedName: String) = SettingChangedDuringOperating(qualifiedName) } diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/core/collector/AbstractCollector.kt b/app/src/main/kotlin/kaist/iclab/abclogger/core/collector/AbstractCollector.kt index e83e550..54ded88 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/core/collector/AbstractCollector.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/core/collector/AbstractCollector.kt @@ -114,6 +114,10 @@ abstract class AbstractCollector( abstract suspend fun list(limit: Long): Collection fun start() { + if (!isAvailable()) { + stop(CollectorError.turningOnRequestWhenUnavaiable(qualifiedName)) + } + isEnabled = true lastErrorMessage = "" @@ -134,7 +138,7 @@ abstract class AbstractCollector( /** * function stop is called only by a user's explicit interaction. */ - fun stop() { + fun stop(throwable: Throwable? = null) { isEnabled = false turnedOnTime = Long.MIN_VALUE @@ -143,6 +147,7 @@ abstract class AbstractCollector( launch { onStop() + if (throwable != null) throw throwable } scope.cancel() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 870f236..f8aa2b8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -386,6 +386,7 @@ Collector error Corresponding collector not found. Cannot change settings during operating. + Invalid request for turning on a collector due to unavailability of data collection.