package main

import "log"
import "os"
import "os/signal"
import um "udi/mqtt"
import "udi/config"


func inputDispatcher() {
  for {
    select {
    case message := <- um.InputChannel:
      log.Printf("Message arrived in inputDispatcher, topic: %s, payload: %s\n", message.Topic, message.Payload)
    }
  }
}

func main() {
  log.SetPrefix("UDI: ")
  log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)

  log.Println("UDI starting")

  config.LoadConfiguration()

  go inputDispatcher()

  um.StartMqttClient()
  defer um.StopMqttClient()

  log.Println("UDI running")

  c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	<-c

  log.Println("Terminating UDI")
}

