Skip to content

Commit

Permalink
Add write approval handling (#17)
Browse files Browse the repository at this point in the history
Allow an application to approve or deny an incoming write message. If
the approval is not given within (default) 1 minute, it will be
automatically rejected. It is also possible to adjust the default
timeout per feature

This fixes #14
  • Loading branch information
DerAndereAndi authored May 9, 2024
2 parents 1f18cd7 + 6961fe7 commit 0b4b37a
Show file tree
Hide file tree
Showing 23 changed files with 457 additions and 36 deletions.
19 changes: 17 additions & 2 deletions api/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ type FeatureInterface interface {
String() string
}

// Callback function used to verify if an incoming SPINE write message should be allowed or not
// The cb function has to be invoked within 1 minute, otherwise the stack will
// deny the write command
type WriteApprovalCallbackFunc func(msg *Message)

// This interface defines all the required functions need to implement a local feature
type FeatureLocalInterface interface {
FeatureInterface
Expand All @@ -37,15 +42,25 @@ type FeatureLocalInterface interface {
// Get the associated EntityLocalInterface implementation
Entity() EntityLocalInterface

// Add a function type with
// Add a function type with allowed operations
AddFunctionType(function model.FunctionType, read, write bool)
// Add a callback function to be invoked when SPINE message comes in with a given msgCounterReference value
//
// Returns an error if there is already a callback for the msgCounter set
AddResponseCallback(msgCounterReference model.MsgCounterType, function func(msg ResponseMessage)) error

// Add a callback function to be invoked when a result message comes in for this feature
AddResultCallback(function func(msg ResponseMessage))
// Sets the callback method for a server feature which is invoked to
// check wether an incoming write message shall be permitted or declined
SetWriteApprovalCallback(function WriteApprovalCallbackFunc) error
// Needs to be invoked within 1 minute of WritePermissionCheckCallbackFunc of
// 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)
// Overwrite the default 1 minute timeout for write approvals
SetWriteApprovalTimeout(duration time.Duration)

// return all functions
Functions() []model.FunctionType
Expand Down
2 changes: 1 addition & 1 deletion mocks/BindingManagerInterface.go

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

2 changes: 1 addition & 1 deletion mocks/ComControlInterface.go

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

2 changes: 1 addition & 1 deletion mocks/DeviceInterface.go

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

2 changes: 1 addition & 1 deletion mocks/DeviceLocalInterface.go

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

2 changes: 1 addition & 1 deletion mocks/DeviceRemoteInterface.go

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

2 changes: 1 addition & 1 deletion mocks/EntityInterface.go

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

2 changes: 1 addition & 1 deletion mocks/EntityLocalInterface.go

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

2 changes: 1 addition & 1 deletion mocks/EntityRemoteInterface.go

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

2 changes: 1 addition & 1 deletion mocks/EventHandlerInterface.go

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

2 changes: 1 addition & 1 deletion mocks/FeatureInterface.go

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

116 changes: 115 additions & 1 deletion mocks/FeatureLocalInterface.go

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

2 changes: 1 addition & 1 deletion mocks/FeatureRemoteInterface.go

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

2 changes: 1 addition & 1 deletion mocks/FunctionDataCmdInterface.go

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

2 changes: 1 addition & 1 deletion mocks/FunctionDataInterface.go

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

2 changes: 1 addition & 1 deletion mocks/HeartbeatManagerInterface.go

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

116 changes: 115 additions & 1 deletion mocks/NodeManagementInterface.go

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

2 changes: 1 addition & 1 deletion mocks/OperationsInterface.go

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

Loading

0 comments on commit 0b4b37a

Please sign in to comment.