Skip to content

Commit

Permalink
Automatically set partial support
Browse files Browse the repository at this point in the history
Check if the stack support partial writes on a local feature function, and automatically set it accordingly
  • Loading branch information
DerAndereAndi committed Jun 5, 2024
1 parent bd2d85f commit ba25f6d
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 3 deletions.
2 changes: 2 additions & 0 deletions api/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type FunctionDataCmdInterface interface {
type FunctionDataInterface interface {
// Get the function type
FunctionType() model.FunctionType
// Return if this function supports partial writes
SupportsPartialWrite() bool
// Get a copy of the functions data
DataCopyAny() any
// Update the functions data
Expand Down
45 changes: 45 additions & 0 deletions mocks/FunctionDataCmdInterface.go

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

45 changes: 45 additions & 0 deletions mocks/FunctionDataInterface.go

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

10 changes: 9 additions & 1 deletion spine/feature_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ func (r *FeatureLocal) AddFunctionType(function model.FunctionType, read, write
if r.operations[function] != nil {
return
}
r.operations[function] = NewOperations(read, false, write, write)
writePartial := false
if write {
// partials are not supported on all features and functions, so check if this function supports it
if fctData := r.functionData(function); fctData != nil {
writePartial = fctData.SupportsPartialWrite()
}
}
// partial reads are currently not supported!
r.operations[function] = NewOperations(read, false, write, writePartial)

if r.role == model.RoleTypeServer &&
r.ftype == model.FeatureTypeTypeDeviceDiagnosis &&
Expand Down
7 changes: 5 additions & 2 deletions spine/function_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func (r *FunctionData[T]) FunctionType() model.FunctionType {
return r.functionType
}

func (r *FunctionData[T]) SupportsPartialWrite() bool {
return util.Implements[T, model.Updater]()
}

func (r *FunctionData[T]) DataCopy() *T {
r.mux.Lock()
defer r.mux.Unlock()
Expand Down Expand Up @@ -58,8 +62,7 @@ func (r *FunctionData[T]) UpdateData(remoteWrite bool, newData *T, filterPartial
return nil
}

supported := util.Implements[T, model.Updater]()
if !supported {
if !r.SupportsPartialWrite() {
return model.NewErrorTypeFromString(fmt.Sprintf("partial updates are not supported for type '%s'", util.Type[T]().Name()))
}

Expand Down
8 changes: 8 additions & 0 deletions spine/function_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ func TestFunctionData_UpdateDataPartial_Supported(t *testing.T) {
functionType := model.FunctionTypeHvacOverrunListData
sut := NewFunctionData[model.HvacOverrunListDataType](functionType)

ok := sut.SupportsPartialWrite()
assert.True(t, ok)

err := sut.UpdateData(false, newData, &model.FilterType{CmdControl: &model.CmdControlType{Partial: &model.ElementTagType{}}}, nil)
assert.Nil(t, err)

functionType = model.FunctionTypeNetworkManagementAddNodeCall
sut2 := NewFunctionData[model.NetworkManagementAddNodeCallType](functionType)
ok = sut2.SupportsPartialWrite()
assert.False(t, ok)
}

0 comments on commit ba25f6d

Please sign in to comment.