-
Notifications
You must be signed in to change notification settings - Fork 13
/
nodemanagement_binding.go
71 lines (58 loc) · 2.77 KB
/
nodemanagement_binding.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
package spine
import (
"fmt"
"github.com/ahmetb/go-linq/v3"
"github.com/enbility/eebus-go/spine/model"
"github.com/enbility/eebus-go/util"
)
func NewNodeManagementBindingRequestCallType(clientAddress *model.FeatureAddressType, serverAddress *model.FeatureAddressType, featureType model.FeatureTypeType) *model.NodeManagementBindingRequestCallType {
return &model.NodeManagementBindingRequestCallType{
BindingRequest: &model.BindingManagementRequestCallType{
ClientAddress: clientAddress,
ServerAddress: serverAddress,
ServerFeatureType: &featureType,
},
}
}
// route bindings request calls to the appropriate feature implementation and add the bindings to the current list
func (r *NodeManagementImpl) processReadBindingData(message *Message) error {
var remoteDeviceBindings []model.BindingManagementEntryDataType
remoteDeviceBindingEntries := r.Device().BindingManager().Bindings(message.FeatureRemote.Device())
linq.From(remoteDeviceBindingEntries).SelectT(func(s *BindingEntry) model.BindingManagementEntryDataType {
return model.BindingManagementEntryDataType{
BindingId: util.Ptr(model.BindingIdType(s.id)),
ServerAddress: s.serverFeature.Address(),
ClientAddress: s.clientFeature.Address(),
}
}).ToSlice(&remoteDeviceBindings)
cmd := model.CmdType{
NodeManagementBindingData: &model.NodeManagementBindingDataType{
BindingEntry: remoteDeviceBindings,
},
}
return message.FeatureRemote.Sender().Reply(message.RequestHeader, r.Address(), cmd)
}
func (r *NodeManagementImpl) handleMsgBindingData(message *Message) error {
switch message.CmdClassifier {
case model.CmdClassifierTypeCall:
return r.processReadBindingData(message)
default:
return fmt.Errorf("nodemanagement.handleBindingDeleteCall: NodeManagementBindingRequestCall CmdClassifierType not implemented: %s", message.CmdClassifier)
}
}
func (r *NodeManagementImpl) handleMsgBindingRequestCall(message *Message, data *model.NodeManagementBindingRequestCallType) error {
switch message.CmdClassifier {
case model.CmdClassifierTypeCall:
return r.Device().BindingManager().AddBinding(r.Device(), message.FeatureRemote.Device(), *data.BindingRequest)
default:
return fmt.Errorf("nodemanagement.handleBindingRequestCall: NodeManagementBindingRequestCall CmdClassifierType not implemented: %s", message.CmdClassifier)
}
}
func (r *NodeManagementImpl) handleMsgBindingDeleteCall(message *Message, data *model.NodeManagementBindingDeleteCallType) error {
switch message.CmdClassifier {
case model.CmdClassifierTypeCall:
return r.Device().BindingManager().RemoveBinding(*data.BindingDelete, message.FeatureRemote.Device())
default:
return fmt.Errorf("nodemanagement.handleBindingDeleteCall: NodeManagementBindingRequestCall CmdClassifierType not implemented: %s", message.CmdClassifier)
}
}