-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathregistry.go
73 lines (62 loc) · 1.64 KB
/
registry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package betwixt
// NewDefaultObjectRegistry instantiates a default rgistry containing the Starter Pack
// objects and IPSO smart objects
func NewDefaultObjectRegistry() Registry {
reg := NewObjectRegistry(&LWM2MCoreObjects{}, &IPSOSmartObjects{})
return reg
}
func NewObjectRegistry(s ...ObjectSource) Registry {
reg := &ObjectRegistry{}
reg.sources = []ObjectSource{}
for _, o := range s {
reg.Register(o)
}
return reg
}
// ObjectRegistry is a registry containing known LWM2M objects registered to te OMA NA as well
// as custom objects
// It contains multiple ObjectSources which in turns each contains multiple Object definitions
type ObjectRegistry struct {
sources []ObjectSource
}
func (m *ObjectRegistry) GetDefinition(n LWM2MObjectType) ObjectDefinition {
for _, s := range m.sources {
if s != nil {
o := s.GetObject(n)
if o != nil {
return o
}
}
}
return nil
}
func (m *ObjectRegistry) GetDefinitions() []ObjectDefinition {
defs := []ObjectDefinition{}
for _, s := range m.sources {
if s != nil {
for _, v := range s.GetObjects() {
defs = append(defs, v)
}
}
}
return defs
}
// Registers a new ObjectSource to the tegistry
func (m *ObjectRegistry) Register(s ObjectSource) {
s.Initialize()
m.sources = append(m.sources, s)
}
// Get all object definitions which are mandatory to be registered by
// a client (such as Firmware, Device etc)
func (m *ObjectRegistry) GetMandatory() []ObjectDefinition {
mandatory := []ObjectDefinition{}
for _, s := range m.sources {
objs := s.GetObjects()
for _, o := range objs {
if o.IsMandatory() {
mandatory = append(mandatory, o)
}
}
}
return mandatory
}