terminal: when closing term, pass status to closing
[src/xds/xds-server.git] / lib / xsapiv1 / targets.go
1 /*
2  * Copyright (C) 2018 "IoT.bzh"
3  * Author Sebastien Douheret <sebastien@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package xsapiv1
19
20 /**
21  * Target
22  **/
23
24 // TargetType definition
25 type TargetType string
26
27 const (
28         // TypeTgtStandard Standard target type
29         TypeTgtStandard = "standard"
30 )
31
32 // Target Status definition
33 const (
34         StatusTgtErrorConfig = "ErrorConfig"
35         StatusTgtDisable     = "Disable"
36         StatusTgtEnable      = "Enable"
37 )
38
39 // TargetConfig config of a target / board
40 type TargetConfig struct {
41         ID     string           `json:"id"`
42         Name   string           `json:"name"`
43         Type   TargetType       `json:"type"`
44         IP     string           `json:"ip"`
45         Status string           `json:"status"`
46         Terms  []TerminalConfig `json:"terms"`
47 }
48
49 /**
50  * Terminal
51  **/
52
53 // TerminalType definition
54 type TerminalType string
55
56 const (
57         // TypeTermSSH ssh terminal type
58         TypeTermSSH = "ssh"
59
60         // StatusTermErrorConfig Configuration error
61         StatusTermErrorConfig = "ErrorConfig"
62         // StatusTermEnable Enable state
63         StatusTermEnable = "Enable"
64         // StatusTermOpen Open state
65         StatusTermOpen = "Open"
66         // StatusTermClose Close state
67         StatusTermClose = "Close"
68         // StatusTermClosing Closing state
69         StatusTermClosing = "Closing"
70
71         // TerminalInEvent Event send in WS when characters are sent (stdin)
72         TerminalInEvent = "term:input"
73         // TerminalOutEvent Event send in WS when characters are received (stdout or stderr)
74         TerminalOutEvent = "term:output"
75         // TerminalExitEvent Event send in WS on terminal/console exit
76         TerminalExitEvent = "term:exit"
77 )
78
79 type (
80
81         // TerminalConfig config of a board terminal
82         TerminalConfig struct {
83                 ID      string       `json:"id"`
84                 Name    string       `json:"name"`
85                 Type    TerminalType `json:"type"`
86                 User    string       `json:"user"`
87                 Options []string     `json:"options"`
88                 Status  string       `json:"status"`
89                 Cols    uint16       `json:"cols"`
90                 Rows    uint16       `json:"rows"`
91         }
92
93         // TerminalInMsg Message used to received input characters (stdin)
94         TerminalInMsg struct {
95                 TermID    string `json:"termID"`
96                 Timestamp string `json:"timestamp"`
97                 Stdin     string `json:"stdin"`
98         }
99
100         // TerminalOutMsg Message used to send output characters (stdout+stderr)
101         TerminalOutMsg struct {
102                 TermID    string `json:"termID"`
103                 Timestamp string `json:"timestamp"`
104                 Stdout    []byte `json:"stdout"`
105                 Stderr    []byte `json:"stderr"`
106         }
107
108         // TerminalExitMsg Message sent on terminal/console exit
109         TerminalExitMsg struct {
110                 TermID    string `json:"termID"`
111                 Timestamp string `json:"timestamp"`
112                 Code      int    `json:"code"`
113                 Error     error  `json:"error"`
114         }
115
116         // TerminalResizeArgs JSON parameters of /terminal/:tid/resize command
117         TerminalResizeArgs struct {
118                 Cols uint16 `json:"cols"`
119                 Rows uint16 `json:"rows"`
120         }
121
122         // TerminalSignalArgs JSON parameters of /terminal/:tid/signal command
123         TerminalSignalArgs struct {
124                 Signal string `json:"signal" binding:"required"` // signal number
125         }
126 )