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
4 changes: 4 additions & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
set noparent

# When using Velocitas gRPC service generation the header file will include the *ServiceImpl.cpp file
# this gives by default an error so lets ignore that
filter=-build/include
MP91 marked this conversation as resolved.
Show resolved Hide resolved

filter=-build/include_order
filter=-build/header_guard
filter=-whitespace/indent
Expand Down
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.1|MIT|
## Workflows
| Dependency | Version | License |
|:-----------|:-------:|--------:|
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ The Vehicle App SDK for C++ allows to create `Vehicle Apps` from the [Velocitas
* 📁 `examples` - example vehicle apps showcasing the use of the SDK
* 📁 `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
* 📁 `example_model` - a handwritten example model used by some of the 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 Expand Up @@ -96,6 +99,25 @@ SampleApp::SampleApp()
1. [Develop your own Vehicle App](https://eclipse.dev/velocitas/docs/tutorials/vehicle_app_development/)

## Contribution

### Release Management

The SDK is installed into the Velocitas Development environment by the [Velocitas Package for DevContainer Setup](https://github.com/eclipse-velocitas/devenv-devcontainer-setup).
To release a new version re-run all GitHub actions manually and verify that they all pass.
Then create a new GitHub release and tag the commit used. No need to include any additional artifacts.

After creating the GitHub release, verify that the new release can be used by the [Vehicle App C++ Template](https://github.com/eclipse-velocitas/vehicle-app-cpp-template).
Update the [conanfile.txt](https://github.com/eclipse-velocitas/vehicle-app-cpp-template/blob/main/conanfile.txt) with the new version in the line

```cpp
vehicle-app-sdk/X.Y.Z
```

Then verify that the example application in the template can be successfully built.
After successful verification, consider creating a Pull Request in the [Vehicle App C++ Template repository](https://github.com/eclipse-velocitas/vehicle-app-cpp-template) tp update the SDK version.

### Resources

- [GitHub Issues](https://github.com/eclipse-velocitas/vehicle-app-cpp-sdk/issues)
- [Mailing List](https://accounts.eclipse.org/mailing-list/velocitas-dev)
- [Contribution](CONTRIBUTING.md)
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

include_directories(example_model)

# Currently only adding examples that can be tested without additional velocitas code generation

add_subdirectory(performance-subscribe)
add_subdirectory(seat-adjuster)
add_subdirectory(set-data-points)
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) 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) 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 "grpc_client")

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) 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 <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) 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) 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 "grpc_server")

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

target_link_libraries(${TARGET_NAME}
${CONAN_LIBS}
)
39 changes: 39 additions & 0 deletions examples/grpc_server/src/Launcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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
*/

#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