mirror of https://bitbucket.org/ausocean/av.git
cmd/revid-cli: remove global revid var
This commit is contained in:
parent
32488d8b9f
commit
86949813fd
|
@ -63,9 +63,6 @@ var canProfile = true
|
||||||
// The logger that will be used throughout
|
// The logger that will be used throughout
|
||||||
var logger *smartlogger.Logger
|
var logger *smartlogger.Logger
|
||||||
|
|
||||||
// Globals
|
|
||||||
var rv *revid.Revid
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
useNetsender := flag.Bool("NetSender", false, "Are we checking vars through netsender?")
|
useNetsender := flag.Bool("NetSender", false, "Are we checking vars through netsender?")
|
||||||
runDurationPtr := flag.Duration("runDuration", defaultRunDuration, "How long do you want revid to run for?")
|
runDurationPtr := flag.Duration("runDuration", defaultRunDuration, "How long do you want revid to run for?")
|
||||||
|
@ -74,13 +71,16 @@ func main() {
|
||||||
|
|
||||||
if !*useNetsender {
|
if !*useNetsender {
|
||||||
// run revid for the specified duration
|
// run revid for the specified duration
|
||||||
startRevid(nil, cfg)
|
rv, _, err := startRevid(nil, cfg)
|
||||||
|
if err != nil {
|
||||||
|
cfg.Logger.Log(smartlogger.Fatal, pkg+"failed to start revid", err.Error())
|
||||||
|
}
|
||||||
time.Sleep(*runDurationPtr)
|
time.Sleep(*runDurationPtr)
|
||||||
stopRevid()
|
stopRevid(rv)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := run(cfg)
|
err := run(nil, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Log(smartlogger.Fatal, pkg+"failed to run revid", "error", err.Error())
|
logger.Log(smartlogger.Fatal, pkg+"failed to run revid", "error", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -281,7 +281,7 @@ func handleFlags() revid.Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize then run the main NetSender client
|
// initialize then run the main NetSender client
|
||||||
func run(cfg revid.Config) error {
|
func run(rv *revid.Revid, cfg revid.Config) error {
|
||||||
// initialize NetSender and use NetSender's logger
|
// initialize NetSender and use NetSender's logger
|
||||||
//config.Logger = netsender.Logger()
|
//config.Logger = netsender.Logger()
|
||||||
logger.Log(smartlogger.Info, pkg+"running in NetSender mode")
|
logger.Log(smartlogger.Info, pkg+"running in NetSender mode")
|
||||||
|
@ -298,14 +298,14 @@ func run(cfg revid.Config) error {
|
||||||
paused = true
|
paused = true
|
||||||
}
|
}
|
||||||
if !paused {
|
if !paused {
|
||||||
cfg, err = updateRevid(&ns, cfg, vars, false)
|
rv, cfg, err = updateRevid(&ns, rv, cfg, vars, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if err := send(&ns); err != nil {
|
if err := send(&ns, rv); err != nil {
|
||||||
logger.Log(smartlogger.Error, pkg+"polling failed", "error", err.Error())
|
logger.Log(smartlogger.Error, pkg+"polling failed", "error", err.Error())
|
||||||
time.Sleep(netSendRetryTime)
|
time.Sleep(netSendRetryTime)
|
||||||
continue
|
continue
|
||||||
|
@ -323,11 +323,11 @@ func run(cfg revid.Config) error {
|
||||||
if vars["mode"] == "Paused" {
|
if vars["mode"] == "Paused" {
|
||||||
if !paused {
|
if !paused {
|
||||||
logger.Log(smartlogger.Info, pkg+"pausing revid")
|
logger.Log(smartlogger.Info, pkg+"pausing revid")
|
||||||
stopRevid()
|
stopRevid(rv)
|
||||||
paused = true
|
paused = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cfg, err = updateRevid(&ns, cfg, vars, !paused)
|
rv, cfg, err = updateRevid(&ns, rv, cfg, vars, !paused)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -343,7 +343,7 @@ func run(cfg revid.Config) error {
|
||||||
|
|
||||||
// send implements our main NetSender client and handles NetReceiver configuration
|
// send implements our main NetSender client and handles NetReceiver configuration
|
||||||
// (as distinct from httpSender which just sends video data).
|
// (as distinct from httpSender which just sends video data).
|
||||||
func send(ns *netsender.Sender) error {
|
func send(ns *netsender.Sender, rv *revid.Revid) error {
|
||||||
// populate input values, if any
|
// populate input values, if any
|
||||||
inputs := netsender.MakePins(ns.Param("ip"), "X")
|
inputs := netsender.MakePins(ns.Param("ip"), "X")
|
||||||
if rv != nil {
|
if rv != nil {
|
||||||
|
@ -365,17 +365,16 @@ func send(ns *netsender.Sender) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrappers for stopping and starting revid
|
// wrappers for stopping and starting revid
|
||||||
func startRevid(ns *netsender.Sender, cfg revid.Config) (revid.Config, error) {
|
func startRevid(ns *netsender.Sender, cfg revid.Config) (*revid.Revid, revid.Config, error) {
|
||||||
var err error
|
rv, err := revid.New(cfg, ns)
|
||||||
rv, err = revid.New(cfg, ns)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, err
|
return nil, cfg, err
|
||||||
}
|
}
|
||||||
rv.Start()
|
rv.Start()
|
||||||
return cfg, nil
|
return rv, cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func stopRevid() {
|
func stopRevid(rv *revid.Revid) {
|
||||||
rv.Stop()
|
rv.Stop()
|
||||||
|
|
||||||
// FIXME(kortschak): Is this waiting on completion of work?
|
// FIXME(kortschak): Is this waiting on completion of work?
|
||||||
|
@ -383,9 +382,9 @@ func stopRevid() {
|
||||||
time.Sleep(revidStopTime)
|
time.Sleep(revidStopTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateRevid(ns *netsender.Sender, cfg revid.Config, vars map[string]string, stop bool) (revid.Config, error) {
|
func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars map[string]string, stop bool) (*revid.Revid, revid.Config, error) {
|
||||||
if stop {
|
if stop {
|
||||||
stopRevid()
|
stopRevid(rv)
|
||||||
}
|
}
|
||||||
|
|
||||||
//look through the vars and update revid where needed
|
//look through the vars and update revid where needed
|
||||||
|
|
Loading…
Reference in New Issue