Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add camera GetProperties #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import com.google.protobuf.Struct;
import com.viam.common.v1.Common;
import com.viam.common.v1.Common.ResponseMetadata;
import com.viam.component.camera.v1.Camera.Format;
import com.viam.component.camera.v1.Camera.GetPropertiesResponse;
import com.viam.component.camera.v1.Camera.Image;
import com.viam.sdk.core.component.Component;
import com.viam.sdk.core.resource.Resource;
import com.viam.sdk.core.resource.Subtype;
import com.viam.sdk.core.robot.RobotClient;
import java.util.AbstractMap.SimpleEntry;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
Expand Down Expand Up @@ -50,7 +54,15 @@ public static Camera fromRobot(final RobotClient robot, final String name) {
public abstract Image getImage(final Format format,
final Optional<Struct> extra);

public abstract Entry<List<Image>, Common.ResponseMetadata> getImages();
public Entry<List<Image>, Common.ResponseMetadata> getImages() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] why provide a default implementation here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was requested

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol k

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to point out that this could be a subtle point of bugs for anyone expecting getImages to work, but a camera implementer didn't provide it. This doesn't provide the user with any feedback (like an unimplemented error)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh yeah. ill change it back.

return new SimpleEntry<>(
Collections.singletonList(getImage(Format.FORMAT_UNSPECIFIED, Optional.empty())),
ResponseMetadata.newBuilder().build());
}

protected GetPropertiesResponse getProperties() {
return GetPropertiesResponse.newBuilder().build();
}

static Format mimeToFormat(final String mimeType) {
switch (mimeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.viam.component.camera.v1.Camera.GetImageResponse;
import com.viam.component.camera.v1.Camera.GetImagesRequest;
import com.viam.component.camera.v1.Camera.GetImagesResponse;
import com.viam.component.camera.v1.Camera.GetPropertiesRequest;
import com.viam.component.camera.v1.Camera.GetPropertiesResponse;
import com.viam.component.camera.v1.Camera.Image;
import com.viam.component.camera.v1.CameraServiceGrpc;
import com.viam.sdk.core.rpc.Channel;
Expand Down Expand Up @@ -53,6 +55,13 @@ public List<Common.Geometry> getGeometries(final Optional<Struct> extra) {
return client.getGeometries(builder.build()).getGeometriesList();
}

@Override
protected GetPropertiesResponse getProperties() {
final GetPropertiesRequest.Builder builder = GetPropertiesRequest.newBuilder().
setName(getName().getName());
return client.getProperties(builder.build());
}

@Override
public Image getImage(final Format format,
Optional<Struct> extra) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.viam.component.camera.v1.Camera.GetImageResponse;
import com.viam.component.camera.v1.Camera.GetImagesRequest;
import com.viam.component.camera.v1.Camera.GetImagesResponse;
import com.viam.component.camera.v1.Camera.GetPropertiesRequest;
import com.viam.component.camera.v1.Camera.GetPropertiesResponse;
import com.viam.component.camera.v1.Camera.Image;
import com.viam.component.camera.v1.CameraServiceGrpc;
import com.viam.sdk.core.resource.ResourceManager;
Expand Down Expand Up @@ -51,6 +53,16 @@ public void getGeometries(Common.GetGeometriesRequest request,
responseObserver.onCompleted();
}

@Override
public void getProperties(GetPropertiesRequest request,
StreamObserver<GetPropertiesResponse> responseObserver) {
final Camera camera = getResource(
Camera.named(request.getName()));
final GetPropertiesResponse result = camera.getProperties();
responseObserver.onNext(result);
responseObserver.onCompleted();
}

@Override
public void getImage(GetImageRequest request,
StreamObserver<GetImageResponse> responseObserver) {
Expand Down