Added target and terminal support.
[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
69         // TerminalInEvent Event send in WS when characters are sent (stdin)
70         TerminalInEvent = "term:input"
71         // TerminalOutEvent Event send in WS when characters are received (stdout or stderr)
72         TerminalOutEvent = "term:output"
73         // TerminalExitEvent Event send in WS on terminal/console exit
74         TerminalExitEvent = "term:exit"
75 )
76
77 type (
78
79         // TerminalConfig config of a board terminal
80         TerminalConfig struct {
81                 ID      string       `json:"id"`
82                 Name    string       `json:"name"`
83                 Type    TerminalType `json:"type"`
84                 User    string       `json:"user"`
85                 Options []string     `json:"options"`
86                 Status  string       `json:"status"`
87                 Cols    uint16       `json:"cols"`
88                 Rows    uint16       `json:"rows"`
89         }
90
91         // TerminalInMsg Message used to received input characters (stdin)
92         TerminalInMsg struct {
93                 TermID    string `json:"termID"`
94                 Timestamp string `json:"timestamp"`
95                 Stdin     string `json:"stdin"`
96         }
97
98         // TerminalOutMsg Message used to send output characters (stdout+stderr)
99         TerminalOutMsg struct {
100                 TermID    string `json:"termID"`
101                 Timestamp string `json:"timestamp"`
102                 Stdout    string `json:"stdout"`
103                 Stderr    string `json:"stderr"`
104         }
105
106         // TerminalExitMsg Message sent on terminal/console exit
107         TerminalExitMsg struct {
108                 TermID    string `json:"termID"`
109                 Timestamp string `json:"timestamp"`
110                 Code      int    `json:"code"`
111                 Error     error  `json:"error"`
112         }
113
114         // TerminalResizeArgs JSON parameters of /terminal/:tid/resize command
115         TerminalResizeArgs struct {
116                 Cols uint16 `json:"cols"`
117                 Rows uint16 `json:"rows"`
118         }
119
120         // TerminalSignalArgs JSON parameters of /terminal/:tid/signal command
121         TerminalSignalArgs struct {
122                 Signal string `json:"signal" binding:"required"` // signal number
123         }
124 )