-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
31 changed files
with
330 additions
and
127 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,49 @@ | ||
# ========================= eCAL LICENSE ================================= | ||
# | ||
# Copyright (C) 2016 - 2019 Continental Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://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. | ||
# | ||
# ========================= eCAL LICENSE ================================= | ||
|
||
cmake_minimum_required(VERSION 3.10) | ||
|
||
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) | ||
|
||
project(proto_dyn_snd) | ||
|
||
find_package(eCAL REQUIRED) | ||
find_package(Protobuf REQUIRED) | ||
|
||
set(proto_dyn_snd_src | ||
src/proto_dyn_snd.cpp | ||
) | ||
|
||
set(proto_dyn_snd_proto | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/animal.proto | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/house.proto | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/person.proto | ||
) | ||
ecal_add_sample(${PROJECT_NAME} ${proto_dyn_snd_src}) | ||
PROTOBUF_TARGET_CPP(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf ${proto_dyn_snd_proto}) | ||
|
||
target_link_libraries(${PROJECT_NAME} | ||
eCAL::core | ||
protobuf::libprotobuf | ||
) | ||
|
||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) | ||
|
||
ecal_install_sample(${PROJECT_NAME}) | ||
|
||
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/pubsub/protobuf) |
99 changes: 99 additions & 0 deletions
99
samples/cpp/pubsub/protobuf/proto_dyn_snd/src/proto_dyn_snd.cpp
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,99 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2019 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://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. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
#include <ecal/ecal.h> | ||
#include <ecal/msg/protobuf/dynamic_publisher.h> | ||
|
||
#include <iostream> | ||
|
||
#include "person.pb.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
// initialize eCAL API | ||
eCAL::Initialize(argc, argv, "person publisher dynamic"); | ||
|
||
// set process state | ||
eCAL::Process::SetState(proc_sev_healthy, proc_sev_level1, "I feel good !"); | ||
|
||
// create a dynamic publisher (topic name "person") | ||
eCAL::protobuf::CDynamicPublisher pub1("person", std::make_shared<pb::People::Person>()); | ||
std::shared_ptr<pb::People::Person> person1 = pub1.GetAs<pb::People::Person>(); | ||
|
||
// create a dynamic publisher (topic name "person") | ||
eCAL::protobuf::CDynamicPublisher pub2("person", "pb.People.Person"); | ||
std::shared_ptr<pb::People::Person> person2 = pub2.GetAs<pb::People::Person>(); | ||
|
||
// set person1 object content | ||
person1->set_name("Max"); | ||
person1->set_stype(pb::People::Person_SType_MALE); | ||
person1->set_email("[email protected]"); | ||
person1->mutable_dog()->set_name("Brandy"); | ||
person1->mutable_house()->set_rooms(4); | ||
|
||
// set person2 object content | ||
person2->set_name("Romy"); | ||
person2->set_stype(pb::People::Person_SType_FEMALE); | ||
person2->set_email("[email protected]"); | ||
person2->mutable_dog()->set_name("Gorky"); | ||
person2->mutable_house()->set_rooms(4); | ||
|
||
// enter main loop | ||
auto cnt = 0; | ||
std::shared_ptr<pb::People::Person> person; | ||
|
||
while(eCAL::Ok()) | ||
{ | ||
if (++cnt % 2) | ||
{ | ||
// modify and send the person1 object | ||
person1->set_id(cnt); | ||
pub1.Send(); | ||
|
||
// for later printing | ||
person = person1; | ||
} | ||
else | ||
{ | ||
// modify and send the person2 object | ||
person2->set_id(cnt); | ||
pub2.Send(); | ||
|
||
// for later printing | ||
person = person2; | ||
} | ||
|
||
// print current person message | ||
std::cout << "person id : " << person->id() << std::endl; | ||
std::cout << "person name : " << person->name() << std::endl; | ||
std::cout << "person stype : " << person->stype() << std::endl; | ||
std::cout << "person email : " << person->email() << std::endl; | ||
std::cout << "dog.name : " << person->dog().name() << std::endl; | ||
std::cout << "house.rooms : " << person->house().rooms() << std::endl; | ||
std::cout << std::endl; | ||
|
||
// sleep 500 ms | ||
eCAL::Process::SleepMS(500); | ||
} | ||
|
||
// finalize eCAL API | ||
eCAL::Finalize(); | ||
|
||
return(0); | ||
} |
28 changes: 28 additions & 0 deletions
28
samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/animal.proto
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,28 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2019 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://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. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
package pb.Animal; | ||
|
||
message Dog | ||
{ | ||
string name = 1; | ||
string colour = 2; | ||
} |
27 changes: 27 additions & 0 deletions
27
samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/house.proto
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,27 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2019 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://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. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
package pb.Environment; | ||
|
||
message House | ||
{ | ||
int32 rooms = 1; | ||
} |
42 changes: 42 additions & 0 deletions
42
samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/person.proto
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,42 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2019 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://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. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
import "animal.proto"; | ||
import "house.proto"; | ||
|
||
package pb.People; | ||
|
||
message Person | ||
{ | ||
enum SType | ||
{ | ||
MALE = 0; | ||
FEMALE = 1; | ||
} | ||
|
||
int32 id = 1; | ||
string name = 2; | ||
SType stype = 3; | ||
string email = 4; | ||
|
||
Animal.Dog dog = 5; | ||
Environment.House house = 6; | ||
} |
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
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
Oops, something went wrong.