~emersion/drmdb

b0fd53fcb413a9ce43f25a3dae3aae4dbc2bd1d7 — Simon Ser 2 years ago a79789e
Fix driver comparison
2 files changed, 50 insertions(+), 14 deletions(-)

M drmtree/drmtree.go
M server.go
M drmtree/drmtree.go => drmtree/drmtree.go +14 -1
@@ 24,7 24,20 @@ func (ver *DriverVersion) String() string {
}

func (ver *DriverVersion) Less(other *DriverVersion) bool {
	return ver.Major < other.Major || ver.Minor < other.Minor || ver.Patch < other.Patch || ver.Date < other.Date
	if ver.Major < other.Major {
		return true
	} else if ver.Major == other.Major {
		if ver.Minor < other.Minor {
			return true
		} else if ver.Minor == other.Minor {
			if ver.Patch < other.Patch {
				return true
			} else if ver.Patch == other.Patch {
				return ver.Date < other.Date
			}
		}
	}
	return false
}

type Kernel struct {

M server.go => server.go +36 -13
@@ 93,17 93,40 @@ func driverLess(a *drmtree.Driver, b *drmtree.Driver) bool {
	if b.Kernel.SysName == "Linux" && a.Kernel.SysName != "Linux" {
		return true
	}
	return version.Compare(a.Kernel.Release, b.Kernel.Release, "<=")
	return version.Compare(a.Kernel.Release, b.Kernel.Release, "<")
}

func walkLatestDriver(fn func(n *drmtree.Node) error) error {
	latest := make(map[string]*drmtree.Node)
type walkLatestField int

const (
	walkLatestDriver walkLatestField = iota
	walkLatestDevice
)

func walkLatest(f walkLatestField, fn func(k string, n *drmtree.Node) error) error {
	type node struct {
		k string
		n *drmtree.Node
	}

	latest := make(map[string]node)
	err := walk(func(k string, n *drmtree.Node) error {
		other, ok := latest[n.Driver.Name]
		if ok && driverLess(n.Driver, other.Driver) {
		var latestKey string
		switch f {
		case walkLatestDriver:
			latestKey = n.Driver.Name
		case walkLatestDevice:
			latestKey = n.Device.BusID()
		}
		if latestKey == "" {
			return nil
		}
		latest[n.Driver.Name] = n

		other, ok := latest[latestKey]
		if ok && driverLess(n.Driver, other.n.Driver) {
			return nil
		}
		latest[latestKey] = node{k, n}
		return nil
	})
	if err != nil {


@@ 111,7 134,7 @@ func walkLatestDriver(fn func(n *drmtree.Node) error) error {
	}

	for _, n := range latest {
		if err := fn(n); err != nil {
		if err := fn(n.k, n.n); err != nil {
			return err
		}
	}


@@ 205,7 228,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 := walkLatest(walkLatestDriver, func(k string, n *drmtree.Node) error {
			drivers = append(drivers, n.Driver)
			return nil
		})


@@ 219,8 242,8 @@ func New() *echo.Echo {
	})

	e.GET("/devices", func(c echo.Context) error {
		devices := make(map[string]deviceData)
		err := walk(func(k string, n *drmtree.Node) error {
		var devices []deviceData
		err := walkLatest(walkLatestDevice, func(k string, n *drmtree.Node) error {
			data := deviceData{
				Key: k,
				BusID: n.Device.BusID(),


@@ 238,7 261,7 @@ func New() *echo.Echo {
				return nil
			}

			devices[data.BusID] = data
			devices = append(devices, data)
			return nil
		})
		if err != nil {


@@ 246,7 269,7 @@ func New() *echo.Echo {
		}

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



@@ 309,7 332,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 := walkLatest(walkLatestDriver, func(k string, n *drmtree.Node) error {
			drv := n.Driver.Name
			drivers = append(drivers, drv)