Documentation
¶
Index ¶
- Variables
- func Client[C any](n *Node) (C, error)
- func FindClient[C any](n *Node, c *C)
- func NilUndo()
- func WithLogStateChange(logger *zap.Logger) grpc.DialOption
- type Announcer
- type AnnouncerFunc
- type ClientFunc
- type Clienter
- type DialOption
- type EmptyDialOption
- type EmptyFeature
- type EmptyFunction
- type Feature
- type Function
- type MetadataChange
- type Node
- func (n *Node) Announce(name string, features ...Feature) Undo
- func (n *Node) Client(p any) error
- func (n *Node) ListAllMetadata(opts ...resource.ReadOption) []*traits.Metadata
- func (n *Node) Name() string
- func (n *Node) PullAllMetadata(ctx context.Context, opts ...resource.ReadOption) <-chan MetadataChange
- func (n *Node) Register(s *grpc.Server)
- func (n *Node) Support(functions ...Function)
- type Remote
- type SelfAnnouncer
- type SelfAnnouncerFunc
- type SelfSupporter
- type Supporter
- type TraitOption
- type Undo
Constants ¶
This section is empty.
Variables ¶
var MetadataTraitNotSupported = errors.New("metadata is not supported")
Functions ¶
func Client ¶
Client returns a new api client of type C which can be used to interact with the named devices in n.
func FindClient ¶
FindClient places into c a client backed by the named devices in n.
func WithLogStateChange ¶
func WithLogStateChange(logger *zap.Logger) grpc.DialOption
Types ¶
type Announcer ¶
type Announcer interface { // Announce signals that the name exists and has the given features. Announce(name string, features ...Feature) Undo }
Announcer defines the Announce method. Calling Announce signals that a given name exists and has the collection of features provided. Typically announcing the same name more than once will combine the features of the existing name with the new features.
func AnnounceContext ¶
AnnounceContext returns a new Announcer that undoes any announcements when ctx is Done. This leaks a go routine if ctx is never done.
func AnnounceFeatures ¶
AnnounceFeatures returns an Announcer that acts like `Announce(name, [moreFeatures..., features...])`
func AnnounceWithNamePrefix ¶
AnnounceWithNamePrefix returns an Announcer whose Announce method acts like `Announce(prefix+name, features...)`
type AnnouncerFunc ¶
AnnouncerFunc allows adapting a func of the correct signature to implement Announcer
type ClientFunc ¶
ClientFunc adapts a func of the correct signature to implement Clienter.
func (ClientFunc) Client ¶
func (c ClientFunc) Client(p any) error
type Clienter ¶
type Clienter interface { // Client sets into the pointer p a client, if one is available, or returns an error. // Argument p should be a pointer to a variable of the required client type. // // Example // // var client traits.OnOffApiClient // err := n.Client(&client) Client(p any) error }
Clienter represents a type that can respond with an API client.
type DialOption ¶
type DialOption interface { grpc.DialOption // contains filtered or unexported methods }
type EmptyDialOption ¶
type EmptyDialOption struct {
grpc.EmptyDialOption
}
EmptyDialOption does not change how a dial will be performed. Useful for embedding into custom DialOption types to extend the dial api.
type EmptyFeature ¶
type EmptyFeature struct{}
EmptyFeature is a Feature that means nothing. It can be embedded in custom Feature types to allow them to extend the capabilities of the Feature system.
type EmptyFunction ¶
type EmptyFunction struct{}
EmptyFunction does not change the functions a Node supports. Can be embedded in custom Function types to allow extending Node support.
type Feature ¶
type Feature interface {
// contains filtered or unexported methods
}
Feature describes some aspect of a named device.
func HasClient ¶
func HasClient(clients ...interface{}) Feature
HasClient indicates that the name implements non-trait apis as defined by these clients. The clients are still added to routers and all requests on the clients should accept a Name.
func HasMetadata ¶
HasMetadata merges the given metadata into any existing metadata held against the device name. Merging metadata is not commutative, two calls to Announce causes the second call to overwrite the first for all common fields. Announce accepts multiple HasMetadata features acting as if Announce were called in sequence with each HasMetadata feature.
See metadata.Model.MergeMetadata for more details. If md is nil, does not adjust the announcement.
func HasNoAutoMetadata ¶
func HasNoAutoMetadata() Feature
HasNoAutoMetadata indicates that announcing the device should not announce automatic metadata for the device. Announcing will normally inspect all traits and announce basic metadata for them, this feature turns that off. HasMetadata will still be applied.
type Function ¶
type Function interface {
// contains filtered or unexported methods
}
Function represents something that is supported by a type. For example an API might be represented as a Function and added to a server.
func Api ¶
Api instructs the node to register the given apis with the grpc.Server when Node.Register is called.
type MetadataChange ¶
type Node ¶
Node represents a smart core node. The node has collection of supported apis, represented by router.Router instances and configured via Support. When new names are created they should call Announce and with the features relevant to the name.
All supported APIs in a Node are routed based on a name. Call Support to add new features to the Node. Calling Support after Register will not have any effect on the served apis.
func (*Node) Announce ¶
Announce adds a new name with the given features to this node. You may call Announce multiple times with the same name to add additional features, for example new traits. Executing the returned Undo will undo any direct changes made.
A note on undoing ¶
The undo process is not perfect but best effort. Hooks and callbacks may have been executed that have side effects that are not undone.
func (*Node) Client ¶
Client implements Clienter backed by clients configured using Support(Clients).
func (*Node) ListAllMetadata ¶
func (n *Node) ListAllMetadata(opts ...resource.ReadOption) []*traits.Metadata
ListAllMetadata returns a slice containing all metadata set via Announce.
func (*Node) PullAllMetadata ¶
func (n *Node) PullAllMetadata(ctx context.Context, opts ...resource.ReadOption) <-chan MetadataChange
PullAllMetadata returns a chan that emits MetadataChange whenever Announce or that announcement is undone.
type Remote ¶
type Remote interface { io.Closer Target() string Connect(ctx context.Context) (*grpc.ClientConn, error) }
Remote represents a remote smart core node
type SelfAnnouncer ¶
SelfAnnouncer is a complement to node.Announcer allowing a type to announce itself.
type SelfAnnouncerFunc ¶
SelfAnnouncerFunc allows adapting a func of the correct signature to implement SelfAnnouncer
func (SelfAnnouncerFunc) AnnounceSelf ¶
func (sa SelfAnnouncerFunc) AnnounceSelf(a Announcer) Undo
type SelfSupporter ¶
type SelfSupporter interface {
AddSupport(supporter Supporter)
}
SelfSupporter inverts the receiver for Supporter.
type Supporter ¶
type Supporter interface {
Support(functions ...Function)
}
Supporter is a type that can have its supported functions changed at runtime.
type TraitOption ¶
type TraitOption func(t *traitFeature)
TraitOption controls how a Node behaves when presented with a new device trait.
func NoAddChildTrait ¶
func NoAddChildTrait() TraitOption
NoAddChildTrait instructs the Node not to add the trait to the nodes parent.Model.
func WithClients ¶
func WithClients(client ...interface{}) TraitOption
WithClients indicates that the trait is implemented by these client instances. The clients will be added to the relevant routers when the trait is announced.