Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subscription and binding handling #33

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading