initial virtual sensor with protobuf
This commit is contained in:
commit
cbee09be85
7 changed files with 326 additions and 0 deletions
sensor-query-cli
30
sensor-query-cli/main.cpp
Normal file
30
sensor-query-cli/main.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <grpc/grpc.h>
|
||||
#include <grpcpp/channel.h>
|
||||
#include <grpcpp/client_context.h>
|
||||
#include <grpcpp/create_channel.h>
|
||||
#include <grpcpp/security/credentials.h>
|
||||
|
||||
#include "sensor.pb.h"
|
||||
#include "sensor.grpc.pb.h"
|
||||
|
||||
int main() {
|
||||
auto channel = std::shared_ptr(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials()));
|
||||
auto stub = Sensor::NewStub(channel);
|
||||
|
||||
grpc::ClientContext context;
|
||||
|
||||
StatusRequest request;
|
||||
SensorStatus status;
|
||||
grpc::Status rpc_status = stub->get_status(&context, request, &status);
|
||||
|
||||
if( rpc_status.ok() ) {
|
||||
std::cout << "Sensor Status:" << std::endl;
|
||||
std::cout << status.DebugString() << std::endl;
|
||||
} else {
|
||||
std::cout << "get_status() failed" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
26
sensor-query-cli/meson.build
Normal file
26
sensor-query-cli/meson.build
Normal file
|
@ -0,0 +1,26 @@
|
|||
project('sensor-query-cli', 'cpp',
|
||||
default_options: ['cpp_std=c++20'])
|
||||
|
||||
protobuf_dep = dependency('protobuf')
|
||||
grpc_dep = dependency('grpc++', required: true)
|
||||
|
||||
proto_files = files('../sensor.proto')
|
||||
|
||||
protobuf_gen = custom_target(
|
||||
'generate_protobuf',
|
||||
input : proto_files,
|
||||
output : ['sensor.pb.cc', 'sensor.pb.h', 'sensor.grpc.pb.cc', 'sensor.grpc.pb.h'],
|
||||
command : [
|
||||
'protoc',
|
||||
'--proto_path=../../',
|
||||
'--cpp_out', '.',
|
||||
'--grpc_out', '.',
|
||||
'--plugin=protoc-gen-grpc=/usr/bin/grpc_cpp_plugin',
|
||||
'@INPUT@'
|
||||
],
|
||||
)
|
||||
|
||||
executable('sensor-query-cli',
|
||||
['main.cpp', protobuf_gen],
|
||||
dependencies: [protobuf_dep, grpc_dep]
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue