github.com/enbility/spine-go@v0.7.0/spine/nodemanagement_binding.go (about) 1 package spine 2 3 import ( 4 "fmt" 5 6 "github.com/ahmetb/go-linq/v3" 7 "github.com/enbility/spine-go/api" 8 "github.com/enbility/spine-go/model" 9 "github.com/enbility/spine-go/util" 10 ) 11 12 func NewNodeManagementBindingRequestCallType(clientAddress *model.FeatureAddressType, serverAddress *model.FeatureAddressType, featureType model.FeatureTypeType) *model.NodeManagementBindingRequestCallType { 13 return &model.NodeManagementBindingRequestCallType{ 14 BindingRequest: &model.BindingManagementRequestCallType{ 15 ClientAddress: clientAddress, 16 ServerAddress: serverAddress, 17 ServerFeatureType: &featureType, 18 }, 19 } 20 } 21 22 func NewNodeManagementBindingDeleteCallType(clientAddress *model.FeatureAddressType, serverAddress *model.FeatureAddressType) *model.NodeManagementBindingDeleteCallType { 23 return &model.NodeManagementBindingDeleteCallType{ 24 BindingDelete: &model.BindingManagementDeleteCallType{ 25 ClientAddress: clientAddress, 26 ServerAddress: serverAddress, 27 }, 28 } 29 } 30 31 // route bindings request calls to the appropriate feature implementation and add the bindings to the current list 32 func (r *NodeManagement) processReadBindingData(message *api.Message) error { 33 var remoteDeviceBindings []model.BindingManagementEntryDataType 34 remoteDeviceBindingEntries := r.Device().BindingManager().Bindings(message.FeatureRemote.Device()) 35 linq.From(remoteDeviceBindingEntries).SelectT(func(s *api.BindingEntry) model.BindingManagementEntryDataType { 36 return model.BindingManagementEntryDataType{ 37 BindingId: util.Ptr(model.BindingIdType(s.Id)), 38 ServerAddress: s.ServerFeature.Address(), 39 ClientAddress: s.ClientFeature.Address(), 40 } 41 }).ToSlice(&remoteDeviceBindings) 42 43 cmd := model.CmdType{ 44 NodeManagementBindingData: &model.NodeManagementBindingDataType{ 45 BindingEntry: remoteDeviceBindings, 46 }, 47 } 48 49 return message.FeatureRemote.Device().Sender().Reply(message.RequestHeader, r.Address(), cmd) 50 } 51 52 func (r *NodeManagement) handleMsgBindingData(message *api.Message) error { 53 switch message.CmdClassifier { 54 case model.CmdClassifierTypeCall: 55 return r.processReadBindingData(message) 56 57 default: 58 return fmt.Errorf("nodemanagement.handleBindingDeleteCall: NodeManagementBindingRequestCall CmdClassifierType not implemented: %s", message.CmdClassifier) 59 } 60 } 61 62 func (r *NodeManagement) handleMsgBindingRequestCall(message *api.Message, data *model.NodeManagementBindingRequestCallType) error { 63 switch message.CmdClassifier { 64 case model.CmdClassifierTypeCall: 65 return r.Device().BindingManager().AddBinding(message.FeatureRemote.Device(), *data.BindingRequest) 66 67 default: 68 return fmt.Errorf("nodemanagement.handleBindingRequestCall: NodeManagementBindingRequestCall CmdClassifierType not implemented: %s", message.CmdClassifier) 69 } 70 } 71 72 func (r *NodeManagement) handleMsgBindingDeleteCall(message *api.Message, data *model.NodeManagementBindingDeleteCallType) error { 73 switch message.CmdClassifier { 74 case model.CmdClassifierTypeCall: 75 return r.Device().BindingManager().RemoveBinding(*data.BindingDelete, message.FeatureRemote.Device()) 76 77 default: 78 return fmt.Errorf("nodemanagement.handleBindingDeleteCall: NodeManagementBindingRequestCall CmdClassifierType not implemented: %s", message.CmdClassifier) 79 } 80 }