Пример #1
0
func (f *fileManagerSG) Access(name string) (sg tr.ToplevelTreeElementIf, err error) {
	var ok bool
	sg, ok = f.signalGraphMap[name]
	if ok {
		return
	}
	sg = behaviour.SignalGraphNew(name, f.context)
	var filedir string
	for _, filedir = range backend.XmlSearchPaths() {
		err = sg.ReadFile(fmt.Sprintf("%s/%s", filedir, name))
		if err == nil {
			break
		}
	}
	if err != nil {
		err = fmt.Errorf("fileManagerSG.Access: graph file %s not found.", name)
		return
	}
	var filename string
	if len(filedir) > 0 {
		filename = fmt.Sprintf("%s/%s", filedir, name)
	} else {
		filename = name
	}
	sg.SetPathPrefix(filedir)
	hint := backend.XmlGraphHintNew(name)
	hintfilename := f.HintFilename(filename)
	var buf []byte
	buf, err = tool.ReadFile(hintfilename)
	if err == nil {
		_, err = hint.Read(buf)
		if err != nil {
			return
		}
		err = behaviour.SignalGraphApplyHints(sg.(bh.SignalGraphIf), hint)
		if err != nil {
			err = fmt.Errorf("fileManagerSG.Access: %s", err)
			return
		}
	}
	var newId string
	newId, err = f.context.FTS().AddToplevel(sg.(bh.SignalGraphIf))
	if err != nil {
		err = fmt.Errorf("fileManagerSG.Access: %s", err)
		return
	}
	f.context.FTV().SelectId(newId)

	var gv views.GraphViewIf
	gv, err = views.SignalGraphViewNew(sg.(bh.SignalGraphIf), f.context)
	if err != nil {
		err = fmt.Errorf("fileManagerSG.Access: %s", err)
		return
	}
	f.context.GVC().Add(gv, name)
	f.signalGraphMap[name] = sg.(bh.SignalGraphIf)
	log.Printf("fileManagerSG.Access: graph %s successfully loaded.\n", name)

	return
}
Пример #2
0
func (f *fileManagerLib) Access(name string) (lib tr.ToplevelTreeElementIf, err error) {
	var ok bool
	lib, ok = f.libraryMap[name]
	if ok {
		return
	}
	lib = behaviour.LibraryNew(name, f.context)
	var filedir string
	for _, filedir := range backend.XmlSearchPaths() {
		err = lib.ReadFile(fmt.Sprintf("%s/%s", filedir, name))
		if err == nil {
			break
		}
	}
	if err != nil {
		err = fmt.Errorf("fileManagerLib.Access: library file %s not found", name)
		return
	}
	lib.SetPathPrefix(filedir)
	f.libraryMap[name] = lib.(bh.LibraryIf)
	var newId string
	newId, err = f.context.FTS().AddToplevel(lib.(bh.LibraryIf))
	if err != nil {
		err = fmt.Errorf("fileManagerLib.Access: %s", err)
		return
	}
	f.context.FTV().SelectId(newId)
	if err != nil {
		err = fmt.Errorf("fileManagerLib.Access: %s", err)
		return
	}
	log.Printf("fileManagerLib.Access: library %s successfully loaded\n", name)
	return
}
Пример #3
0
func (f *fileManagerMap) Access(name string) (m tr.ToplevelTreeElementIf, err error) {
	var ok bool
	m, ok = f.mappingMap[name]
	if ok {
		return
	}
	m = mapping.MappingNew(name, f.context)
	var filedir string
	for _, filedir = range backend.XmlSearchPaths() {
		err = m.ReadFile(fmt.Sprintf("%s/%s", filedir, name))
		if err != nil {
			log.Printf("fileManagerMap.Access error: %s\n", err)
		}
		if err == nil {
			break
		}
	}
	if err != nil {
		err = fmt.Errorf("fileManagerMap.Access: mapping file %s not found.", name)
		return
	}
	var filename string
	if len(filedir) > 0 {
		filename = fmt.Sprintf("%s/%s", filedir, name)
	} else {
		filename = name
	}
	m.SetPathPrefix(filedir)
	// TODO: check consistency with graph/platform
	//mapping.AddMapping(n, nId, nil)
	//melem, _ = mapping.MappedElement(nId)
	err = f.Consistent(m.(mp.MappingIf))
	if err != nil {
		return
	}

	hint := backend.XmlMappingHintNew(name)
	hintfilename := f.HintFilename(filename)
	var buf []byte
	buf, err = tool.ReadFile(hintfilename)
	if err == nil {
		_, err = hint.Read(buf)
		if err != nil {
			return
		}
		err = mapping.MappingApplyHints(m.(mp.MappingIf), hint)
		if err != nil {
			err = fmt.Errorf("fileManagerMap.Access: %s", err)
			return
		}
	}
	var newId string
	newId, err = f.context.FTS().AddToplevel(m.(mp.MappingIf))
	if err != nil {
		err = fmt.Errorf("fileManagerMap.Access: %s", err)
		return
	}
	f.context.FTV().SelectId(newId)
	var mv views.GraphViewIf
	mv, err = views.MappingViewNew(m.(mp.MappingIf), f.context)
	if err != nil {
		err = fmt.Errorf("fileManagerMap.Access: Could not create platform view.")
		return
	}
	f.context.GVC().Add(mv, name)
	log.Printf("fileManagerMap.Access: platform %s successfully loaded.\n", name)
	f.mappingMap[name] = m.(mp.MappingIf)
	return
}