Skip to content

Commit dd9e56d

Browse files
committed
Reactor bindings and subscriptions
- Refactor BindingManager and SubscriptionManager interface APIs - Add support for read requests to NodeManagementBindingData and NodeManagementSubscriptionData - Exclude sending notifications for updates on NodeManagementBindingData and NodeManagementSubscriptionData (see code comment in `spine/feature_local.go` method `SetData` on why this is done) - Store bindings and subscriptions in NodeManagement data structures - Store bindings and subscriptions for local client and server features - Only store a requested binding or subscription if the remote accepted it - Adding an already existing binding or subcription again will not return an error - On add requests, only check for proper roles, if the `serverFeatureType` is provided on request - Add support for deleting all bindings or subscriptions with the same role relation by omitting feature address or also entity address - Add support for delete requests from a server feature to a client feature - Fix a crash when incoming subscription requests where missing the optional `serverFeatureType`
1 parent 174299d commit dd9e56d

34 files changed

+1873
-1132
lines changed

api/api.go

+30-11
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,43 @@ type EventHandlerInterface interface {
1414

1515
// implemented by BindingManagerImpl
1616
type BindingManagerInterface interface {
17+
// Add a binding between a client and server feature where one of each is local and the other one is remote
1718
AddBinding(remoteDevice DeviceRemoteInterface, data model.BindingManagementRequestCallType) error
18-
RemoveBinding(data model.BindingManagementDeleteCallType, remoteDevice DeviceRemoteInterface) error
19-
RemoveBindingsForDevice(remoteDevice DeviceRemoteInterface)
20-
RemoveBindingsForEntity(remoteEntity EntityRemoteInterface)
21-
Bindings(remoteDevice DeviceRemoteInterface) []*BindingEntry
22-
BindingsOnFeature(featureAddress model.FeatureAddressType) []*BindingEntry
23-
HasLocalFeatureRemoteBinding(localAddress, remoteAddress *model.FeatureAddressType) bool
19+
// Remove a binding between a client and server feature where one of each is local and the other one is remote
20+
RemoveBinding(remoteDevice DeviceRemoteInterface, data model.BindingManagementDeleteCallType) error
21+
// Remove all stored bindings for a given remote device
22+
RemoveBindingsForRemoteDevice(remoteDevice DeviceRemoteInterface)
23+
// Remove all stored bindings for a given remote device entity
24+
RemoveBindingsForRemoteEntity(remoteEntity EntityRemoteInterface)
25+
// Remove all stored bindings for a given local device entity
26+
RemoveBindingsForLocalEntity(localEntity EntityLocalInterface)
27+
// Checks if a binding between the client and server feature exists
28+
HasBinding(clientAddress, serverAddress *model.FeatureAddressType) bool
29+
// Return all stored bindings for a given remote device
30+
BindingsForRemoteDevice(remoteDevice DeviceRemoteInterface) []model.BindingManagementEntryDataType
31+
// Return all stored bindings for a given feature address
32+
BindingsForFeatureAddress(localAddress model.FeatureAddressType) []model.BindingManagementEntryDataType
2433
}
2534

2635
/* Subscription Manager */
2736

2837
type SubscriptionManagerInterface interface {
38+
// Add a subscription between a client and server feature where one of each is local and the other one is remote
2939
AddSubscription(remoteDevice DeviceRemoteInterface, data model.SubscriptionManagementRequestCallType) error
30-
RemoveSubscription(data model.SubscriptionManagementDeleteCallType, remoteDevice DeviceRemoteInterface) error
31-
RemoveSubscriptionsForDevice(remoteDevice DeviceRemoteInterface)
32-
RemoveSubscriptionsForEntity(remoteEntity EntityRemoteInterface)
33-
Subscriptions(remoteDevice DeviceRemoteInterface) []*SubscriptionEntry
34-
SubscriptionsOnFeature(featureAddress model.FeatureAddressType) []*SubscriptionEntry
40+
// Remove a subscription between a client and server feature where one of each is local and the other one is remote
41+
RemoveSubscription(remoteDevice DeviceRemoteInterface, data model.SubscriptionManagementDeleteCallType) error
42+
// Remove all stored subscription for a given remote device
43+
RemoveSubscriptionsForRemoteDevice(remoteDevice DeviceRemoteInterface)
44+
// Remove all stored subscription for a given remote device entity
45+
RemoveSubscriptionsForRemoteEntity(remoteEntity EntityRemoteInterface)
46+
// Remove all stored subscription for a given local device entity
47+
RemoveSubscriptionsForLocalEntity(localEntity EntityLocalInterface)
48+
// Checks if a subscription between the client and server feature exists
49+
HasSubscription(clientAddress, serverAddress *model.FeatureAddressType) bool
50+
// Return all stored subscriptions for a given remote device
51+
SubscriptionsForRemoteDevice(remoteDevice DeviceRemoteInterface) []model.SubscriptionManagementEntryDataType
52+
// Return all stored subscriptions for a given feature address
53+
SubscriptionsForFeatureAddress(localAddress model.FeatureAddressType) []model.SubscriptionManagementEntryDataType
3554
}
3655

3756
/* Heartbeats */

api/binding.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package api
22

33
type BindingEntry struct {
44
Id uint64
5-
ServerFeature FeatureLocalInterface
6-
ClientFeature FeatureRemoteInterface
5+
LocalFeature FeatureLocalInterface
6+
RemoteFeature FeatureRemoteInterface
77
}

api/entity.go

-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ type EntityLocalInterface interface {
5858
// Remove all usecases
5959
RemoveAllUseCaseSupports()
6060

61-
// Remove all subscriptions
62-
RemoveAllSubscriptions()
63-
64-
// Remove all bindings
65-
RemoveAllBindings()
66-
6761
// Get the SPINE data structure for NodeManagementDetailDiscoveryData messages for this entity
6862
Information() *model.NodeManagementDetailedDiscoveryEntityInformationType
6963
}

api/feature.go

-4
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,13 @@ type FeatureLocalInterface interface {
101101
SubscribeToRemote(remoteAddress *model.FeatureAddressType) (*model.MsgCounterType, *model.ErrorType)
102102
// Trigger a subscription removal request for a given feature remote address
103103
RemoveRemoteSubscription(remoteAddress *model.FeatureAddressType) (*model.MsgCounterType, *model.ErrorType)
104-
// Trigger subscription removal requests for all subscriptions of this feature
105-
RemoveAllRemoteSubscriptions()
106104

107105
// Check if there already is a binding to a given feature remote address
108106
HasBindingToRemote(remoteAddress *model.FeatureAddressType) bool
109107
// Trigger a binding request to a given feature remote address
110108
BindToRemote(remoteAddress *model.FeatureAddressType) (*model.MsgCounterType, *model.ErrorType)
111109
// Trigger a binding removal request for a given feature remote address
112110
RemoveRemoteBinding(remoteAddress *model.FeatureAddressType) (*model.MsgCounterType, *model.ErrorType)
113-
// Trigger binding removal requests for all subscriptions of this feature
114-
RemoveAllRemoteBindings()
115111

116112
// Handle an incoming SPINE message for this feature
117113
HandleMessage(message *Message) *model.ErrorType

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/enbility/spine-go
33
go 1.22.0
44

55
require (
6-
github.com/ahmetb/go-linq/v3 v3.2.0
76
github.com/enbility/ship-go v0.0.0-20241006160314-3a4325a1a6d6
87
github.com/golanguzb70/lrucache v1.2.0
98
github.com/google/go-cmp v0.6.0

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/ahmetb/go-linq/v3 v3.2.0 h1:BEuMfp+b59io8g5wYzNoFe9pWPalRklhlhbiU3hYZDE=
2-
github.com/ahmetb/go-linq/v3 v3.2.0/go.mod h1:haQ3JfOeWK8HpVxMtHHEMPVgBKiYyQ+f1/kLZh/cj9U=
31
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
42
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
53
github.com/enbility/ship-go v0.0.0-20241006160314-3a4325a1a6d6 h1:bjrcJ4wxEsG5rXHlXnedRzqAV9JYglj82S14Nf1oLvs=

0 commit comments

Comments
 (0)