Skip to content

Commit

Permalink
Fix subscription and binding handling (#33)
Browse files Browse the repository at this point in the history
- `HasSubscription` and `HasBinding` now properly reports the remote
subscriptions depending on if the remote device/entity is still
connected
- Add API to remove subscriptions and binding data for a specific remote
entity and remote device
  • Loading branch information
DerAndereAndi committed Sep 11, 2024
2 parents 0024041 + 910ec64 commit b637b53
Show file tree
Hide file tree
Showing 11 changed files with 446 additions and 38 deletions.
3 changes: 3 additions & 0 deletions api/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type DeviceLocalInterface interface {
// Get a FeatureLocalInterface implementation for a given feature address
FeatureByAddress(address *model.FeatureAddressType) FeatureLocalInterface

// Clean all entity specific caches
CleanRemoteEntityCaches(remoteAddress *model.EntityAddressType)

// Process incoming SPINE datagram
ProcessCmd(datagram model.DatagramType, remoteDevice DeviceRemoteInterface) error

Expand Down
8 changes: 6 additions & 2 deletions api/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ type FeatureLocalInterface interface {
// Overwrite the default 1 minute timeout for write approvals
SetWriteApprovalTimeout(duration time.Duration)

// Clean all device specific caches
CleanCaches(ski string)
// Clean all write approval caches for a remote device ski
CleanWriteApprovalCaches(ski string)
// Clean all remote device specific caches
CleanRemoteDeviceCaches(remoteAddress *model.DeviceAddressType)
// Clean all remote entity specific caches
CleanRemoteEntityCaches(remoteAddress *model.EntityAddressType)

// return all functions
Functions() []model.FunctionType
Expand Down
33 changes: 33 additions & 0 deletions mocks/DeviceLocalInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 76 additions & 10 deletions mocks/FeatureLocalInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 76 additions & 10 deletions mocks/NodeManagementInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions spine/device_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ func (r *DeviceLocal) RemoveRemoteDeviceConnection(ski string) {
}

func (r *DeviceLocal) RemoveRemoteDevice(ski string) {
if r.RemoteDeviceForSki(ski) == nil {
remoteDevice := r.RemoteDeviceForSki(ski)
if remoteDevice == nil {
return
}

Expand All @@ -177,10 +178,14 @@ func (r *DeviceLocal) RemoveRemoteDevice(ski string) {
_ = Events.unsubscribe(api.EventHandlerLevelCore, r)
}

remoteDeviceAddress := &model.DeviceAddressType{
Device: remoteDevice.Address(),
}
// remove all data caches for this device
for _, entity := range r.entities {
for _, feature := range entity.Features() {
feature.CleanCaches(ski)
feature.CleanWriteApprovalCaches(ski)
feature.CleanRemoteDeviceCaches(remoteDeviceAddress)
}
}
}
Expand Down Expand Up @@ -287,6 +292,14 @@ func (r *DeviceLocal) FeatureByAddress(address *model.FeatureAddressType) api.Fe
return nil
}

func (r *DeviceLocal) CleanRemoteEntityCaches(remoteAddress *model.EntityAddressType) {
for _, entity := range r.entities {
for _, feature := range entity.Features() {
feature.CleanRemoteEntityCaches(remoteAddress)
}
}
}

func (r *DeviceLocal) ProcessCmd(datagram model.DatagramType, remoteDevice api.DeviceRemoteInterface) error {
destAddr := datagram.Header.AddressDestination
localFeature := r.FeatureByAddress(destAddr)
Expand Down
Loading

0 comments on commit b637b53

Please sign in to comment.