Skip to content

Commit

Permalink
clang-tidy fixes
Browse files Browse the repository at this point in the history
one new sample proto_dyn_snd
  • Loading branch information
rex-schilasky committed Feb 9, 2024
1 parent 9964636 commit 8106e65
Show file tree
Hide file tree
Showing 31 changed files with 330 additions and 127 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ endif()
# additional builds (adapt to your needs)
# ------------------------------------------------------------------------------------------------------------------------------------------------------------------
option(ECAL_CORE_BUILD_SAMPLES "Build the eCAL samples" ON)
option(ECAL_CORE_BUILD_SAMPLES_PROTOBUF "Build the eCAL samples using google protobuf message definition" OFF)
option(ECAL_CORE_BUILD_SAMPLES_PROTOBUF "Build the eCAL samples using google protobuf message definition" ON)
option(ECAL_CORE_BUILD_TESTS "Build the eCAL google tests" ON)
option(ECAL_CORE_BUILD_TESTS_PROTOBUF "Build the eCAL google tests using google protobuf message definition" OFF)
option(ECAL_CORE_BUILD_TESTS_PROTOBUF "Build the eCAL google tests using google protobuf message definition" ON)

# ------------------------------------------------------------------------------------------------------------------------------------------------------------------
# core internal feature configuration (adapt to your needs)
# ------------------------------------------------------------------------------------------------------------------------------------------------------------------
option(ECAL_CORE_CONFIG_INIFILE "Enables to configure eCAL via ecal.ini file" ON)
option(ECAL_CORE_COMMAND_LINE "Enables eCAL application cmd line interfaces" ON)
option(ECAL_CORE_REGISTRATION "Enables the eCAL registration layer" ON)
option(ECAL_CORE_MONITORING "Enables the eCAL monitoring functionality" OFF)
option(ECAL_CORE_MONITORING "Enables the eCAL monitoring functionality" ON)
option(ECAL_CORE_PUBLISHER "Enables the eCAL publisher functionality" ON)
option(ECAL_CORE_SUBSCRIBER "Enables the eCAL subscriber functionality" ON)
option(ECAL_CORE_SERVICE "Enables the eCAL server/client functionality" ON)
Expand All @@ -98,7 +98,7 @@ option(ECAL_CORE_REGISTRATION_SHM "Enables the eCAL regis
# core transport layer options (change with care)
# ------------------------------------------------------------------------------------------------------------------------------------------------------------------
option(ECAL_CORE_TRANSPORT_UDP "Enables the eCAL to transport payload via UDP multicast" ON)
option(ECAL_CORE_TRANSPORT_TCP "Enables the eCAL to transport payload via TCP" OFF)
option(ECAL_CORE_TRANSPORT_TCP "Enables the eCAL to transport payload via TCP" ON)
option(ECAL_CORE_TRANSPORT_SHM "Enables the eCAL to transport payload via local shared memory" ON)

# ------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ if(ECAL_CORE_SUBSCRIBER)
add_subdirectory(cpp/pubsub/protobuf/proto_dyn_json_rec)
if(ECAL_CORE_MONITORING)
add_subdirectory(cpp/pubsub/protobuf/proto_dyn_rec)
add_subdirectory(cpp/pubsub/protobuf/proto_dyn_snd)
endif()
endif()
endif()
Expand Down
49 changes: 49 additions & 0 deletions samples/cpp/pubsub/protobuf/proto_dyn_snd/CMakeLists.txt
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 samples/cpp/pubsub/protobuf/proto_dyn_snd/src/proto_dyn_snd.cpp
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);
}
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 samples/cpp/pubsub/protobuf/proto_dyn_snd/src/protobuf/house.proto
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;
}
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;
}
6 changes: 3 additions & 3 deletions src/core/include/ecal/ecal_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace eCAL
*
* @param service_name_ Unique service name.
**/
ECAL_API CServiceClient(const std::string& service_name_);
ECAL_API explicit CServiceClient(const std::string& service_name_);

/**
* @brief Destructor.
Expand All @@ -64,12 +64,12 @@ namespace eCAL
/**
* @brief CServiceClients are non-copyable
**/
ECAL_API CServiceClient(const CServiceClient&) = delete;
CServiceClient(const CServiceClient&) = delete;

/**
* @brief CServiceClients are non-copyable
**/
ECAL_API CServiceClient& operator=(const CServiceClient&) = delete;
CServiceClient& operator=(const CServiceClient&) = delete;

/**
* @brief Creates this object.
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/ecal/ecal_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace eCAL
*
* @param time_ns_ Time to sleep in ns.
**/
ECAL_API void SleepNS(const long long time_ns_);
ECAL_API void SleepNS(long long time_ns_);

/**
* @brief Sleep current thread.
Expand Down
12 changes: 6 additions & 6 deletions src/core/include/ecal/ecal_publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace eCAL
*
* @param topic_name_ Unique topic name.
**/
ECAL_API CPublisher(const std::string& topic_name_);
ECAL_API explicit CPublisher(const std::string& topic_name_);

/**
* @brief Destructor.
Expand All @@ -100,12 +100,12 @@ namespace eCAL
/**
* @brief CPublishers are non-copyable
**/
ECAL_API CPublisher(const CPublisher&) = delete;
CPublisher(const CPublisher&) = delete;

/**
* @brief CPublishers are non-copyable
**/
ECAL_API CPublisher& operator=(const CPublisher&) = delete;
CPublisher& operator=(const CPublisher&) = delete;

/**
* @brief CPublishers are move-enabled
Expand All @@ -125,7 +125,7 @@ namespace eCAL
*
* @return True if it succeeds, false if it fails.
**/
ECAL_API bool Create(const std::string& topic_name_, const SDataTypeInformation& topic_info_);
ECAL_API virtual bool Create(const std::string& topic_name_, const SDataTypeInformation& topic_info_);

/**
* @brief Creates this object.
Expand All @@ -134,14 +134,14 @@ namespace eCAL
*
* @return True if it succeeds, false if it fails.
**/
ECAL_API bool Create(const std::string& topic_name_);
ECAL_API virtual bool Create(const std::string& topic_name_);

/**
* @brief Destroys this object.
*
* @return True if it succeeds, false if it fails.
**/
ECAL_API bool Destroy();
ECAL_API virtual bool Destroy();

/**
* @brief Setup topic information.
Expand Down
6 changes: 3 additions & 3 deletions src/core/include/ecal/ecal_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace eCAL
*
* @param service_name_ Unique service name.
**/
ECAL_API CServiceServer(const std::string& service_name_);
ECAL_API explicit CServiceServer(const std::string& service_name_);

/**
* @brief Destructor.
Expand All @@ -63,12 +63,12 @@ namespace eCAL
/**
* @brief CServiceServers are non-copyable
**/
ECAL_API CServiceServer(const CServiceServer&) = delete;
CServiceServer(const CServiceServer&) = delete;

/**
* @brief CServiceServers are non-copyable
**/
ECAL_API CServiceServer& operator=(const CServiceServer&) = delete;
CServiceServer& operator=(const CServiceServer&) = delete;

/**
* @brief Creates this object.
Expand Down
Loading

0 comments on commit 8106e65

Please sign in to comment.