-
Notifications
You must be signed in to change notification settings - Fork 110
/
framesystem_service.go
120 lines (109 loc) · 3.73 KB
/
framesystem_service.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package inject
import (
"context"
"go.viam.com/rdk/pointcloud"
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/robot/framesystem"
)
// FrameSystemService represents a fake instance of a framesystem service.
// Due to the nature of the framesystem service, there should never be more than one on a robot.
// If you use an injected frame system, do not also create the system's default frame system as well.
type FrameSystemService struct {
framesystem.Service
name resource.Name
TransformPoseFunc func(
ctx context.Context,
pose *referenceframe.PoseInFrame,
dst string,
additionalTransforms []*referenceframe.LinkInFrame,
) (*referenceframe.PoseInFrame, error)
TransformPointCloudFunc func(
ctx context.Context,
srcpc pointcloud.PointCloud,
srcName, dstName string,
) (pointcloud.PointCloud, error)
CurrentInputsFunc func(ctx context.Context) (map[string][]referenceframe.Input, map[string]referenceframe.InputEnabled, error)
FrameSystemFunc func(
ctx context.Context,
additionalTransforms []*referenceframe.LinkInFrame,
) (referenceframe.FrameSystem, error)
DoCommandFunc func(
ctx context.Context,
cmd map[string]interface{},
) (map[string]interface{}, error)
CloseFunc func(ctx context.Context) error
}
// NewFrameSystemService returns a new injected framesystem service.
func NewFrameSystemService(name string) *FrameSystemService {
resourceName := resource.NewName(
resource.APINamespaceRDKInternal.WithServiceType("framesystem"),
name,
)
return &FrameSystemService{name: resourceName}
}
// Name returns the name of the resource.
func (fs *FrameSystemService) Name() resource.Name {
return fs.name
}
// TransformPose calls the injected method or the real variant.
func (fs *FrameSystemService) TransformPose(
ctx context.Context,
pose *referenceframe.PoseInFrame,
dst string,
additionalTransforms []*referenceframe.LinkInFrame,
) (*referenceframe.PoseInFrame, error) {
if fs.TransformPoseFunc == nil {
return fs.Service.TransformPose(ctx, pose, dst, additionalTransforms)
}
return fs.TransformPoseFunc(ctx, pose, dst, additionalTransforms)
}
// TransformPointCloud calls the injected method or the real variant.
func (fs *FrameSystemService) TransformPointCloud(
ctx context.Context,
srcpc pointcloud.PointCloud,
srcName, dstName string,
) (pointcloud.PointCloud, error) {
if fs.TransformPointCloudFunc == nil {
return fs.Service.TransformPointCloud(ctx, srcpc, srcName, dstName)
}
return fs.TransformPointCloudFunc(ctx, srcpc, srcName, dstName)
}
// CurrentInputs calls the injected method or the real variant.
func (fs *FrameSystemService) CurrentInputs(
ctx context.Context,
) (map[string][]referenceframe.Input, map[string]referenceframe.InputEnabled, error) {
if fs.CurrentInputsFunc == nil {
return fs.Service.CurrentInputs(ctx)
}
return fs.CurrentInputsFunc(ctx)
}
// FrameSystem calls the injected method of the real variant.
func (fs *FrameSystemService) FrameSystem(
ctx context.Context,
additionalTransforms []*referenceframe.LinkInFrame,
) (referenceframe.FrameSystem, error) {
if fs.FrameSystemFunc == nil {
return fs.Service.FrameSystem(ctx, additionalTransforms)
}
return fs.FrameSystemFunc(ctx, additionalTransforms)
}
// DoCommand calls the injected DoCommand or the real variant.
func (fs *FrameSystemService) DoCommand(ctx context.Context,
cmd map[string]interface{},
) (map[string]interface{}, error) {
if fs.DoCommandFunc == nil {
return fs.Service.DoCommand(ctx, cmd)
}
return fs.DoCommandFunc(ctx, cmd)
}
// Close calls the injected Close or the real version.
func (fs *FrameSystemService) Close(ctx context.Context) error {
if fs.CloseFunc == nil {
if fs.Service == nil {
return nil
}
return fs.Service.Close(ctx)
}
return fs.CloseFunc(ctx)
}