forked from eclipse-velocitas/vehicle-app-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build Protobuf Files for App (eclipse-velocitas#4)
This PR makes sure, that the proto file which is put inside the app/src/main/proto folder correctly generates the corresponding services.
- Loading branch information
Showing
5 changed files
with
143 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.example.service | ||
|
||
interface CarService { | ||
fun lockDoor(): Boolean | ||
fun unlockDoor(): Boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.example.service | ||
|
||
import android.util.Log | ||
import door.DoorGrpc | ||
import door.DoorGrpc.DoorFutureStub | ||
import door.DoorService | ||
import io.grpc.Grpc | ||
import io.grpc.InsecureChannelCredentials | ||
|
||
private const val TAG = "SampleServiceImpl" | ||
|
||
class GrpcCarService( | ||
host: String, | ||
port: Int, | ||
) : CarService { | ||
|
||
private val doorService: DoorFutureStub | ||
|
||
init { | ||
Log.i(TAG, "Connecting to gRPC service at $host:$port") | ||
|
||
val channelCredentials = InsecureChannelCredentials.create() | ||
val channel = Grpc.newChannelBuilderForAddress(host, port, channelCredentials).build() | ||
|
||
doorService = DoorGrpc.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 | ||
} | ||
|
||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters