Skip to content

Commit

Permalink
Added an interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
dmhilly committed May 10, 2023
1 parent 8529267 commit 0c35618
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
8 changes: 6 additions & 2 deletions components/camera/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package camera

import (
"bytes"
"context"
"fmt"
"image"
Expand Down Expand Up @@ -132,6 +131,8 @@ func (c *client) Stream(
}

func (c *client) NextPointCloud(ctx context.Context) (pointcloud.PointCloud, error) {
c.logger.Info("here in client NextPointCloud")

ctx, span := trace.StartSpan(ctx, "camera::client::NextPointCloud")
defer span.End()

Expand All @@ -141,6 +142,8 @@ func (c *client) NextPointCloud(ctx context.Context) (pointcloud.PointCloud, err
MimeType: utils.MimeTypePCD,
})
getPcdSpan.End()

return nil, nil
if err != nil {
return nil, err
}
Expand All @@ -153,7 +156,8 @@ func (c *client) NextPointCloud(ctx context.Context) (pointcloud.PointCloud, err
_, span := trace.StartSpan(ctx, "camera::client::NextPointCloud::ReadPCD")
defer span.End()

return pointcloud.ReadPCD(bytes.NewReader(resp.PointCloud))
return nil, nil
//return pointcloud.ReadPCD(bytes.NewReader(resp.PointCloud))
}()
}

Expand Down
8 changes: 7 additions & 1 deletion components/camera/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,14 @@ func (s *serviceServer) GetPointCloud(
if err != nil {
return nil, err
}
// Return nil point cloud
s.logger.Info("In serviceServer GetPointCloud")
if pc == nil {
panic("point cloud was nil")
s.logger.Info("point cloud was nil")
return &pb.GetPointCloudResponse{
MimeType: utils.MimeTypePCD,
PointCloud: []byte{},
}, nil
}

var buf bytes.Buffer
Expand Down
24 changes: 24 additions & 0 deletions robot/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client

import (
"context"
"fmt"
"io"
"strings"
"sync"
Expand All @@ -24,9 +25,11 @@ import (
"go.viam.com/utils/rpc"
googlegrpc "google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
reflectpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
"google.golang.org/grpc/status"

"go.viam.com/rdk/components/camera"
"go.viam.com/rdk/grpc"
"go.viam.com/rdk/operation"
"go.viam.com/rdk/pointcloud"
Expand Down Expand Up @@ -248,6 +251,25 @@ func (rc *RobotClient) handleStreamDisconnect(
return &handleDisconnectClientStream{cs, rc}, err
}

func myInterceptor(ctx context.Context, method string, req, reply interface{}, cc *googlegrpc.ClientConn, invoker googlegrpc.UnaryInvoker, opts ...googlegrpc.CallOption) error {
var header metadata.MD
opts = append(opts, googlegrpc.Header(&header))
invoker(
ctx,
method,
req,
reply,
cc,
opts...,
)

if len(header.Get(camera.TimeRequestedMetadataKey)) > 0 {
panic(fmt.Sprint("!! I PANICKED !!", header.Get(camera.TimeRequestedMetadataKey)[0]))
panic(header.Get(camera.TimeRequestedMetadataKey))
}
return nil
}

// New constructs a new RobotClient that is served at the given address. The given
// context can be used to cancel the operation.
func New(ctx context.Context, address string, logger golog.Logger, opts ...RobotClientOption) (*RobotClient, error) {
Expand Down Expand Up @@ -289,6 +311,8 @@ func New(ctx context.Context, address string, logger golog.Logger, opts ...Robot
// operations
rpc.WithUnaryClientInterceptor(operation.UnaryClientInterceptor),
rpc.WithStreamClientInterceptor(operation.StreamClientInterceptor),
// camera
rpc.WithUnaryClientInterceptor(myInterceptor),
)

if err := rc.connect(ctx); err != nil {
Expand Down

0 comments on commit 0c35618

Please sign in to comment.