diff --git a/api/feature.go b/api/feature.go index 258322e..f370674 100644 --- a/api/feature.go +++ b/api/feature.go @@ -57,8 +57,8 @@ type FeatureLocalInterface interface { // SetWritePermissionCheckCallback being invoked by the stack returning wether // the remote requested write command shall be allowed or not // - // reason contains the error string reported back when write is not allwed - ApproveOrDenyWrite(msg *Message, allow bool, reason string) + // ErrorType.ErrorNumber should be 0 if write is allowed + ApproveOrDenyWrite(msg *Message, err model.ErrorType) // Overwrite the default 1 minute timeout for write approvals SetWriteApprovalTimeout(duration time.Duration) diff --git a/spine/feature_local.go b/spine/feature_local.go index 401220c..65e072e 100644 --- a/spine/feature_local.go +++ b/spine/feature_local.go @@ -182,7 +182,7 @@ func (r *FeatureLocal) addPendingApproval(msg *api.Message) { r.muxResponseCB.Unlock() } -func (r *FeatureLocal) ApproveOrDenyWrite(msg *api.Message, allow bool, reason string) { +func (r *FeatureLocal) ApproveOrDenyWrite(msg *api.Message, err model.ErrorType) { if r.Role() != model.RoleTypeServer { return } @@ -198,13 +198,12 @@ func (r *FeatureLocal) ApproveOrDenyWrite(msg *api.Message, allow bool, reason s timer.Stop() - if allow { + if err.ErrorNumber == 0 { r.processWrite(msg) return } - err := model.NewErrorTypeFromString(reason) - _ = msg.FeatureRemote.Device().Sender().ResultError(msg.RequestHeader, r.Address(), err) + _ = msg.FeatureRemote.Device().Sender().ResultError(msg.RequestHeader, r.Address(), &err) } func (r *FeatureLocal) SetWriteApprovalTimeout(duration time.Duration) { diff --git a/spine/feature_local_test.go b/spine/feature_local_test.go index 1353eb0..e3072d6 100644 --- a/spine/feature_local_test.go +++ b/spine/feature_local_test.go @@ -379,7 +379,10 @@ func (suite *DeviceClassificationTestSuite) Test_SetWriteApprovalCallback_Invali cb := func(msg *api.Message) {} err := suite.localFeature.AddWriteApprovalCallback(cb) assert.NotNil(suite.T(), err) - suite.localFeature.ApproveOrDenyWrite(&api.Message{}, true, "") + result := model.ErrorType{ + ErrorNumber: 0, + } + suite.localFeature.ApproveOrDenyWrite(&api.Message{}, result) } func (suite *DeviceClassificationTestSuite) Test_AddPendingApproval_Invalid() { @@ -412,7 +415,10 @@ func (suite *DeviceClassificationTestSuite) Test_Write_Callback() { } cb := func(msg *api.Message) { - suite.localServerFeatureWrite.ApproveOrDenyWrite(msg, true, "") + result := model.ErrorType{ + ErrorNumber: 0, + } + suite.localServerFeatureWrite.ApproveOrDenyWrite(msg, result) } suite.localServerFeatureWrite.AddWriteApprovalCallback(cb) @@ -422,7 +428,11 @@ func (suite *DeviceClassificationTestSuite) Test_Write_Callback() { suite.senderMock.EXPECT().ResultError(mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() cb = func(msg *api.Message) { - suite.localServerFeatureWrite.ApproveOrDenyWrite(msg, false, "not allowed by application") + result := model.ErrorType{ + ErrorNumber: 7, + Description: util.Ptr(model.DescriptionType("not allowed by application")), + } + suite.localServerFeatureWrite.ApproveOrDenyWrite(msg, result) } suite.localServerFeatureWrite.AddWriteApprovalCallback(cb) @@ -451,7 +461,10 @@ func (suite *DeviceClassificationTestSuite) Test_Write_Callback_Timeout() { cb := func(msg *api.Message) { time.Sleep(time.Second * 1) - suite.localServerFeatureWrite.ApproveOrDenyWrite(msg, true, "") + result := model.ErrorType{ + ErrorNumber: 0, + } + suite.localServerFeatureWrite.ApproveOrDenyWrite(msg, result) } suite.localServerFeatureWrite.AddWriteApprovalCallback(cb)