client

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2022 License: Apache-2.0 Imports: 9 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

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) (err 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 Client

type Client struct {
	FuncInfo FunctionInfo
	// contains filtered or unexported fields
}

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.

func NewClientFromSocketAddress

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

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

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

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 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 NewServiceInfo

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

NewServiceInfo creates a new avahi server if necessary, browses interfaces for the specified mdns service and returns a service info object The service address consists of <instance_name>.<service_name>.<protocol> 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) 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