-
Notifications
You must be signed in to change notification settings - Fork 14
/
MessageListener.kt
145 lines (122 loc) · 5.42 KB
/
MessageListener.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright © 2017-2024 Kynetics LLC
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hara.ddiclient.api
/**
* Listener to be up to date with the client state.
*/
interface MessageListener {
/**
* Callback called to notify an event or a state change
*/
fun onMessage(message: Message)
/**
* Message notified by the client.
* @property description string describing the state/event
*/
sealed class Message(val description: String) {
override fun toString(): String {
return this.javaClass.simpleName
}
/**
* State messages
*/
sealed class State(description: String) : Message(description) {
/**
* Client is downloading artifacts from server
*/
data class Downloading(val artifacts: List<Artifact>) : State("Client is downloading artifacts from server") {
/**
* @property name
* @property size in bytes
* @property md5
*/
data class Artifact(val name: String, val size: Long, val md5: String)
}
/**
* The update process is started.
* Any request to cancel an update will be rejected
*/
object Updating : State("The update process is started. Any request to cancel an update will be rejected")
/**
* Last update request is being cancelled.
*/
object CancellingUpdate : State("Last update request is being cancelled")
/**
* Client is waiting for the authorization to start downloading
* @property forcedDownload: if true, immediate download is requested from server
*/
class WaitingDownloadAuthorization(val forcedDownload:Boolean) : State("Waiting authorization to start download")
/**
* Client is waiting for the authorization to start updating
* @property forcedUpdate: if true, immediate update is requested from server
*/
class WaitingUpdateAuthorization(val forcedUpdate:Boolean) : State("Waiting authorization to start update")
/**
* Client is waiting for new requests from server
*/
object Idle : State("Client is waiting for new requests from server")
}
/**
* Event messages
*/
sealed class Event(description: String) : Message(description) {
/**
* Client is contacting server to retrieve new actions to execute
*/
object Polling : Event("Client is contacting server to retrieve new action to execute")
/**
* An update is available on the server
*/
data class UpdateAvailable(val id: String) : Event("An update is available on the server")
/**
* A file download has started
*/
data class StartDownloadFile(val fileName: String) : Event("A file download has started")
/**
* A file has been successfully downloaded
*/
data class FileDownloaded(val fileDownloaded: String) : Event("A file has been downloaded")
/**
* Progress of a download file
* @property fileName, name of the file that the client is downloading
* @property percentage, percentage of downloaded file
*/
data class DownloadProgress(val fileName: String, val percentage: Double = 0.0) : Event("Percent of file downloaded")
/**
* All files have been successfully downloaded
*/
object AllFilesDownloaded : Event("All file needed have been downloaded")
/**
* The update has finished.
* @property successApply, true if the update has been successfully applied, false otherwise
* @property details
*/
data class UpdateFinished(val successApply: Boolean, val details: List<String>) : Event("The update has finished")
object NoUpdate : Event("No update to apply")
object NoNewState : Event("Server state is not changed")
/**
* The result of the deployment feedback request sent to the server
* @property success, true if the request has been successful, false otherwise
* @property id, action id of the update
* @property closeAction, true if the feedback request execution status is Execution.closed, false otherwise
*/
data class DeployFeedbackRequestResult(val success: Boolean,
val id: String,
val closeAction: Boolean,
val requestDetails: List<String>) :
Event("Result of the feedback request to the server")
/**
* An error occurred during the update.
* @property details, contains additional info about the error
*/
data class Error(val details: List<String>) : Event("An error has occurred")
}
}
}