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

Adding grpc examples #107

Merged
merged 11 commits into from
Oct 30, 2024
10 changes: 5 additions & 5 deletions NOTICE-3RD-PARTY-CONTENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
|bottle|0.12.25|MIT|
|certifi|2024.8.30|Mozilla Public License 2.0|
|cfgv|3.4.0|MIT|
|charset-normalizer|3.3.2|MIT|
|charset-normalizer|3.4.0|MIT|
|colorama|0.4.6|BSD|
|conan|1.63.0|MIT|
|cpplint|1.6.1|New BSD|
|distlib|0.3.8|Python Software Foundation License|
|distlib|0.3.9|Python Software Foundation License|
|distro|1.8.0|Apache 2.0|
|fasteners|0.19|Apache 2.0|
|filelock|3.16.1|The Unlicense (Unlicense)|
Expand All @@ -19,7 +19,7 @@
|idna|3.10|BSD|
|jinja2|3.1.4|BSD|
|lxml|5.3.0|New BSD|
|MarkupSafe|2.1.5|New BSD|
|MarkupSafe|3.0.2|BSD|
|node-semver|0.6.1|MIT|
|nodeenv|1.9.1|BSD|
|patch-ng|1.17.4|MIT|
Expand All @@ -32,9 +32,9 @@
|PyYAML|6.0.2|MIT|
|requests|2.32.3|Apache 2.0|
|six|1.16.0|MIT|
|tqdm|4.66.5|MIT<br/>Mozilla Public License 2.0 (MPL 2.0)|
|tqdm|4.66.6|MIT<br/>Mozilla Public License 2.0 (MPL 2.0)|
|urllib3|1.26.20|MIT|
|virtualenv|20.26.5|MIT|
|virtualenv|20.27.0|MIT|
## Workflows
| Dependency | Version | License |
|:-----------|:-------:|--------:|
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ The Vehicle App SDK for C++ allows to create `Vehicle Apps` from the [Velocitas
* 📁 `seat-adjuster` - an example application showing how to adjust the driver seat when receiving MQTT messages
* 📁 `set-data-points` - an example application showing how to set single and multiple data points
* 📁 `example_model` - a handwritten example model to be used by all examples
* 📁 `performance-subscribe` - an example application subscribing to signals and printing time and value when updates are received.
* 📁 `grpc_client` - an example application implementing a gRPC client, matching the example in [Velocitas documentation](https://eclipse.dev/velocitas/docs/tutorials/grpc_service_generation/create_client/).
* 📁 `grpc_server` - an example application implementing a gRPC server, matching the example in [Velocitas documentation](https://eclipse.dev/velocitas/docs/tutorials/grpc_service_generation/create_server/).
* 📁 `sdk`
* 📁 `include` - the headers which need to be included by users of the SDK
* 📁 `src` - contains the source code for the SDK from which the SDK library is built
Expand Down
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
#
# SPDX-License-Identifier: Apache-2.0

# Adding examples that contain header files but no CMakeLists.txt

include_directories(example_model)

# Adding examples that contain a CMakeLists.txt

add_subdirectory(performance-subscribe)
add_subdirectory(seat-adjuster)
add_subdirectory(set-data-points)
add_subdirectory(grpc_client)
add_subdirectory(grpc_server)
17 changes: 17 additions & 0 deletions examples/grpc_client/AppManifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"manifestVersion": "v3",
"name": "SampleApp",
"interfaces": [
{
"type": "grpc-interface",
"config": {
"src": "https://raw.githubusercontent.com/eclipse-kuksa/kuksa-incubation/0.4.0/seat_service/proto/sdv/edge/comfort/seats/v1/seats.proto",
"required": {
"methods": [
"Move", "CurrentPosition"
]
}
}
}
]
}
24 changes: 24 additions & 0 deletions examples/grpc_client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2022-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

include_directories(
${CMAKE_BINARY_DIR}/gens
${CONAN_INCLUDE_DIRS}
)

link_directories(
${CONAN_LIB_DIRS}
)

add_subdirectory(src)
3 changes: 3 additions & 0 deletions examples/grpc_client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# GRPC Client Example

Used for the [Client](https://eclipse.dev/velocitas/docs/tutorials/grpc_service_generation/create_client/) example.
23 changes: 23 additions & 0 deletions examples/grpc_client/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2022-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

set(TARGET_NAME "app")
erikbosch marked this conversation as resolved.
Show resolved Hide resolved

add_executable(${TARGET_NAME}
Launcher.cpp
)

target_link_libraries(${TARGET_NAME}
${CONAN_LIBS}
)
77 changes: 77 additions & 0 deletions examples/grpc_client/src/Launcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright (c) 2022-2024 Contributors to the Eclipse Foundation
erikbosch marked this conversation as resolved.
Show resolved Hide resolved
*
* 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
*/

#include <sdk/middleware/Middleware.h>
#include <services/seats/SeatsServiceClientFactory.h>
#include <services/seats/seats.grpc.pb.h>

#include <iostream>

using namespace velocitas;

int main(int argc, char** argv) {
// The default Velocitas Middleware class performs service discovery by
// environment variables.
// For this client it expects SDV_SEATS_ADDRESS to be defined
// for example:
// export SDV_SEATS_ADDRESS=grpc://127.0.0.1:5556

std::cout << "Starting " << std::endl;
auto serviceClient = SeatsServiceClientFactory::create(Middleware::getInstance());

::grpc::ClientContext context;
::sdv::edge::comfort::seats::v1::MoveRequest request;
::sdv::edge::comfort::seats::v1::MoveReply response;

::sdv::edge::comfort::seats::v1::Seat seat;

::sdv::edge::comfort::seats::v1::SeatLocation seat_location;
seat_location.set_row(1);
seat_location.set_index(1);

::sdv::edge::comfort::seats::v1::Position seat_position;

seat_position.set_base(75.0);

seat.set_allocated_location(&seat_location);
seat.set_allocated_position(&seat_position);

request.set_allocated_seat(&seat);

auto status = serviceClient->Move(&context, request, &response);

std::cout << "gRPC Server returned code: " << status.error_code() << std::endl;
std::cout << "gRPC error message: " << status.error_message().c_str() << std::endl;

if (status.error_code() != ::grpc::StatusCode::OK) {
// Some error
return 1;
} else {
::grpc::ClientContext context;
::sdv::edge::comfort::seats::v1::CurrentPositionRequest request;
::sdv::edge::comfort::seats::v1::CurrentPositionReply response;

request.set_row(1);
request.set_index(1);

auto status_curr_pos = serviceClient->CurrentPosition(&context, request, &response);
std::cout << "gRPC Server returned code: " << status_curr_pos.error_code() << std::endl;
std::cout << "gRPC error message: " << status_curr_pos.error_message().c_str() << std::endl;
if (status_curr_pos.ok())
std::cout << "current Position:" << response.seat().position().base() << std::endl;
return 0;
}
}
27 changes: 27 additions & 0 deletions examples/grpc_server/AppManifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"manifestVersion": "v3",
"name": "SampleApp",
"interfaces": [
{
"type": "grpc-interface",
"config": {
"src": "https://raw.githubusercontent.com/eclipse-kuksa/kuksa-incubation/0.4.0/seat_service/proto/sdv/edge/comfort/seats/v1/seats.proto",
"provided": { }
}
},
{
"type": "vehicle-signal-interface",
"config": {
"src": "https://github.com/COVESA/vehicle_signal_specification/releases/download/v4.0/vss_rel_4.0.json",
"datapoints": {
"required": [
{
"path": "Vehicle.Cabin.Seat.Row1.DriverSide.Position",
"access": "write"
}
]
}
}
}
]
}
24 changes: 24 additions & 0 deletions examples/grpc_server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2022-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

include_directories(
${CMAKE_BINARY_DIR}/gens
${CONAN_INCLUDE_DIRS}
)

link_directories(
${CONAN_LIB_DIRS}
)

add_subdirectory(src)
3 changes: 3 additions & 0 deletions examples/grpc_server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# GRPC Server Example

Used for the [Server](https://eclipse.dev/velocitas/docs/tutorials/grpc_service_generation/create_server/) example.
24 changes: 24 additions & 0 deletions examples/grpc_server/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2022-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

set(TARGET_NAME "app")

add_executable(${TARGET_NAME}
# SeatsServiceImpl.cpp - No need to include as included from header file
Launcher.cpp
)

target_link_libraries(${TARGET_NAME}
${CONAN_LIBS}
)
23 changes: 23 additions & 0 deletions examples/grpc_server/src/Launcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "SeatsServiceImpl.h"
#include <sdk/middleware/Middleware.h>
#include <services/seats/SeatsServiceServerFactory.h>

#include "vehicle/Vehicle.hpp"

#include <memory>

using namespace velocitas;

int main(int argc, char** argv) {
auto seatsImpl = std::make_shared<SeatsService>();

velocitas::VehicleModelContext::getInstance().setVdbc(
velocitas::IVehicleDataBrokerClient::createInstance("vehicledatabroker"));

auto seatServer = SeatsServiceServerFactory::create(Middleware::getInstance(), seatsImpl);

seatServer->Wait();

std::cout << "Waiting!" << std::endl;
return 0;
}
Loading
Loading