package main

// #cgo CFLAGS: -v

import (
	"fmt"

	"gitlab.com/ics_cinnamon/voicegateway/icsconf"
	"gitlab.com/ics_cinnamon/voicegateway/icslog"
	"gitlab.com/ics_cinnamon/voicegateway/icssvc"
	"gitlab.com/ics_cinnamon/voicegateway/sim/simapp"
	"gitlab.com/ics_cinnamon/voicegateway/sim/siptemplate"
)

func main() {
	service := icssvc.NewService()

	fmt.Println("Hello VoiceGateway! Here We Go~\n")

	conf, confErr := icsconf.OpenSimConfig("/home/icsvg/sim/simvg.xml", "/home/icsvg/sim/")
	if confErr != nil {
		confErr.PrintWithCaller(0)
		return
	}
	_, sipScenErr := icsconf.OpenSimScenarioConfig("/home/icsvg/sim/scen.xml", "/home/icsvg/sim/")
	if sipScenErr != nil {
		sipScenErr.PrintWithCaller(0)
		return
	}
	icsLog, lerr := icslog.NewIcsLog(
		&conf.LogConfig,
		icslog.GetLogLevelID(conf.LogConfig.Level),
		icslog.GetLogOutputID(conf.LogConfig.Output),
		conf.LogConfig.Path,
		conf.LogConfig.Disklimit,
	)
	if lerr != nil {
		lerr.Print()
	}

	service.SetIcsLog(icsLog)
	go service.LogWatcher()

	icsLog.Print(icslog.LOG_LEVEL_INFO, -1, "Hello VoiceGateway! Here We Go~\n")
	confmsg := conf.ShowConfig()
	icsLog.Print(icslog.LOG_LEVEL_INFO, -1, confmsg)

	siptemplate.Init()
	//fmt.Println(">>>>", t.String(0))

	//sp := simphone.NewSimPhone()
	//fmt.Println("call id", sp.CallID)

	app := simapp.Init()
	app.Execute()
}
