-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
165 lines (156 loc) · 5.41 KB
/
main.go
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package main
import (
"fmt"
"os"
"os/exec"
"strconv"
. "github.com/pspaces/gospace"
"github.com/ryllari/tuplespace/manager"
)
func main() {
//Cria uma Tuple Space
espacoTupla := NewSpace("Manager")
ambcount := 1
usercount := 1
dispcount := 1
var ambName, userName, dispName string
for {
var option string
fmt.Println("#########################################################")
fmt.Println("############ GERENCIAMENTO DE AMBIENTES #############")
fmt.Println("#########################################################")
fmt.Println()
fmt.Println("# DIGITE O NUMERO REFERENTE AO QUE DESEJA NO MENU")
fmt.Println("1 - Criar ambiente")
fmt.Println("2 - Listar ambientes")
fmt.Println("3 - Cadastrar usuário")
fmt.Println("4 - Listar usuários de um ambiente")
fmt.Println("5 - Mover usuários de um ambiente")
fmt.Println("6 - Cadastrar dispositivo")
fmt.Println("7 - Listar dispositivos de um ambiente")
fmt.Println("8 - Mover dispositivos de um ambiente")
fmt.Println("9 - Destruir ambientes vazios")
fmt.Println("0 - Sair")
fmt.Print("Digite uma opção: ")
fmt.Scanf("%s", &option)
fmt.Printf("\n\n")
switch option {
case "1":
fmt.Println("Criando novo ambiente...")
ambName = "amb" + strconv.Itoa(ambcount)
manager.CriarAmb(&espacoTupla, ambName)
ambcount++
case "2":
fmt.Println("Listando ambientes...")
manager.ListarAmb(&espacoTupla)
case "3":
fmt.Printf("\nEm qual ambiente deseja cadastrar o usuário? ")
fmt.Scanf("%s", &ambName)
_, err := espacoTupla.QueryP(ambName)
if err == nil {
fmt.Println("Cadastrando um novo usuário...")
userName := "user" + strconv.Itoa(usercount)
manager.CriarUser(&espacoTupla, ambName, userName)
usercount++
} else {
fmt.Printf("\nNão foi possível cadastrar usuário: O ambiente %s não existe!\n", ambName)
}
case "4":
fmt.Printf("\nDe qual ambiente deseja listar usuários? ")
fmt.Scanf("%s", &ambName)
_, err := espacoTupla.QueryP(ambName)
if err == nil {
manager.ListarUser(&espacoTupla, ambName)
} else {
fmt.Printf("\nNão foi possível listar usuários: O ambiente %s não existe!\n", ambName)
}
case "5":
var ambOrigem, ambDestino string
fmt.Printf("\nDe qual ambiente de origem do usuário desejado? ")
fmt.Scanf("%s", &ambOrigem)
_, err := espacoTupla.QueryP(ambOrigem)
if err == nil {
fmt.Printf("\nQual o usuário desejado? ")
fmt.Scanf("%s", &userName)
_, err = espacoTupla.QueryP(ambOrigem, userName)
if err != nil {
fmt.Printf("\nDe qual ambiente de destino do usuário desejado? ")
fmt.Scanf("%s", &ambDestino)
_, err := espacoTupla.QueryP(ambDestino)
if err == nil {
fmt.Println("Movendo usuário...")
manager.MoverUser(&espacoTupla, userName, ambOrigem, ambDestino)
} else {
fmt.Printf("\nNão foi possível mover usuário: O ambiente %s não existe!\n", ambDestino)
}
} else {
fmt.Printf("\nNão foi possível mover usuário: O usuário %s não existe no ambiente %s!\n", userName, ambOrigem)
}
manager.ListarUser(&espacoTupla, ambName)
} else {
fmt.Printf("\nNão foi possível mover usuário: O ambiente %s não existe!\n", ambOrigem)
}
case "6":
fmt.Printf("\nEm qual ambiente deseja cadastrar o dispositivo? ")
fmt.Scanf("%s", &ambName)
_, err := espacoTupla.QueryP(ambName)
if err == nil {
fmt.Println("Cadastrando um novo dispositivo...")
dispName := "disp" + strconv.Itoa(dispcount)
manager.CriarDisp(&espacoTupla, ambName, dispName)
dispcount++
} else {
fmt.Printf("\nNão foi possível cadastrar dispositivo: O ambiente %s não existe!\n", ambName)
}
case "7":
fmt.Printf("\nDe qual ambiente deseja listar dispositivos? ")
fmt.Scanf("%s", &ambName)
_, err := espacoTupla.QueryP(ambName)
if err == nil {
manager.ListarDisp(&espacoTupla, ambName)
} else {
fmt.Printf("\nNão foi possível listar dispositivos: O ambiente %s não existe!\n", ambName)
}
case "8":
var ambOrigem, ambDestino string
fmt.Printf("\nDe qual ambiente de origem do dispositivo desejado? ")
fmt.Scanf("%s", &ambOrigem)
_, err := espacoTupla.QueryP(ambOrigem)
if err == nil {
fmt.Printf("\nQual o dispositivo desejado? ")
fmt.Scanf("%s", &dispName)
_, err = espacoTupla.QueryP(ambOrigem, dispName)
if err != nil {
fmt.Printf("\nDe qual ambiente de destino do dispositivo desejado? ")
fmt.Scanf("%s", &ambDestino)
_, err := espacoTupla.QueryP(ambDestino)
if err == nil {
fmt.Println("Movendo dispositivo...")
manager.MoverUser(&espacoTupla, dispName, ambOrigem, ambDestino)
} else {
fmt.Printf("\nNão foi possível mover dispositivo: O ambiente %s não existe!\n", ambDestino)
}
} else {
fmt.Printf("\nNão foi possível mover dispositivo: O dispositivo %s não existe no ambiente %s!\n", dispName, ambOrigem)
}
manager.ListarUser(&espacoTupla, ambName)
} else {
fmt.Printf("\nNão foi possível mover dispositivo: O ambiente %s não existe!\n", ambOrigem)
}
case "9":
fmt.Println("Destruindo ambientes vazios...")
manager.RemoverAmbs(&espacoTupla)
case "0":
fmt.Println("TCHAU <3")
break
default:
fmt.Println("Opção invalida!")
}
fmt.Printf("Pressione qualquer tecla + Enter para voltar ao menu principal...")
var tecla string
fmt.Scanf("%v", &tecla)
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
cmd.Run()
}
}