| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 | package tcimport (    "github.com/astaxie/beego/logs"    "github.com/astaxie/beego"    "strings"    "fmt"    "time"    "net"    "wb/ut"    "wb/lg"    "testbench/models/statusMgr")type TConn struct {    Logger     *logs.BeeLogger    Conn       net.Conn    Typo       string    TermId     string    ReadBuf    []byte    IsConnect  bool    StatusMgr  *statusMgr.StatusMgr    StatusMap   map[string]interface{}}func (this *TConn) Init(termId string) {    this.TermId = termId    this.InitLog(termId)}func (this *TConn) Write(req []byte) (n int, err error) {    n, err = this.Conn.Write(req)    this.LogSend(ut.BytesToHexStr(req))    return n, err}func (this *TConn) Close(){    this.LogInfo("Connect close:", this.TermId)    this.IsConnect = false    this.Conn.Close()}func (this *TConn) GetType() string{    return this.Typo}func (this *TConn) GetTermId() string{    return this.TermId}func (this *TConn) AddStatus(statusMap map[string]interface{}){    if this.StatusMgr == nil{        lg.Error("TConn.AddPosition:Add position before statusMgr initd")        return    }    this.StatusMgr.AddStatus(statusMap)}func (this *TConn) RefreshStatus(){    if this.StatusMgr == nil{        lg.Error("TConn.AddPosition:Add position before statusMgr initd")        return    }    //lg.Debug("Refresh status")    this.StatusMgr.RefreshStatus(this.TermId)}func (this *TConn) AddPosition(sid string, x, y float64){    if this.StatusMgr == nil{        lg.Error("TConn.AddPosition:Add position before statusMgr initd")        return    }    this.StatusMgr.AddPosition(sid, x, y)}func (this *TConn) InitDtu(startId ...string)bool{    return true}func (this *TConn) InitLog(termId string){    this.Logger = logs.NewLogger(1025)    if beego.BConfig.RunMode != "dev" {        this.Logger.SetLevel(logs.LevelInformational)    }    this.Logger.SetLogger("file", fmt.Sprintf(`{"filename":"%s", "maxdays":192}`, "data/log/msg/" + termId + ".log"))    this.Logger.Info("=================================start new connect at %s =====================================", time.Now().String())}func (this *TConn) LogRecv(msg interface{}) {    if this.Logger != nil {        //lg.Debug(this.Typo, " [R]:", msg)        this.Logger.Info("[R]:%v", msg)    } else {        lg.Info(this.Typo, " [R]:", msg)    }}func (this *TConn)LogSend(msg interface{}) {    if this.Logger != nil {        this.Logger.Info("[S]:%v", msg)    } else {        lg.Info(this.Typo, " [S]:", msg)    }}func (this *TConn)LogInfo(v ...interface{}) {    if this.Logger != nil {        this.Logger.Info(strings.Repeat("%v ", len(v)), v...)    } else {        beego.BeeLogger.Info(this.Typo + strings.Repeat("%v ", len(v)), v...)    }}func (this *TConn)LogDebug(v ...interface{}) {    if this.Logger != nil {        this.Logger.Debug(strings.Repeat("%v ", len(v)), v...)    }else{        beego.BeeLogger.Debug(this.Typo + strings.Repeat("%v ", len(v)), v...)    }}func (this *TConn)LogWarn(v ...interface{}){    lg.Warn(v...)    if this.Logger != nil {        this.Logger.Warn(strings.Repeat("%v ", len(v)), v...)    }}func (this *TConn)LogError(v ...interface{}) {    lg.Error(v...)    if this.Logger != nil {        this.Logger.Error(strings.Repeat("%v ", len(v)), v...)    }}
 |