Beispiel #1
0
func (m *Manual) Init() { //TODO add the proper return statements with a commandStatus
	id, err := uuid.NewV4()
	if err != nil {
		panic(err) //TODO
	}
	m.Manager = *equipmentManager.NewAnthaEquipmentManager(id.String())
	idm, err := uuid.NewV4()
	if err != nil {
		panic(err) //TODO
	}
	var md equipment.Equipment
	md = manual.NewAnthaManual(idm.String())
	m.Manager.RegisterEquipment(&md)
}
Beispiel #2
0
func NewFrontend() (*Frontend, error) {
	fe := &Frontend{}

	eid, err := uuid.NewV4()
	if err != nil {
		return nil, err
	}
	// TODO need to shudown equipmentmanager here on error
	fe.equipmentManager = equipmentManager.NewAnthaEquipmentManager(eid.String())
	fee := equipmentManager.EquipmentManager(fe.equipmentManager)
	equipmentManager.SetEquipmentManager(&fee)

	mid, err := uuid.NewV4()
	if err != nil {
		return nil, err
	}
	md := manual.NewAnthaManual(mid.String())
	mdd := equipment.Equipment(md)
	fe.equipmentManager.RegisterEquipment(&mdd)

	//cui logger middleware
	fe.cui = md.Cui
	cmw := middleware.NewLogToCui(&md.Cui)
	logId, err := uuid.NewV4()
	if err != nil {
		return nil, err
	}

	fe.logger = logger.NewAnthaFileLogger(logId.String())
	fe.logger.RegisterMiddleware(cmw)
	var logRef logger.Logger
	logRef = fe.logger
	logger.SetLogger(&logRef)

	var writer io.Writer
	if len(logFile) > 0 {
		w, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE, 0600)
		if err != nil {
			return nil, err
		}
		writer = w
	} else {
		writer = ioutil.Discard
	}

	fe.debugLogger = log.New(writer, "", log.LstdFlags)

	return fe, nil
}