Skip to content

Commit

Permalink
samples aligned with eclipse-ecal
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Feb 3, 2024
1 parent c405edc commit ad3dcc4
Show file tree
Hide file tree
Showing 20 changed files with 888 additions and 13 deletions.
34 changes: 23 additions & 11 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ if(ECAL_CORE_PUBLISHER AND ECAL_CORE_SUBSCRIBER)
add_subdirectory(cpp/benchmarks/perftool)
endif()

# misc
add_subdirectory(cpp/misc/process)
add_subdirectory(cpp/misc/time)
add_subdirectory(cpp/misc/timer)

# monitoring
if(ECAL_CORE_MONITORING)
add_subdirectory(cpp/monitoring/monitoring_get_services)
add_subdirectory(cpp/monitoring/monitoring_get_topics)
add_subdirectory(cpp/monitoring/monitoring_performance)
if(ECAL_CORE_BUILD_SAMPLES_PROTOBUF)
add_subdirectory(cpp/monitoring/monitoring_rec)
add_subdirectory(cpp/monitoring/monitoring_reg)
endif()
endif()

# orchestration
if(ECAL_CORE_PUBLISHER AND ECAL_CORE_SUBSCRIBER AND ECAL_CORE_SERVICE AND ECAL_CORE_BUILD_SAMPLES_PROTOBUF)
add_subdirectory(cpp/orchestration/component1)
add_subdirectory(cpp/orchestration/component2)
add_subdirectory(cpp/orchestration/orchestrator)
endif()

# pubsub
if(ECAL_CORE_PUBLISHER)
add_subdirectory(cpp/pubsub/binary/binary_snd)
Expand Down Expand Up @@ -92,17 +115,6 @@ if(ECAL_CORE_PUBLISHER AND ECAL_CORE_SUBSCRIBER)
endif()
endif()

# monitoring
if(ECAL_CORE_MONITORING)
add_subdirectory(cpp/monitoring/monitoring_get_services)
add_subdirectory(cpp/monitoring/monitoring_get_topics)
add_subdirectory(cpp/monitoring/monitoring_performance)
if(ECAL_CORE_BUILD_SAMPLES_PROTOBUF)
add_subdirectory(cpp/monitoring/monitoring_rec)
add_subdirectory(cpp/monitoring/monitoring_reg)
endif()
endif()

# services
if(ECAL_CORE_SERVICE)
add_subdirectory(cpp/services/latency_client)
Expand Down
43 changes: 43 additions & 0 deletions samples/cpp/misc/process/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ========================= 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(process)

find_package(eCAL REQUIRED)

set(process_src
src/process.cpp
)

ecal_add_sample(${PROJECT_NAME} ${process_src})

target_include_directories(${PROJECT_NAME} PRIVATE .)

target_link_libraries (${PROJECT_NAME}
eCAL::core
)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

ecal_install_sample(${PROJECT_NAME})

set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/misc)
58 changes: 58 additions & 0 deletions samples/cpp/misc/process/src/process.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* ========================= 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>

#ifdef ECAL_OS_WINDOWS
const char* proc_name = "notepad.exe";
#else // ECAL_OS_WINDOWS
const char* proc_name = "gedit";
#endif // ECAL_OS_WINDOWS

int main(int argc, char **argv)
{
// initialize eCAL API
eCAL::Initialize(argc, argv, "process", eCAL::Init::None);

// start process
eCAL::Process::StartProcess(proc_name, "", "", false, proc_smode_normal, false);

// sleep 2 seconds
eCAL::Process::SleepMS(2000);

// stop process
eCAL::Process::StopProcess(proc_name);

// sleep 2 seconds
eCAL::Process::SleepMS(2000);

// start process
int pid = eCAL::Process::StartProcess(proc_name, "", "", false, proc_smode_normal, false);

// sleep 2 seconds
eCAL::Process::SleepMS(2000);

// stop notepad
eCAL::Process::StopProcess(pid);

// finalize eCAL API
eCAL::Finalize();

return(0);
}
39 changes: 39 additions & 0 deletions samples/cpp/misc/time/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ========================= 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(time)

find_package(eCAL REQUIRED)

set(time_src
src/time.cpp
)

ecal_add_sample(${PROJECT_NAME} ${time_src})

target_link_libraries(${PROJECT_NAME} eCAL::core)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

ecal_install_sample(${PROJECT_NAME})

set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/misc)
46 changes: 46 additions & 0 deletions samples/cpp/misc/time/src/time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* ========================= 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 <iostream>
#include <chrono>

int main(int argc, char **argv)
{
// initialize eCAL API
eCAL::Initialize(argc, argv, "timer");

std::cout << "eCAL Time Interface : " << eCAL::Time::GetName() << std::endl;
std::cout << "eCAL Time is Synchronized : " << eCAL::Time::IsSynchronized() << std::endl;
std::cout << "eCAL Time is Master : " << eCAL::Time::IsMaster() << std::endl;
std::cout << std::endl;
eCAL::Process::SleepMS(3000);

while(eCAL::Ok())
{
auto now = eCAL::Time::ecal_clock::now();
std::cout << "eCAL Time " << std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count() << " ms" << std::endl;
eCAL::Process::SleepMS(100);
}

// finalize eCAL API
eCAL::Finalize();

return(0);
}
39 changes: 39 additions & 0 deletions samples/cpp/misc/timer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ========================= 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(timer)

find_package(eCAL REQUIRED)

set(timer_src
src/timer.cpp
)

ecal_add_sample(${PROJECT_NAME} ${timer_src})

target_link_libraries(${PROJECT_NAME} eCAL::core)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

ecal_install_sample(${PROJECT_NAME})

set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/misc)
56 changes: 56 additions & 0 deletions samples/cpp/misc/timer/src/timer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* ========================= 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/string/publisher.h>

#include <iostream>
#include <functional>

const int timout_ms = 10;

int main(int argc, char **argv)
{
// initialize eCAL API
eCAL::Initialize(argc, argv, "person publisher");
// set process state
eCAL::Process::SetState(proc_sev_healthy, proc_sev_level1, "I feel good !");

eCAL::string::CPublisher<std::string> pub("hello");
eCAL::CTimer timer;

timer.Start(timout_ms, [&pub](){
pub.Send("Hello world");
std::cout << "Sent: Hello world" << std::endl;
});

// enter main loop
while(eCAL::Ok())
{
// sleep 500 ms
eCAL::Process::SleepMS(500);
}

timer.Stop();
// finalize eCAL API
eCAL::Finalize();

return(0);
}

48 changes: 48 additions & 0 deletions samples/cpp/orchestration/component1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2022 Eclipse Foundation
#
# 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(component1)

find_package(eCAL REQUIRED)
find_package(Protobuf REQUIRED)

set(component1_src
src/component1.cpp
)

set(component1_proto
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/component.proto
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/orchestrator.proto
)
ecal_add_sample(${PROJECT_NAME} ${component1_src})
PROTOBUF_TARGET_CPP(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf ${component1_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/orchestration)
Loading

0 comments on commit ad3dcc4

Please sign in to comment.