diff options
Diffstat (limited to 'src/rhctl/telnet.go')
-rw-r--r-- | src/rhctl/telnet.go | 85 |
1 files changed, 79 insertions, 6 deletions
diff --git a/src/rhctl/telnet.go b/src/rhctl/telnet.go index 3cc2b44..8d73846 100644 --- a/src/rhctl/telnet.go +++ b/src/rhctl/telnet.go @@ -29,13 +29,82 @@ type TelnetInterface struct { server *telgo.Server } -func status(c *telgo.Client, args []string, ctrl *SwitchControl) bool { - // TODO: get status from ctrl - c.Sayln("not yet implemented!") +func telnetStatus(c *telgo.Client, args []string, ctrl *SwitchControl) bool { + ctrl.Commands <- &Command{Type: CmdStatus} + // TODO: implement this return false } -func quit(c *telgo.Client, args []string) bool { +func telnetListen(c *telgo.Client, args []string, ctrl *SwitchControl) bool { + ctrl.Commands <- &Command{Type: CmdListen} + // TODO: implement this + return false +} + +func telnetServer(c *telgo.Client, args []string, ctrl *SwitchControl) bool { + ctrl.Commands <- &Command{Type: CmdServer} + // TODO: implement this + return false +} + +func telnetSwitch(c *telgo.Client, args []string, ctrl *SwitchControl) bool { + ctrl.Commands <- &Command{Type: CmdSwitch} + // TODO: implement this + return false +} + +func telnetHelp(c *telgo.Client, args []string) bool { + switch len(args) { + case 2: + switch args[1] { + case "quit": + c.Sayln("usage: quit") + c.Sayln(" terminates the client connection. You may also use Ctrl-D to do this.") + return false + case "help": + c.Sayln("usage: help [ <cmd> ]") + c.Sayln(" prints command overview or detailed info to <cmd>.") + return false + case "status": + c.Sayln("usage: status") + c.Sayln(" show the status of the switch and servers") + return false + case "listen": + c.Sayln("usage: listen [ <type> ]") + c.Sayln(" subscribe to messages of type <type>. The following types are allowed:") + c.Sayln(" - status audio input/output mapping changes") + c.Sayln(" - gpi general purpose input status messages") + c.Sayln(" - oc open-collector status messages") + c.Sayln(" - relay relay status messages") + c.Sayln(" - silence status of the silence detector") + c.Sayln("") + c.Sayln(" if you omit the type this client you will be subscribed to all types.") + return false + case "server": + c.Sayln("usage: server <name>") + c.Sayln(" switch to the server of name <name>. If the given server name does not") + c.Sayln(" exist or is dead, the switch-over will be denied") + return false + case "switch": + c.Sayln("usage: switch <cmd> [ [ <arg1> ] ... ]") + c.Sayln(" send commands to tha audio switch directley.") + return false + } + fallthrough + default: + c.Sayln("usage: <cmd> [ [ <arg1> ] ... ]") + c.Sayln(" available commands:") + c.Sayln(" quit close connection (or use Ctrl-D)") + c.Sayln(" help [ <cmd> ] print this, or help for specific command") + c.Sayln(" status show status of switch and all servers") + c.Sayln(" listen [ <type> ] add listener for messages of type <type>") + c.Sayln(" server <name> switch to server <name>") + c.Sayln(" switch <cmd> [ [ <arg1> ] ... ] send command to switch") + } + return false +} + +func telnetQuit(c *telgo.Client, args []string) bool { return true } @@ -50,8 +119,12 @@ func TelnetInit(conf *Config, ctrl *SwitchControl) (telnet *TelnetInterface) { telnet = &TelnetInterface{} cmdlist := make(telgo.CmdList) - cmdlist["status"] = func(c *telgo.Client, args []string) bool { return status(c, args, ctrl) } - cmdlist["quit"] = quit + cmdlist["status"] = func(c *telgo.Client, args []string) bool { return telnetStatus(c, args, ctrl) } + cmdlist["listen"] = func(c *telgo.Client, args []string) bool { return telnetListen(c, args, ctrl) } + cmdlist["server"] = func(c *telgo.Client, args []string) bool { return telnetServer(c, args, ctrl) } + cmdlist["switch"] = func(c *telgo.Client, args []string) bool { return telnetSwitch(c, args, ctrl) } + cmdlist["help"] = telnetHelp + cmdlist["quit"] = telnetQuit telnet.server = telgo.NewServer(conf.Clients.Telnet.Address, "rhctl> ", cmdlist, ctrl) |