Exemple #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
}
Exemple #2
0
func (m *XmlMapping) ReadFile(filepath string) error {
	data, err := tool.ReadFile(filepath)
	if err != nil {
		return fmt.Errorf("XmlMapping.ReadFile error: Failed to read file %s", filepath)
	}
	_, err = m.Read(data)
	if err != nil {
		return fmt.Errorf("XmlMapping.ReadFile error: %v", err)
	}
	return err
}
Exemple #3
0
func (g *XmlSignalGraph) ReadFile(filepath string) error {
	data, err := tool.ReadFile(filepath)
	if err != nil {
		return fmt.Errorf("XmlSignalGraph.ReadFile error: Failed to read file %s", filepath)
	}
	_, err = g.Read(data)
	if err != nil {
		return fmt.Errorf("XmlSignalGraph.ReadFile error: %v", err)
	}
	return err
}
Exemple #4
0
func (p *XmlPlatform) ReadFile(filepath string) (err error) {
	var data []byte
	data, err = tool.ReadFile(filepath)
	if err != nil {
		err = fmt.Errorf("XmlPlatform.ReadFile error: Failed to read file %s", filepath)
		return
	}
	_, err = p.Read(data)
	if err != nil {
		err = fmt.Errorf("XmlPlatform.ReadFile error: %v", err)
	}
	return
}
Exemple #5
0
func (f *FileViewer) Init(filename string) (err error) {
	// Read file content to buf
	buf, err := tool.ReadFile(filename)
	if err != nil {
		log.Println("Warning: could not read file", filename, err)
		return
	}

	// Create a new text view to show the file content
	f.view, err = gtk.TextViewNew()
	if err != nil {
		log.Println("Unable to create textview:", err)
		return
	}
	textbuf, err := f.view.GetBuffer()
	if err != nil {
		log.Println("view.GetBuffer failed:", err)
		return
	}

	f.scrolled.Add(f.view)
	textbuf.SetText(string(buf))
	return
}
Exemple #6
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
}