2023-01-05 09:06:39 +01:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/container"
|
|
|
|
"fyne.io/fyne/v2/layout"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
2023-05-12 09:10:24 +02:00
|
|
|
"gitea.mmo.to/ppForge/ppforge/packet"
|
|
|
|
"gitea.mmo.to/ppForge/ppforge/protocol"
|
|
|
|
"gitea.mmo.to/ppForge/ppforge/protocolctl"
|
2023-01-05 09:06:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Metadata struct {
|
|
|
|
Representation *fyne.Container
|
|
|
|
}
|
|
|
|
type PacketMetadata struct {
|
|
|
|
Metadata
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProtocolMetadata struct {
|
|
|
|
Metadata
|
|
|
|
NameValue *widget.Entry
|
|
|
|
VersionValue *widget.Entry
|
|
|
|
ExtendsValue *widget.Entry
|
|
|
|
TcpIpLayer *widget.Select
|
|
|
|
OsiLayer *widget.Select
|
|
|
|
DescValue *widget.Entry
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pmd *ProtocolMetadata) SetChanged(setfunc func(s string)) {
|
|
|
|
pmd.NameValue.OnChanged = setfunc
|
|
|
|
pmd.ExtendsValue.OnChanged = setfunc
|
|
|
|
pmd.DescValue.OnChanged = setfunc
|
|
|
|
pmd.VersionValue.OnChanged = setfunc
|
|
|
|
pmd.TcpIpLayer.OnChanged = setfunc
|
|
|
|
pmd.OsiLayer.OnChanged = setfunc
|
|
|
|
}
|
|
|
|
|
2023-01-05 14:16:41 +01:00
|
|
|
func NewMetadataProtocol() *ProtocolMetadata {
|
2023-01-05 09:06:39 +01:00
|
|
|
md := ProtocolMetadata{}
|
|
|
|
vbox := container.NewVBox()
|
|
|
|
vbox.Add(widget.NewLabel("Protocol Metadata"))
|
|
|
|
form := container.New(layout.NewFormLayout())
|
|
|
|
form.Add(widget.NewLabel("Name:"))
|
|
|
|
md.NameValue = widget.NewEntry()
|
|
|
|
form.Add(md.NameValue)
|
|
|
|
form.Add(widget.NewLabel("Version:"))
|
|
|
|
md.VersionValue = widget.NewEntry()
|
|
|
|
form.Add(md.VersionValue)
|
|
|
|
form.Add(widget.NewLabel("Extends:"))
|
|
|
|
md.ExtendsValue = widget.NewEntry()
|
|
|
|
form.Add(md.ExtendsValue)
|
|
|
|
md.TcpIpLayer = widget.NewSelect(
|
|
|
|
[]string{
|
|
|
|
"Network Access",
|
|
|
|
"Internet",
|
|
|
|
"Transport",
|
|
|
|
"Application",
|
|
|
|
},
|
|
|
|
func(s string) {
|
|
|
|
})
|
|
|
|
form.Add(widget.NewLabel("TcpIpLayer*:"))
|
|
|
|
form.Add(md.TcpIpLayer)
|
|
|
|
md.OsiLayer = widget.NewSelect(
|
|
|
|
[]string{
|
|
|
|
"(Physical)",
|
|
|
|
"Data Link",
|
|
|
|
"Network",
|
|
|
|
"Transport",
|
|
|
|
"Session",
|
|
|
|
"Presentation",
|
|
|
|
"Application",
|
|
|
|
},
|
|
|
|
func(s string) {
|
|
|
|
|
|
|
|
})
|
|
|
|
form.Add(widget.NewLabel("OSI Layer:"))
|
|
|
|
form.Add(md.OsiLayer)
|
|
|
|
vbox.Add(form)
|
|
|
|
vbox.Add(widget.NewLabel("Description"))
|
|
|
|
multiline := widget.NewMultiLineEntry()
|
|
|
|
multiline.SetMinRowsVisible(3)
|
|
|
|
md.DescValue = multiline
|
|
|
|
vbox.Add(multiline)
|
|
|
|
md.Representation = vbox
|
|
|
|
return &md
|
|
|
|
}
|
|
|
|
|
2023-01-05 14:16:41 +01:00
|
|
|
func (md *ProtocolMetadata) SetProtocol(prot *protocol.ProtocolStructure) {
|
2023-01-05 09:06:39 +01:00
|
|
|
setfunc := func(s string) {
|
|
|
|
protocolctl.UpdateMetaData(
|
|
|
|
prot,
|
|
|
|
md.NameValue.Text,
|
|
|
|
md.VersionValue.Text,
|
2023-03-03 14:24:11 +01:00
|
|
|
uint(md.OsiLayer.SelectedIndex()),
|
|
|
|
uint(md.TcpIpLayer.SelectedIndex()),
|
2023-01-05 09:06:39 +01:00
|
|
|
md.ExtendsValue.Text,
|
|
|
|
md.DescValue.Text,
|
|
|
|
)
|
|
|
|
fmt.Printf("%s", protocolctl.ToJson(prot))
|
|
|
|
}
|
2023-03-03 14:24:11 +01:00
|
|
|
md.NameValue.SetText(prot.Metadata.Name)
|
|
|
|
md.VersionValue.SetText(prot.Metadata.Version)
|
|
|
|
md.DescValue.SetText(prot.Metadata.Description)
|
|
|
|
md.ExtendsValue.SetText(prot.Metadata.ExtensionTo)
|
|
|
|
md.OsiLayer.SetSelectedIndex(int(prot.Metadata.OSILayer))
|
|
|
|
md.TcpIpLayer.SetSelectedIndex(int(prot.Metadata.TCPIPLayer))
|
2023-01-05 09:06:39 +01:00
|
|
|
md.SetChanged(setfunc)
|
2023-01-05 14:16:41 +01:00
|
|
|
md.Representation.Refresh()
|
2023-01-05 09:06:39 +01:00
|
|
|
}
|
|
|
|
|
2023-01-05 14:16:41 +01:00
|
|
|
func (md *ProtocolMetadata) Unset() {
|
|
|
|
md.SetChanged(func(s string) {})
|
|
|
|
}
|
|
|
|
|
2023-04-12 15:14:19 +02:00
|
|
|
func (md *PacketMetadata) SetData(pack *packet.Structure) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-01-05 14:16:41 +01:00
|
|
|
func NewMetadataPacket() *PacketMetadata {
|
2023-01-05 09:06:39 +01:00
|
|
|
md := PacketMetadata{}
|
|
|
|
vbox := container.NewVBox()
|
|
|
|
vbox.Add(widget.NewLabel("Packet Metadata"))
|
|
|
|
form := container.New(layout.NewFormLayout())
|
|
|
|
form.Add(widget.NewLabel("Name:"))
|
|
|
|
form.Add(widget.NewEntry())
|
|
|
|
vbox.Add(form)
|
|
|
|
vbox.Add(widget.NewLabel("Description:"))
|
|
|
|
multiline := widget.NewMultiLineEntry()
|
|
|
|
multiline.SetMinRowsVisible(3)
|
|
|
|
vbox.Add(multiline)
|
|
|
|
return &md
|
|
|
|
}
|