defs

package
v0.0.0-...-ad0604f Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownParamName = iota
	InvalidParamValue
	NoRequiredParam
)
View Source
const ParamNameOpenAttemptsInterval = "openAttemptsInterval"

ParamNameOpenAttemptsInterval parameter name for the time interval between attempts to open (serial port)

View Source
const ParamNameOutgoingMaxTTL = "outgoingMaxTTL"

ParamNameOutgoingMaxTTL parameter name for the maximum time to live of outgoing messages

Variables

View Source
var (
	// ErrProtocolNotSupported is the error in case if provided protocol is not supported
	ErrProtocolNotSupported error = errors.New("the protocol is not supported")
	// ErrTransportNotSupported is the error in case if provided transport is not supported
	ErrTransportNotSupported error = errors.New("the transport is not supported")
	// ErrNoProtocolTransport is the error in case if provided transport is not supported for given protocol
	ErrNoProtocolTransport error = errors.New("the transport is not supported for the protocol")
)

errors

View Source
var (
	// ErrServiceExists is the error in case if service already exists
	ErrServiceExists error = errors.New("the service already exists")
	// ErrAliasExists is the error in case if service already exists
	ErrAliasExists error = errors.New("the service alias already exists")
	// ErrServiceNotExists returns if service is not exists (Remove, Status methods)
	ErrServiceNotExists error = errors.New("the service not exists")

	// ErrBadPayload returned by Send method in case if message's payload is not valid has no payload
	ErrBadPayload error = errors.New("the message's payload is not valid")
	// ErrSendBusy returned by Send method in case if service is unable to send message at this time
	ErrSendBusy error = errors.New("the service is too busy and unable to send the message")

	// ErrNoDiscovery returned by Discover method in case if service is not providing discovery function
	ErrNoDiscovery error = errors.New("no discovery service")
	// ErrDiscoveryBusy returned by Discover method in case if there are too many discovery requests are running
	ErrDiscoveryBusy error = errors.New("the discovery service is busy")
	// ErrNoDiscoveryID returned by Discovery method if discovery id is not found
	ErrNoDiscoveryID error = errors.New("the discovery id not found")
	// ErrDiscoveryPending returned by Discovery method if requested discovery query is not completed yet
	ErrDiscoveryPending error = errors.New("the discovery is not completed yet")
)

errors

View Source
var ErrNotOpen error = errors.New("the transport entry is not open")

ErrNotOpen error

View Source
var ErrStatusGood error = errors.New("the service is functioning normally")

non-error service status

Protocols contains protocols definitions (defined in service module)

Transports contains transports definitions (defined in services module)

Functions

func NewParseError

func NewParseError(code int, name, value string) error

NewParseError creates new parse error

func ProtocolByName

func ProtocolByName(name string) (api.ProtocolIdentifier, bool)

ProtocolByName resolves protocol name into identifier

func ProtocolName

func ProtocolName(p api.ProtocolIdentifier) string

ProtocolName return name of the transport for provided identifier

func ResolveProtocolAndTransport

ResolveProtocolAndTransport resolves protocol-transport pair

func TransportByName

func TransportByName(name string) (api.TransportIdentifier, bool)

TransportByName resolves transport name into identifier

func TransportName

func TransportName(t api.TransportIdentifier) string

TransportName return name of the transport for provided identifier

Types

type DiscoveryFunc

type DiscoveryFunc func(ctx context.Context, params api.ParamValues) ([]*api.DiscoveryEntry, error)

DiscoveryFunc is a method which returns discovered service entries or error

type ListFunc

type ListFunc func(key *api.ServiceKey, alias string, status ServiceStatus, params api.ParamValues) bool

ListFunc is a the callback function used in ServiceRegistry List method. Returnning true will stop services iteration

type MessageFindFunc

type MessageFindFunc func() (int, bool)

MessageFindFunc is a the callback function used in MessageLog to find first message in the List method

type MessageFunc

type MessageFunc func(index int, key *api.ServiceKey, message *api.Message) bool

MessageFunc is a the callback function used in MessageLog methods. Returnning true will stop messages iteration

func UntilCounter

func UntilCounter(count int, next MessageFunc) MessageFunc

UntilCounter limits messages iteration by provided count

func UntilID

func UntilID(id uuid.UUID, exclusive bool, next MessageFunc) MessageFunc

UntilID limits messages iteration by provided id, could be inclusive or exclusive

func UntilIndex

func UntilIndex(index int, exclusive bool, next MessageFunc) MessageFunc

UntilIndex limits messages iteration by provided index, could be inclusive or exclusive

func UntilTime

func UntilTime(time time.Time, exclusive bool, next MessageFunc) MessageFunc

UntilTime limits messages iteration by provided time, could be inclusive or exclusive

func WithPayload

func WithPayload(matches [][]api.PayloadMatch, next MessageFunc) MessageFunc

WithPayload filters messages based on their payload

func WithServices

func WithServices(services []*api.ServiceKey, next MessageFunc) MessageFunc

WithPayload filters messages based on their services

func WithStates

func WithStates(states []api.MessageState, next MessageFunc) MessageFunc

WithPayload filters messages based on their state

type MessageLog

type MessageLog interface {
	Persist()
	Register(key *api.ServiceKey, payload []byte, state api.MessageState) *api.Message
	UpdateState(id uuid.UUID, state api.MessageState) (*api.ServiceKey, *api.Message)
	Get(id uuid.UUID) (*api.ServiceKey, *api.Message)
	List(find MessageFindFunc, filter MessageFunc) int

	// non thread safe
	FromIndex(index int, exclusive bool) MessageFindFunc
	FromID(id uuid.UUID, exclusive bool) MessageFindFunc
	FromTime(time time.Time, exclusive bool) MessageFindFunc
}

MessageLog defines message log interface

var Messages MessageLog

Messages provides access to MessageLog implementation (set in messages module)

type ParamFlags

type ParamFlags uint8

ParamFlags type of parameter bit flags

const (
	ParamFlagConst ParamFlags = 1 << iota
	ParamFlagRequired
)

Parameter's bit flags

type ParamInfo

type ParamInfo struct {
	Description  string
	Type         ParamType
	Flags        ParamFlags
	DefaultValue string
	EnumValues   []string
}

ParamInfo parameter description

func (ParamInfo) Parse

func (p ParamInfo) Parse(name, value string) (interface{}, error)

Parse function parses provided parameter value

type ParamType

type ParamType uint8

ParamType type of parameter type enum

const (
	ParamTypeInt8 ParamType = iota
	ParamTypeInt16
	ParamTypeInt32
	ParamTypeInt64
	ParamTypeUint8
	ParamTypeUint16
	ParamTypeUint32
	ParamTypeUint64
	ParamTypeBool
	ParamTypeString
	ParamTypeEnum
)

Parameter's data types

func (ParamType) String

func (pt ParamType) String() string

type Params

type Params map[string]*ParamInfo

Params type defines named parameter collection

func (Params) Merge

func (p Params) Merge(subp Params) (result Params)

Merge returns copy of combined parameters with subordinate parameters

func (Params) Parse

func (p Params) Parse(name, value string) (interface{}, error)

Parse function validates parameter name and parses its value

func (Params) ParseValues

func (p Params) ParseValues(values api.RawParamValues) (api.ParamValues, error)

ParseValues function validates parameters and parses their value. Returns values map or parameter name + associated error

type ParseError

type ParseError struct {
	Code  int
	Name  string
	Value string
}

ParseError is the structure which contains parameter parse error

func (*ParseError) Error

func (pe *ParseError) Error() string

Error is the implementation of error interface

func (*ParseError) Is

func (pe *ParseError) Is(target error) bool

type ProtocolInfo

type ProtocolInfo struct {
	Name       string
	Transports map[api.TransportIdentifier]*ProtocolTransportOptions
}

ProtocolInfo protocol definition structure

type ProtocolTransportOptions

type ProtocolTransportOptions struct {
	ServiceFunc     // required
	Params          // protocol parameters
	DiscoveryFunc   // could be nil
	DiscoveryParams Params
}

ProtocolTransportOptions defines transport options specific for the protocol

type ResolveIDsInput

type ResolveIDsInput func() (key *api.ServiceKey, alias string, stop bool)

ResolveIDsInput is the input iteration method for ServiceREgistry ResoveIDs

type ResolveIDsOutput

type ResolveIDsOutput func(key *api.ServiceKey, alias string)

ResolveIDsInput is the output method for ServiceREgistry ResoveIDs

type Service

type Service interface {
	Start()
	Stop()
	Status() ServiceStatus
	Send(payload []byte) (*api.Message, error)
}

Service interface, defines minimal set of methods the service needs to support

type ServiceFunc

type ServiceFunc func(entry string, params api.ParamValues) (Service, error)

ServiceFunc is a method which creates service or returns error

type ServiceRegistry

type ServiceRegistry interface {
	Discover(protocol api.ProtocolIdentifier, transport api.TransportIdentifier, params api.RawParamValues) (uuid.UUID, error)
	Discovery(id uuid.UUID, stop bool) ([]*api.DiscoveryEntry, error)

	Add(key *api.ServiceKey, params api.RawParamValues, alias string) error
	Alias(key *api.ServiceKey, oldAlias string, newAlias string) error
	Remove(key *api.ServiceKey, alias string) error
	Status(key *api.ServiceKey, alias string) (ServiceStatus, bool)
	List(listFn ListFunc)

	ResolveIDs(out ResolveIDsOutput, in ResolveIDsInput)

	Send(key *api.ServiceKey, alias string, payload []byte) (*api.Message, error)
}

ServiceRegistry defines possible operations with services

var Services ServiceRegistry

Services provides access to ServiceRegistry implementation (set in services module)

type ServiceStatus

type ServiceStatus error

ServiceStatus describes the status of the service

type Transport

type Transport interface {
	ID() api.TransportIdentifier
	Open(entry string, params api.ParamValues) error
	ReadyToRead() <-chan struct{}
	io.ReadWriteCloser
}

Transport interface - blocking transport operations

type TransportInfo

type TransportInfo struct {
	Name string
	Params
}

TransportInfo transport definition structure

Jump to

Keyboard shortcuts

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