Documentation ¶
Overview ¶
Package client provides the API for io4edge I/O devices
Index ¶
- func ParseInstanceAndService(serviceAddr string) (string, string, error)
- func ServiceObserver(serviceNamePattern string, serviceAdded func(ServiceInfo) error, ...) error
- type Channel
- type ChannelIf
- type Client
- func NewClient(c *Channel, funcInfo FunctionInfo) *Client
- func NewClientFromService(serviceAddr string, timeout time.Duration) (*Client, error)
- func NewClientFromSocketAddress(address string) (*Client, error)
- func NewClientFromUniversalAddress(addrOrService string, service string, timeout time.Duration) (*Client, error)
- type FuncInfoDefault
- type FunctionInfo
- type If
- type ServiceInfo
- func (svcInf *ServiceInfo) AuxPort() (string, int, error)
- func (svcInf *ServiceInfo) AuxSchemaID() (string, error)
- func (svcInf *ServiceInfo) FuncClass() (string, error)
- func (svcInf *ServiceInfo) GetIPAddressPort() string
- func (svcInf *ServiceInfo) GetInstanceName() string
- func (svcInf *ServiceInfo) GetServiceType() string
- func (svcInf *ServiceInfo) NetAddress() (string, int, error)
- func (svcInf *ServiceInfo) Security() (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseInstanceAndService ¶
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 ¶
NewChannel creates a new channel using the transport mechanism in t
func (*Channel) ReadMessage ¶
ReadMessage waits until Timeout for a new message in transport stream and decodes it via protobuf timeout of 0 waits forever
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 ¶
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 ¶
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
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