diff options
author | Christian Pointner <equinox@spreadspace.org> | 2016-03-29 22:04:00 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2016-03-29 22:04:00 (GMT) |
commit | 4ee99882db8019a6b49fd22f42b23fc00d2644d6 (patch) | |
tree | 80186d65e9121486ce089feddadd48840d642def | |
parent | 59f010d9d418992e30fc9c798019a76b9d3df07b (diff) |
basic telnet commands
-rw-r--r-- | src/rhctl/switch_control.go | 47 | ||||
-rw-r--r-- | src/rhctl/telnet.go | 85 |
2 files changed, 123 insertions, 9 deletions
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go index 40dd788..b48ac07 100644 --- a/src/rhctl/switch_control.go +++ b/src/rhctl/switch_control.go @@ -21,9 +21,48 @@ package main +type CommandType uint8 + +const ( + CmdStatus CommandType = iota + CmdListen + CmdServer + CmdSwitch +) + +func (c CommandType) String() string { + switch c { + case CmdStatus: + return "status" + case CmdListen: + return "listen" + case CmdServer: + return "server" + case CmdSwitch: + return "switch" + } + return "unknown" +} + +type Command struct { + Type CommandType + args []string +} + type SwitchControl struct { - sw *AudioSwitch - servers []*PlayoutServer + sw *AudioSwitch + servers []*PlayoutServer + Commands chan *Command +} + +func (ctrl *SwitchControl) handleCommand(cmd *Command) { + rhdl.Printf("Telnet: got command: %+v", cmd) + switch cmd.Type { + case CmdStatus: + case CmdListen: + case CmdServer: + case CmdSwitch: + } } func handleServer(in <-chan ServerStatus, out chan<- ServerStatus) { @@ -52,8 +91,9 @@ func (ctrl *SwitchControl) Run() { case status := <-serverUpdates: rhdl.Printf("got server status update: %+v", status) // TODO: recalculate overall status and send out commands to switch + case cmd := <-ctrl.Commands: + ctrl.handleCommand(cmd) } - // TODO: add handler for requests from control clients } } @@ -61,5 +101,6 @@ func SwitchControlInit(conf *Config, sw *AudioSwitch, servers []*PlayoutServer) ctrl = &SwitchControl{} ctrl.sw = sw ctrl.servers = servers + ctrl.Commands = make(chan *Command, 8) return } 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) |