-
Notifications
You must be signed in to change notification settings - Fork 110
/
generic.go
39 lines (31 loc) · 1.29 KB
/
generic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Package generic defines an abstract generic device and DoCommand() method
package generic
import (
pb "go.viam.com/api/component/generic/v1"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/robot"
)
func init() {
resource.RegisterAPI(API, resource.APIRegistration[resource.Resource]{
RPCServiceServerConstructor: NewRPCServiceServer,
RPCServiceHandler: pb.RegisterGenericServiceHandlerFromEndpoint,
RPCServiceDesc: &pb.GenericService_ServiceDesc,
RPCClient: NewClientFromConn,
})
}
// SubtypeName is a constant that identifies the component resource API string "Generic".
const SubtypeName = "generic"
// API is a variable that identifies the component resource API.
var API = resource.APINamespaceRDK.WithComponentType(SubtypeName)
// Named is a helper for getting the named Generic's typed resource name.
func Named(name string) resource.Name {
return resource.NewName(API, name)
}
// FromRobot is a helper for getting the named Generic from the given Robot.
func FromRobot(r robot.Robot, name string) (resource.Resource, error) {
return robot.ResourceFromRobot[resource.Resource](r, Named(name))
}
// NamesFromRobot is a helper for getting all generic names from the given Robot.
func NamesFromRobot(r robot.Robot) []string {
return robot.NamesByAPI(r, API)
}