From 94c7f37ba03f995290baa5b639c78d673e1ed7c3 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 14 Nov 2024 13:42:54 +0100 Subject: [PATCH] Adapt Proto Files --- .../java/com/example/service/CarService.kt | 0 .../com/example/service/GrpcCarService.kt | 25 +++++------ SampleApp/src/main/proto/DoorService.proto | 20 +++++++++ SampleApp/src/main/proto/FoldingService.proto | 37 ++++++++++++++++ .../src/main/proto/FronthousingService.proto | 37 ++++++++++++++++ app/src/main/proto/door.proto | 44 ------------------- settings.gradle.kts | 2 +- 7 files changed, 107 insertions(+), 58 deletions(-) rename {app => SampleApp}/src/main/java/com/example/service/CarService.kt (100%) rename {app => SampleApp}/src/main/java/com/example/service/GrpcCarService.kt (61%) create mode 100644 SampleApp/src/main/proto/DoorService.proto create mode 100644 SampleApp/src/main/proto/FoldingService.proto create mode 100644 SampleApp/src/main/proto/FronthousingService.proto delete mode 100644 app/src/main/proto/door.proto diff --git a/app/src/main/java/com/example/service/CarService.kt b/SampleApp/src/main/java/com/example/service/CarService.kt similarity index 100% rename from app/src/main/java/com/example/service/CarService.kt rename to SampleApp/src/main/java/com/example/service/CarService.kt diff --git a/app/src/main/java/com/example/service/GrpcCarService.kt b/SampleApp/src/main/java/com/example/service/GrpcCarService.kt similarity index 61% rename from app/src/main/java/com/example/service/GrpcCarService.kt rename to SampleApp/src/main/java/com/example/service/GrpcCarService.kt index 8de24a4..90ee432 100644 --- a/app/src/main/java/com/example/service/GrpcCarService.kt +++ b/SampleApp/src/main/java/com/example/service/GrpcCarService.kt @@ -16,10 +16,9 @@ package com.example.service +import DoorServiceGrpc +import DoorServiceOuterClass import android.util.Log -import door.DoorGrpc -import door.DoorGrpc.DoorFutureStub -import door.DoorService import io.grpc.Grpc import io.grpc.InsecureChannelCredentials @@ -30,7 +29,7 @@ class GrpcCarService( port: Int, ) : CarService { - private val doorService: DoorFutureStub + private val doorService: DoorServiceGrpc.DoorServiceFutureStub init { Log.i(TAG, "Connecting to gRPC service at $host:$port") @@ -38,21 +37,21 @@ class GrpcCarService( val channelCredentials = InsecureChannelCredentials.create() val channel = Grpc.newChannelBuilderForAddress(host, port, channelCredentials).build() - doorService = DoorGrpc.newFutureStub(channel) + doorService = DoorServiceGrpc.newFutureStub(channel) } // Door service override fun lockDoor(): Boolean { - val request = DoorService.LockRequest.newBuilder().build() - val response = doorService.lock(request).get() // blocking call - Log.i(TAG, "lockDoor: Got response: " + response.getCode()) - return response.getCode() == DoorService.BCMReturnCode.BCM_RETURN_CODE_SUCCESS + val request = DoorServiceOuterClass.LockDoorRequest.newBuilder().build() + val response = doorService.lockDoor(request).get() // blocking call + Log.i(TAG, "lockDoor: Got response: " + response.success) + return response.success } override fun unlockDoor(): Boolean { - val request = DoorService.UnlockRequest.newBuilder().build() - val response = doorService.unlock(request).get() // blocking call - Log.i(TAG, "unlockDoor: Got response: " + response.getCode()) - return response.getCode() == DoorService.BCMReturnCode.BCM_RETURN_CODE_SUCCESS + val request = DoorServiceOuterClass.UnlockDoorRequest.newBuilder().build() + val response = doorService.unlockDoor(request).get() // blocking call + Log.i(TAG, "unlockDoor: Got response: " + response.success) + return response.success } } diff --git a/SampleApp/src/main/proto/DoorService.proto b/SampleApp/src/main/proto/DoorService.proto new file mode 100644 index 0000000..efd0a29 --- /dev/null +++ b/SampleApp/src/main/proto/DoorService.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +message UnlockDoorRequest { +} + +message UnlockDoorResponse { + optional bool success = 1; +} + +message LockDoorRequest { +} + +message LockDoorResponse { + optional bool success = 1; +} + +service DoorService { + rpc UnlockDoor(UnlockDoorRequest) returns (UnlockDoorResponse); + rpc LockDoor(LockDoorRequest) returns (LockDoorResponse); +} diff --git a/SampleApp/src/main/proto/FoldingService.proto b/SampleApp/src/main/proto/FoldingService.proto new file mode 100644 index 0000000..0056640 --- /dev/null +++ b/SampleApp/src/main/proto/FoldingService.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +message FoldMirrorsRequest { +} + +message FoldMirrorsResponse { + optional bool success = 1; +} + +message UnfoldMirrorsRequest { +} + +message UnfoldMirrorsResponse { + optional bool success = 1; +} + +message GetMirrorFoldStatusRequest { +} + +message GetMirrorFoldStatusResponse { + optional uint32 status = 1; +} + +message SetMirrorFoldStatusRequest { + optional uint32 mirrorFoldStatus = 1; +} + +message SetMirrorFoldStatusResponse { + optional bool success = 1; +} + +service FoldingService { + rpc FoldMirrors(FoldMirrorsRequest) returns (FoldMirrorsResponse); + rpc UnfoldMirrors(UnfoldMirrorsRequest) returns (UnfoldMirrorsResponse); + rpc GetMirrorFoldStatus(GetMirrorFoldStatusRequest) returns (GetMirrorFoldStatusResponse); + rpc SetMirrorFoldStatus(SetMirrorFoldStatusRequest) returns (SetMirrorFoldStatusResponse); +} diff --git a/SampleApp/src/main/proto/FronthousingService.proto b/SampleApp/src/main/proto/FronthousingService.proto new file mode 100644 index 0000000..1398523 --- /dev/null +++ b/SampleApp/src/main/proto/FronthousingService.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +message EnableAirConditioningRequest { +} + +message EnableAirConditioningResponse { + optional bool success = 1; +} + +message DisableAirConditioningRequest { +} + +message DisableAirConditioningResponse { + optional bool success = 1; +} + +message GetAirConditioningStatusRequest { +} + +message GetAirConditioningStatusResponse { + optional uint32 status = 1; +} + +message SetAirConditioningStatusRequest { + optional uint32 airConditioningStatus = 1; +} + +message SetAirConditioningStatusResponse { + optional bool success = 1; +} + +service FronthousingService { + rpc EnableAirConditioning(EnableAirConditioningRequest) returns (EnableAirConditioningResponse); + rpc DisableAirConditioning(DisableAirConditioningRequest) returns (DisableAirConditioningResponse); + rpc GetAirConditioningStatus(GetAirConditioningStatusRequest) returns (GetAirConditioningStatusResponse); + rpc SetAirConditioningStatus(SetAirConditioningStatusRequest) returns (SetAirConditioningStatusResponse); +} diff --git a/app/src/main/proto/door.proto b/app/src/main/proto/door.proto deleted file mode 100644 index 96e15c8..0000000 --- a/app/src/main/proto/door.proto +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Provides door control and status service, one atomic service for each door. - */ -syntax = "proto3"; - -package door; - -option java_outer_classname = "DoorService"; - -service Door { - /* Unlock the door. */ - rpc Unlock(UnlockRequest) returns (UnlockResponse); - - /* Lock the door. */ - rpc Lock(LockRequest) returns (LockResponse); -} - -message UnlockRequest {} - -message UnlockResponse { - BCMReturnCode code = 1; -} - -message LockRequest {} - -message LockResponse { - BCMReturnCode code = 1; -} - -/* - * The Body Atomic Services API call returned information - */ -enum BCMReturnCode { - BCM_RETURN_CODE_UNSPECIFIED = 0; - /* - * Success - */ - BCM_RETURN_CODE_SUCCESS = 1; - - /* - * Execution failed - */ - BCM_RETURN_CODE_FAIL = 2; -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 80ece6d..7ca3083 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -37,4 +37,4 @@ dependencyResolutionManagement { rootProject.name = "vehicle-app-kotlin-template" include(":sdk") -include(":app") +include(":SampleApp")