Skip to content

Commit

Permalink
Merge pull request #1 from johnwason/drekar
Browse files Browse the repository at this point in the history
Rename to drekar-launch-process-cpp
  • Loading branch information
johnwason authored Jun 17, 2023
2 parents eb36846 + c3be45d commit ef0847b
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 57 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI

on:
push:
pull_request:
release:
types:
- created
workflow_dispatch:

jobs:
ubuntu_test:
strategy:
matrix:
runs-on: [ubuntu-20.04, ubuntu-22.04]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v3
- name: apt
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake python3-pip python3-setuptools python3-wheel
- name: pip
run: |
python3 -m pip install --upgrade pip
python3 -m pip install --user git+https://github.com/johnwason/drekar-launch-process.git
python3 -m pip install --user git+https://github.com/johnwason/drekar-launch.git
- name: configure
run: |
mkdir build
cd build
cmake -DBUILD_TESTING=ON ..
- name: build
run: |
cd build
cmake --build .
- name: test
run: |
python3 -m drekar_launch --config=test/drekar-launch/drekar-launch.yaml
windows_test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: pip
run: |
python -m pip install --user git+https://github.com/johnwason/drekar-launch-process.git
python -m pip install --user git+https://github.com/johnwason/drekar-launch.git
- name: configure
run: |
mkdir build
cd build
cmake -G Ninja -DBUILD_TESTING=ON ..
- name: build
run: |
cd build
cmake --build .
- name: test
run: |
python -m drekar_launch --config=test/drekar-launch/drekar-launch.yaml
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ cmake_minimum_required(VERSION 3.3)

FILE (STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/package.xml" lib_version1 REGEX "<version>[0-9]+\\.[0-9]+\\.[0-9]+</version>")
IF ("${lib_version1}" STREQUAL "" )
MESSAGE(FATAL_ERROR "Could not read simple-laurch-process-cpp version.")
MESSAGE(FATAL_ERROR "Could not read drekar-launch-process-cpp version.")
ENDIF()
STRING (REGEX REPLACE "<version>([0-9]+\\.[0-9]+\\.[0-9]+)</version>" "\\1" lib_version2 ${lib_version1})
STRING (STRIP ${lib_version2} lib_version)
MESSAGE(STATUS "simple-laurch-process-cpp version: ${lib_version}")
MESSAGE(STATUS "drekar-launch-process-cpp version: ${lib_version}")

project(simple-launch-process-cpp VERSION ${lib_version} LANGUAGES CXX)
project(drekar-launch-process-cpp VERSION ${lib_version} LANGUAGES CXX)

set (CMAKE_CXX_STANDARD 11)

option(BUILD_SHARED_LIBS "Build shared libraries" ON)

if (WIN32)
add_definitions(-D_WIN32_WINNT=0x0601)
set(SRCS src/simple_launch_process_cpp_win32.cpp)
set(SRCS src/drekar_launch_process_cpp_win32.cpp)
else()
set(SRCS src/simple_launch_process_cpp_posix.cpp)
set(SRCS src/drekar_launch_process_cpp_posix.cpp)
endif()

add_library(${PROJECT_NAME} ${SRCS})
Expand Down Expand Up @@ -47,8 +47,8 @@ install(EXPORT ${PROJECT_NAME}-targets
DESTINATION "${CONFIG_EXPORT_DIR}")

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/simple-launch-process-cpp-config.cmake.in"
"${PROJECT_BINARY_DIR}/simple-launch-process-cpp-config.cmake"
"${PROJECT_SOURCE_DIR}/cmake/drekar-launch-process-cpp-config.cmake.in"
"${PROJECT_BINARY_DIR}/drekar-launch-process-cpp-config.cmake"
INSTALL_DESTINATION "${CONFIG_EXPORT_DIR}"
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR CONFIG_EXPORT_DIR BUILD_SHARED_LIBS)
unset(EXPORT_TARGETS)
Expand All @@ -66,9 +66,9 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-version.cmake
# include(CTest)
if (BUILD_TESTING)

add_executable(${PROJECT_NAME}_wait_exit_test test/test_simple_launch_process_cpp_wait_exit.cpp)
add_executable(${PROJECT_NAME}_wait_exit_test test/test_drekar_launch_process_cpp_wait_exit.cpp)
target_link_libraries(${PROJECT_NAME}_wait_exit_test ${PROJECT_NAME})

add_executable(${PROJECT_NAME}_callback_exit_test test/test_simple_launch_process_cpp_callback_exit.cpp)
add_executable(${PROJECT_NAME}_callback_exit_test test/test_drekar_launch_process_cpp_callback_exit.cpp)
target_link_libraries(${PROJECT_NAME}_callback_exit_test ${PROJECT_NAME})
endif()
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Simple Launch Process C++
# Drekar Launch Process C++

This library contains client utility functions for processes launched using `simple-launch`, although they may also be used without `simple-launch`. Currently this package provides a reliable way for processes to receive shutdown signals from a process manager or the user using `ctrl-c`. This package contains
C++ implementations, analogous to `simple-launch-process` for Python. See https://github.com/johnwason/simple-launch-process for more information.
This library contains client utility functions for processes launched using `drekar-launch`, although they may also be used without `drekar-launch`. Currently this package provides a reliable way for processes to receive shutdown signals from a process manager or the user using `ctrl-c`. This package contains
C++ implementations, analogous to `drekar-launch-process` for Python. See https://github.com/johnwason/drekar-launch-process for more information.

## Building

Use cmake to build the library.

```
git clone https://github.com/johnwason/simple-launch-process-process-cpp
git clone https://github.com/johnwason/drekar-launch-process-process-cpp
mkdir build
cd build
cmake ..
Expand All @@ -21,7 +21,7 @@ Alternatively build using vcpkg:
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
git clone https://github.com/robotraconteur/vcpkg-robotraconteur.git
vcpkg --overlay-ports=vcpkg-robotraconteur\ports install simple-launch-process-cpp:x64-windows
vcpkg --overlay-ports=vcpkg-robotraconteur\ports install drekar-launch-process-cpp:x64-windows
```

## Usage
Expand All @@ -33,12 +33,12 @@ trigger a callback when the exit signal is received.
Blocking example:

```cpp
#include "simple_launch_process_cpp/simple_launch_process_cpp.h"
#include "drekar_launch_process_cpp/drekar_launch_process_cpp.h"
#include <iostream>

int main()
{
simple_launch_process_cpp::CWaitForExit wait_for_exit;
drekar_launch_process_cpp::CWaitForExit wait_for_exit;
std::cout << "Press Ctrl+C to exit" << std::endl;
wait_for_exit.WaitForExit();
std::cout << "Exit" << std::endl;
Expand All @@ -49,7 +49,7 @@ int main()
Callback example:

```cpp
#include "simple_launch_process_cpp/simple_launch_process_cpp.h"
#include "drekar_launch_process_cpp/drekar_launch_process_cpp.h"
#include <iostream>
#include <condition_variable>
#include <functional>
Expand All @@ -67,7 +67,7 @@ void exit_callback()

int main()
{
simple_launch_process_cpp::CWaitForExit wait_for_exit;
drekar_launch_process_cpp::CWaitForExit wait_for_exit;
wait_for_exit.CallbackWaitForExit(exit_callback);
std::unique_lock<std::mutex> lock(cv_mutex);
std::cout << "Press Ctrl+C to exit" << std::endl;
Expand Down
22 changes: 22 additions & 0 deletions cmake/drekar-launch-process-cpp-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# - Config file for the drekar-launch-process-cpp package
# It defines the following variables
# DREKAR_LAUNCH_PROCESS_CPP_INCLUDE_DIR - include directory
# DREKAR_LAUNCH_PROCESS_CPP_LIBRARY_DIR - directory containing libraries
# DREKAR_LAUNCH_PROCESS_CPP_SHARED_LIBS_BUILT - whether we have built shared libraries or not
# DREKAR_LAUNCH_PROCESS_CPP_LIBRARIES - libraries to link against

@PACKAGE_INIT@

set_and_check(DREKAR_LAUNCH_PROCESS_CPP_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(DREKAR_LAUNCH_PROCESS_CPP_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")

# Are we building shared libraries?
set(DREKAR_LAUNCH_PROCESS_CPP_SHARED_LIBS_BUILT "@PACKAGE_BUILD_SHARED_LIBS@")

# Our library dependencies (contains definitions for IMPORTED targets)
include(${CMAKE_CURRENT_LIST_DIR}/drekar-launch-process-cpp-targets.cmake)

# These are IMPORTED targets created by drekar-launch-process-cpp-targets.cmake
set(DREKAR_LAUNCH_PROCESS_CPP_LIBRARIES "drekar-launch-process-cpp")

check_required_components(drekar-launch-process-cpp)
22 changes: 0 additions & 22 deletions cmake/simple-launch-process-cpp-config.cmake.in

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#ifndef SIMPLE_LAUNCH_PROCESS_CPP_H
#define SIMPLE_LAUNCH_PROCESS_CPP_H
#ifndef DREKAR_LAUNCH_PROCESS_CPP_H
#define DREKAR_LAUNCH_PROCESS_CPP_H

#pragma once

namespace simple_launch_process_cpp
namespace drekar_launch_process_cpp
{
namespace detail
{
Expand All @@ -22,4 +22,4 @@ namespace simple_launch_process_cpp
};
}

#endif // SIMPLE_LAUNCH_PROCESS_CPP_H
#endif // DREKAR_LAUNCH_PROCESS_CPP_H
6 changes: 3 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0"?>
<package format="2">
<name>simple_launch_process_cpp</name>
<name>drekar_launch_process_cpp</name>
<version>0.1.0</version>
<description>C++ client for the simple-launch orchestractor</description>
<description>C++ client for the drekar-launch orchestractor</description>

<maintainer email="[email protected]">John Wason</maintainer>

<license>Apache 2.0</license>

<url type="website">https://github.com/johnwason/simple-launch-process-cpp</url>
<url type="website">https://github.com/johnwason/drekar-launch-process-cpp</url>
<author email="[email protected]">John Wason</author>

<export>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <signal.h>
#include <assert.h>
#include "simple_launch_process_cpp/simple_launch_process_cpp.h"
#include "drekar_launch_process_cpp/drekar_launch_process_cpp.h"
#include <condition_variable>
#include <iostream>

namespace simple_launch_process_cpp
namespace drekar_launch_process_cpp
{
namespace detail
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <thread>
#include <assert.h>

#include "simple_launch_process_cpp/simple_launch_process_cpp.h"
// Create a class with a message only window and a simple message loop
#include "drekar_launch_process_cpp/drekar_launch_process_cpp.h"
// Create a class with a message only window and a drekar message loop

namespace simple_launch_process_cpp
namespace drekar_launch_process_cpp
{
namespace detail
{
Expand Down Expand Up @@ -180,7 +180,7 @@ bool CWaitForExit::CallbackWaitForExit(void (*exit_callback)())
void CWaitForExit::WaitForExit()
{
// Create the message window
if (!impl->Create("simple_launch_process", "simple_launch_process"))
if (!impl->Create("drekar_message_window", "drekar_hidden_window"))
{
std::cerr << "Failed to create message window" << std::endl;
return;
Expand Down
11 changes: 11 additions & 0 deletions test/drekar-launch/drekar-launch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: test_cpp_launch
tasks:
- name: wait_exit
program: ./build/drekar-launch-process-cpp_wait_exit_test
- name: callback_exit
program: ./build/drekar-launch-process-cpp_callback_exit_test
- name: sleep
program: sleep
args: ["5"]
quit-on-terminate: true

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "simple_launch_process_cpp/simple_launch_process_cpp.h"
#include "drekar_launch_process_cpp/drekar_launch_process_cpp.h"
#include <iostream>
#include <condition_variable>
#include <functional>
Expand All @@ -16,7 +16,7 @@ void exit_callback()

int main()
{
simple_launch_process_cpp::CWaitForExit wait_for_exit;
drekar_launch_process_cpp::CWaitForExit wait_for_exit;
wait_for_exit.CallbackWaitForExit(exit_callback);
std::unique_lock<std::mutex> lock(cv_mutex);
std::cout << "Press Ctrl+C to exit" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "simple_launch_process_cpp/simple_launch_process_cpp.h"
#include "drekar_launch_process_cpp/drekar_launch_process_cpp.h"
#include <iostream>

int main()
{
simple_launch_process_cpp::CWaitForExit wait_for_exit;
drekar_launch_process_cpp::CWaitForExit wait_for_exit;
std::cout << "Press Ctrl+C to exit" << std::endl;
wait_for_exit.WaitForExit();
std::cout << "Exit" << std::endl;
Expand Down

0 comments on commit ef0847b

Please sign in to comment.