diff options
Diffstat (limited to 'pkg/subsystem')
| -rw-r--r-- | pkg/subsystem/list.go | 4 | ||||
| -rw-r--r-- | pkg/subsystem/service.go | 44 |
2 files changed, 48 insertions, 0 deletions
diff --git a/pkg/subsystem/list.go b/pkg/subsystem/list.go index 7842f8620..d512a3fe1 100644 --- a/pkg/subsystem/list.go +++ b/pkg/subsystem/list.go @@ -26,3 +26,7 @@ func RegisterList(name string, list []*Subsystem) { func GetList(name string) []*Subsystem { return lists[name] } + +func ListService(name string) *Service { + return MustMakeService(lists[name]) +} diff --git a/pkg/subsystem/service.go b/pkg/subsystem/service.go new file mode 100644 index 000000000..e3dabcfce --- /dev/null +++ b/pkg/subsystem/service.go @@ -0,0 +1,44 @@ +// Copyright 2023 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package subsystem + +import ( + "fmt" +) + +type Service struct { + *Extractor + perName map[string]*Subsystem +} + +func MustMakeService(list []*Subsystem) *Service { + service, err := MakeService(list) + if err != nil { + panic(fmt.Sprintf("service creation failed: %s", err)) + } + return service +} + +func MakeService(list []*Subsystem) (*Service, error) { + extractor := MakeExtractor(list) + perName := map[string]*Subsystem{} + for _, item := range list { + if item.Name == "" { + return nil, fmt.Errorf("input contains a subsystem without a name") + } + if perName[item.Name] != nil { + return nil, fmt.Errorf("collision on %#v name", item.Name) + } + perName[item.Name] = item + } + + return &Service{ + Extractor: extractor, + perName: perName, + }, nil +} + +func (s *Service) ByName(name string) *Subsystem { + return s.perName[name] +} |
