~emersion/drmdb

925209c63a2c93f532a72ea08a0327ea5af5e944 — Simon Ser 2 years ago 651ca3a
go fmt
1 files changed, 28 insertions(+), 28 deletions(-)

M server.go
M server.go => server.go +28 -28
@@ 11,8 11,8 @@ import (

	"git.sr.ht/~emersion/drmdb/drmtree"
	"git.sr.ht/~emersion/go-drm"
	"github.com/labstack/echo/v4"
	"git.sr.ht/~emersion/go-hwids"
	"github.com/labstack/echo/v4"
	"github.com/mcuadros/go-version"
)



@@ 36,17 36,17 @@ type indexData struct {
}

type propertyData struct {
	Type drm.PropertyType
	Type       drm.PropertyType
	ObjectType drm.ObjectType
	Drivers map[string]bool
	Drivers    map[string]bool
}

type deviceData struct {
	ID string
	ID      string
	BusType drm.BusType
	Vendor string
	Name string
	Driver string
	Vendor  string
	Name    string
	Driver  string
}

func walkProps(props drmtree.PropertyMap, obj drm.AnyID, f func(drm.AnyID, string, *drmtree.Property) error) error {


@@ 130,7 130,7 @@ func loadPCIIDs() (vendors map[uint16]string, devices map[uint32]string, err err
		case hwids.PCIVendor:
			vendors[id.Vendor] = id.VendorName
		case hwids.PCIDevice:
			k := uint32(id.Vendor) << 16 | uint32(id.Device)
			k := uint32(id.Vendor)<<16 | uint32(id.Device)
			devices[k] = id.DeviceName
		}
	}


@@ 194,7 194,7 @@ func New() *echo.Echo {

	e.GET("/drivers", func(c echo.Context) error {
		var drivers []*drmtree.Driver
		err := walkLatestDriver(func (n *drmtree.Node) error {
		err := walkLatestDriver(func(n *drmtree.Node) error {
			drivers = append(drivers, n.Driver)
			return nil
		})


@@ 202,30 202,30 @@ func New() *echo.Echo {
			return err
		}

		return c.Render(http.StatusOK, "drivers.html", struct{
		return c.Render(http.StatusOK, "drivers.html", struct {
			Drivers []*drmtree.Driver
		}{drivers})
	})

	e.GET("/devices", func(c echo.Context) error {
		devices := make(map[string]deviceData)
		err := walk(func (n *drmtree.Node) error {
		err := walk(func(n *drmtree.Node) error {
			switch dev := n.Device.DeviceData.(type) {
			case *drmtree.DevicePCI:
				id := fmt.Sprintf("%04X:%04X", dev.Vendor, dev.Device)
				devices[id] = deviceData{
					ID: id,
					ID:      id,
					BusType: n.Device.BusType,
					Vendor: pciVendors[uint16(dev.Vendor)],
					Name: pciDevices[dev.Vendor << 16 | dev.Device],
					Driver: n.Driver.Name,
					Vendor:  pciVendors[uint16(dev.Vendor)],
					Name:    pciDevices[dev.Vendor<<16|dev.Device],
					Driver:  n.Driver.Name,
				}
			case *drmtree.DevicePlatform:
				id := strings.Join(dev.Compatible, " ")
				devices[id] = deviceData{
					ID: id,
					ID:      id,
					BusType: n.Device.BusType,
					Driver: n.Driver.Name,
					Driver:  n.Driver.Name,
				}
			}



@@ 235,7 235,7 @@ func New() *echo.Echo {
			return err
		}

		return c.Render(http.StatusOK, "devices.html", struct{
		return c.Render(http.StatusOK, "devices.html", struct {
			Devices map[string]deviceData
		}{devices})
	})


@@ 244,7 244,7 @@ func New() *echo.Echo {
		var drivers []string
		caps := make(map[string]map[string]*uint64)
		clientCaps := make(map[string]map[string]bool)
		err := walkLatestDriver(func (n *drmtree.Node) error {
		err := walkLatestDriver(func(n *drmtree.Node) error {
			drv := n.Driver.Name
			drivers = append(drivers, drv)



@@ 268,9 268,9 @@ func New() *echo.Echo {
			return err
		}

		return c.Render(http.StatusOK, "capabilities.html", struct{
			Drivers []string
			Caps map[string]map[string]*uint64
		return c.Render(http.StatusOK, "capabilities.html", struct {
			Drivers    []string
			Caps       map[string]map[string]*uint64
			ClientCaps map[string]map[string]bool
		}{drivers, caps, clientCaps})
	})


@@ 278,16 278,16 @@ func New() *echo.Echo {
	e.GET("/properties", func(c echo.Context) error {
		drivers := make(map[string]struct{})
		props := make(map[string]propertyData)
		err := walk(func (n *drmtree.Node) error {
		err := walk(func(n *drmtree.Node) error {
			drv := n.Driver.Name
			drivers[drv] = struct{}{}

			return walkNodeProps(n, func (obj drm.AnyID, name string, prop *drmtree.Property) error {
			return walkNodeProps(n, func(obj drm.AnyID, name string, prop *drmtree.Property) error {
				if _, ok := props[name]; !ok {
					props[name] = propertyData{
						Type: prop.Type,
						Type:       prop.Type,
						ObjectType: obj.Type(),
						Drivers: make(map[string]bool),
						Drivers:    make(map[string]bool),
					}
				}
				props[name].Drivers[drv] = true


@@ 298,8 298,8 @@ func New() *echo.Echo {
			return err
		}

		return c.Render(http.StatusOK, "properties.html", struct{
			Drivers map[string]struct{}
		return c.Render(http.StatusOK, "properties.html", struct {
			Drivers    map[string]struct{}
			Properties map[string]propertyData
		}{drivers, props})
	})