Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package devicemenu |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | |
| 22 | "github.com/bclicn/color" |
| 23 | "github.com/opencord/voltha-go/cli/util" |
| 24 | "google.golang.org/grpc" |
| 25 | ) |
| 26 | |
| 27 | /* |
| 28 | Conn - the grpc connection to use for making calls to voltha core |
| 29 | */ |
| 30 | var ( |
| 31 | Conn *grpc.ClientConn |
| 32 | DeviceId *string |
| 33 | InputPrompt *string |
| 34 | Commands *[]string |
| 35 | ) |
| 36 | |
| 37 | /* |
| 38 | MainLoop - the loop which processes commands at the main level |
| 39 | */ |
| 40 | func MainLoop(conn *grpc.ClientConn, deviceId string) { |
| 41 | |
| 42 | DeviceId = &deviceId |
| 43 | inputPrompt := fmt.Sprint("(" + color.LightRed("device "+deviceId) + ") ") |
| 44 | InputPrompt = &inputPrompt |
| 45 | funcTable := make(map[string]func(bool)) |
| 46 | // inputPromptSize := len(inputPrompt) |
| 47 | Conn = conn |
| 48 | funcTable["quit"] = util.Exit |
| 49 | funcTable["exit"] = nil |
| 50 | funcTable["edit"] = doEdit |
| 51 | funcTable["history"] = doHistory |
| 52 | funcTable["img_dnld_request"] = doImgDnldRequest |
| 53 | funcTable["perf_config"] = doPerfConfig |
| 54 | funcTable["save"] = doSave |
| 55 | funcTable["eof"] = doEof |
| 56 | funcTable["images"] = doImages |
| 57 | funcTable["img_dnld_status"] = doImgDnldStatus |
| 58 | funcTable["ports"] = doPorts |
| 59 | funcTable["set"] = doSet |
| 60 | funcTable["img_activate"] = doImgActivate |
| 61 | funcTable["img_revert"] = doImgRevert |
| 62 | funcTable["py"] = doPy |
| 63 | funcTable["shell"] = doShell |
| 64 | funcTable["flows"] = doFlows |
| 65 | funcTable["img_dnld_canel"] = doImgDnldCancel |
| 66 | funcTable["list"] = doList |
| 67 | funcTable["shortcuts"] = doShortCuts |
| 68 | funcTable["help"] = doHelp |
| 69 | funcTable["img_dnld_list"] = doImgDnldList |
| 70 | funcTable["pause"] = doPause |
| 71 | funcTable["run"] = doRun |
| 72 | funcTable["show"] = doShow |
| 73 | |
| 74 | commands := make([]string, len(funcTable)) |
| 75 | i := 0 |
| 76 | for key, _ := range funcTable { |
| 77 | commands[i] = key |
| 78 | i++ |
| 79 | } |
| 80 | Commands = &commands |
| 81 | |
| 82 | util.ProcessTable(funcTable, inputPrompt) |
| 83 | |
| 84 | } |