resource

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: AGPL-3.0 Imports: 8 Imported by: 121

Documentation

Overview

Package resource contains a Resource type that can be used to hold information about a robot component or service.

Index

Constants

View Source
const (
	ResourceNamespaceRDK  = Namespace("rdk")
	ResourceTypeComponent = TypeName("component")
	ResourceTypeService   = TypeName("service")
	DefaultModelName      = "builtin"
	DefaultMaxInstance    = 1
)

Placeholder definitions for a few known constants.

Variables

View Source
var DefaultServices []Name

DefaultServices is a list of default robot services. services should add themseleves in an init if they should be included by default.

Functions

func AddDefaultService

func AddDefaultService(n Name)

AddDefaultService add a default service.

func ContainsReservedCharacter added in v0.0.6

func ContainsReservedCharacter(val string) error

ContainsReservedCharacter returns error if string contains a reserved character.

func NewReservedCharacterUsedError added in v0.0.6

func NewReservedCharacterUsedError(val, reservedChar string) error

NewReservedCharacterUsedError is used when a reserved character is wrongly used in a name.

func ReconfigureResource added in v0.0.6

func ReconfigureResource(ctx context.Context, old, newR interface{}) (interface{}, error)

ReconfigureResource tries to reconfigure/replace an old resource with a new one.

Types

type Graph

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

Graph The Graph maintains a collection of resources and their dependencies between each other.

func NewGraph

func NewGraph() *Graph

NewGraph creates a new resource graph.

func (*Graph) AddChildren

func (g *Graph) AddChildren(child, parent Name) error

AddChildren add a dependency to a parent, create the parent if it doesn't exists yet.

func (*Graph) AddNode

func (g *Graph) AddNode(node Name, iface interface{})

AddNode adds a node to the graph.

func (*Graph) Clone

func (g *Graph) Clone() *Graph

Clone deep copy of the resource graph.

func (*Graph) CopyNodeAndChildren

func (g *Graph) CopyNodeAndChildren(node Name, origin *Graph) error

CopyNodeAndChildren adds a Node and it's children from another graph.

func (*Graph) FindNodeByName

func (g *Graph) FindNodeByName(name string) (*Name, bool)

FindNodeByName returns a full resource name based on name, note if name is a duplicate the first one found will be returned.

func (*Graph) FindNodesByShortNameAndSubtype

func (g *Graph) FindNodesByShortNameAndSubtype(name Name) []Name

FindNodesByShortNameAndSubtype will look for resources matching both the subtype and the Name.

func (*Graph) GetAllChildrenOf

func (g *Graph) GetAllChildrenOf(node Name) []Name

GetAllChildrenOf returns all direct children of a node.

func (*Graph) GetAllParentsOf

func (g *Graph) GetAllParentsOf(node Name) []Name

GetAllParentsOf returns all parents of a given node.

func (*Graph) IsNodeDependingOn

func (g *Graph) IsNodeDependingOn(node, child Name) bool

IsNodeDependingOn returns true if child is depending on node.

func (*Graph) MergeAdd

func (g *Graph) MergeAdd(toAdd *Graph) error

MergeAdd merges two Graphs, if a node exists in both graphs, then it is silently replaced.

func (*Graph) MergeRemove

func (g *Graph) MergeRemove(toRemove *Graph)

MergeRemove remove common nodes in both graphs.

func (*Graph) Names

func (g *Graph) Names() []Name

Names returns the all resource graph names.

func (*Graph) Node

func (g *Graph) Node(node Name) (interface{}, bool)

Node returns the node named name.

func (*Graph) Remove

func (g *Graph) Remove(node Name)

Remove remove a given node and all it's dependencies.

func (*Graph) RemoveChildren

func (g *Graph) RemoveChildren(child, parent Name)

RemoveChildren unlink a child from its parent.

func (*Graph) RenameNode

func (g *Graph) RenameNode(old, newName Name) error

RenameNode rename a node from old to new keeping it's dependencies. On success the old node is destroyed.

func (*Graph) ReplaceNodesParents

func (g *Graph) ReplaceNodesParents(node Name, other *Graph) error

ReplaceNodesParents replaces all parent of a given node with the parents of the other graph.

func (*Graph) ReverseTopologicalSort

func (g *Graph) ReverseTopologicalSort() []Name

ReverseTopologicalSort returns an array of nodes' Name ordered by most edges first.

func (*Graph) SubGraphFrom

func (g *Graph) SubGraphFrom(node Name) (*Graph, error)

SubGraphFrom returns a Sub-Graph containing all linked dependencies starting with node Name.

func (*Graph) TopologicalSort

func (g *Graph) TopologicalSort() []Name

TopologicalSort returns an array of nodes' Name ordered by fewest edges first.

type MovingCheckable

type MovingCheckable interface {
	// IsMoving returns whether the resource is moving or not
	IsMoving(context.Context) (bool, error)
}

MovingCheckable is implemented when a resource of a robot returns whether it is moving or not.

type Name

type Name struct {
	Subtype
	Remote RemoteName
	Name   string
}

Name represents a known component/service representation of a robot.

func NameFromSubtype

func NameFromSubtype(subtype Subtype, name string) Name

NameFromSubtype creates a new Name based on a Subtype and name string passed in.

func NewFromString

func NewFromString(resourceName string) (Name, error)

NewFromString creates a new Name based on a fully qualified resource name string passed in.

func NewName

func NewName(namespace Namespace, rType TypeName, subtype SubtypeName, name string) Name

NewName creates a new Name based on parameters passed in.

func RemoveRemoteName added in v0.1.0

func RemoveRemoteName(n Name) Name

RemoveRemoteName returns a new name with remote removed.

func (Name) ContainsRemoteNames

func (n Name) ContainsRemoteNames() bool

ContainsRemoteNames return true if the resource is a remote resource.

func (Name) PopRemote

func (n Name) PopRemote() Name

PopRemote pop the first remote from a Name (if any) and returns the new Name.

func (Name) PrependRemote

func (n Name) PrependRemote(remote RemoteName) Name

PrependRemote returns a Name with a remote prepended.

func (Name) ShortName

func (n Name) ShortName() string

ShortName returns the short name on Name n in the form of <remote>:<name>.

func (Name) String

func (n Name) String() string

String returns the fully qualified name for the resource.

func (Name) Validate

func (n Name) Validate() error

Validate ensures that important fields exist and are valid.

type Namespace

type Namespace string

Namespace identifies the namespaces robot resources can live in.

type OldStoppable

type OldStoppable interface {
	// Stop stops all movement for the resource
	Stop(context.Context) error
}

OldStoppable will be deprecated soon. See Stoppable. TODO[RSDK-328].

type RPCSubtype

type RPCSubtype struct {
	Subtype Subtype
	Desc    *desc.ServiceDescriptor
}

An RPCSubtype provides RPC information about a particular subtype.

type Reconfigurable

type Reconfigurable interface {
	// Reconfigure reconfigures the resource
	Reconfigure(ctx context.Context, newResource Reconfigurable) error
}

Reconfigurable is implemented when component/service of a robot is reconfigurable.

type RemoteName

type RemoteName string

RemoteName identifies the remote the resource is attached to.

type Stoppable

type Stoppable interface {
	// Stop stops all movement for the resource
	Stop(context.Context, map[string]interface{}) error
}

Stoppable is implemented when a resource of a robot can stop its movement.

type Subtype

type Subtype struct {
	Type
	ResourceSubtype SubtypeName
}

Subtype represents a known component/service subtype of a robot.

func NewSubtype

func NewSubtype(namespace Namespace, rType TypeName, subtype SubtypeName) Subtype

NewSubtype creates a new Subtype based on parameters passed in.

func (Subtype) String

func (s Subtype) String() string

String returns the resource subtype string for the component.

func (Subtype) Validate

func (s Subtype) Validate() error

Validate ensures that important fields exist and are valid.

type SubtypeName

type SubtypeName string

SubtypeName identifies the resources subtypes that robot resources can be.

type Type

type Type struct {
	Namespace    Namespace
	ResourceType TypeName
}

Type represents a known component/service type of a robot.

func NewType

func NewType(namespace Namespace, rType TypeName) Type

NewType creates a new Type based on parameters passed in.

func (Type) String

func (t Type) String() string

String returns the resource type string for the component.

func (Type) Validate

func (t Type) Validate() error

Validate ensures that important fields exist and are valid.

type TypeName

type TypeName string

TypeName identifies the resource types that robot resources can be.

type Updateable

type Updateable interface {
	// Update updates the resource
	Update(context.Context, map[Name]interface{}) error
}

Updateable is implemented when component/service of a robot should be updated after the robot reconfiguration process is done.

Jump to

Keyboard shortcuts

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