client

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Overview

Package client provides the API for io4edge I/O devices

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseInstanceAndService

func ParseInstanceAndService(serviceAddr string) (string, string, error)

ParseInstanceAndService parses one string, which describes a service and split it up into instance name and service name

func ServiceObserver added in v1.0.0

func ServiceObserver(serviceNamePattern string, serviceAdded func(ServiceInfo) error, serviceRemoved func(ServiceInfo) error) error

ServiceObserver watches for added or removed services whose serviceTypes are matching the serviceNamePattern serviceNamePattern is compared as a glob pattern, i.e. if you want to observe service types beginning with "_io4edge", specify "_io4edge.*"; if you want to observe all services, specify "*".

serviceObserver runs in a loop until one of the callbacks returns an error. serviceAdded and serviceRemoved are called when an instance of an observed service type is added or removed.

Types

type Channel

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

Channel represents a connection between the host and the device used to exchange protobuf messages

func NewChannel

func NewChannel(ms transport.MsgStream) *Channel

NewChannel creates a new channel using the transport mechanism in t

func (*Channel) Close

func (c *Channel) Close()

Close terminates the message stream

func (*Channel) ReadMessage

func (c *Channel) ReadMessage(m proto.Message, timeout time.Duration) error

ReadMessage waits until Timeout for a new message in transport stream and decodes it via protobuf timeout of 0 waits forever

func (*Channel) WriteMessage

func (c *Channel) WriteMessage(m proto.Message) error

WriteMessage encodes m using protobuf and sends the encoded value through the message stream

type ChannelIf added in v0.1.4

type ChannelIf interface {
	Close()
	WriteMessage(m proto.Message) error
	ReadMessage(m proto.Message, timeout time.Duration) error
}

ChannelIf is a interface for the Channel

type Client

type Client struct {
	Ch       *Channel
	FuncInfo FunctionInfo
}

Client represents a client for an io4edge function

func NewClient

func NewClient(c *Channel, funcInfo FunctionInfo) *Client

NewClient creates a new client for an io4edge function

func NewClientFromService

func NewClientFromService(serviceAddr string, timeout time.Duration) (*Client, error)

NewClientFromService creates a new function client from a socket with a address, which was acquired from the specified service. The timeout specifies the maximal time waiting for a service to show up. If 0, use default timeout

func NewClientFromSocketAddress

func NewClientFromSocketAddress(address string) (*Client, error)

NewClientFromSocketAddress creates a new function client from a socket with the specified address.

func NewClientFromUniversalAddress added in v0.2.0

func NewClientFromUniversalAddress(addrOrService string, service string, timeout time.Duration) (*Client, error)

NewClientFromUniversalAddress creates a new function client from addrOrService. If addrOrService is of the form "host:port", it creates the client from that host/port, otherwise it assumes addrOrService is the instance name of an mdns service. If service is non-empty and addrOrService is a mdns instance name, it is appended to the addrOrService. .e.g. if addrOrService is "iou01-sn01-binio" and service is "_io4edge_binaryIoTypeA._tcp", the mdns instance name "iou01-sn01-binio._io4edge_binaryIoTypeA._tcp" is used. The timeout specifies the maximal time waiting for a service to show up. Not used for "host:port"

func (*Client) Close added in v1.0.0

func (c *Client) Close()

Close terminates the underlying connection to the service

func (*Client) Command

func (c *Client) Command(cmd proto.Message, res proto.Message, timeout time.Duration) error

Command issues a command cmd to a channel, waits for the devices response and returns it in res

func (*Client) ReadMessage added in v0.1.4

func (c *Client) ReadMessage(res proto.Message, timeout time.Duration) error

ReadMessage reads the next message from the channel and unmarshalles it

func (*Client) RestartChannel added in v1.8.0

func (c *Client) RestartChannel() error

RestartChannel restarts the connection to the device May be used to reestablish a connection after a device reset or after network disconnection of the device (e.g. WLAN roaming)

type FuncInfoDefault

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

FuncInfoDefault provides the default FunctionInfo implementation

func NewFuncInfoDefault

func NewFuncInfoDefault(address string) *FuncInfoDefault

NewFuncInfoDefault creates a new FuncInfoDefault object with no aux port

func NewFuncInfoDefaultWithAuxPort

func NewFuncInfoDefaultWithAuxPort(address string, auxPort int, auxProtocol string, auxSchemaID string) *FuncInfoDefault

NewFuncInfoDefaultWithAuxPort creates a new FuncInfoDefault object with an aux port

func (*FuncInfoDefault) AuxPort

func (f *FuncInfoDefault) AuxPort() (string, int, error)

AuxPort gives the caller the auxport value of the service protocol and port

func (*FuncInfoDefault) AuxSchemaID

func (f *FuncInfoDefault) AuxSchemaID() (string, error)

AuxSchemaID gives the caller the auxschema value of the service

func (*FuncInfoDefault) FuncClass

func (f *FuncInfoDefault) FuncClass() (string, error)

FuncClass gives the caller the funcclass value of the service

func (*FuncInfoDefault) NetAddress

func (f *FuncInfoDefault) NetAddress() (string, int, error)

NetAddress gives the caller the ip address and port of the service

func (*FuncInfoDefault) Security

func (f *FuncInfoDefault) Security() (string, error)

Security gives the caller the security value of the service

type FunctionInfo

type FunctionInfo interface {
	// NetAddress returns the IP address (or host name) and the default port of the function
	NetAddress() (host string, port int, err error)
	// FuncClass returns the class of the io4edge function: e.g. core/datalogger/controlio/ttynvt
	FuncClass() (class string, err error)
	// Security tells whether function channels use encryption (no/tls)
	Security() (security string, err error)
	// AuxPort returns the protocol of the aux port (tcp/udp) and the port
	// returns error if no aux port for function
	AuxPort() (protcol string, port int, err error)
	// AuxSchema returns the schema name of the aux channel
	// returns error if no aux port for function
	AuxSchemaID() (schemaID string, err error)
}

FunctionInfo is an interface to query properties of the io4edge function

type If added in v0.2.0

type If interface {
	Command(cmd proto.Message, res proto.Message, timeout time.Duration) error
	ReadMessage(res proto.Message, timeout time.Duration) error
}

If is a interface for the Client

type ServiceInfo

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

ServiceInfo stores the avahi service struct of a service to make information about the service available through getter functions

func GetServiceInfo added in v1.0.0

func GetServiceInfo(instanceName string, serviceName string, timeout time.Duration) (*ServiceInfo, error)

GetServiceInfo creates a new avahi server if necessary and starts a new service observer instance if no one is already running for the given mdns service name. If a service with the correct service address (consisting of <instance_name>.<service_name>.<protocol>) is found within the specified timeout, a service info object is returned. The instanceName should contain the instance name of the service address The serviceName should contain the service name of the service address together with the protocol The timeout specifies the time to wait for the service to show up

func (*ServiceInfo) AuxPort

func (svcInf *ServiceInfo) AuxPort() (string, int, error)

AuxPort gives the caller the auxport value of the service protocol and port

func (*ServiceInfo) AuxSchemaID

func (svcInf *ServiceInfo) AuxSchemaID() (string, error)

AuxSchemaID gives the caller the auxschema value of the service

func (*ServiceInfo) FuncClass

func (svcInf *ServiceInfo) FuncClass() (string, error)

FuncClass gives the caller the funcclass value of the service

func (*ServiceInfo) GetIPAddressPort

func (svcInf *ServiceInfo) GetIPAddressPort() string

GetIPAddressPort gets the ip address and port from the given service info object. It passes the caller the ip address and the port separated by ":" together in a string.

func (*ServiceInfo) GetInstanceName added in v1.0.0

func (svcInf *ServiceInfo) GetInstanceName() string

GetInstanceName gets the instance name of the given service info object.

func (*ServiceInfo) GetServiceType added in v1.0.0

func (svcInf *ServiceInfo) GetServiceType() string

GetServiceType gets the service type of the given service info object

func (*ServiceInfo) NetAddress

func (svcInf *ServiceInfo) NetAddress() (string, int, error)

NetAddress gives the caller the ip address and port of the service

func (*ServiceInfo) Security

func (svcInf *ServiceInfo) Security() (string, error)

Security gives the caller the security value of the service

Jump to

Keyboard shortcuts

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