Skip to content

Commit 86e905c

Browse files
committed
Remove redundant variables
Also made the code more readable Signed-off-by: Saeed Rezaee <[email protected]>
1 parent f9add5e commit 86e905c

File tree

3 files changed

+25
-46
lines changed

3 files changed

+25
-46
lines changed

src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/DeploymentManager.kt

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ package org.eclipse.hara.ddiclient.api.actors
1212

1313
import org.eclipse.hara.ddi.api.model.CancelFeedbackRequest
1414
import org.eclipse.hara.ddi.api.model.DeploymentBaseResponse
15-
import org.eclipse.hara.ddi.api.model.DeploymentBaseResponse.Deployment.ProvisioningType
16-
import org.eclipse.hara.ddi.api.model.DeploymentFeedbackRequest
1715
import org.eclipse.hara.ddiclient.api.actors.ActionManager.Companion.Message.CancelForced
1816
import org.eclipse.hara.ddiclient.api.actors.ActionManager.Companion.Message.UpdateStopped
1917
import org.eclipse.hara.ddiclient.api.actors.ConnectionManager.Companion.Message.Out.DeploymentCancelInfo
2018
import org.eclipse.hara.ddiclient.api.actors.ConnectionManager.Companion.Message.Out.DeploymentInfo
2119
import org.eclipse.hara.ddiclient.api.MessageListener
22-
import kotlinx.coroutines.Job
2320
import kotlinx.coroutines.ObsoleteCoroutinesApi
2421

2522
@OptIn(ObsoleteCoroutinesApi::class, kotlinx.coroutines.ExperimentalCoroutinesApi::class)
@@ -28,7 +25,6 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
2825

2926
private val connectionManager = coroutineContext[CMActor]!!.ref
3027
private val notificationManager = coroutineContext[NMActor]!!.ref
31-
private var waitingAuthJob: Job? = null
3228
private fun beginningReceive(state: State): Receive = { msg ->
3329
when(msg) {
3430
is DeploymentInfo -> {
@@ -108,38 +104,16 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
108104
parent!!.send(UpdateStopped)
109105
}
110106

111-
private fun DeploymentInfo.downloadIs(level: ProvisioningType): Boolean {
112-
return this.info.deployment.download == level
113-
}
114-
115107
init {
116108
actorOf("downloadManager") { DownloadManager.of(it) }
117109
actorOf("updateManager") { UpdateManager.of(it) }
118110
become(beginningReceive(State()))
119-
channel.invokeOnClose {
120-
waitingAuthJob?.cancel()
121-
}
122-
}
123-
124-
private suspend fun sendFeedback(id: String, vararg messages: String) {
125-
connectionManager.send(
126-
ConnectionManager.Companion.Message.In.DeploymentFeedback(
127-
DeploymentFeedbackRequest.newInstance(id,
128-
DeploymentFeedbackRequest.Status.Execution.proceeding,
129-
DeploymentFeedbackRequest.Status.Result.Progress(0, 0),
130-
DeploymentFeedbackRequest.Status.Result.Finished.none,
131-
*messages
132-
)
133-
)
134-
)
135111
}
136112

137113
companion object {
138114
fun of(scope: ActorScope) = DeploymentManager(scope)
139115

140-
data class State(val deplBaseResp: DeploymentBaseResponse? = null) {
141-
fun updateIs(level: ProvisioningType): Boolean = deplBaseResp!!.deployment.update == level
142-
}
116+
data class State(val deplBaseResp: DeploymentBaseResponse? = null)
143117

144118
sealed class Message {
145119
object DownloadFinished : Message()

src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/DownloadManager.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,15 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
6161
checkAndHandleFilesAlreadyDownloaded(msg) {
6262

6363
when {
64-
msg.downloadIs(
65-
DeploymentBaseResponse.Deployment.ProvisioningType.forced) -> {
64+
msg.isDownloadForced -> {
6665
forceDownloadTheArtifact(msg)
6766
}
6867

69-
msg.downloadIs(
70-
DeploymentBaseResponse.Deployment.ProvisioningType.attempt) -> {
68+
msg.isDownloadSoft -> {
7169
attemptDownloadingTheArtifact(State(msg.info), msg)
7270
}
7371

74-
msg.downloadIs(
75-
DeploymentBaseResponse.Deployment.ProvisioningType.skip) -> {
72+
msg.isDownloadSkip -> {
7673
// todo implement download skip option
7774
LOG.warn("skip download not yet implemented (used attempt)")
7875
attemptDownloadingTheArtifact(State(msg.info), msg)
@@ -176,9 +173,7 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
176173
when (msg) {
177174
is DeploymentInfo -> {
178175
when {
179-
180-
msg.downloadIs(DeploymentBaseResponse.Deployment.ProvisioningType.attempt)
181-
&& !msg.forceAuthRequest -> {}
176+
msg.isDownloadSoft && !msg.forceAuthRequest -> {}
182177

183178
else -> {
184179
become(beforeStartReceive())
@@ -309,9 +304,14 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
309304
parent!!.send(ActionManager.Companion.Message.UpdateStopped)
310305
}
311306

312-
private fun DeploymentInfo.downloadIs(level: DeploymentBaseResponse.Deployment.ProvisioningType): Boolean {
313-
return this.info.deployment.download == level
314-
}
307+
private val DeploymentInfo.isDownloadForced: Boolean
308+
get() = info.deployment.download == forced
309+
310+
private val DeploymentInfo.isDownloadSoft: Boolean
311+
get() = info.deployment.download == attempt
312+
313+
private val DeploymentInfo.isDownloadSkip: Boolean
314+
get() = info.deployment.download == attempt
315315

316316
private fun childName(md5: String) = "fileDownloader_for_$md5"
317317

src/main/kotlin/org/eclipse/hara/ddiclient/api/actors/UpdateManager.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
4949
when (msg) {
5050

5151
is DeploymentInfo -> {
52-
val state = DeploymentManager.Companion.State(deplBaseResp = msg.info)
52+
val state = State(deplBaseResp = msg.info)
5353
val message = when {
54-
state.updateIs(DeploymentBaseResponse.Deployment.ProvisioningType.forced) -> {
54+
state.isUpdateForced -> {
5555
forceUpdateDevice(state)
5656
}
5757
else -> {
@@ -66,7 +66,7 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
6666
}
6767
}
6868

69-
private fun waitingUpdateAuthorization(state: DeploymentManager.Companion.State): Receive = { msg ->
69+
private fun waitingUpdateAuthorization(state: State): Receive = { msg ->
7070
when (msg) {
7171

7272
is DeploymentInfo -> {
@@ -93,7 +93,7 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
9393
}
9494
}
9595

96-
private fun forceUpdateDevice(state: DeploymentManager.Companion.State): String {
96+
private fun forceUpdateDevice(state: State): String {
9797
waitingAuthJob = launch(Dispatchers.IO) {
9898
forceRequest.onAuthorizationReceive {
9999
startUpdateProcedure(DeploymentInfo(state.deplBaseResp!!))
@@ -103,10 +103,10 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
103103
return "Start updating the device"
104104
}
105105

106-
private suspend fun attemptUpdateDevice(state: DeploymentManager.Companion.State): String {
106+
private suspend fun attemptUpdateDevice(state: State): String {
107107
become(waitingUpdateAuthorization(state))
108-
notificationManager.send(MessageListener.Message.State.WaitingUpdateAuthorization(state.updateIs(
109-
DeploymentBaseResponse.Deployment.ProvisioningType.forced)))
108+
notificationManager.send(
109+
MessageListener.Message.State.WaitingUpdateAuthorization(state.isUpdateForced))
110110
waitingAuthJob = launch(Dispatchers.IO) {
111111
softRequest.onAuthorizationReceive {
112112
channel.send(Message.UpdateGranted)
@@ -228,6 +228,11 @@ private constructor(scope: ActorScope) : AbstractActor(scope) {
228228
companion object {
229229
fun of(scope: ActorScope) = UpdateManager(scope)
230230

231+
data class State(val deplBaseResp: DeploymentBaseResponse? = null) {
232+
val isUpdateForced: Boolean
233+
get() = deplBaseResp!!.deployment.update ==
234+
DeploymentBaseResponse.Deployment.ProvisioningType.forced
235+
}
231236
sealed class Message {
232237
object UpdateGranted : Message()
233238
}

0 commit comments

Comments
 (0)