commands

package
v0.1.0-M4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2023 License: Apache-2.0, EPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmdLogFields

func CmdLogFields(cmd *protocol.Envelope) watermill.LogFields

CmdLogFields builds a command log data.

func EventPublishTopic

func EventPublishTopic(deviceID string, topic *protocol.Topic) string

EventPublishTopic builds the message topic from the provided event envelope topic.

func NewFeatureNotFoundError

func NewFeatureNotFoundError(cmdEnvelope *protocol.Envelope, thingID string, featureID string) *protocol.Envelope

NewFeatureNotFoundError creates feature not found error.

func NewFeaturesNotFoundError

func NewFeaturesNotFoundError(cmdEnvelope *protocol.Envelope, thingID string) *protocol.Envelope

NewFeaturesNotFoundError creates features not found error.

func NewIDInvalidError

func NewIDInvalidError(cmdEnvelope *protocol.Envelope, thingID string) *protocol.Envelope

NewIDInvalidError creates invalid Thing ID error.

func NewIDNotSettableError

func NewIDNotSettableError(cmdEnvelope *protocol.Envelope) *protocol.Envelope

NewIDNotSettableError creates Thing ID not settable error.

func NewInvalidFieldSelectorError

func NewInvalidFieldSelectorError(cmdEnvelope *protocol.Envelope, jsonError error) *protocol.Envelope

NewInvalidFieldSelectorError creates invalid json field selector error.

func NewInvalidJSONValueError

func NewInvalidJSONValueError(cmdEnvelope *protocol.Envelope, jsonError error) *protocol.Envelope

NewInvalidJSONValueError creates invalid json format error.

func NewPropertiesNotFoundError

func NewPropertiesNotFoundError(
	cmdEnvelope *protocol.Envelope, thingID string, featureID string, desired bool,
) *protocol.Envelope

NewPropertiesNotFoundError creates properties not found error.

func NewPropertyNotFoundError

func NewPropertyNotFoundError(
	cmdEnvelope *protocol.Envelope, thingID string, featureID string, pointer string, desired bool,
) *protocol.Envelope

NewPropertyNotFoundError creates property not found error.

func NewThingConflictError

func NewThingConflictError(cmdEnvelope *protocol.Envelope, thingID string) *protocol.Envelope

NewThingConflictError creates thing conflict error.

func NewThingNotFoundError

func NewThingNotFoundError(cmdEnvelope *protocol.Envelope, thingID string) *protocol.Envelope

NewThingNotFoundError creates thing not found error.

func NewUnknownError

func NewUnknownError(cmdEnvelope *protocol.Envelope, msg string, error error) *protocol.Envelope

NewUnknownError creates ThingError for unexpected error.

func PublishHonoMsg

func PublishHonoMsg(msg *message.Message, publisher message.Publisher, dInfo DeviceInfo, thingID string) error

PublishHonoMsg publishes the message with device to cloud messaging topic.

func ResponseEnvelopeWithValue

func ResponseEnvelopeWithValue(
	cmdEnvelope *protocol.Envelope, status int, value interface{},
) *protocol.Envelope

ResponseEnvelopeWithValue builds a response envelope.

func ResponsePublishTopic

func ResponsePublishTopic(deviceID string, envTopic *protocol.Topic) string

ResponsePublishTopic builds the message topic from the provided response envelope topic.

func TopicNamespaceID

func TopicNamespaceID(topic *protocol.Topic) string

TopicNamespaceID returns the namespace defined by the provided topic.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command contains the parsed command data used by CommandFunc to perform the ditto command.

The thingID is parsed from the envelop topic. The target and the additional path (if any) are get form the envelope path, e.g. "sensor" as target and "temperature/value" as internal path if the envelope path is "/features/sensor/properties/temperature/value".

type CommandFunc

type CommandFunc func(h *Handler, cmd *Command, out *CommandOutput)

CommandFunc performs the passed Command using the provided Handler. Generates the command output, i.e. the response if required and the event to be published if the command is executed successfully.

type CommandOutput

type CommandOutput struct {
	// contains filtered or unexported fields
}

CommandOutput contains response and event which must be published or invalid value error. In addition it could contain the thing/feature local revision that could be marked as synchronized if the command is successfully forwarded to the cloud.

type DeviceInfo

type DeviceInfo struct {
	DeviceID         string
	TenantID         string
	AutoProvisioning bool
}

DeviceInfo contains the gateway device details.

type Handler

type Handler struct {
	DeviceInfo

	MosquittoPub message.Publisher
	HonoPub      message.Publisher
	Storage      persistence.ThingsStorage

	Logger logger.Logger
}

Handler manages ditto protocol commands using the local digital twins storage.

func (*Handler) HandleCommand

func (h *Handler) HandleCommand(msg *message.Message) ([]*message.Message, error)

HandleCommand executes ditto protocol command using the local digital twins storage.

func (*Handler) LoadFeature

func (h *Handler) LoadFeature(
	thingID string, featureID string, envelope *protocol.Envelope,
) (*model.Feature, error)

LoadFeature loads the feature from the given thing if present. If there is no such thing and auto-provisioning is enabled the thing is created, persisted and a thing created event is published. Then tries to load the feature from the created thing. Returns error if the thing is not presenting and auto-provisioning is disabled or there is no such feature.

func (*Handler) LoadThing

func (h *Handler) LoadThing(thingID string, envelope *protocol.Envelope) (*model.Thing, error)

LoadThing loads a persisted thing if present. If there is no such thing and auto-provisioning is enabled the thing is created, persisted and a thing created event is published. Returns error if other case.

type Scope

type Scope int

Scope type is used to define the command target resource type.

const (
	ScopeUnknown Scope = iota

	ScopeThing
	ScopeAttributes // unsupported
	ScopeDefinition // unsupported
	ScopePolicy     // unsupported

	ScopeFeatures
	ScopeFeature
	ScopeFeatureProperties
	ScopeFeatureProperty
	ScopeFeatureDesiredProperties
	ScopeFeatureDesiredProperty
	ScopeFeatureDefinition // unsupported
)

Scope types.

func ParseCmdPath

func ParseCmdPath(path string) (Scope, string, string)

ParseCmdPath parses a ditto protocol path finding the type and name of the thing referenced resource returning the command SCOPE, id and additional path, e.g. ScopeFeatureProperties as scope, "sensor" as id and "temperature/value" as internal path if the command path is "/features/sensor/properties/temperature/value".

type ThingError

type ThingError struct {
	Status      int    `json:"status"`
	Error       string `json:"error"`
	Message     string `json:"message"`
	Description string `json:"description,omitempty"`
}

ThingError represents error within the "things" namespace

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL