service

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package service implements a default service that can be used to quickly implement a connector. Together with connector.ConnectorHandler it implements the whole connector protocol. Developers can therefore focus on implementing technology specific details by implementing the Provider interface. It will listen to the provider.UpdateChannel() and update thing properties and action requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultConnectorService

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

ConnectorService provides the callback functions used by the HTTP handler.

func NewConnectorService

func NewConnectorService(dbClient connector.Database, connctdClient connector.Client, provider connector.Provider, thingTemplates connector.ThingTemplates, logger logr.Logger) (*DefaultConnectorService, error)

NewConnectorService returns a new instance of the default connector.

func (*DefaultConnectorService) AddInstallation

func (s *DefaultConnectorService) AddInstallation(ctx context.Context, request connector.InstallationRequest) (*connector.InstallationResponse, error)

AddInstallation is called by the HTTP handler when it receives an installation request. It will persist the new installation and its configuration and register the new installation with the provider.

func (*DefaultConnectorService) AddInstance

func (s *DefaultConnectorService) AddInstance(ctx context.Context, request connector.InstantiationRequest) (*connector.InstantiationResponse, error)

AddInstantiation is called by the HTTP handler when it receives an instantiation request. It will persist the new instance, create new things for the instance and register the new instance with the provider.

func (*DefaultConnectorService) CreateThing

func (s *DefaultConnectorService) CreateThing(ctx context.Context, instanceId string, thing connctd.Thing, externalId string) (*connctd.Thing, error)

CreateThing can be called by the connector to register a new thing for the given instance. It retrieves the instance token from the database and uses the token to create a new thing via the connctd API client. The new thing ID is then stored in the database referencing the instance id.

func (*DefaultConnectorService) EventHandler

func (s *DefaultConnectorService) EventHandler(ctx context.Context)

EventHandler handles events coming from the provider.

func (*DefaultConnectorService) PerformAction

func (s *DefaultConnectorService) PerformAction(ctx context.Context, actionRequest connector.ActionRequest) (*connector.ActionResponse, error)

HandleAction is called by the HTTP handler when it receives an action request.

func (*DefaultConnectorService) RemoveInstallation

func (s *DefaultConnectorService) RemoveInstallation(ctx context.Context, installationId string) error

RemoveInstallation is called by the HTTP handler when it receives an installation removal request. It will remove the installation from the database (including the installation token) and from the provider. Note that we will not be able to communicate with the connctd platform about the removed installation after this, since the token is deleted.

func (*DefaultConnectorService) RemoveInstance

func (s *DefaultConnectorService) RemoveInstance(ctx context.Context, instanceId string) error

RemoveInstance is called by the HTTP handler when it receives an instance removal request. It will remove the instance from the database (including the instance token) and from the provider. Note that we will not be able to communicate with the connctd platform about the removed instance after this, since the token is deleted.

func (*DefaultConnectorService) UpdateActionStatus

func (s *DefaultConnectorService) UpdateActionStatus(ctx context.Context, instanceId string, actionRequestId string, actionResponse *connector.ActionResponse) error

UpdateActionStatus can be called by the connector to update the status of an action request.

func (*DefaultConnectorService) UpdateProperty

func (s *DefaultConnectorService) UpdateProperty(ctx context.Context, instanceId, thingId, componentId, propertyId, value string) error

UpdateProperty can be called by the connector to update a component property of a thing belonging to an instance.

Jump to

Keyboard shortcuts

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